1 /* bnx2x_sp.c: Broadcom Everest network driver.
3 * Copyright 2011 Broadcom Corporation
5 * Unless you and Broadcom execute a separate written software license
6 * agreement governing use of this software, this software is licensed to you
7 * under the terms of the GNU General Public License version 2, available
8 * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
10 * Notwithstanding the above, under no circumstances may you combine this
11 * software in any way with any other Broadcom software provided under a
12 * license other than the GPL, without Broadcom's express prior written
15 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
16 * Written by: Vladislav Zolotarov
20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 #include <linux/module.h>
23 #include <linux/crc32.h>
24 #include <linux/netdevice.h>
25 #include <linux/etherdevice.h>
26 #include <linux/crc32c.h>
28 #include "bnx2x_cmn.h"
31 #define BNX2X_MAX_EMUL_MULTI 16
33 #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
35 /**** Exe Queue interfaces ****/
38 * bnx2x_exe_queue_init - init the Exe Queue object
40 * @o: poiter to the object
42 * @owner: poiter to the owner
43 * @validate: validate function pointer
44 * @optimize: optimize function pointer
45 * @exec: execute function pointer
46 * @get: get function pointer
48 static inline void bnx2x_exe_queue_init(struct bnx2x
*bp
,
49 struct bnx2x_exe_queue_obj
*o
,
51 union bnx2x_qable_obj
*owner
,
52 exe_q_validate validate
,
54 exe_q_optimize optimize
,
58 memset(o
, 0, sizeof(*o
));
60 INIT_LIST_HEAD(&o
->exe_queue
);
61 INIT_LIST_HEAD(&o
->pending_comp
);
63 spin_lock_init(&o
->lock
);
65 o
->exe_chunk_len
= exe_len
;
68 /* Owner specific callbacks */
69 o
->validate
= validate
;
71 o
->optimize
= optimize
;
75 DP(BNX2X_MSG_SP
, "Setup the execution queue with the chunk "
76 "length of %d\n", exe_len
);
79 static inline void bnx2x_exe_queue_free_elem(struct bnx2x
*bp
,
80 struct bnx2x_exeq_elem
*elem
)
82 DP(BNX2X_MSG_SP
, "Deleting an exe_queue element\n");
86 static inline int bnx2x_exe_queue_length(struct bnx2x_exe_queue_obj
*o
)
88 struct bnx2x_exeq_elem
*elem
;
91 spin_lock_bh(&o
->lock
);
93 list_for_each_entry(elem
, &o
->exe_queue
, link
)
96 spin_unlock_bh(&o
->lock
);
102 * bnx2x_exe_queue_add - add a new element to the execution queue
106 * @cmd: new command to add
107 * @restore: true - do not optimize the command
109 * If the element is optimized or is illegal, frees it.
111 static inline int bnx2x_exe_queue_add(struct bnx2x
*bp
,
112 struct bnx2x_exe_queue_obj
*o
,
113 struct bnx2x_exeq_elem
*elem
,
118 spin_lock_bh(&o
->lock
);
121 /* Try to cancel this element queue */
122 rc
= o
->optimize(bp
, o
->owner
, elem
);
126 /* Check if this request is ok */
127 rc
= o
->validate(bp
, o
->owner
, elem
);
129 BNX2X_ERR("Preamble failed: %d\n", rc
);
134 /* If so, add it to the execution queue */
135 list_add_tail(&elem
->link
, &o
->exe_queue
);
137 spin_unlock_bh(&o
->lock
);
142 bnx2x_exe_queue_free_elem(bp
, elem
);
144 spin_unlock_bh(&o
->lock
);
150 static inline void __bnx2x_exe_queue_reset_pending(
152 struct bnx2x_exe_queue_obj
*o
)
154 struct bnx2x_exeq_elem
*elem
;
156 while (!list_empty(&o
->pending_comp
)) {
157 elem
= list_first_entry(&o
->pending_comp
,
158 struct bnx2x_exeq_elem
, link
);
160 list_del(&elem
->link
);
161 bnx2x_exe_queue_free_elem(bp
, elem
);
165 static inline void bnx2x_exe_queue_reset_pending(struct bnx2x
*bp
,
166 struct bnx2x_exe_queue_obj
*o
)
169 spin_lock_bh(&o
->lock
);
171 __bnx2x_exe_queue_reset_pending(bp
, o
);
173 spin_unlock_bh(&o
->lock
);
178 * bnx2x_exe_queue_step - execute one execution chunk atomically
182 * @ramrod_flags: flags
184 * (Atomicy is ensured using the exe_queue->lock).
186 static inline int bnx2x_exe_queue_step(struct bnx2x
*bp
,
187 struct bnx2x_exe_queue_obj
*o
,
188 unsigned long *ramrod_flags
)
190 struct bnx2x_exeq_elem
*elem
, spacer
;
193 memset(&spacer
, 0, sizeof(spacer
));
195 spin_lock_bh(&o
->lock
);
198 * Next step should not be performed until the current is finished,
199 * unless a DRV_CLEAR_ONLY bit is set. In this case we just want to
200 * properly clear object internals without sending any command to the FW
201 * which also implies there won't be any completion to clear the
204 if (!list_empty(&o
->pending_comp
)) {
205 if (test_bit(RAMROD_DRV_CLR_ONLY
, ramrod_flags
)) {
206 DP(BNX2X_MSG_SP
, "RAMROD_DRV_CLR_ONLY requested: "
207 "resetting pending_comp\n");
208 __bnx2x_exe_queue_reset_pending(bp
, o
);
210 spin_unlock_bh(&o
->lock
);
216 * Run through the pending commands list and create a next
219 while (!list_empty(&o
->exe_queue
)) {
220 elem
= list_first_entry(&o
->exe_queue
, struct bnx2x_exeq_elem
,
222 WARN_ON(!elem
->cmd_len
);
224 if (cur_len
+ elem
->cmd_len
<= o
->exe_chunk_len
) {
225 cur_len
+= elem
->cmd_len
;
227 * Prevent from both lists being empty when moving an
228 * element. This will allow the call of
229 * bnx2x_exe_queue_empty() without locking.
231 list_add_tail(&spacer
.link
, &o
->pending_comp
);
233 list_del(&elem
->link
);
234 list_add_tail(&elem
->link
, &o
->pending_comp
);
235 list_del(&spacer
.link
);
242 spin_unlock_bh(&o
->lock
);
246 rc
= o
->execute(bp
, o
->owner
, &o
->pending_comp
, ramrod_flags
);
249 * In case of an error return the commands back to the queue
250 * and reset the pending_comp.
252 list_splice_init(&o
->pending_comp
, &o
->exe_queue
);
255 * If zero is returned, means there are no outstanding pending
256 * completions and we may dismiss the pending list.
258 __bnx2x_exe_queue_reset_pending(bp
, o
);
260 spin_unlock_bh(&o
->lock
);
264 static inline bool bnx2x_exe_queue_empty(struct bnx2x_exe_queue_obj
*o
)
266 bool empty
= list_empty(&o
->exe_queue
);
268 /* Don't reorder!!! */
271 return empty
&& list_empty(&o
->pending_comp
);
274 static inline struct bnx2x_exeq_elem
*bnx2x_exe_queue_alloc_elem(
277 DP(BNX2X_MSG_SP
, "Allocating a new exe_queue element\n");
278 return kzalloc(sizeof(struct bnx2x_exeq_elem
), GFP_ATOMIC
);
281 /************************ raw_obj functions ***********************************/
282 static bool bnx2x_raw_check_pending(struct bnx2x_raw_obj
*o
)
284 return !!test_bit(o
->state
, o
->pstate
);
287 static void bnx2x_raw_clear_pending(struct bnx2x_raw_obj
*o
)
289 smp_mb__before_clear_bit();
290 clear_bit(o
->state
, o
->pstate
);
291 smp_mb__after_clear_bit();
294 static void bnx2x_raw_set_pending(struct bnx2x_raw_obj
*o
)
296 smp_mb__before_clear_bit();
297 set_bit(o
->state
, o
->pstate
);
298 smp_mb__after_clear_bit();
302 * bnx2x_state_wait - wait until the given bit(state) is cleared
305 * @state: state which is to be cleared
306 * @state_p: state buffer
309 static inline int bnx2x_state_wait(struct bnx2x
*bp
, int state
,
310 unsigned long *pstate
)
312 /* can take a while if any port is running */
316 if (CHIP_REV_IS_EMUL(bp
))
319 DP(BNX2X_MSG_SP
, "waiting for state to become %d\n", state
);
323 if (!test_bit(state
, pstate
)) {
324 #ifdef BNX2X_STOP_ON_ERROR
325 DP(BNX2X_MSG_SP
, "exit (cnt %d)\n", 5000 - cnt
);
330 usleep_range(1000, 1000);
337 BNX2X_ERR("timeout waiting for state %d\n", state
);
338 #ifdef BNX2X_STOP_ON_ERROR
345 static int bnx2x_raw_wait(struct bnx2x
*bp
, struct bnx2x_raw_obj
*raw
)
347 return bnx2x_state_wait(bp
, raw
->state
, raw
->pstate
);
350 /***************** Classification verbs: Set/Del MAC/VLAN/VLAN-MAC ************/
351 /* credit handling callbacks */
352 static bool bnx2x_get_cam_offset_mac(struct bnx2x_vlan_mac_obj
*o
, int *offset
)
354 struct bnx2x_credit_pool_obj
*mp
= o
->macs_pool
;
358 return mp
->get_entry(mp
, offset
);
361 static bool bnx2x_get_credit_mac(struct bnx2x_vlan_mac_obj
*o
)
363 struct bnx2x_credit_pool_obj
*mp
= o
->macs_pool
;
367 return mp
->get(mp
, 1);
370 static bool bnx2x_get_cam_offset_vlan(struct bnx2x_vlan_mac_obj
*o
, int *offset
)
372 struct bnx2x_credit_pool_obj
*vp
= o
->vlans_pool
;
376 return vp
->get_entry(vp
, offset
);
379 static bool bnx2x_get_credit_vlan(struct bnx2x_vlan_mac_obj
*o
)
381 struct bnx2x_credit_pool_obj
*vp
= o
->vlans_pool
;
385 return vp
->get(vp
, 1);
388 static bool bnx2x_get_credit_vlan_mac(struct bnx2x_vlan_mac_obj
*o
)
390 struct bnx2x_credit_pool_obj
*mp
= o
->macs_pool
;
391 struct bnx2x_credit_pool_obj
*vp
= o
->vlans_pool
;
396 if (!vp
->get(vp
, 1)) {
404 static bool bnx2x_put_cam_offset_mac(struct bnx2x_vlan_mac_obj
*o
, int offset
)
406 struct bnx2x_credit_pool_obj
*mp
= o
->macs_pool
;
408 return mp
->put_entry(mp
, offset
);
411 static bool bnx2x_put_credit_mac(struct bnx2x_vlan_mac_obj
*o
)
413 struct bnx2x_credit_pool_obj
*mp
= o
->macs_pool
;
415 return mp
->put(mp
, 1);
418 static bool bnx2x_put_cam_offset_vlan(struct bnx2x_vlan_mac_obj
*o
, int offset
)
420 struct bnx2x_credit_pool_obj
*vp
= o
->vlans_pool
;
422 return vp
->put_entry(vp
, offset
);
425 static bool bnx2x_put_credit_vlan(struct bnx2x_vlan_mac_obj
*o
)
427 struct bnx2x_credit_pool_obj
*vp
= o
->vlans_pool
;
429 return vp
->put(vp
, 1);
432 static bool bnx2x_put_credit_vlan_mac(struct bnx2x_vlan_mac_obj
*o
)
434 struct bnx2x_credit_pool_obj
*mp
= o
->macs_pool
;
435 struct bnx2x_credit_pool_obj
*vp
= o
->vlans_pool
;
440 if (!vp
->put(vp
, 1)) {
448 static int bnx2x_get_n_elements(struct bnx2x
*bp
, struct bnx2x_vlan_mac_obj
*o
,
451 struct bnx2x_vlan_mac_registry_elem
*pos
;
456 list_for_each_entry(pos
, &o
->head
, link
) {
458 /* place leading zeroes in buffer */
459 memset(next
, 0, MAC_LEADING_ZERO_CNT
);
461 /* place mac after leading zeroes*/
462 memcpy(next
+ MAC_LEADING_ZERO_CNT
, pos
->u
.mac
.mac
,
465 /* calculate address of next element and
469 next
= buf
+ counter
* ALIGN(ETH_ALEN
, sizeof(u32
));
471 DP(BNX2X_MSG_SP
, "copied element number %d to address %p element was %pM\n",
472 counter
, next
, pos
->u
.mac
.mac
);
475 return counter
* ETH_ALEN
;
478 /* check_add() callbacks */
479 static int bnx2x_check_mac_add(struct bnx2x_vlan_mac_obj
*o
,
480 union bnx2x_classification_ramrod_data
*data
)
482 struct bnx2x_vlan_mac_registry_elem
*pos
;
484 if (!is_valid_ether_addr(data
->mac
.mac
))
487 /* Check if a requested MAC already exists */
488 list_for_each_entry(pos
, &o
->head
, link
)
489 if (!memcmp(data
->mac
.mac
, pos
->u
.mac
.mac
, ETH_ALEN
))
495 static int bnx2x_check_vlan_add(struct bnx2x_vlan_mac_obj
*o
,
496 union bnx2x_classification_ramrod_data
*data
)
498 struct bnx2x_vlan_mac_registry_elem
*pos
;
500 list_for_each_entry(pos
, &o
->head
, link
)
501 if (data
->vlan
.vlan
== pos
->u
.vlan
.vlan
)
507 static int bnx2x_check_vlan_mac_add(struct bnx2x_vlan_mac_obj
*o
,
508 union bnx2x_classification_ramrod_data
*data
)
510 struct bnx2x_vlan_mac_registry_elem
*pos
;
512 list_for_each_entry(pos
, &o
->head
, link
)
513 if ((data
->vlan_mac
.vlan
== pos
->u
.vlan_mac
.vlan
) &&
514 (!memcmp(data
->vlan_mac
.mac
, pos
->u
.vlan_mac
.mac
,
522 /* check_del() callbacks */
523 static struct bnx2x_vlan_mac_registry_elem
*
524 bnx2x_check_mac_del(struct bnx2x_vlan_mac_obj
*o
,
525 union bnx2x_classification_ramrod_data
*data
)
527 struct bnx2x_vlan_mac_registry_elem
*pos
;
529 list_for_each_entry(pos
, &o
->head
, link
)
530 if (!memcmp(data
->mac
.mac
, pos
->u
.mac
.mac
, ETH_ALEN
))
536 static struct bnx2x_vlan_mac_registry_elem
*
537 bnx2x_check_vlan_del(struct bnx2x_vlan_mac_obj
*o
,
538 union bnx2x_classification_ramrod_data
*data
)
540 struct bnx2x_vlan_mac_registry_elem
*pos
;
542 list_for_each_entry(pos
, &o
->head
, link
)
543 if (data
->vlan
.vlan
== pos
->u
.vlan
.vlan
)
549 static struct bnx2x_vlan_mac_registry_elem
*
550 bnx2x_check_vlan_mac_del(struct bnx2x_vlan_mac_obj
*o
,
551 union bnx2x_classification_ramrod_data
*data
)
553 struct bnx2x_vlan_mac_registry_elem
*pos
;
555 list_for_each_entry(pos
, &o
->head
, link
)
556 if ((data
->vlan_mac
.vlan
== pos
->u
.vlan_mac
.vlan
) &&
557 (!memcmp(data
->vlan_mac
.mac
, pos
->u
.vlan_mac
.mac
,
564 /* check_move() callback */
565 static bool bnx2x_check_move(struct bnx2x_vlan_mac_obj
*src_o
,
566 struct bnx2x_vlan_mac_obj
*dst_o
,
567 union bnx2x_classification_ramrod_data
*data
)
569 struct bnx2x_vlan_mac_registry_elem
*pos
;
572 /* Check if we can delete the requested configuration from the first
575 pos
= src_o
->check_del(src_o
, data
);
577 /* check if configuration can be added */
578 rc
= dst_o
->check_add(dst_o
, data
);
580 /* If this classification can not be added (is already set)
581 * or can't be deleted - return an error.
589 static bool bnx2x_check_move_always_err(
590 struct bnx2x_vlan_mac_obj
*src_o
,
591 struct bnx2x_vlan_mac_obj
*dst_o
,
592 union bnx2x_classification_ramrod_data
*data
)
598 static inline u8
bnx2x_vlan_mac_get_rx_tx_flag(struct bnx2x_vlan_mac_obj
*o
)
600 struct bnx2x_raw_obj
*raw
= &o
->raw
;
603 if ((raw
->obj_type
== BNX2X_OBJ_TYPE_TX
) ||
604 (raw
->obj_type
== BNX2X_OBJ_TYPE_RX_TX
))
605 rx_tx_flag
|= ETH_CLASSIFY_CMD_HEADER_TX_CMD
;
607 if ((raw
->obj_type
== BNX2X_OBJ_TYPE_RX
) ||
608 (raw
->obj_type
== BNX2X_OBJ_TYPE_RX_TX
))
609 rx_tx_flag
|= ETH_CLASSIFY_CMD_HEADER_RX_CMD
;
614 /* LLH CAM line allocations */
616 LLH_CAM_ISCSI_ETH_LINE
= 0,
618 LLH_CAM_MAX_PF_LINE
= NIG_REG_LLH1_FUNC_MEM_SIZE
/ 2
621 static inline void bnx2x_set_mac_in_nig(struct bnx2x
*bp
,
622 bool add
, unsigned char *dev_addr
, int index
)
625 u32 reg_offset
= BP_PORT(bp
) ? NIG_REG_LLH1_FUNC_MEM
:
626 NIG_REG_LLH0_FUNC_MEM
;
628 if (!IS_MF_SI(bp
) || index
> LLH_CAM_MAX_PF_LINE
)
631 DP(BNX2X_MSG_SP
, "Going to %s LLH configuration at entry %d\n",
632 (add
? "ADD" : "DELETE"), index
);
635 /* LLH_FUNC_MEM is a u64 WB register */
636 reg_offset
+= 8*index
;
638 wb_data
[0] = ((dev_addr
[2] << 24) | (dev_addr
[3] << 16) |
639 (dev_addr
[4] << 8) | dev_addr
[5]);
640 wb_data
[1] = ((dev_addr
[0] << 8) | dev_addr
[1]);
642 REG_WR_DMAE(bp
, reg_offset
, wb_data
, 2);
645 REG_WR(bp
, (BP_PORT(bp
) ? NIG_REG_LLH1_FUNC_MEM_ENABLE
:
646 NIG_REG_LLH0_FUNC_MEM_ENABLE
) + 4*index
, add
);
650 * bnx2x_vlan_mac_set_cmd_hdr_e2 - set a header in a single classify ramrod
653 * @o: queue for which we want to configure this rule
654 * @add: if true the command is an ADD command, DEL otherwise
655 * @opcode: CLASSIFY_RULE_OPCODE_XXX
656 * @hdr: pointer to a header to setup
659 static inline void bnx2x_vlan_mac_set_cmd_hdr_e2(struct bnx2x
*bp
,
660 struct bnx2x_vlan_mac_obj
*o
, bool add
, int opcode
,
661 struct eth_classify_cmd_header
*hdr
)
663 struct bnx2x_raw_obj
*raw
= &o
->raw
;
665 hdr
->client_id
= raw
->cl_id
;
666 hdr
->func_id
= raw
->func_id
;
668 /* Rx or/and Tx (internal switching) configuration ? */
669 hdr
->cmd_general_data
|=
670 bnx2x_vlan_mac_get_rx_tx_flag(o
);
673 hdr
->cmd_general_data
|= ETH_CLASSIFY_CMD_HEADER_IS_ADD
;
675 hdr
->cmd_general_data
|=
676 (opcode
<< ETH_CLASSIFY_CMD_HEADER_OPCODE_SHIFT
);
680 * bnx2x_vlan_mac_set_rdata_hdr_e2 - set the classify ramrod data header
682 * @cid: connection id
683 * @type: BNX2X_FILTER_XXX_PENDING
684 * @hdr: poiter to header to setup
687 * currently we always configure one rule and echo field to contain a CID and an
690 static inline void bnx2x_vlan_mac_set_rdata_hdr_e2(u32 cid
, int type
,
691 struct eth_classify_header
*hdr
, int rule_cnt
)
693 hdr
->echo
= (cid
& BNX2X_SWCID_MASK
) | (type
<< BNX2X_SWCID_SHIFT
);
694 hdr
->rule_cnt
= (u8
)rule_cnt
;
698 /* hw_config() callbacks */
699 static void bnx2x_set_one_mac_e2(struct bnx2x
*bp
,
700 struct bnx2x_vlan_mac_obj
*o
,
701 struct bnx2x_exeq_elem
*elem
, int rule_idx
,
704 struct bnx2x_raw_obj
*raw
= &o
->raw
;
705 struct eth_classify_rules_ramrod_data
*data
=
706 (struct eth_classify_rules_ramrod_data
*)(raw
->rdata
);
707 int rule_cnt
= rule_idx
+ 1, cmd
= elem
->cmd_data
.vlan_mac
.cmd
;
708 union eth_classify_rule_cmd
*rule_entry
= &data
->rules
[rule_idx
];
709 bool add
= (cmd
== BNX2X_VLAN_MAC_ADD
) ? true : false;
710 unsigned long *vlan_mac_flags
= &elem
->cmd_data
.vlan_mac
.vlan_mac_flags
;
711 u8
*mac
= elem
->cmd_data
.vlan_mac
.u
.mac
.mac
;
714 * Set LLH CAM entry: currently only iSCSI and ETH macs are
715 * relevant. In addition, current implementation is tuned for a
718 * When multiple unicast ETH MACs PF configuration in switch
719 * independent mode is required (NetQ, multiple netdev MACs,
720 * etc.), consider better utilisation of 8 per function MAC
721 * entries in the LLH register. There is also
722 * NIG_REG_P[01]_LLH_FUNC_MEM2 registers that complete the
723 * total number of CAM entries to 16.
725 * Currently we won't configure NIG for MACs other than a primary ETH
726 * MAC and iSCSI L2 MAC.
728 * If this MAC is moving from one Queue to another, no need to change
731 if (cmd
!= BNX2X_VLAN_MAC_MOVE
) {
732 if (test_bit(BNX2X_ISCSI_ETH_MAC
, vlan_mac_flags
))
733 bnx2x_set_mac_in_nig(bp
, add
, mac
,
734 LLH_CAM_ISCSI_ETH_LINE
);
735 else if (test_bit(BNX2X_ETH_MAC
, vlan_mac_flags
))
736 bnx2x_set_mac_in_nig(bp
, add
, mac
, LLH_CAM_ETH_LINE
);
739 /* Reset the ramrod data buffer for the first rule */
741 memset(data
, 0, sizeof(*data
));
743 /* Setup a command header */
744 bnx2x_vlan_mac_set_cmd_hdr_e2(bp
, o
, add
, CLASSIFY_RULE_OPCODE_MAC
,
745 &rule_entry
->mac
.header
);
747 DP(BNX2X_MSG_SP
, "About to %s MAC %pM for Queue %d\n",
748 add
? "add" : "delete", mac
, raw
->cl_id
);
750 /* Set a MAC itself */
751 bnx2x_set_fw_mac_addr(&rule_entry
->mac
.mac_msb
,
752 &rule_entry
->mac
.mac_mid
,
753 &rule_entry
->mac
.mac_lsb
, mac
);
755 /* MOVE: Add a rule that will add this MAC to the target Queue */
756 if (cmd
== BNX2X_VLAN_MAC_MOVE
) {
760 /* Setup ramrod data */
761 bnx2x_vlan_mac_set_cmd_hdr_e2(bp
,
762 elem
->cmd_data
.vlan_mac
.target_obj
,
763 true, CLASSIFY_RULE_OPCODE_MAC
,
764 &rule_entry
->mac
.header
);
766 /* Set a MAC itself */
767 bnx2x_set_fw_mac_addr(&rule_entry
->mac
.mac_msb
,
768 &rule_entry
->mac
.mac_mid
,
769 &rule_entry
->mac
.mac_lsb
, mac
);
772 /* Set the ramrod data header */
773 /* TODO: take this to the higher level in order to prevent multiple
775 bnx2x_vlan_mac_set_rdata_hdr_e2(raw
->cid
, raw
->state
, &data
->header
,
780 * bnx2x_vlan_mac_set_rdata_hdr_e1x - set a header in a single classify ramrod
785 * @cam_offset: offset in cam memory
786 * @hdr: pointer to a header to setup
790 static inline void bnx2x_vlan_mac_set_rdata_hdr_e1x(struct bnx2x
*bp
,
791 struct bnx2x_vlan_mac_obj
*o
, int type
, int cam_offset
,
792 struct mac_configuration_hdr
*hdr
)
794 struct bnx2x_raw_obj
*r
= &o
->raw
;
797 hdr
->offset
= (u8
)cam_offset
;
798 hdr
->client_id
= 0xff;
799 hdr
->echo
= ((r
->cid
& BNX2X_SWCID_MASK
) | (type
<< BNX2X_SWCID_SHIFT
));
802 static inline void bnx2x_vlan_mac_set_cfg_entry_e1x(struct bnx2x
*bp
,
803 struct bnx2x_vlan_mac_obj
*o
, bool add
, int opcode
, u8
*mac
,
804 u16 vlan_id
, struct mac_configuration_entry
*cfg_entry
)
806 struct bnx2x_raw_obj
*r
= &o
->raw
;
807 u32 cl_bit_vec
= (1 << r
->cl_id
);
809 cfg_entry
->clients_bit_vector
= cpu_to_le32(cl_bit_vec
);
810 cfg_entry
->pf_id
= r
->func_id
;
811 cfg_entry
->vlan_id
= cpu_to_le16(vlan_id
);
814 SET_FLAG(cfg_entry
->flags
, MAC_CONFIGURATION_ENTRY_ACTION_TYPE
,
815 T_ETH_MAC_COMMAND_SET
);
816 SET_FLAG(cfg_entry
->flags
,
817 MAC_CONFIGURATION_ENTRY_VLAN_FILTERING_MODE
, opcode
);
819 /* Set a MAC in a ramrod data */
820 bnx2x_set_fw_mac_addr(&cfg_entry
->msb_mac_addr
,
821 &cfg_entry
->middle_mac_addr
,
822 &cfg_entry
->lsb_mac_addr
, mac
);
824 SET_FLAG(cfg_entry
->flags
, MAC_CONFIGURATION_ENTRY_ACTION_TYPE
,
825 T_ETH_MAC_COMMAND_INVALIDATE
);
828 static inline void bnx2x_vlan_mac_set_rdata_e1x(struct bnx2x
*bp
,
829 struct bnx2x_vlan_mac_obj
*o
, int type
, int cam_offset
, bool add
,
830 u8
*mac
, u16 vlan_id
, int opcode
, struct mac_configuration_cmd
*config
)
832 struct mac_configuration_entry
*cfg_entry
= &config
->config_table
[0];
833 struct bnx2x_raw_obj
*raw
= &o
->raw
;
835 bnx2x_vlan_mac_set_rdata_hdr_e1x(bp
, o
, type
, cam_offset
,
837 bnx2x_vlan_mac_set_cfg_entry_e1x(bp
, o
, add
, opcode
, mac
, vlan_id
,
840 DP(BNX2X_MSG_SP
, "%s MAC %pM CLID %d CAM offset %d\n",
841 add
? "setting" : "clearing",
842 mac
, raw
->cl_id
, cam_offset
);
846 * bnx2x_set_one_mac_e1x - fill a single MAC rule ramrod data
849 * @o: bnx2x_vlan_mac_obj
850 * @elem: bnx2x_exeq_elem
851 * @rule_idx: rule_idx
852 * @cam_offset: cam_offset
854 static void bnx2x_set_one_mac_e1x(struct bnx2x
*bp
,
855 struct bnx2x_vlan_mac_obj
*o
,
856 struct bnx2x_exeq_elem
*elem
, int rule_idx
,
859 struct bnx2x_raw_obj
*raw
= &o
->raw
;
860 struct mac_configuration_cmd
*config
=
861 (struct mac_configuration_cmd
*)(raw
->rdata
);
863 * 57710 and 57711 do not support MOVE command,
864 * so it's either ADD or DEL
866 bool add
= (elem
->cmd_data
.vlan_mac
.cmd
== BNX2X_VLAN_MAC_ADD
) ?
869 /* Reset the ramrod data buffer */
870 memset(config
, 0, sizeof(*config
));
872 bnx2x_vlan_mac_set_rdata_e1x(bp
, o
, BNX2X_FILTER_MAC_PENDING
,
874 elem
->cmd_data
.vlan_mac
.u
.mac
.mac
, 0,
875 ETH_VLAN_FILTER_ANY_VLAN
, config
);
878 static void bnx2x_set_one_vlan_e2(struct bnx2x
*bp
,
879 struct bnx2x_vlan_mac_obj
*o
,
880 struct bnx2x_exeq_elem
*elem
, int rule_idx
,
883 struct bnx2x_raw_obj
*raw
= &o
->raw
;
884 struct eth_classify_rules_ramrod_data
*data
=
885 (struct eth_classify_rules_ramrod_data
*)(raw
->rdata
);
886 int rule_cnt
= rule_idx
+ 1;
887 union eth_classify_rule_cmd
*rule_entry
= &data
->rules
[rule_idx
];
888 int cmd
= elem
->cmd_data
.vlan_mac
.cmd
;
889 bool add
= (cmd
== BNX2X_VLAN_MAC_ADD
) ? true : false;
890 u16 vlan
= elem
->cmd_data
.vlan_mac
.u
.vlan
.vlan
;
892 /* Reset the ramrod data buffer for the first rule */
894 memset(data
, 0, sizeof(*data
));
896 /* Set a rule header */
897 bnx2x_vlan_mac_set_cmd_hdr_e2(bp
, o
, add
, CLASSIFY_RULE_OPCODE_VLAN
,
898 &rule_entry
->vlan
.header
);
900 DP(BNX2X_MSG_SP
, "About to %s VLAN %d\n", (add
? "add" : "delete"),
903 /* Set a VLAN itself */
904 rule_entry
->vlan
.vlan
= cpu_to_le16(vlan
);
906 /* MOVE: Add a rule that will add this MAC to the target Queue */
907 if (cmd
== BNX2X_VLAN_MAC_MOVE
) {
911 /* Setup ramrod data */
912 bnx2x_vlan_mac_set_cmd_hdr_e2(bp
,
913 elem
->cmd_data
.vlan_mac
.target_obj
,
914 true, CLASSIFY_RULE_OPCODE_VLAN
,
915 &rule_entry
->vlan
.header
);
917 /* Set a VLAN itself */
918 rule_entry
->vlan
.vlan
= cpu_to_le16(vlan
);
921 /* Set the ramrod data header */
922 /* TODO: take this to the higher level in order to prevent multiple
924 bnx2x_vlan_mac_set_rdata_hdr_e2(raw
->cid
, raw
->state
, &data
->header
,
928 static void bnx2x_set_one_vlan_mac_e2(struct bnx2x
*bp
,
929 struct bnx2x_vlan_mac_obj
*o
,
930 struct bnx2x_exeq_elem
*elem
,
931 int rule_idx
, int cam_offset
)
933 struct bnx2x_raw_obj
*raw
= &o
->raw
;
934 struct eth_classify_rules_ramrod_data
*data
=
935 (struct eth_classify_rules_ramrod_data
*)(raw
->rdata
);
936 int rule_cnt
= rule_idx
+ 1;
937 union eth_classify_rule_cmd
*rule_entry
= &data
->rules
[rule_idx
];
938 int cmd
= elem
->cmd_data
.vlan_mac
.cmd
;
939 bool add
= (cmd
== BNX2X_VLAN_MAC_ADD
) ? true : false;
940 u16 vlan
= elem
->cmd_data
.vlan_mac
.u
.vlan_mac
.vlan
;
941 u8
*mac
= elem
->cmd_data
.vlan_mac
.u
.vlan_mac
.mac
;
944 /* Reset the ramrod data buffer for the first rule */
946 memset(data
, 0, sizeof(*data
));
948 /* Set a rule header */
949 bnx2x_vlan_mac_set_cmd_hdr_e2(bp
, o
, add
, CLASSIFY_RULE_OPCODE_PAIR
,
950 &rule_entry
->pair
.header
);
952 /* Set VLAN and MAC themselvs */
953 rule_entry
->pair
.vlan
= cpu_to_le16(vlan
);
954 bnx2x_set_fw_mac_addr(&rule_entry
->pair
.mac_msb
,
955 &rule_entry
->pair
.mac_mid
,
956 &rule_entry
->pair
.mac_lsb
, mac
);
958 /* MOVE: Add a rule that will add this MAC to the target Queue */
959 if (cmd
== BNX2X_VLAN_MAC_MOVE
) {
963 /* Setup ramrod data */
964 bnx2x_vlan_mac_set_cmd_hdr_e2(bp
,
965 elem
->cmd_data
.vlan_mac
.target_obj
,
966 true, CLASSIFY_RULE_OPCODE_PAIR
,
967 &rule_entry
->pair
.header
);
969 /* Set a VLAN itself */
970 rule_entry
->pair
.vlan
= cpu_to_le16(vlan
);
971 bnx2x_set_fw_mac_addr(&rule_entry
->pair
.mac_msb
,
972 &rule_entry
->pair
.mac_mid
,
973 &rule_entry
->pair
.mac_lsb
, mac
);
976 /* Set the ramrod data header */
977 /* TODO: take this to the higher level in order to prevent multiple
979 bnx2x_vlan_mac_set_rdata_hdr_e2(raw
->cid
, raw
->state
, &data
->header
,
984 * bnx2x_set_one_vlan_mac_e1h -
987 * @o: bnx2x_vlan_mac_obj
988 * @elem: bnx2x_exeq_elem
989 * @rule_idx: rule_idx
990 * @cam_offset: cam_offset
992 static void bnx2x_set_one_vlan_mac_e1h(struct bnx2x
*bp
,
993 struct bnx2x_vlan_mac_obj
*o
,
994 struct bnx2x_exeq_elem
*elem
,
995 int rule_idx
, int cam_offset
)
997 struct bnx2x_raw_obj
*raw
= &o
->raw
;
998 struct mac_configuration_cmd
*config
=
999 (struct mac_configuration_cmd
*)(raw
->rdata
);
1001 * 57710 and 57711 do not support MOVE command,
1002 * so it's either ADD or DEL
1004 bool add
= (elem
->cmd_data
.vlan_mac
.cmd
== BNX2X_VLAN_MAC_ADD
) ?
1007 /* Reset the ramrod data buffer */
1008 memset(config
, 0, sizeof(*config
));
1010 bnx2x_vlan_mac_set_rdata_e1x(bp
, o
, BNX2X_FILTER_VLAN_MAC_PENDING
,
1012 elem
->cmd_data
.vlan_mac
.u
.vlan_mac
.mac
,
1013 elem
->cmd_data
.vlan_mac
.u
.vlan_mac
.vlan
,
1014 ETH_VLAN_FILTER_CLASSIFY
, config
);
1017 #define list_next_entry(pos, member) \
1018 list_entry((pos)->member.next, typeof(*(pos)), member)
1021 * bnx2x_vlan_mac_restore - reconfigure next MAC/VLAN/VLAN-MAC element
1023 * @bp: device handle
1024 * @p: command parameters
1025 * @ppos: pointer to the cooky
1027 * reconfigure next MAC/VLAN/VLAN-MAC element from the
1028 * previously configured elements list.
1030 * from command parameters only RAMROD_COMP_WAIT bit in ramrod_flags is taken
1033 * pointer to the cooky - that should be given back in the next call to make
1034 * function handle the next element. If *ppos is set to NULL it will restart the
1035 * iterator. If returned *ppos == NULL this means that the last element has been
1039 static int bnx2x_vlan_mac_restore(struct bnx2x
*bp
,
1040 struct bnx2x_vlan_mac_ramrod_params
*p
,
1041 struct bnx2x_vlan_mac_registry_elem
**ppos
)
1043 struct bnx2x_vlan_mac_registry_elem
*pos
;
1044 struct bnx2x_vlan_mac_obj
*o
= p
->vlan_mac_obj
;
1046 /* If list is empty - there is nothing to do here */
1047 if (list_empty(&o
->head
)) {
1052 /* make a step... */
1054 *ppos
= list_first_entry(&o
->head
,
1055 struct bnx2x_vlan_mac_registry_elem
,
1058 *ppos
= list_next_entry(*ppos
, link
);
1062 /* If it's the last step - return NULL */
1063 if (list_is_last(&pos
->link
, &o
->head
))
1066 /* Prepare a 'user_req' */
1067 memcpy(&p
->user_req
.u
, &pos
->u
, sizeof(pos
->u
));
1069 /* Set the command */
1070 p
->user_req
.cmd
= BNX2X_VLAN_MAC_ADD
;
1072 /* Set vlan_mac_flags */
1073 p
->user_req
.vlan_mac_flags
= pos
->vlan_mac_flags
;
1075 /* Set a restore bit */
1076 __set_bit(RAMROD_RESTORE
, &p
->ramrod_flags
);
1078 return bnx2x_config_vlan_mac(bp
, p
);
1082 * bnx2x_exeq_get_mac/bnx2x_exeq_get_vlan/bnx2x_exeq_get_vlan_mac return a
1083 * pointer to an element with a specific criteria and NULL if such an element
1084 * hasn't been found.
1086 static struct bnx2x_exeq_elem
*bnx2x_exeq_get_mac(
1087 struct bnx2x_exe_queue_obj
*o
,
1088 struct bnx2x_exeq_elem
*elem
)
1090 struct bnx2x_exeq_elem
*pos
;
1091 struct bnx2x_mac_ramrod_data
*data
= &elem
->cmd_data
.vlan_mac
.u
.mac
;
1093 /* Check pending for execution commands */
1094 list_for_each_entry(pos
, &o
->exe_queue
, link
)
1095 if (!memcmp(&pos
->cmd_data
.vlan_mac
.u
.mac
, data
,
1097 (pos
->cmd_data
.vlan_mac
.cmd
== elem
->cmd_data
.vlan_mac
.cmd
))
1103 static struct bnx2x_exeq_elem
*bnx2x_exeq_get_vlan(
1104 struct bnx2x_exe_queue_obj
*o
,
1105 struct bnx2x_exeq_elem
*elem
)
1107 struct bnx2x_exeq_elem
*pos
;
1108 struct bnx2x_vlan_ramrod_data
*data
= &elem
->cmd_data
.vlan_mac
.u
.vlan
;
1110 /* Check pending for execution commands */
1111 list_for_each_entry(pos
, &o
->exe_queue
, link
)
1112 if (!memcmp(&pos
->cmd_data
.vlan_mac
.u
.vlan
, data
,
1114 (pos
->cmd_data
.vlan_mac
.cmd
== elem
->cmd_data
.vlan_mac
.cmd
))
1120 static struct bnx2x_exeq_elem
*bnx2x_exeq_get_vlan_mac(
1121 struct bnx2x_exe_queue_obj
*o
,
1122 struct bnx2x_exeq_elem
*elem
)
1124 struct bnx2x_exeq_elem
*pos
;
1125 struct bnx2x_vlan_mac_ramrod_data
*data
=
1126 &elem
->cmd_data
.vlan_mac
.u
.vlan_mac
;
1128 /* Check pending for execution commands */
1129 list_for_each_entry(pos
, &o
->exe_queue
, link
)
1130 if (!memcmp(&pos
->cmd_data
.vlan_mac
.u
.vlan_mac
, data
,
1132 (pos
->cmd_data
.vlan_mac
.cmd
== elem
->cmd_data
.vlan_mac
.cmd
))
1139 * bnx2x_validate_vlan_mac_add - check if an ADD command can be executed
1141 * @bp: device handle
1142 * @qo: bnx2x_qable_obj
1143 * @elem: bnx2x_exeq_elem
1145 * Checks that the requested configuration can be added. If yes and if
1146 * requested, consume CAM credit.
1148 * The 'validate' is run after the 'optimize'.
1151 static inline int bnx2x_validate_vlan_mac_add(struct bnx2x
*bp
,
1152 union bnx2x_qable_obj
*qo
,
1153 struct bnx2x_exeq_elem
*elem
)
1155 struct bnx2x_vlan_mac_obj
*o
= &qo
->vlan_mac
;
1156 struct bnx2x_exe_queue_obj
*exeq
= &o
->exe_queue
;
1159 /* Check the registry */
1160 rc
= o
->check_add(o
, &elem
->cmd_data
.vlan_mac
.u
);
1162 DP(BNX2X_MSG_SP
, "ADD command is not allowed considering "
1163 "current registry state\n");
1168 * Check if there is a pending ADD command for this
1169 * MAC/VLAN/VLAN-MAC. Return an error if there is.
1171 if (exeq
->get(exeq
, elem
)) {
1172 DP(BNX2X_MSG_SP
, "There is a pending ADD command already\n");
1177 * TODO: Check the pending MOVE from other objects where this
1178 * object is a destination object.
1181 /* Consume the credit if not requested not to */
1182 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT
,
1183 &elem
->cmd_data
.vlan_mac
.vlan_mac_flags
) ||
1191 * bnx2x_validate_vlan_mac_del - check if the DEL command can be executed
1193 * @bp: device handle
1194 * @qo: quable object to check
1195 * @elem: element that needs to be deleted
1197 * Checks that the requested configuration can be deleted. If yes and if
1198 * requested, returns a CAM credit.
1200 * The 'validate' is run after the 'optimize'.
1202 static inline int bnx2x_validate_vlan_mac_del(struct bnx2x
*bp
,
1203 union bnx2x_qable_obj
*qo
,
1204 struct bnx2x_exeq_elem
*elem
)
1206 struct bnx2x_vlan_mac_obj
*o
= &qo
->vlan_mac
;
1207 struct bnx2x_vlan_mac_registry_elem
*pos
;
1208 struct bnx2x_exe_queue_obj
*exeq
= &o
->exe_queue
;
1209 struct bnx2x_exeq_elem query_elem
;
1211 /* If this classification can not be deleted (doesn't exist)
1212 * - return a BNX2X_EXIST.
1214 pos
= o
->check_del(o
, &elem
->cmd_data
.vlan_mac
.u
);
1216 DP(BNX2X_MSG_SP
, "DEL command is not allowed considering "
1217 "current registry state\n");
1222 * Check if there are pending DEL or MOVE commands for this
1223 * MAC/VLAN/VLAN-MAC. Return an error if so.
1225 memcpy(&query_elem
, elem
, sizeof(query_elem
));
1227 /* Check for MOVE commands */
1228 query_elem
.cmd_data
.vlan_mac
.cmd
= BNX2X_VLAN_MAC_MOVE
;
1229 if (exeq
->get(exeq
, &query_elem
)) {
1230 BNX2X_ERR("There is a pending MOVE command already\n");
1234 /* Check for DEL commands */
1235 if (exeq
->get(exeq
, elem
)) {
1236 DP(BNX2X_MSG_SP
, "There is a pending DEL command already\n");
1240 /* Return the credit to the credit pool if not requested not to */
1241 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT
,
1242 &elem
->cmd_data
.vlan_mac
.vlan_mac_flags
) ||
1243 o
->put_credit(o
))) {
1244 BNX2X_ERR("Failed to return a credit\n");
1252 * bnx2x_validate_vlan_mac_move - check if the MOVE command can be executed
1254 * @bp: device handle
1255 * @qo: quable object to check (source)
1256 * @elem: element that needs to be moved
1258 * Checks that the requested configuration can be moved. If yes and if
1259 * requested, returns a CAM credit.
1261 * The 'validate' is run after the 'optimize'.
1263 static inline int bnx2x_validate_vlan_mac_move(struct bnx2x
*bp
,
1264 union bnx2x_qable_obj
*qo
,
1265 struct bnx2x_exeq_elem
*elem
)
1267 struct bnx2x_vlan_mac_obj
*src_o
= &qo
->vlan_mac
;
1268 struct bnx2x_vlan_mac_obj
*dest_o
= elem
->cmd_data
.vlan_mac
.target_obj
;
1269 struct bnx2x_exeq_elem query_elem
;
1270 struct bnx2x_exe_queue_obj
*src_exeq
= &src_o
->exe_queue
;
1271 struct bnx2x_exe_queue_obj
*dest_exeq
= &dest_o
->exe_queue
;
1274 * Check if we can perform this operation based on the current registry
1277 if (!src_o
->check_move(src_o
, dest_o
, &elem
->cmd_data
.vlan_mac
.u
)) {
1278 DP(BNX2X_MSG_SP
, "MOVE command is not allowed considering "
1279 "current registry state\n");
1284 * Check if there is an already pending DEL or MOVE command for the
1285 * source object or ADD command for a destination object. Return an
1288 memcpy(&query_elem
, elem
, sizeof(query_elem
));
1290 /* Check DEL on source */
1291 query_elem
.cmd_data
.vlan_mac
.cmd
= BNX2X_VLAN_MAC_DEL
;
1292 if (src_exeq
->get(src_exeq
, &query_elem
)) {
1293 BNX2X_ERR("There is a pending DEL command on the source "
1298 /* Check MOVE on source */
1299 if (src_exeq
->get(src_exeq
, elem
)) {
1300 DP(BNX2X_MSG_SP
, "There is a pending MOVE command already\n");
1304 /* Check ADD on destination */
1305 query_elem
.cmd_data
.vlan_mac
.cmd
= BNX2X_VLAN_MAC_ADD
;
1306 if (dest_exeq
->get(dest_exeq
, &query_elem
)) {
1307 BNX2X_ERR("There is a pending ADD command on the "
1308 "destination queue already\n");
1312 /* Consume the credit if not requested not to */
1313 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT_DEST
,
1314 &elem
->cmd_data
.vlan_mac
.vlan_mac_flags
) ||
1315 dest_o
->get_credit(dest_o
)))
1318 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT
,
1319 &elem
->cmd_data
.vlan_mac
.vlan_mac_flags
) ||
1320 src_o
->put_credit(src_o
))) {
1321 /* return the credit taken from dest... */
1322 dest_o
->put_credit(dest_o
);
1329 static int bnx2x_validate_vlan_mac(struct bnx2x
*bp
,
1330 union bnx2x_qable_obj
*qo
,
1331 struct bnx2x_exeq_elem
*elem
)
1333 switch (elem
->cmd_data
.vlan_mac
.cmd
) {
1334 case BNX2X_VLAN_MAC_ADD
:
1335 return bnx2x_validate_vlan_mac_add(bp
, qo
, elem
);
1336 case BNX2X_VLAN_MAC_DEL
:
1337 return bnx2x_validate_vlan_mac_del(bp
, qo
, elem
);
1338 case BNX2X_VLAN_MAC_MOVE
:
1339 return bnx2x_validate_vlan_mac_move(bp
, qo
, elem
);
1345 static int bnx2x_remove_vlan_mac(struct bnx2x
*bp
,
1346 union bnx2x_qable_obj
*qo
,
1347 struct bnx2x_exeq_elem
*elem
)
1351 /* If consumption wasn't required, nothing to do */
1352 if (test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT
,
1353 &elem
->cmd_data
.vlan_mac
.vlan_mac_flags
))
1356 switch (elem
->cmd_data
.vlan_mac
.cmd
) {
1357 case BNX2X_VLAN_MAC_ADD
:
1358 case BNX2X_VLAN_MAC_MOVE
:
1359 rc
= qo
->vlan_mac
.put_credit(&qo
->vlan_mac
);
1361 case BNX2X_VLAN_MAC_DEL
:
1362 rc
= qo
->vlan_mac
.get_credit(&qo
->vlan_mac
);
1375 * bnx2x_wait_vlan_mac - passivly wait for 5 seconds until all work completes.
1377 * @bp: device handle
1378 * @o: bnx2x_vlan_mac_obj
1381 static int bnx2x_wait_vlan_mac(struct bnx2x
*bp
,
1382 struct bnx2x_vlan_mac_obj
*o
)
1385 struct bnx2x_exe_queue_obj
*exeq
= &o
->exe_queue
;
1386 struct bnx2x_raw_obj
*raw
= &o
->raw
;
1389 /* Wait for the current command to complete */
1390 rc
= raw
->wait_comp(bp
, raw
);
1394 /* Wait until there are no pending commands */
1395 if (!bnx2x_exe_queue_empty(exeq
))
1396 usleep_range(1000, 1000);
1405 * bnx2x_complete_vlan_mac - complete one VLAN-MAC ramrod
1407 * @bp: device handle
1408 * @o: bnx2x_vlan_mac_obj
1410 * @cont: if true schedule next execution chunk
1413 static int bnx2x_complete_vlan_mac(struct bnx2x
*bp
,
1414 struct bnx2x_vlan_mac_obj
*o
,
1415 union event_ring_elem
*cqe
,
1416 unsigned long *ramrod_flags
)
1418 struct bnx2x_raw_obj
*r
= &o
->raw
;
1421 /* Reset pending list */
1422 bnx2x_exe_queue_reset_pending(bp
, &o
->exe_queue
);
1425 r
->clear_pending(r
);
1427 /* If ramrod failed this is most likely a SW bug */
1428 if (cqe
->message
.error
)
1431 /* Run the next bulk of pending commands if requeted */
1432 if (test_bit(RAMROD_CONT
, ramrod_flags
)) {
1433 rc
= bnx2x_exe_queue_step(bp
, &o
->exe_queue
, ramrod_flags
);
1438 /* If there is more work to do return PENDING */
1439 if (!bnx2x_exe_queue_empty(&o
->exe_queue
))
1446 * bnx2x_optimize_vlan_mac - optimize ADD and DEL commands.
1448 * @bp: device handle
1449 * @o: bnx2x_qable_obj
1450 * @elem: bnx2x_exeq_elem
1452 static int bnx2x_optimize_vlan_mac(struct bnx2x
*bp
,
1453 union bnx2x_qable_obj
*qo
,
1454 struct bnx2x_exeq_elem
*elem
)
1456 struct bnx2x_exeq_elem query
, *pos
;
1457 struct bnx2x_vlan_mac_obj
*o
= &qo
->vlan_mac
;
1458 struct bnx2x_exe_queue_obj
*exeq
= &o
->exe_queue
;
1460 memcpy(&query
, elem
, sizeof(query
));
1462 switch (elem
->cmd_data
.vlan_mac
.cmd
) {
1463 case BNX2X_VLAN_MAC_ADD
:
1464 query
.cmd_data
.vlan_mac
.cmd
= BNX2X_VLAN_MAC_DEL
;
1466 case BNX2X_VLAN_MAC_DEL
:
1467 query
.cmd_data
.vlan_mac
.cmd
= BNX2X_VLAN_MAC_ADD
;
1470 /* Don't handle anything other than ADD or DEL */
1474 /* If we found the appropriate element - delete it */
1475 pos
= exeq
->get(exeq
, &query
);
1478 /* Return the credit of the optimized command */
1479 if (!test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT
,
1480 &pos
->cmd_data
.vlan_mac
.vlan_mac_flags
)) {
1481 if ((query
.cmd_data
.vlan_mac
.cmd
==
1482 BNX2X_VLAN_MAC_ADD
) && !o
->put_credit(o
)) {
1483 BNX2X_ERR("Failed to return the credit for the "
1484 "optimized ADD command\n");
1486 } else if (!o
->get_credit(o
)) { /* VLAN_MAC_DEL */
1487 BNX2X_ERR("Failed to recover the credit from "
1488 "the optimized DEL command\n");
1493 DP(BNX2X_MSG_SP
, "Optimizing %s command\n",
1494 (elem
->cmd_data
.vlan_mac
.cmd
== BNX2X_VLAN_MAC_ADD
) ?
1497 list_del(&pos
->link
);
1498 bnx2x_exe_queue_free_elem(bp
, pos
);
1506 * bnx2x_vlan_mac_get_registry_elem - prepare a registry element
1508 * @bp: device handle
1514 * prepare a registry element according to the current command request.
1516 static inline int bnx2x_vlan_mac_get_registry_elem(
1518 struct bnx2x_vlan_mac_obj
*o
,
1519 struct bnx2x_exeq_elem
*elem
,
1521 struct bnx2x_vlan_mac_registry_elem
**re
)
1523 int cmd
= elem
->cmd_data
.vlan_mac
.cmd
;
1524 struct bnx2x_vlan_mac_registry_elem
*reg_elem
;
1526 /* Allocate a new registry element if needed. */
1528 ((cmd
== BNX2X_VLAN_MAC_ADD
) || (cmd
== BNX2X_VLAN_MAC_MOVE
))) {
1529 reg_elem
= kzalloc(sizeof(*reg_elem
), GFP_ATOMIC
);
1533 /* Get a new CAM offset */
1534 if (!o
->get_cam_offset(o
, ®_elem
->cam_offset
)) {
1536 * This shell never happen, because we have checked the
1537 * CAM availiability in the 'validate'.
1544 DP(BNX2X_MSG_SP
, "Got cam offset %d\n", reg_elem
->cam_offset
);
1546 /* Set a VLAN-MAC data */
1547 memcpy(®_elem
->u
, &elem
->cmd_data
.vlan_mac
.u
,
1548 sizeof(reg_elem
->u
));
1550 /* Copy the flags (needed for DEL and RESTORE flows) */
1551 reg_elem
->vlan_mac_flags
=
1552 elem
->cmd_data
.vlan_mac
.vlan_mac_flags
;
1553 } else /* DEL, RESTORE */
1554 reg_elem
= o
->check_del(o
, &elem
->cmd_data
.vlan_mac
.u
);
1561 * bnx2x_execute_vlan_mac - execute vlan mac command
1563 * @bp: device handle
1568 * go and send a ramrod!
1570 static int bnx2x_execute_vlan_mac(struct bnx2x
*bp
,
1571 union bnx2x_qable_obj
*qo
,
1572 struct list_head
*exe_chunk
,
1573 unsigned long *ramrod_flags
)
1575 struct bnx2x_exeq_elem
*elem
;
1576 struct bnx2x_vlan_mac_obj
*o
= &qo
->vlan_mac
, *cam_obj
;
1577 struct bnx2x_raw_obj
*r
= &o
->raw
;
1579 bool restore
= test_bit(RAMROD_RESTORE
, ramrod_flags
);
1580 bool drv_only
= test_bit(RAMROD_DRV_CLR_ONLY
, ramrod_flags
);
1581 struct bnx2x_vlan_mac_registry_elem
*reg_elem
;
1585 * If DRIVER_ONLY execution is requested, cleanup a registry
1586 * and exit. Otherwise send a ramrod to FW.
1589 WARN_ON(r
->check_pending(r
));
1594 /* Fill tha ramrod data */
1595 list_for_each_entry(elem
, exe_chunk
, link
) {
1596 cmd
= elem
->cmd_data
.vlan_mac
.cmd
;
1598 * We will add to the target object in MOVE command, so
1599 * change the object for a CAM search.
1601 if (cmd
== BNX2X_VLAN_MAC_MOVE
)
1602 cam_obj
= elem
->cmd_data
.vlan_mac
.target_obj
;
1606 rc
= bnx2x_vlan_mac_get_registry_elem(bp
, cam_obj
,
1614 /* Push a new entry into the registry */
1616 ((cmd
== BNX2X_VLAN_MAC_ADD
) ||
1617 (cmd
== BNX2X_VLAN_MAC_MOVE
)))
1618 list_add(®_elem
->link
, &cam_obj
->head
);
1620 /* Configure a single command in a ramrod data buffer */
1621 o
->set_one_rule(bp
, o
, elem
, idx
,
1622 reg_elem
->cam_offset
);
1624 /* MOVE command consumes 2 entries in the ramrod data */
1625 if (cmd
== BNX2X_VLAN_MAC_MOVE
)
1632 * No need for an explicit memory barrier here as long we would
1633 * need to ensure the ordering of writing to the SPQ element
1634 * and updating of the SPQ producer which involves a memory
1635 * read and we will have to put a full memory barrier there
1636 * (inside bnx2x_sp_post()).
1639 rc
= bnx2x_sp_post(bp
, o
->ramrod_cmd
, r
->cid
,
1640 U64_HI(r
->rdata_mapping
),
1641 U64_LO(r
->rdata_mapping
),
1642 ETH_CONNECTION_TYPE
);
1647 /* Now, when we are done with the ramrod - clean up the registry */
1648 list_for_each_entry(elem
, exe_chunk
, link
) {
1649 cmd
= elem
->cmd_data
.vlan_mac
.cmd
;
1650 if ((cmd
== BNX2X_VLAN_MAC_DEL
) ||
1651 (cmd
== BNX2X_VLAN_MAC_MOVE
)) {
1652 reg_elem
= o
->check_del(o
, &elem
->cmd_data
.vlan_mac
.u
);
1656 o
->put_cam_offset(o
, reg_elem
->cam_offset
);
1657 list_del(®_elem
->link
);
1668 r
->clear_pending(r
);
1670 /* Cleanup a registry in case of a failure */
1671 list_for_each_entry(elem
, exe_chunk
, link
) {
1672 cmd
= elem
->cmd_data
.vlan_mac
.cmd
;
1674 if (cmd
== BNX2X_VLAN_MAC_MOVE
)
1675 cam_obj
= elem
->cmd_data
.vlan_mac
.target_obj
;
1679 /* Delete all newly added above entries */
1681 ((cmd
== BNX2X_VLAN_MAC_ADD
) ||
1682 (cmd
== BNX2X_VLAN_MAC_MOVE
))) {
1683 reg_elem
= o
->check_del(cam_obj
,
1684 &elem
->cmd_data
.vlan_mac
.u
);
1686 list_del(®_elem
->link
);
1695 static inline int bnx2x_vlan_mac_push_new_cmd(
1697 struct bnx2x_vlan_mac_ramrod_params
*p
)
1699 struct bnx2x_exeq_elem
*elem
;
1700 struct bnx2x_vlan_mac_obj
*o
= p
->vlan_mac_obj
;
1701 bool restore
= test_bit(RAMROD_RESTORE
, &p
->ramrod_flags
);
1703 /* Allocate the execution queue element */
1704 elem
= bnx2x_exe_queue_alloc_elem(bp
);
1708 /* Set the command 'length' */
1709 switch (p
->user_req
.cmd
) {
1710 case BNX2X_VLAN_MAC_MOVE
:
1717 /* Fill the object specific info */
1718 memcpy(&elem
->cmd_data
.vlan_mac
, &p
->user_req
, sizeof(p
->user_req
));
1720 /* Try to add a new command to the pending list */
1721 return bnx2x_exe_queue_add(bp
, &o
->exe_queue
, elem
, restore
);
1725 * bnx2x_config_vlan_mac - configure VLAN/MAC/VLAN_MAC filtering rules.
1727 * @bp: device handle
1731 int bnx2x_config_vlan_mac(
1733 struct bnx2x_vlan_mac_ramrod_params
*p
)
1736 struct bnx2x_vlan_mac_obj
*o
= p
->vlan_mac_obj
;
1737 unsigned long *ramrod_flags
= &p
->ramrod_flags
;
1738 bool cont
= test_bit(RAMROD_CONT
, ramrod_flags
);
1739 struct bnx2x_raw_obj
*raw
= &o
->raw
;
1742 * Add new elements to the execution list for commands that require it.
1745 rc
= bnx2x_vlan_mac_push_new_cmd(bp
, p
);
1751 * If nothing will be executed further in this iteration we want to
1752 * return PENDING if there are pending commands
1754 if (!bnx2x_exe_queue_empty(&o
->exe_queue
))
1757 if (test_bit(RAMROD_DRV_CLR_ONLY
, ramrod_flags
)) {
1758 DP(BNX2X_MSG_SP
, "RAMROD_DRV_CLR_ONLY requested: "
1759 "clearing a pending bit.\n");
1760 raw
->clear_pending(raw
);
1763 /* Execute commands if required */
1764 if (cont
|| test_bit(RAMROD_EXEC
, ramrod_flags
) ||
1765 test_bit(RAMROD_COMP_WAIT
, ramrod_flags
)) {
1766 rc
= bnx2x_exe_queue_step(bp
, &o
->exe_queue
, ramrod_flags
);
1772 * RAMROD_COMP_WAIT is a superset of RAMROD_EXEC. If it was set
1773 * then user want to wait until the last command is done.
1775 if (test_bit(RAMROD_COMP_WAIT
, &p
->ramrod_flags
)) {
1777 * Wait maximum for the current exe_queue length iterations plus
1778 * one (for the current pending command).
1780 int max_iterations
= bnx2x_exe_queue_length(&o
->exe_queue
) + 1;
1782 while (!bnx2x_exe_queue_empty(&o
->exe_queue
) &&
1785 /* Wait for the current command to complete */
1786 rc
= raw
->wait_comp(bp
, raw
);
1790 /* Make a next step */
1791 rc
= bnx2x_exe_queue_step(bp
, &o
->exe_queue
,
1806 * bnx2x_vlan_mac_del_all - delete elements with given vlan_mac_flags spec
1808 * @bp: device handle
1811 * @ramrod_flags: execution flags to be used for this deletion
1813 * if the last operation has completed successfully and there are no
1814 * moreelements left, positive value if the last operation has completed
1815 * successfully and there are more previously configured elements, negative
1816 * value is current operation has failed.
1818 static int bnx2x_vlan_mac_del_all(struct bnx2x
*bp
,
1819 struct bnx2x_vlan_mac_obj
*o
,
1820 unsigned long *vlan_mac_flags
,
1821 unsigned long *ramrod_flags
)
1823 struct bnx2x_vlan_mac_registry_elem
*pos
= NULL
;
1825 struct bnx2x_vlan_mac_ramrod_params p
;
1826 struct bnx2x_exe_queue_obj
*exeq
= &o
->exe_queue
;
1827 struct bnx2x_exeq_elem
*exeq_pos
, *exeq_pos_n
;
1829 /* Clear pending commands first */
1831 spin_lock_bh(&exeq
->lock
);
1833 list_for_each_entry_safe(exeq_pos
, exeq_pos_n
, &exeq
->exe_queue
, link
) {
1834 if (exeq_pos
->cmd_data
.vlan_mac
.vlan_mac_flags
==
1836 rc
= exeq
->remove(bp
, exeq
->owner
, exeq_pos
);
1838 BNX2X_ERR("Failed to remove command\n");
1841 list_del(&exeq_pos
->link
);
1845 spin_unlock_bh(&exeq
->lock
);
1847 /* Prepare a command request */
1848 memset(&p
, 0, sizeof(p
));
1850 p
.ramrod_flags
= *ramrod_flags
;
1851 p
.user_req
.cmd
= BNX2X_VLAN_MAC_DEL
;
1854 * Add all but the last VLAN-MAC to the execution queue without actually
1855 * execution anything.
1857 __clear_bit(RAMROD_COMP_WAIT
, &p
.ramrod_flags
);
1858 __clear_bit(RAMROD_EXEC
, &p
.ramrod_flags
);
1859 __clear_bit(RAMROD_CONT
, &p
.ramrod_flags
);
1861 list_for_each_entry(pos
, &o
->head
, link
) {
1862 if (pos
->vlan_mac_flags
== *vlan_mac_flags
) {
1863 p
.user_req
.vlan_mac_flags
= pos
->vlan_mac_flags
;
1864 memcpy(&p
.user_req
.u
, &pos
->u
, sizeof(pos
->u
));
1865 rc
= bnx2x_config_vlan_mac(bp
, &p
);
1867 BNX2X_ERR("Failed to add a new DEL command\n");
1873 p
.ramrod_flags
= *ramrod_flags
;
1874 __set_bit(RAMROD_CONT
, &p
.ramrod_flags
);
1876 return bnx2x_config_vlan_mac(bp
, &p
);
1879 static inline void bnx2x_init_raw_obj(struct bnx2x_raw_obj
*raw
, u8 cl_id
,
1880 u32 cid
, u8 func_id
, void *rdata
, dma_addr_t rdata_mapping
, int state
,
1881 unsigned long *pstate
, bnx2x_obj_type type
)
1883 raw
->func_id
= func_id
;
1887 raw
->rdata_mapping
= rdata_mapping
;
1889 raw
->pstate
= pstate
;
1890 raw
->obj_type
= type
;
1891 raw
->check_pending
= bnx2x_raw_check_pending
;
1892 raw
->clear_pending
= bnx2x_raw_clear_pending
;
1893 raw
->set_pending
= bnx2x_raw_set_pending
;
1894 raw
->wait_comp
= bnx2x_raw_wait
;
1897 static inline void bnx2x_init_vlan_mac_common(struct bnx2x_vlan_mac_obj
*o
,
1898 u8 cl_id
, u32 cid
, u8 func_id
, void *rdata
, dma_addr_t rdata_mapping
,
1899 int state
, unsigned long *pstate
, bnx2x_obj_type type
,
1900 struct bnx2x_credit_pool_obj
*macs_pool
,
1901 struct bnx2x_credit_pool_obj
*vlans_pool
)
1903 INIT_LIST_HEAD(&o
->head
);
1905 o
->macs_pool
= macs_pool
;
1906 o
->vlans_pool
= vlans_pool
;
1908 o
->delete_all
= bnx2x_vlan_mac_del_all
;
1909 o
->restore
= bnx2x_vlan_mac_restore
;
1910 o
->complete
= bnx2x_complete_vlan_mac
;
1911 o
->wait
= bnx2x_wait_vlan_mac
;
1913 bnx2x_init_raw_obj(&o
->raw
, cl_id
, cid
, func_id
, rdata
, rdata_mapping
,
1914 state
, pstate
, type
);
1918 void bnx2x_init_mac_obj(struct bnx2x
*bp
,
1919 struct bnx2x_vlan_mac_obj
*mac_obj
,
1920 u8 cl_id
, u32 cid
, u8 func_id
, void *rdata
,
1921 dma_addr_t rdata_mapping
, int state
,
1922 unsigned long *pstate
, bnx2x_obj_type type
,
1923 struct bnx2x_credit_pool_obj
*macs_pool
)
1925 union bnx2x_qable_obj
*qable_obj
= (union bnx2x_qable_obj
*)mac_obj
;
1927 bnx2x_init_vlan_mac_common(mac_obj
, cl_id
, cid
, func_id
, rdata
,
1928 rdata_mapping
, state
, pstate
, type
,
1931 /* CAM credit pool handling */
1932 mac_obj
->get_credit
= bnx2x_get_credit_mac
;
1933 mac_obj
->put_credit
= bnx2x_put_credit_mac
;
1934 mac_obj
->get_cam_offset
= bnx2x_get_cam_offset_mac
;
1935 mac_obj
->put_cam_offset
= bnx2x_put_cam_offset_mac
;
1937 if (CHIP_IS_E1x(bp
)) {
1938 mac_obj
->set_one_rule
= bnx2x_set_one_mac_e1x
;
1939 mac_obj
->check_del
= bnx2x_check_mac_del
;
1940 mac_obj
->check_add
= bnx2x_check_mac_add
;
1941 mac_obj
->check_move
= bnx2x_check_move_always_err
;
1942 mac_obj
->ramrod_cmd
= RAMROD_CMD_ID_ETH_SET_MAC
;
1945 bnx2x_exe_queue_init(bp
,
1946 &mac_obj
->exe_queue
, 1, qable_obj
,
1947 bnx2x_validate_vlan_mac
,
1948 bnx2x_remove_vlan_mac
,
1949 bnx2x_optimize_vlan_mac
,
1950 bnx2x_execute_vlan_mac
,
1951 bnx2x_exeq_get_mac
);
1953 mac_obj
->set_one_rule
= bnx2x_set_one_mac_e2
;
1954 mac_obj
->check_del
= bnx2x_check_mac_del
;
1955 mac_obj
->check_add
= bnx2x_check_mac_add
;
1956 mac_obj
->check_move
= bnx2x_check_move
;
1957 mac_obj
->ramrod_cmd
=
1958 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES
;
1959 mac_obj
->get_n_elements
= bnx2x_get_n_elements
;
1962 bnx2x_exe_queue_init(bp
,
1963 &mac_obj
->exe_queue
, CLASSIFY_RULES_COUNT
,
1964 qable_obj
, bnx2x_validate_vlan_mac
,
1965 bnx2x_remove_vlan_mac
,
1966 bnx2x_optimize_vlan_mac
,
1967 bnx2x_execute_vlan_mac
,
1968 bnx2x_exeq_get_mac
);
1972 void bnx2x_init_vlan_obj(struct bnx2x
*bp
,
1973 struct bnx2x_vlan_mac_obj
*vlan_obj
,
1974 u8 cl_id
, u32 cid
, u8 func_id
, void *rdata
,
1975 dma_addr_t rdata_mapping
, int state
,
1976 unsigned long *pstate
, bnx2x_obj_type type
,
1977 struct bnx2x_credit_pool_obj
*vlans_pool
)
1979 union bnx2x_qable_obj
*qable_obj
= (union bnx2x_qable_obj
*)vlan_obj
;
1981 bnx2x_init_vlan_mac_common(vlan_obj
, cl_id
, cid
, func_id
, rdata
,
1982 rdata_mapping
, state
, pstate
, type
, NULL
,
1985 vlan_obj
->get_credit
= bnx2x_get_credit_vlan
;
1986 vlan_obj
->put_credit
= bnx2x_put_credit_vlan
;
1987 vlan_obj
->get_cam_offset
= bnx2x_get_cam_offset_vlan
;
1988 vlan_obj
->put_cam_offset
= bnx2x_put_cam_offset_vlan
;
1990 if (CHIP_IS_E1x(bp
)) {
1991 BNX2X_ERR("Do not support chips others than E2 and newer\n");
1994 vlan_obj
->set_one_rule
= bnx2x_set_one_vlan_e2
;
1995 vlan_obj
->check_del
= bnx2x_check_vlan_del
;
1996 vlan_obj
->check_add
= bnx2x_check_vlan_add
;
1997 vlan_obj
->check_move
= bnx2x_check_move
;
1998 vlan_obj
->ramrod_cmd
=
1999 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES
;
2002 bnx2x_exe_queue_init(bp
,
2003 &vlan_obj
->exe_queue
, CLASSIFY_RULES_COUNT
,
2004 qable_obj
, bnx2x_validate_vlan_mac
,
2005 bnx2x_remove_vlan_mac
,
2006 bnx2x_optimize_vlan_mac
,
2007 bnx2x_execute_vlan_mac
,
2008 bnx2x_exeq_get_vlan
);
2012 void bnx2x_init_vlan_mac_obj(struct bnx2x
*bp
,
2013 struct bnx2x_vlan_mac_obj
*vlan_mac_obj
,
2014 u8 cl_id
, u32 cid
, u8 func_id
, void *rdata
,
2015 dma_addr_t rdata_mapping
, int state
,
2016 unsigned long *pstate
, bnx2x_obj_type type
,
2017 struct bnx2x_credit_pool_obj
*macs_pool
,
2018 struct bnx2x_credit_pool_obj
*vlans_pool
)
2020 union bnx2x_qable_obj
*qable_obj
=
2021 (union bnx2x_qable_obj
*)vlan_mac_obj
;
2023 bnx2x_init_vlan_mac_common(vlan_mac_obj
, cl_id
, cid
, func_id
, rdata
,
2024 rdata_mapping
, state
, pstate
, type
,
2025 macs_pool
, vlans_pool
);
2027 /* CAM pool handling */
2028 vlan_mac_obj
->get_credit
= bnx2x_get_credit_vlan_mac
;
2029 vlan_mac_obj
->put_credit
= bnx2x_put_credit_vlan_mac
;
2031 * CAM offset is relevant for 57710 and 57711 chips only which have a
2032 * single CAM for both MACs and VLAN-MAC pairs. So the offset
2033 * will be taken from MACs' pool object only.
2035 vlan_mac_obj
->get_cam_offset
= bnx2x_get_cam_offset_mac
;
2036 vlan_mac_obj
->put_cam_offset
= bnx2x_put_cam_offset_mac
;
2038 if (CHIP_IS_E1(bp
)) {
2039 BNX2X_ERR("Do not support chips others than E2\n");
2041 } else if (CHIP_IS_E1H(bp
)) {
2042 vlan_mac_obj
->set_one_rule
= bnx2x_set_one_vlan_mac_e1h
;
2043 vlan_mac_obj
->check_del
= bnx2x_check_vlan_mac_del
;
2044 vlan_mac_obj
->check_add
= bnx2x_check_vlan_mac_add
;
2045 vlan_mac_obj
->check_move
= bnx2x_check_move_always_err
;
2046 vlan_mac_obj
->ramrod_cmd
= RAMROD_CMD_ID_ETH_SET_MAC
;
2049 bnx2x_exe_queue_init(bp
,
2050 &vlan_mac_obj
->exe_queue
, 1, qable_obj
,
2051 bnx2x_validate_vlan_mac
,
2052 bnx2x_remove_vlan_mac
,
2053 bnx2x_optimize_vlan_mac
,
2054 bnx2x_execute_vlan_mac
,
2055 bnx2x_exeq_get_vlan_mac
);
2057 vlan_mac_obj
->set_one_rule
= bnx2x_set_one_vlan_mac_e2
;
2058 vlan_mac_obj
->check_del
= bnx2x_check_vlan_mac_del
;
2059 vlan_mac_obj
->check_add
= bnx2x_check_vlan_mac_add
;
2060 vlan_mac_obj
->check_move
= bnx2x_check_move
;
2061 vlan_mac_obj
->ramrod_cmd
=
2062 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES
;
2065 bnx2x_exe_queue_init(bp
,
2066 &vlan_mac_obj
->exe_queue
,
2067 CLASSIFY_RULES_COUNT
,
2068 qable_obj
, bnx2x_validate_vlan_mac
,
2069 bnx2x_remove_vlan_mac
,
2070 bnx2x_optimize_vlan_mac
,
2071 bnx2x_execute_vlan_mac
,
2072 bnx2x_exeq_get_vlan_mac
);
2077 /* RX_MODE verbs: DROP_ALL/ACCEPT_ALL/ACCEPT_ALL_MULTI/ACCEPT_ALL_VLAN/NORMAL */
2078 static inline void __storm_memset_mac_filters(struct bnx2x
*bp
,
2079 struct tstorm_eth_mac_filter_config
*mac_filters
,
2082 size_t size
= sizeof(struct tstorm_eth_mac_filter_config
);
2084 u32 addr
= BAR_TSTRORM_INTMEM
+
2085 TSTORM_MAC_FILTER_CONFIG_OFFSET(pf_id
);
2087 __storm_memset_struct(bp
, addr
, size
, (u32
*)mac_filters
);
2090 static int bnx2x_set_rx_mode_e1x(struct bnx2x
*bp
,
2091 struct bnx2x_rx_mode_ramrod_params
*p
)
2093 /* update the bp MAC filter structure */
2094 u32 mask
= (1 << p
->cl_id
);
2096 struct tstorm_eth_mac_filter_config
*mac_filters
=
2097 (struct tstorm_eth_mac_filter_config
*)p
->rdata
;
2099 /* initial seeting is drop-all */
2100 u8 drop_all_ucast
= 1, drop_all_mcast
= 1;
2101 u8 accp_all_ucast
= 0, accp_all_bcast
= 0, accp_all_mcast
= 0;
2102 u8 unmatched_unicast
= 0;
2104 /* In e1x there we only take into account rx acceot flag since tx switching
2106 if (test_bit(BNX2X_ACCEPT_UNICAST
, &p
->rx_accept_flags
))
2107 /* accept matched ucast */
2110 if (test_bit(BNX2X_ACCEPT_MULTICAST
, &p
->rx_accept_flags
))
2111 /* accept matched mcast */
2114 if (test_bit(BNX2X_ACCEPT_ALL_UNICAST
, &p
->rx_accept_flags
)) {
2115 /* accept all mcast */
2119 if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST
, &p
->rx_accept_flags
)) {
2120 /* accept all mcast */
2124 if (test_bit(BNX2X_ACCEPT_BROADCAST
, &p
->rx_accept_flags
))
2125 /* accept (all) bcast */
2127 if (test_bit(BNX2X_ACCEPT_UNMATCHED
, &p
->rx_accept_flags
))
2128 /* accept unmatched unicasts */
2129 unmatched_unicast
= 1;
2131 mac_filters
->ucast_drop_all
= drop_all_ucast
?
2132 mac_filters
->ucast_drop_all
| mask
:
2133 mac_filters
->ucast_drop_all
& ~mask
;
2135 mac_filters
->mcast_drop_all
= drop_all_mcast
?
2136 mac_filters
->mcast_drop_all
| mask
:
2137 mac_filters
->mcast_drop_all
& ~mask
;
2139 mac_filters
->ucast_accept_all
= accp_all_ucast
?
2140 mac_filters
->ucast_accept_all
| mask
:
2141 mac_filters
->ucast_accept_all
& ~mask
;
2143 mac_filters
->mcast_accept_all
= accp_all_mcast
?
2144 mac_filters
->mcast_accept_all
| mask
:
2145 mac_filters
->mcast_accept_all
& ~mask
;
2147 mac_filters
->bcast_accept_all
= accp_all_bcast
?
2148 mac_filters
->bcast_accept_all
| mask
:
2149 mac_filters
->bcast_accept_all
& ~mask
;
2151 mac_filters
->unmatched_unicast
= unmatched_unicast
?
2152 mac_filters
->unmatched_unicast
| mask
:
2153 mac_filters
->unmatched_unicast
& ~mask
;
2155 DP(BNX2X_MSG_SP
, "drop_ucast 0x%x\ndrop_mcast 0x%x\n accp_ucast 0x%x\n"
2156 "accp_mcast 0x%x\naccp_bcast 0x%x\n",
2157 mac_filters
->ucast_drop_all
,
2158 mac_filters
->mcast_drop_all
,
2159 mac_filters
->ucast_accept_all
,
2160 mac_filters
->mcast_accept_all
,
2161 mac_filters
->bcast_accept_all
);
2163 /* write the MAC filter structure*/
2164 __storm_memset_mac_filters(bp
, mac_filters
, p
->func_id
);
2166 /* The operation is completed */
2167 clear_bit(p
->state
, p
->pstate
);
2168 smp_mb__after_clear_bit();
2173 /* Setup ramrod data */
2174 static inline void bnx2x_rx_mode_set_rdata_hdr_e2(u32 cid
,
2175 struct eth_classify_header
*hdr
,
2179 hdr
->rule_cnt
= rule_cnt
;
2182 static inline void bnx2x_rx_mode_set_cmd_state_e2(struct bnx2x
*bp
,
2183 unsigned long accept_flags
,
2184 struct eth_filter_rules_cmd
*cmd
,
2185 bool clear_accept_all
)
2189 /* start with 'drop-all' */
2190 state
= ETH_FILTER_RULES_CMD_UCAST_DROP_ALL
|
2191 ETH_FILTER_RULES_CMD_MCAST_DROP_ALL
;
2194 if (test_bit(BNX2X_ACCEPT_UNICAST
, &accept_flags
))
2195 state
&= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL
;
2197 if (test_bit(BNX2X_ACCEPT_MULTICAST
, &accept_flags
))
2198 state
&= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL
;
2200 if (test_bit(BNX2X_ACCEPT_ALL_UNICAST
, &accept_flags
)) {
2201 state
&= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL
;
2202 state
|= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL
;
2205 if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST
, &accept_flags
)) {
2206 state
|= ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL
;
2207 state
&= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL
;
2209 if (test_bit(BNX2X_ACCEPT_BROADCAST
, &accept_flags
))
2210 state
|= ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL
;
2212 if (test_bit(BNX2X_ACCEPT_UNMATCHED
, &accept_flags
)) {
2213 state
&= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL
;
2214 state
|= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED
;
2216 if (test_bit(BNX2X_ACCEPT_ANY_VLAN
, &accept_flags
))
2217 state
|= ETH_FILTER_RULES_CMD_ACCEPT_ANY_VLAN
;
2220 /* Clear ACCEPT_ALL_XXX flags for FCoE L2 Queue */
2221 if (clear_accept_all
) {
2222 state
&= ~ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL
;
2223 state
&= ~ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL
;
2224 state
&= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL
;
2225 state
&= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED
;
2228 cmd
->state
= cpu_to_le16(state
);
2232 static int bnx2x_set_rx_mode_e2(struct bnx2x
*bp
,
2233 struct bnx2x_rx_mode_ramrod_params
*p
)
2235 struct eth_filter_rules_ramrod_data
*data
= p
->rdata
;
2239 /* Reset the ramrod data buffer */
2240 memset(data
, 0, sizeof(*data
));
2242 /* Setup ramrod data */
2244 /* Tx (internal switching) */
2245 if (test_bit(RAMROD_TX
, &p
->ramrod_flags
)) {
2246 data
->rules
[rule_idx
].client_id
= p
->cl_id
;
2247 data
->rules
[rule_idx
].func_id
= p
->func_id
;
2249 data
->rules
[rule_idx
].cmd_general_data
=
2250 ETH_FILTER_RULES_CMD_TX_CMD
;
2252 bnx2x_rx_mode_set_cmd_state_e2(bp
, p
->tx_accept_flags
,
2253 &(data
->rules
[rule_idx
++]), false);
2257 if (test_bit(RAMROD_RX
, &p
->ramrod_flags
)) {
2258 data
->rules
[rule_idx
].client_id
= p
->cl_id
;
2259 data
->rules
[rule_idx
].func_id
= p
->func_id
;
2261 data
->rules
[rule_idx
].cmd_general_data
=
2262 ETH_FILTER_RULES_CMD_RX_CMD
;
2264 bnx2x_rx_mode_set_cmd_state_e2(bp
, p
->rx_accept_flags
,
2265 &(data
->rules
[rule_idx
++]), false);
2270 * If FCoE Queue configuration has been requested configure the Rx and
2271 * internal switching modes for this queue in separate rules.
2273 * FCoE queue shell never be set to ACCEPT_ALL packets of any sort:
2274 * MCAST_ALL, UCAST_ALL, BCAST_ALL and UNMATCHED.
2276 if (test_bit(BNX2X_RX_MODE_FCOE_ETH
, &p
->rx_mode_flags
)) {
2277 /* Tx (internal switching) */
2278 if (test_bit(RAMROD_TX
, &p
->ramrod_flags
)) {
2279 data
->rules
[rule_idx
].client_id
= bnx2x_fcoe(bp
, cl_id
);
2280 data
->rules
[rule_idx
].func_id
= p
->func_id
;
2282 data
->rules
[rule_idx
].cmd_general_data
=
2283 ETH_FILTER_RULES_CMD_TX_CMD
;
2285 bnx2x_rx_mode_set_cmd_state_e2(bp
, p
->tx_accept_flags
,
2286 &(data
->rules
[rule_idx
++]),
2291 if (test_bit(RAMROD_RX
, &p
->ramrod_flags
)) {
2292 data
->rules
[rule_idx
].client_id
= bnx2x_fcoe(bp
, cl_id
);
2293 data
->rules
[rule_idx
].func_id
= p
->func_id
;
2295 data
->rules
[rule_idx
].cmd_general_data
=
2296 ETH_FILTER_RULES_CMD_RX_CMD
;
2298 bnx2x_rx_mode_set_cmd_state_e2(bp
, p
->rx_accept_flags
,
2299 &(data
->rules
[rule_idx
++]),
2305 * Set the ramrod header (most importantly - number of rules to
2308 bnx2x_rx_mode_set_rdata_hdr_e2(p
->cid
, &data
->header
, rule_idx
);
2310 DP(BNX2X_MSG_SP
, "About to configure %d rules, rx_accept_flags 0x%lx, "
2311 "tx_accept_flags 0x%lx\n",
2312 data
->header
.rule_cnt
, p
->rx_accept_flags
,
2313 p
->tx_accept_flags
);
2316 * No need for an explicit memory barrier here as long we would
2317 * need to ensure the ordering of writing to the SPQ element
2318 * and updating of the SPQ producer which involves a memory
2319 * read and we will have to put a full memory barrier there
2320 * (inside bnx2x_sp_post()).
2324 rc
= bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_FILTER_RULES
, p
->cid
,
2325 U64_HI(p
->rdata_mapping
),
2326 U64_LO(p
->rdata_mapping
),
2327 ETH_CONNECTION_TYPE
);
2331 /* Ramrod completion is pending */
2335 static int bnx2x_wait_rx_mode_comp_e2(struct bnx2x
*bp
,
2336 struct bnx2x_rx_mode_ramrod_params
*p
)
2338 return bnx2x_state_wait(bp
, p
->state
, p
->pstate
);
2341 static int bnx2x_empty_rx_mode_wait(struct bnx2x
*bp
,
2342 struct bnx2x_rx_mode_ramrod_params
*p
)
2348 int bnx2x_config_rx_mode(struct bnx2x
*bp
,
2349 struct bnx2x_rx_mode_ramrod_params
*p
)
2353 /* Configure the new classification in the chip */
2354 rc
= p
->rx_mode_obj
->config_rx_mode(bp
, p
);
2358 /* Wait for a ramrod completion if was requested */
2359 if (test_bit(RAMROD_COMP_WAIT
, &p
->ramrod_flags
)) {
2360 rc
= p
->rx_mode_obj
->wait_comp(bp
, p
);
2368 void bnx2x_init_rx_mode_obj(struct bnx2x
*bp
,
2369 struct bnx2x_rx_mode_obj
*o
)
2371 if (CHIP_IS_E1x(bp
)) {
2372 o
->wait_comp
= bnx2x_empty_rx_mode_wait
;
2373 o
->config_rx_mode
= bnx2x_set_rx_mode_e1x
;
2375 o
->wait_comp
= bnx2x_wait_rx_mode_comp_e2
;
2376 o
->config_rx_mode
= bnx2x_set_rx_mode_e2
;
2380 /********************* Multicast verbs: SET, CLEAR ****************************/
2381 static inline u8
bnx2x_mcast_bin_from_mac(u8
*mac
)
2383 return (crc32c_le(0, mac
, ETH_ALEN
) >> 24) & 0xff;
2386 struct bnx2x_mcast_mac_elem
{
2387 struct list_head link
;
2389 u8 pad
[2]; /* For a natural alignment of the following buffer */
2392 struct bnx2x_pending_mcast_cmd
{
2393 struct list_head link
;
2394 int type
; /* BNX2X_MCAST_CMD_X */
2396 struct list_head macs_head
;
2397 u32 macs_num
; /* Needed for DEL command */
2398 int next_bin
; /* Needed for RESTORE flow with aprox match */
2401 bool done
; /* set to true, when the command has been handled,
2402 * practically used in 57712 handling only, where one pending
2403 * command may be handled in a few operations. As long as for
2404 * other chips every operation handling is completed in a
2405 * single ramrod, there is no need to utilize this field.
2409 static int bnx2x_mcast_wait(struct bnx2x
*bp
,
2410 struct bnx2x_mcast_obj
*o
)
2412 if (bnx2x_state_wait(bp
, o
->sched_state
, o
->raw
.pstate
) ||
2413 o
->raw
.wait_comp(bp
, &o
->raw
))
2419 static int bnx2x_mcast_enqueue_cmd(struct bnx2x
*bp
,
2420 struct bnx2x_mcast_obj
*o
,
2421 struct bnx2x_mcast_ramrod_params
*p
,
2425 struct bnx2x_pending_mcast_cmd
*new_cmd
;
2426 struct bnx2x_mcast_mac_elem
*cur_mac
= NULL
;
2427 struct bnx2x_mcast_list_elem
*pos
;
2428 int macs_list_len
= ((cmd
== BNX2X_MCAST_CMD_ADD
) ?
2429 p
->mcast_list_len
: 0);
2431 /* If the command is empty ("handle pending commands only"), break */
2432 if (!p
->mcast_list_len
)
2435 total_sz
= sizeof(*new_cmd
) +
2436 macs_list_len
* sizeof(struct bnx2x_mcast_mac_elem
);
2438 /* Add mcast is called under spin_lock, thus calling with GFP_ATOMIC */
2439 new_cmd
= kzalloc(total_sz
, GFP_ATOMIC
);
2444 DP(BNX2X_MSG_SP
, "About to enqueue a new %d command. "
2445 "macs_list_len=%d\n", cmd
, macs_list_len
);
2447 INIT_LIST_HEAD(&new_cmd
->data
.macs_head
);
2449 new_cmd
->type
= cmd
;
2450 new_cmd
->done
= false;
2453 case BNX2X_MCAST_CMD_ADD
:
2454 cur_mac
= (struct bnx2x_mcast_mac_elem
*)
2455 ((u8
*)new_cmd
+ sizeof(*new_cmd
));
2457 /* Push the MACs of the current command into the pendig command
2460 list_for_each_entry(pos
, &p
->mcast_list
, link
) {
2461 memcpy(cur_mac
->mac
, pos
->mac
, ETH_ALEN
);
2462 list_add_tail(&cur_mac
->link
, &new_cmd
->data
.macs_head
);
2468 case BNX2X_MCAST_CMD_DEL
:
2469 new_cmd
->data
.macs_num
= p
->mcast_list_len
;
2472 case BNX2X_MCAST_CMD_RESTORE
:
2473 new_cmd
->data
.next_bin
= 0;
2477 BNX2X_ERR("Unknown command: %d\n", cmd
);
2481 /* Push the new pending command to the tail of the pending list: FIFO */
2482 list_add_tail(&new_cmd
->link
, &o
->pending_cmds_head
);
2490 * bnx2x_mcast_get_next_bin - get the next set bin (index)
2493 * @last: index to start looking from (including)
2495 * returns the next found (set) bin or a negative value if none is found.
2497 static inline int bnx2x_mcast_get_next_bin(struct bnx2x_mcast_obj
*o
, int last
)
2499 int i
, j
, inner_start
= last
% BIT_VEC64_ELEM_SZ
;
2501 for (i
= last
/ BIT_VEC64_ELEM_SZ
; i
< BNX2X_MCAST_VEC_SZ
; i
++) {
2502 if (o
->registry
.aprox_match
.vec
[i
])
2503 for (j
= inner_start
; j
< BIT_VEC64_ELEM_SZ
; j
++) {
2504 int cur_bit
= j
+ BIT_VEC64_ELEM_SZ
* i
;
2505 if (BIT_VEC64_TEST_BIT(o
->registry
.aprox_match
.
2518 * bnx2x_mcast_clear_first_bin - find the first set bin and clear it
2522 * returns the index of the found bin or -1 if none is found
2524 static inline int bnx2x_mcast_clear_first_bin(struct bnx2x_mcast_obj
*o
)
2526 int cur_bit
= bnx2x_mcast_get_next_bin(o
, 0);
2529 BIT_VEC64_CLEAR_BIT(o
->registry
.aprox_match
.vec
, cur_bit
);
2534 static inline u8
bnx2x_mcast_get_rx_tx_flag(struct bnx2x_mcast_obj
*o
)
2536 struct bnx2x_raw_obj
*raw
= &o
->raw
;
2539 if ((raw
->obj_type
== BNX2X_OBJ_TYPE_TX
) ||
2540 (raw
->obj_type
== BNX2X_OBJ_TYPE_RX_TX
))
2541 rx_tx_flag
|= ETH_MULTICAST_RULES_CMD_TX_CMD
;
2543 if ((raw
->obj_type
== BNX2X_OBJ_TYPE_RX
) ||
2544 (raw
->obj_type
== BNX2X_OBJ_TYPE_RX_TX
))
2545 rx_tx_flag
|= ETH_MULTICAST_RULES_CMD_RX_CMD
;
2550 static void bnx2x_mcast_set_one_rule_e2(struct bnx2x
*bp
,
2551 struct bnx2x_mcast_obj
*o
, int idx
,
2552 union bnx2x_mcast_config_data
*cfg_data
,
2555 struct bnx2x_raw_obj
*r
= &o
->raw
;
2556 struct eth_multicast_rules_ramrod_data
*data
=
2557 (struct eth_multicast_rules_ramrod_data
*)(r
->rdata
);
2558 u8 func_id
= r
->func_id
;
2559 u8 rx_tx_add_flag
= bnx2x_mcast_get_rx_tx_flag(o
);
2562 if ((cmd
== BNX2X_MCAST_CMD_ADD
) || (cmd
== BNX2X_MCAST_CMD_RESTORE
))
2563 rx_tx_add_flag
|= ETH_MULTICAST_RULES_CMD_IS_ADD
;
2565 data
->rules
[idx
].cmd_general_data
|= rx_tx_add_flag
;
2567 /* Get a bin and update a bins' vector */
2569 case BNX2X_MCAST_CMD_ADD
:
2570 bin
= bnx2x_mcast_bin_from_mac(cfg_data
->mac
);
2571 BIT_VEC64_SET_BIT(o
->registry
.aprox_match
.vec
, bin
);
2574 case BNX2X_MCAST_CMD_DEL
:
2575 /* If there were no more bins to clear
2576 * (bnx2x_mcast_clear_first_bin() returns -1) then we would
2577 * clear any (0xff) bin.
2578 * See bnx2x_mcast_validate_e2() for explanation when it may
2581 bin
= bnx2x_mcast_clear_first_bin(o
);
2584 case BNX2X_MCAST_CMD_RESTORE
:
2585 bin
= cfg_data
->bin
;
2589 BNX2X_ERR("Unknown command: %d\n", cmd
);
2593 DP(BNX2X_MSG_SP
, "%s bin %d\n",
2594 ((rx_tx_add_flag
& ETH_MULTICAST_RULES_CMD_IS_ADD
) ?
2595 "Setting" : "Clearing"), bin
);
2597 data
->rules
[idx
].bin_id
= (u8
)bin
;
2598 data
->rules
[idx
].func_id
= func_id
;
2599 data
->rules
[idx
].engine_id
= o
->engine_id
;
2603 * bnx2x_mcast_handle_restore_cmd_e2 - restore configuration from the registry
2605 * @bp: device handle
2607 * @start_bin: index in the registry to start from (including)
2608 * @rdata_idx: index in the ramrod data to start from
2610 * returns last handled bin index or -1 if all bins have been handled
2612 static inline int bnx2x_mcast_handle_restore_cmd_e2(
2613 struct bnx2x
*bp
, struct bnx2x_mcast_obj
*o
, int start_bin
,
2616 int cur_bin
, cnt
= *rdata_idx
;
2617 union bnx2x_mcast_config_data cfg_data
= {0};
2619 /* go through the registry and configure the bins from it */
2620 for (cur_bin
= bnx2x_mcast_get_next_bin(o
, start_bin
); cur_bin
>= 0;
2621 cur_bin
= bnx2x_mcast_get_next_bin(o
, cur_bin
+ 1)) {
2623 cfg_data
.bin
= (u8
)cur_bin
;
2624 o
->set_one_rule(bp
, o
, cnt
, &cfg_data
,
2625 BNX2X_MCAST_CMD_RESTORE
);
2629 DP(BNX2X_MSG_SP
, "About to configure a bin %d\n", cur_bin
);
2631 /* Break if we reached the maximum number
2634 if (cnt
>= o
->max_cmd_len
)
2643 static inline void bnx2x_mcast_hdl_pending_add_e2(struct bnx2x
*bp
,
2644 struct bnx2x_mcast_obj
*o
, struct bnx2x_pending_mcast_cmd
*cmd_pos
,
2647 struct bnx2x_mcast_mac_elem
*pmac_pos
, *pmac_pos_n
;
2648 int cnt
= *line_idx
;
2649 union bnx2x_mcast_config_data cfg_data
= {0};
2651 list_for_each_entry_safe(pmac_pos
, pmac_pos_n
, &cmd_pos
->data
.macs_head
,
2654 cfg_data
.mac
= &pmac_pos
->mac
[0];
2655 o
->set_one_rule(bp
, o
, cnt
, &cfg_data
, cmd_pos
->type
);
2659 DP(BNX2X_MSG_SP
, "About to configure %pM mcast MAC\n",
2662 list_del(&pmac_pos
->link
);
2664 /* Break if we reached the maximum number
2667 if (cnt
>= o
->max_cmd_len
)
2673 /* if no more MACs to configure - we are done */
2674 if (list_empty(&cmd_pos
->data
.macs_head
))
2675 cmd_pos
->done
= true;
2678 static inline void bnx2x_mcast_hdl_pending_del_e2(struct bnx2x
*bp
,
2679 struct bnx2x_mcast_obj
*o
, struct bnx2x_pending_mcast_cmd
*cmd_pos
,
2682 int cnt
= *line_idx
;
2684 while (cmd_pos
->data
.macs_num
) {
2685 o
->set_one_rule(bp
, o
, cnt
, NULL
, cmd_pos
->type
);
2689 cmd_pos
->data
.macs_num
--;
2691 DP(BNX2X_MSG_SP
, "Deleting MAC. %d left,cnt is %d\n",
2692 cmd_pos
->data
.macs_num
, cnt
);
2694 /* Break if we reached the maximum
2697 if (cnt
>= o
->max_cmd_len
)
2703 /* If we cleared all bins - we are done */
2704 if (!cmd_pos
->data
.macs_num
)
2705 cmd_pos
->done
= true;
2708 static inline void bnx2x_mcast_hdl_pending_restore_e2(struct bnx2x
*bp
,
2709 struct bnx2x_mcast_obj
*o
, struct bnx2x_pending_mcast_cmd
*cmd_pos
,
2712 cmd_pos
->data
.next_bin
= o
->hdl_restore(bp
, o
, cmd_pos
->data
.next_bin
,
2715 if (cmd_pos
->data
.next_bin
< 0)
2716 /* If o->set_restore returned -1 we are done */
2717 cmd_pos
->done
= true;
2719 /* Start from the next bin next time */
2720 cmd_pos
->data
.next_bin
++;
2723 static inline int bnx2x_mcast_handle_pending_cmds_e2(struct bnx2x
*bp
,
2724 struct bnx2x_mcast_ramrod_params
*p
)
2726 struct bnx2x_pending_mcast_cmd
*cmd_pos
, *cmd_pos_n
;
2728 struct bnx2x_mcast_obj
*o
= p
->mcast_obj
;
2730 list_for_each_entry_safe(cmd_pos
, cmd_pos_n
, &o
->pending_cmds_head
,
2732 switch (cmd_pos
->type
) {
2733 case BNX2X_MCAST_CMD_ADD
:
2734 bnx2x_mcast_hdl_pending_add_e2(bp
, o
, cmd_pos
, &cnt
);
2737 case BNX2X_MCAST_CMD_DEL
:
2738 bnx2x_mcast_hdl_pending_del_e2(bp
, o
, cmd_pos
, &cnt
);
2741 case BNX2X_MCAST_CMD_RESTORE
:
2742 bnx2x_mcast_hdl_pending_restore_e2(bp
, o
, cmd_pos
,
2747 BNX2X_ERR("Unknown command: %d\n", cmd_pos
->type
);
2751 /* If the command has been completed - remove it from the list
2752 * and free the memory
2754 if (cmd_pos
->done
) {
2755 list_del(&cmd_pos
->link
);
2759 /* Break if we reached the maximum number of rules */
2760 if (cnt
>= o
->max_cmd_len
)
2767 static inline void bnx2x_mcast_hdl_add(struct bnx2x
*bp
,
2768 struct bnx2x_mcast_obj
*o
, struct bnx2x_mcast_ramrod_params
*p
,
2771 struct bnx2x_mcast_list_elem
*mlist_pos
;
2772 union bnx2x_mcast_config_data cfg_data
= {0};
2773 int cnt
= *line_idx
;
2775 list_for_each_entry(mlist_pos
, &p
->mcast_list
, link
) {
2776 cfg_data
.mac
= mlist_pos
->mac
;
2777 o
->set_one_rule(bp
, o
, cnt
, &cfg_data
, BNX2X_MCAST_CMD_ADD
);
2781 DP(BNX2X_MSG_SP
, "About to configure %pM mcast MAC\n",
2788 static inline void bnx2x_mcast_hdl_del(struct bnx2x
*bp
,
2789 struct bnx2x_mcast_obj
*o
, struct bnx2x_mcast_ramrod_params
*p
,
2792 int cnt
= *line_idx
, i
;
2794 for (i
= 0; i
< p
->mcast_list_len
; i
++) {
2795 o
->set_one_rule(bp
, o
, cnt
, NULL
, BNX2X_MCAST_CMD_DEL
);
2799 DP(BNX2X_MSG_SP
, "Deleting MAC. %d left\n",
2800 p
->mcast_list_len
- i
- 1);
2807 * bnx2x_mcast_handle_current_cmd -
2809 * @bp: device handle
2812 * @start_cnt: first line in the ramrod data that may be used
2814 * This function is called iff there is enough place for the current command in
2816 * Returns number of lines filled in the ramrod data in total.
2818 static inline int bnx2x_mcast_handle_current_cmd(struct bnx2x
*bp
,
2819 struct bnx2x_mcast_ramrod_params
*p
, int cmd
,
2822 struct bnx2x_mcast_obj
*o
= p
->mcast_obj
;
2823 int cnt
= start_cnt
;
2825 DP(BNX2X_MSG_SP
, "p->mcast_list_len=%d\n", p
->mcast_list_len
);
2828 case BNX2X_MCAST_CMD_ADD
:
2829 bnx2x_mcast_hdl_add(bp
, o
, p
, &cnt
);
2832 case BNX2X_MCAST_CMD_DEL
:
2833 bnx2x_mcast_hdl_del(bp
, o
, p
, &cnt
);
2836 case BNX2X_MCAST_CMD_RESTORE
:
2837 o
->hdl_restore(bp
, o
, 0, &cnt
);
2841 BNX2X_ERR("Unknown command: %d\n", cmd
);
2845 /* The current command has been handled */
2846 p
->mcast_list_len
= 0;
2851 static int bnx2x_mcast_validate_e2(struct bnx2x
*bp
,
2852 struct bnx2x_mcast_ramrod_params
*p
,
2855 struct bnx2x_mcast_obj
*o
= p
->mcast_obj
;
2856 int reg_sz
= o
->get_registry_size(o
);
2859 /* DEL command deletes all currently configured MACs */
2860 case BNX2X_MCAST_CMD_DEL
:
2861 o
->set_registry_size(o
, 0);
2864 /* RESTORE command will restore the entire multicast configuration */
2865 case BNX2X_MCAST_CMD_RESTORE
:
2866 /* Here we set the approximate amount of work to do, which in
2867 * fact may be only less as some MACs in postponed ADD
2868 * command(s) scheduled before this command may fall into
2869 * the same bin and the actual number of bins set in the
2870 * registry would be less than we estimated here. See
2871 * bnx2x_mcast_set_one_rule_e2() for further details.
2873 p
->mcast_list_len
= reg_sz
;
2876 case BNX2X_MCAST_CMD_ADD
:
2877 case BNX2X_MCAST_CMD_CONT
:
2878 /* Here we assume that all new MACs will fall into new bins.
2879 * However we will correct the real registry size after we
2880 * handle all pending commands.
2882 o
->set_registry_size(o
, reg_sz
+ p
->mcast_list_len
);
2886 BNX2X_ERR("Unknown command: %d\n", cmd
);
2891 /* Increase the total number of MACs pending to be configured */
2892 o
->total_pending_num
+= p
->mcast_list_len
;
2897 static void bnx2x_mcast_revert_e2(struct bnx2x
*bp
,
2898 struct bnx2x_mcast_ramrod_params
*p
,
2901 struct bnx2x_mcast_obj
*o
= p
->mcast_obj
;
2903 o
->set_registry_size(o
, old_num_bins
);
2904 o
->total_pending_num
-= p
->mcast_list_len
;
2908 * bnx2x_mcast_set_rdata_hdr_e2 - sets a header values
2910 * @bp: device handle
2912 * @len: number of rules to handle
2914 static inline void bnx2x_mcast_set_rdata_hdr_e2(struct bnx2x
*bp
,
2915 struct bnx2x_mcast_ramrod_params
*p
,
2918 struct bnx2x_raw_obj
*r
= &p
->mcast_obj
->raw
;
2919 struct eth_multicast_rules_ramrod_data
*data
=
2920 (struct eth_multicast_rules_ramrod_data
*)(r
->rdata
);
2922 data
->header
.echo
= ((r
->cid
& BNX2X_SWCID_MASK
) |
2923 (BNX2X_FILTER_MCAST_PENDING
<< BNX2X_SWCID_SHIFT
));
2924 data
->header
.rule_cnt
= len
;
2928 * bnx2x_mcast_refresh_registry_e2 - recalculate the actual number of set bins
2930 * @bp: device handle
2933 * Recalculate the actual number of set bins in the registry using Brian
2934 * Kernighan's algorithm: it's execution complexity is as a number of set bins.
2936 * returns 0 for the compliance with bnx2x_mcast_refresh_registry_e1().
2938 static inline int bnx2x_mcast_refresh_registry_e2(struct bnx2x
*bp
,
2939 struct bnx2x_mcast_obj
*o
)
2944 for (i
= 0; i
< BNX2X_MCAST_VEC_SZ
; i
++) {
2945 elem
= o
->registry
.aprox_match
.vec
[i
];
2950 o
->set_registry_size(o
, cnt
);
2955 static int bnx2x_mcast_setup_e2(struct bnx2x
*bp
,
2956 struct bnx2x_mcast_ramrod_params
*p
,
2959 struct bnx2x_raw_obj
*raw
= &p
->mcast_obj
->raw
;
2960 struct bnx2x_mcast_obj
*o
= p
->mcast_obj
;
2961 struct eth_multicast_rules_ramrod_data
*data
=
2962 (struct eth_multicast_rules_ramrod_data
*)(raw
->rdata
);
2965 /* Reset the ramrod data buffer */
2966 memset(data
, 0, sizeof(*data
));
2968 cnt
= bnx2x_mcast_handle_pending_cmds_e2(bp
, p
);
2970 /* If there are no more pending commands - clear SCHEDULED state */
2971 if (list_empty(&o
->pending_cmds_head
))
2974 /* The below may be true iff there was enough room in ramrod
2975 * data for all pending commands and for the current
2976 * command. Otherwise the current command would have been added
2977 * to the pending commands and p->mcast_list_len would have been
2980 if (p
->mcast_list_len
> 0)
2981 cnt
= bnx2x_mcast_handle_current_cmd(bp
, p
, cmd
, cnt
);
2983 /* We've pulled out some MACs - update the total number of
2986 o
->total_pending_num
-= cnt
;
2989 WARN_ON(o
->total_pending_num
< 0);
2990 WARN_ON(cnt
> o
->max_cmd_len
);
2992 bnx2x_mcast_set_rdata_hdr_e2(bp
, p
, (u8
)cnt
);
2994 /* Update a registry size if there are no more pending operations.
2996 * We don't want to change the value of the registry size if there are
2997 * pending operations because we want it to always be equal to the
2998 * exact or the approximate number (see bnx2x_mcast_validate_e2()) of
2999 * set bins after the last requested operation in order to properly
3000 * evaluate the size of the next DEL/RESTORE operation.
3002 * Note that we update the registry itself during command(s) handling
3003 * - see bnx2x_mcast_set_one_rule_e2(). That's because for 57712 we
3004 * aggregate multiple commands (ADD/DEL/RESTORE) into one ramrod but
3005 * with a limited amount of update commands (per MAC/bin) and we don't
3006 * know in this scope what the actual state of bins configuration is
3007 * going to be after this ramrod.
3009 if (!o
->total_pending_num
)
3010 bnx2x_mcast_refresh_registry_e2(bp
, o
);
3013 * If CLEAR_ONLY was requested - don't send a ramrod and clear
3014 * RAMROD_PENDING status immediately.
3016 if (test_bit(RAMROD_DRV_CLR_ONLY
, &p
->ramrod_flags
)) {
3017 raw
->clear_pending(raw
);
3021 * No need for an explicit memory barrier here as long we would
3022 * need to ensure the ordering of writing to the SPQ element
3023 * and updating of the SPQ producer which involves a memory
3024 * read and we will have to put a full memory barrier there
3025 * (inside bnx2x_sp_post()).
3029 rc
= bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_MULTICAST_RULES
,
3030 raw
->cid
, U64_HI(raw
->rdata_mapping
),
3031 U64_LO(raw
->rdata_mapping
),
3032 ETH_CONNECTION_TYPE
);
3036 /* Ramrod completion is pending */
3041 static int bnx2x_mcast_validate_e1h(struct bnx2x
*bp
,
3042 struct bnx2x_mcast_ramrod_params
*p
,
3045 /* Mark, that there is a work to do */
3046 if ((cmd
== BNX2X_MCAST_CMD_DEL
) || (cmd
== BNX2X_MCAST_CMD_RESTORE
))
3047 p
->mcast_list_len
= 1;
3052 static void bnx2x_mcast_revert_e1h(struct bnx2x
*bp
,
3053 struct bnx2x_mcast_ramrod_params
*p
,
3059 #define BNX2X_57711_SET_MC_FILTER(filter, bit) \
3061 (filter)[(bit) >> 5] |= (1 << ((bit) & 0x1f)); \
3064 static inline void bnx2x_mcast_hdl_add_e1h(struct bnx2x
*bp
,
3065 struct bnx2x_mcast_obj
*o
,
3066 struct bnx2x_mcast_ramrod_params
*p
,
3069 struct bnx2x_mcast_list_elem
*mlist_pos
;
3072 list_for_each_entry(mlist_pos
, &p
->mcast_list
, link
) {
3073 bit
= bnx2x_mcast_bin_from_mac(mlist_pos
->mac
);
3074 BNX2X_57711_SET_MC_FILTER(mc_filter
, bit
);
3076 DP(BNX2X_MSG_SP
, "About to configure %pM mcast MAC, bin %d\n",
3077 mlist_pos
->mac
, bit
);
3079 /* bookkeeping... */
3080 BIT_VEC64_SET_BIT(o
->registry
.aprox_match
.vec
,
3085 static inline void bnx2x_mcast_hdl_restore_e1h(struct bnx2x
*bp
,
3086 struct bnx2x_mcast_obj
*o
, struct bnx2x_mcast_ramrod_params
*p
,
3091 for (bit
= bnx2x_mcast_get_next_bin(o
, 0);
3093 bit
= bnx2x_mcast_get_next_bin(o
, bit
+ 1)) {
3094 BNX2X_57711_SET_MC_FILTER(mc_filter
, bit
);
3095 DP(BNX2X_MSG_SP
, "About to set bin %d\n", bit
);
3099 /* On 57711 we write the multicast MACs' aproximate match
3100 * table by directly into the TSTORM's internal RAM. So we don't
3101 * really need to handle any tricks to make it work.
3103 static int bnx2x_mcast_setup_e1h(struct bnx2x
*bp
,
3104 struct bnx2x_mcast_ramrod_params
*p
,
3108 struct bnx2x_mcast_obj
*o
= p
->mcast_obj
;
3109 struct bnx2x_raw_obj
*r
= &o
->raw
;
3111 /* If CLEAR_ONLY has been requested - clear the registry
3112 * and clear a pending bit.
3114 if (!test_bit(RAMROD_DRV_CLR_ONLY
, &p
->ramrod_flags
)) {
3115 u32 mc_filter
[MC_HASH_SIZE
] = {0};
3117 /* Set the multicast filter bits before writing it into
3118 * the internal memory.
3121 case BNX2X_MCAST_CMD_ADD
:
3122 bnx2x_mcast_hdl_add_e1h(bp
, o
, p
, mc_filter
);
3125 case BNX2X_MCAST_CMD_DEL
:
3127 "Invalidating multicast MACs configuration\n");
3129 /* clear the registry */
3130 memset(o
->registry
.aprox_match
.vec
, 0,
3131 sizeof(o
->registry
.aprox_match
.vec
));
3134 case BNX2X_MCAST_CMD_RESTORE
:
3135 bnx2x_mcast_hdl_restore_e1h(bp
, o
, p
, mc_filter
);
3139 BNX2X_ERR("Unknown command: %d\n", cmd
);
3143 /* Set the mcast filter in the internal memory */
3144 for (i
= 0; i
< MC_HASH_SIZE
; i
++)
3145 REG_WR(bp
, MC_HASH_OFFSET(bp
, i
), mc_filter
[i
]);
3147 /* clear the registry */
3148 memset(o
->registry
.aprox_match
.vec
, 0,
3149 sizeof(o
->registry
.aprox_match
.vec
));
3152 r
->clear_pending(r
);
3157 static int bnx2x_mcast_validate_e1(struct bnx2x
*bp
,
3158 struct bnx2x_mcast_ramrod_params
*p
,
3161 struct bnx2x_mcast_obj
*o
= p
->mcast_obj
;
3162 int reg_sz
= o
->get_registry_size(o
);
3165 /* DEL command deletes all currently configured MACs */
3166 case BNX2X_MCAST_CMD_DEL
:
3167 o
->set_registry_size(o
, 0);
3170 /* RESTORE command will restore the entire multicast configuration */
3171 case BNX2X_MCAST_CMD_RESTORE
:
3172 p
->mcast_list_len
= reg_sz
;
3173 DP(BNX2X_MSG_SP
, "Command %d, p->mcast_list_len=%d\n",
3174 cmd
, p
->mcast_list_len
);
3177 case BNX2X_MCAST_CMD_ADD
:
3178 case BNX2X_MCAST_CMD_CONT
:
3179 /* Multicast MACs on 57710 are configured as unicast MACs and
3180 * there is only a limited number of CAM entries for that
3183 if (p
->mcast_list_len
> o
->max_cmd_len
) {
3184 BNX2X_ERR("Can't configure more than %d multicast MACs"
3185 "on 57710\n", o
->max_cmd_len
);
3188 /* Every configured MAC should be cleared if DEL command is
3189 * called. Only the last ADD command is relevant as long as
3190 * every ADD commands overrides the previous configuration.
3192 DP(BNX2X_MSG_SP
, "p->mcast_list_len=%d\n", p
->mcast_list_len
);
3193 if (p
->mcast_list_len
> 0)
3194 o
->set_registry_size(o
, p
->mcast_list_len
);
3199 BNX2X_ERR("Unknown command: %d\n", cmd
);
3204 /* We want to ensure that commands are executed one by one for 57710.
3205 * Therefore each none-empty command will consume o->max_cmd_len.
3207 if (p
->mcast_list_len
)
3208 o
->total_pending_num
+= o
->max_cmd_len
;
3213 static void bnx2x_mcast_revert_e1(struct bnx2x
*bp
,
3214 struct bnx2x_mcast_ramrod_params
*p
,
3217 struct bnx2x_mcast_obj
*o
= p
->mcast_obj
;
3219 o
->set_registry_size(o
, old_num_macs
);
3221 /* If current command hasn't been handled yet and we are
3222 * here means that it's meant to be dropped and we have to
3223 * update the number of outstandling MACs accordingly.
3225 if (p
->mcast_list_len
)
3226 o
->total_pending_num
-= o
->max_cmd_len
;
3229 static void bnx2x_mcast_set_one_rule_e1(struct bnx2x
*bp
,
3230 struct bnx2x_mcast_obj
*o
, int idx
,
3231 union bnx2x_mcast_config_data
*cfg_data
,
3234 struct bnx2x_raw_obj
*r
= &o
->raw
;
3235 struct mac_configuration_cmd
*data
=
3236 (struct mac_configuration_cmd
*)(r
->rdata
);
3239 if ((cmd
== BNX2X_MCAST_CMD_ADD
) || (cmd
== BNX2X_MCAST_CMD_RESTORE
)) {
3240 bnx2x_set_fw_mac_addr(&data
->config_table
[idx
].msb_mac_addr
,
3241 &data
->config_table
[idx
].middle_mac_addr
,
3242 &data
->config_table
[idx
].lsb_mac_addr
,
3245 data
->config_table
[idx
].vlan_id
= 0;
3246 data
->config_table
[idx
].pf_id
= r
->func_id
;
3247 data
->config_table
[idx
].clients_bit_vector
=
3248 cpu_to_le32(1 << r
->cl_id
);
3250 SET_FLAG(data
->config_table
[idx
].flags
,
3251 MAC_CONFIGURATION_ENTRY_ACTION_TYPE
,
3252 T_ETH_MAC_COMMAND_SET
);
3257 * bnx2x_mcast_set_rdata_hdr_e1 - set header values in mac_configuration_cmd
3259 * @bp: device handle
3261 * @len: number of rules to handle
3263 static inline void bnx2x_mcast_set_rdata_hdr_e1(struct bnx2x
*bp
,
3264 struct bnx2x_mcast_ramrod_params
*p
,
3267 struct bnx2x_raw_obj
*r
= &p
->mcast_obj
->raw
;
3268 struct mac_configuration_cmd
*data
=
3269 (struct mac_configuration_cmd
*)(r
->rdata
);
3271 u8 offset
= (CHIP_REV_IS_SLOW(bp
) ?
3272 BNX2X_MAX_EMUL_MULTI
*(1 + r
->func_id
) :
3273 BNX2X_MAX_MULTICAST
*(1 + r
->func_id
));
3275 data
->hdr
.offset
= offset
;
3276 data
->hdr
.client_id
= 0xff;
3277 data
->hdr
.echo
= ((r
->cid
& BNX2X_SWCID_MASK
) |
3278 (BNX2X_FILTER_MCAST_PENDING
<< BNX2X_SWCID_SHIFT
));
3279 data
->hdr
.length
= len
;
3283 * bnx2x_mcast_handle_restore_cmd_e1 - restore command for 57710
3285 * @bp: device handle
3287 * @start_idx: index in the registry to start from
3288 * @rdata_idx: index in the ramrod data to start from
3290 * restore command for 57710 is like all other commands - always a stand alone
3291 * command - start_idx and rdata_idx will always be 0. This function will always
3293 * returns -1 to comply with 57712 variant.
3295 static inline int bnx2x_mcast_handle_restore_cmd_e1(
3296 struct bnx2x
*bp
, struct bnx2x_mcast_obj
*o
, int start_idx
,
3299 struct bnx2x_mcast_mac_elem
*elem
;
3301 union bnx2x_mcast_config_data cfg_data
= {0};
3303 /* go through the registry and configure the MACs from it. */
3304 list_for_each_entry(elem
, &o
->registry
.exact_match
.macs
, link
) {
3305 cfg_data
.mac
= &elem
->mac
[0];
3306 o
->set_one_rule(bp
, o
, i
, &cfg_data
, BNX2X_MCAST_CMD_RESTORE
);
3310 DP(BNX2X_MSG_SP
, "About to configure %pM mcast MAC\n",
3320 static inline int bnx2x_mcast_handle_pending_cmds_e1(
3321 struct bnx2x
*bp
, struct bnx2x_mcast_ramrod_params
*p
)
3323 struct bnx2x_pending_mcast_cmd
*cmd_pos
;
3324 struct bnx2x_mcast_mac_elem
*pmac_pos
;
3325 struct bnx2x_mcast_obj
*o
= p
->mcast_obj
;
3326 union bnx2x_mcast_config_data cfg_data
= {0};
3330 /* If nothing to be done - return */
3331 if (list_empty(&o
->pending_cmds_head
))
3334 /* Handle the first command */
3335 cmd_pos
= list_first_entry(&o
->pending_cmds_head
,
3336 struct bnx2x_pending_mcast_cmd
, link
);
3338 switch (cmd_pos
->type
) {
3339 case BNX2X_MCAST_CMD_ADD
:
3340 list_for_each_entry(pmac_pos
, &cmd_pos
->data
.macs_head
, link
) {
3341 cfg_data
.mac
= &pmac_pos
->mac
[0];
3342 o
->set_one_rule(bp
, o
, cnt
, &cfg_data
, cmd_pos
->type
);
3346 DP(BNX2X_MSG_SP
, "About to configure %pM mcast MAC\n",
3351 case BNX2X_MCAST_CMD_DEL
:
3352 cnt
= cmd_pos
->data
.macs_num
;
3353 DP(BNX2X_MSG_SP
, "About to delete %d multicast MACs\n", cnt
);
3356 case BNX2X_MCAST_CMD_RESTORE
:
3357 o
->hdl_restore(bp
, o
, 0, &cnt
);
3361 BNX2X_ERR("Unknown command: %d\n", cmd_pos
->type
);
3365 list_del(&cmd_pos
->link
);
3372 * bnx2x_get_fw_mac_addr - revert the bnx2x_set_fw_mac_addr().
3379 static inline void bnx2x_get_fw_mac_addr(__le16
*fw_hi
, __le16
*fw_mid
,
3380 __le16
*fw_lo
, u8
*mac
)
3382 mac
[1] = ((u8
*)fw_hi
)[0];
3383 mac
[0] = ((u8
*)fw_hi
)[1];
3384 mac
[3] = ((u8
*)fw_mid
)[0];
3385 mac
[2] = ((u8
*)fw_mid
)[1];
3386 mac
[5] = ((u8
*)fw_lo
)[0];
3387 mac
[4] = ((u8
*)fw_lo
)[1];
3391 * bnx2x_mcast_refresh_registry_e1 -
3393 * @bp: device handle
3396 * Check the ramrod data first entry flag to see if it's a DELETE or ADD command
3397 * and update the registry correspondingly: if ADD - allocate a memory and add
3398 * the entries to the registry (list), if DELETE - clear the registry and free
3401 static inline int bnx2x_mcast_refresh_registry_e1(struct bnx2x
*bp
,
3402 struct bnx2x_mcast_obj
*o
)
3404 struct bnx2x_raw_obj
*raw
= &o
->raw
;
3405 struct bnx2x_mcast_mac_elem
*elem
;
3406 struct mac_configuration_cmd
*data
=
3407 (struct mac_configuration_cmd
*)(raw
->rdata
);
3409 /* If first entry contains a SET bit - the command was ADD,
3410 * otherwise - DEL_ALL
3412 if (GET_FLAG(data
->config_table
[0].flags
,
3413 MAC_CONFIGURATION_ENTRY_ACTION_TYPE
)) {
3414 int i
, len
= data
->hdr
.length
;
3416 /* Break if it was a RESTORE command */
3417 if (!list_empty(&o
->registry
.exact_match
.macs
))
3420 elem
= kcalloc(len
, sizeof(*elem
), GFP_ATOMIC
);
3422 BNX2X_ERR("Failed to allocate registry memory\n");
3426 for (i
= 0; i
< len
; i
++, elem
++) {
3427 bnx2x_get_fw_mac_addr(
3428 &data
->config_table
[i
].msb_mac_addr
,
3429 &data
->config_table
[i
].middle_mac_addr
,
3430 &data
->config_table
[i
].lsb_mac_addr
,
3432 DP(BNX2X_MSG_SP
, "Adding registry entry for [%pM]\n",
3434 list_add_tail(&elem
->link
,
3435 &o
->registry
.exact_match
.macs
);
3438 elem
= list_first_entry(&o
->registry
.exact_match
.macs
,
3439 struct bnx2x_mcast_mac_elem
, link
);
3440 DP(BNX2X_MSG_SP
, "Deleting a registry\n");
3442 INIT_LIST_HEAD(&o
->registry
.exact_match
.macs
);
3448 static int bnx2x_mcast_setup_e1(struct bnx2x
*bp
,
3449 struct bnx2x_mcast_ramrod_params
*p
,
3452 struct bnx2x_mcast_obj
*o
= p
->mcast_obj
;
3453 struct bnx2x_raw_obj
*raw
= &o
->raw
;
3454 struct mac_configuration_cmd
*data
=
3455 (struct mac_configuration_cmd
*)(raw
->rdata
);
3458 /* Reset the ramrod data buffer */
3459 memset(data
, 0, sizeof(*data
));
3461 /* First set all entries as invalid */
3462 for (i
= 0; i
< o
->max_cmd_len
; i
++)
3463 SET_FLAG(data
->config_table
[i
].flags
,
3464 MAC_CONFIGURATION_ENTRY_ACTION_TYPE
,
3465 T_ETH_MAC_COMMAND_INVALIDATE
);
3467 /* Handle pending commands first */
3468 cnt
= bnx2x_mcast_handle_pending_cmds_e1(bp
, p
);
3470 /* If there are no more pending commands - clear SCHEDULED state */
3471 if (list_empty(&o
->pending_cmds_head
))
3474 /* The below may be true iff there were no pending commands */
3476 cnt
= bnx2x_mcast_handle_current_cmd(bp
, p
, cmd
, 0);
3478 /* For 57710 every command has o->max_cmd_len length to ensure that
3479 * commands are done one at a time.
3481 o
->total_pending_num
-= o
->max_cmd_len
;
3485 WARN_ON(cnt
> o
->max_cmd_len
);
3487 /* Set ramrod header (in particular, a number of entries to update) */
3488 bnx2x_mcast_set_rdata_hdr_e1(bp
, p
, (u8
)cnt
);
3490 /* update a registry: we need the registry contents to be always up
3491 * to date in order to be able to execute a RESTORE opcode. Here
3492 * we use the fact that for 57710 we sent one command at a time
3493 * hence we may take the registry update out of the command handling
3494 * and do it in a simpler way here.
3496 rc
= bnx2x_mcast_refresh_registry_e1(bp
, o
);
3501 * If CLEAR_ONLY was requested - don't send a ramrod and clear
3502 * RAMROD_PENDING status immediately.
3504 if (test_bit(RAMROD_DRV_CLR_ONLY
, &p
->ramrod_flags
)) {
3505 raw
->clear_pending(raw
);
3509 * No need for an explicit memory barrier here as long we would
3510 * need to ensure the ordering of writing to the SPQ element
3511 * and updating of the SPQ producer which involves a memory
3512 * read and we will have to put a full memory barrier there
3513 * (inside bnx2x_sp_post()).
3517 rc
= bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_SET_MAC
, raw
->cid
,
3518 U64_HI(raw
->rdata_mapping
),
3519 U64_LO(raw
->rdata_mapping
),
3520 ETH_CONNECTION_TYPE
);
3524 /* Ramrod completion is pending */
3530 static int bnx2x_mcast_get_registry_size_exact(struct bnx2x_mcast_obj
*o
)
3532 return o
->registry
.exact_match
.num_macs_set
;
3535 static int bnx2x_mcast_get_registry_size_aprox(struct bnx2x_mcast_obj
*o
)
3537 return o
->registry
.aprox_match
.num_bins_set
;
3540 static void bnx2x_mcast_set_registry_size_exact(struct bnx2x_mcast_obj
*o
,
3543 o
->registry
.exact_match
.num_macs_set
= n
;
3546 static void bnx2x_mcast_set_registry_size_aprox(struct bnx2x_mcast_obj
*o
,
3549 o
->registry
.aprox_match
.num_bins_set
= n
;
3552 int bnx2x_config_mcast(struct bnx2x
*bp
,
3553 struct bnx2x_mcast_ramrod_params
*p
,
3556 struct bnx2x_mcast_obj
*o
= p
->mcast_obj
;
3557 struct bnx2x_raw_obj
*r
= &o
->raw
;
3558 int rc
= 0, old_reg_size
;
3560 /* This is needed to recover number of currently configured mcast macs
3561 * in case of failure.
3563 old_reg_size
= o
->get_registry_size(o
);
3565 /* Do some calculations and checks */
3566 rc
= o
->validate(bp
, p
, cmd
);
3570 /* Return if there is no work to do */
3571 if ((!p
->mcast_list_len
) && (!o
->check_sched(o
)))
3574 DP(BNX2X_MSG_SP
, "o->total_pending_num=%d p->mcast_list_len=%d "
3575 "o->max_cmd_len=%d\n", o
->total_pending_num
,
3576 p
->mcast_list_len
, o
->max_cmd_len
);
3578 /* Enqueue the current command to the pending list if we can't complete
3579 * it in the current iteration
3581 if (r
->check_pending(r
) ||
3582 ((o
->max_cmd_len
> 0) && (o
->total_pending_num
> o
->max_cmd_len
))) {
3583 rc
= o
->enqueue_cmd(bp
, p
->mcast_obj
, p
, cmd
);
3587 /* As long as the current command is in a command list we
3588 * don't need to handle it separately.
3590 p
->mcast_list_len
= 0;
3593 if (!r
->check_pending(r
)) {
3595 /* Set 'pending' state */
3598 /* Configure the new classification in the chip */
3599 rc
= o
->config_mcast(bp
, p
, cmd
);
3603 /* Wait for a ramrod completion if was requested */
3604 if (test_bit(RAMROD_COMP_WAIT
, &p
->ramrod_flags
))
3605 rc
= o
->wait_comp(bp
, o
);
3611 r
->clear_pending(r
);
3614 o
->revert(bp
, p
, old_reg_size
);
3619 static void bnx2x_mcast_clear_sched(struct bnx2x_mcast_obj
*o
)
3621 smp_mb__before_clear_bit();
3622 clear_bit(o
->sched_state
, o
->raw
.pstate
);
3623 smp_mb__after_clear_bit();
3626 static void bnx2x_mcast_set_sched(struct bnx2x_mcast_obj
*o
)
3628 smp_mb__before_clear_bit();
3629 set_bit(o
->sched_state
, o
->raw
.pstate
);
3630 smp_mb__after_clear_bit();
3633 static bool bnx2x_mcast_check_sched(struct bnx2x_mcast_obj
*o
)
3635 return !!test_bit(o
->sched_state
, o
->raw
.pstate
);
3638 static bool bnx2x_mcast_check_pending(struct bnx2x_mcast_obj
*o
)
3640 return o
->raw
.check_pending(&o
->raw
) || o
->check_sched(o
);
3643 void bnx2x_init_mcast_obj(struct bnx2x
*bp
,
3644 struct bnx2x_mcast_obj
*mcast_obj
,
3645 u8 mcast_cl_id
, u32 mcast_cid
, u8 func_id
,
3646 u8 engine_id
, void *rdata
, dma_addr_t rdata_mapping
,
3647 int state
, unsigned long *pstate
, bnx2x_obj_type type
)
3649 memset(mcast_obj
, 0, sizeof(*mcast_obj
));
3651 bnx2x_init_raw_obj(&mcast_obj
->raw
, mcast_cl_id
, mcast_cid
, func_id
,
3652 rdata
, rdata_mapping
, state
, pstate
, type
);
3654 mcast_obj
->engine_id
= engine_id
;
3656 INIT_LIST_HEAD(&mcast_obj
->pending_cmds_head
);
3658 mcast_obj
->sched_state
= BNX2X_FILTER_MCAST_SCHED
;
3659 mcast_obj
->check_sched
= bnx2x_mcast_check_sched
;
3660 mcast_obj
->set_sched
= bnx2x_mcast_set_sched
;
3661 mcast_obj
->clear_sched
= bnx2x_mcast_clear_sched
;
3663 if (CHIP_IS_E1(bp
)) {
3664 mcast_obj
->config_mcast
= bnx2x_mcast_setup_e1
;
3665 mcast_obj
->enqueue_cmd
= bnx2x_mcast_enqueue_cmd
;
3666 mcast_obj
->hdl_restore
=
3667 bnx2x_mcast_handle_restore_cmd_e1
;
3668 mcast_obj
->check_pending
= bnx2x_mcast_check_pending
;
3670 if (CHIP_REV_IS_SLOW(bp
))
3671 mcast_obj
->max_cmd_len
= BNX2X_MAX_EMUL_MULTI
;
3673 mcast_obj
->max_cmd_len
= BNX2X_MAX_MULTICAST
;
3675 mcast_obj
->wait_comp
= bnx2x_mcast_wait
;
3676 mcast_obj
->set_one_rule
= bnx2x_mcast_set_one_rule_e1
;
3677 mcast_obj
->validate
= bnx2x_mcast_validate_e1
;
3678 mcast_obj
->revert
= bnx2x_mcast_revert_e1
;
3679 mcast_obj
->get_registry_size
=
3680 bnx2x_mcast_get_registry_size_exact
;
3681 mcast_obj
->set_registry_size
=
3682 bnx2x_mcast_set_registry_size_exact
;
3684 /* 57710 is the only chip that uses the exact match for mcast
3687 INIT_LIST_HEAD(&mcast_obj
->registry
.exact_match
.macs
);
3689 } else if (CHIP_IS_E1H(bp
)) {
3690 mcast_obj
->config_mcast
= bnx2x_mcast_setup_e1h
;
3691 mcast_obj
->enqueue_cmd
= NULL
;
3692 mcast_obj
->hdl_restore
= NULL
;
3693 mcast_obj
->check_pending
= bnx2x_mcast_check_pending
;
3695 /* 57711 doesn't send a ramrod, so it has unlimited credit
3698 mcast_obj
->max_cmd_len
= -1;
3699 mcast_obj
->wait_comp
= bnx2x_mcast_wait
;
3700 mcast_obj
->set_one_rule
= NULL
;
3701 mcast_obj
->validate
= bnx2x_mcast_validate_e1h
;
3702 mcast_obj
->revert
= bnx2x_mcast_revert_e1h
;
3703 mcast_obj
->get_registry_size
=
3704 bnx2x_mcast_get_registry_size_aprox
;
3705 mcast_obj
->set_registry_size
=
3706 bnx2x_mcast_set_registry_size_aprox
;
3708 mcast_obj
->config_mcast
= bnx2x_mcast_setup_e2
;
3709 mcast_obj
->enqueue_cmd
= bnx2x_mcast_enqueue_cmd
;
3710 mcast_obj
->hdl_restore
=
3711 bnx2x_mcast_handle_restore_cmd_e2
;
3712 mcast_obj
->check_pending
= bnx2x_mcast_check_pending
;
3713 /* TODO: There should be a proper HSI define for this number!!!
3715 mcast_obj
->max_cmd_len
= 16;
3716 mcast_obj
->wait_comp
= bnx2x_mcast_wait
;
3717 mcast_obj
->set_one_rule
= bnx2x_mcast_set_one_rule_e2
;
3718 mcast_obj
->validate
= bnx2x_mcast_validate_e2
;
3719 mcast_obj
->revert
= bnx2x_mcast_revert_e2
;
3720 mcast_obj
->get_registry_size
=
3721 bnx2x_mcast_get_registry_size_aprox
;
3722 mcast_obj
->set_registry_size
=
3723 bnx2x_mcast_set_registry_size_aprox
;
3727 /*************************** Credit handling **********************************/
3730 * atomic_add_ifless - add if the result is less than a given value.
3732 * @v: pointer of type atomic_t
3733 * @a: the amount to add to v...
3734 * @u: ...if (v + a) is less than u.
3736 * returns true if (v + a) was less than u, and false otherwise.
3739 static inline bool __atomic_add_ifless(atomic_t
*v
, int a
, int u
)
3745 if (unlikely(c
+ a
>= u
))
3748 old
= atomic_cmpxchg((v
), c
, c
+ a
);
3749 if (likely(old
== c
))
3758 * atomic_dec_ifmoe - dec if the result is more or equal than a given value.
3760 * @v: pointer of type atomic_t
3761 * @a: the amount to dec from v...
3762 * @u: ...if (v - a) is more or equal than u.
3764 * returns true if (v - a) was more or equal than u, and false
3767 static inline bool __atomic_dec_ifmoe(atomic_t
*v
, int a
, int u
)
3773 if (unlikely(c
- a
< u
))
3776 old
= atomic_cmpxchg((v
), c
, c
- a
);
3777 if (likely(old
== c
))
3785 static bool bnx2x_credit_pool_get(struct bnx2x_credit_pool_obj
*o
, int cnt
)
3790 rc
= __atomic_dec_ifmoe(&o
->credit
, cnt
, 0);
3796 static bool bnx2x_credit_pool_put(struct bnx2x_credit_pool_obj
*o
, int cnt
)
3802 /* Don't let to refill if credit + cnt > pool_sz */
3803 rc
= __atomic_add_ifless(&o
->credit
, cnt
, o
->pool_sz
+ 1);
3810 static int bnx2x_credit_pool_check(struct bnx2x_credit_pool_obj
*o
)
3815 cur_credit
= atomic_read(&o
->credit
);
3820 static bool bnx2x_credit_pool_always_true(struct bnx2x_credit_pool_obj
*o
,
3827 static bool bnx2x_credit_pool_get_entry(
3828 struct bnx2x_credit_pool_obj
*o
,
3835 /* Find "internal cam-offset" then add to base for this object... */
3836 for (vec
= 0; vec
< BNX2X_POOL_VEC_SIZE
; vec
++) {
3838 /* Skip the current vector if there are no free entries in it */
3839 if (!o
->pool_mirror
[vec
])
3842 /* If we've got here we are going to find a free entry */
3843 for (idx
= vec
* BNX2X_POOL_VEC_SIZE
, i
= 0;
3844 i
< BIT_VEC64_ELEM_SZ
; idx
++, i
++)
3846 if (BIT_VEC64_TEST_BIT(o
->pool_mirror
, idx
)) {
3848 BIT_VEC64_CLEAR_BIT(o
->pool_mirror
, idx
);
3849 *offset
= o
->base_pool_offset
+ idx
;
3857 static bool bnx2x_credit_pool_put_entry(
3858 struct bnx2x_credit_pool_obj
*o
,
3861 if (offset
< o
->base_pool_offset
)
3864 offset
-= o
->base_pool_offset
;
3866 if (offset
>= o
->pool_sz
)
3869 /* Return the entry to the pool */
3870 BIT_VEC64_SET_BIT(o
->pool_mirror
, offset
);
3875 static bool bnx2x_credit_pool_put_entry_always_true(
3876 struct bnx2x_credit_pool_obj
*o
,
3882 static bool bnx2x_credit_pool_get_entry_always_true(
3883 struct bnx2x_credit_pool_obj
*o
,
3890 * bnx2x_init_credit_pool - initialize credit pool internals.
3893 * @base: Base entry in the CAM to use.
3894 * @credit: pool size.
3896 * If base is negative no CAM entries handling will be performed.
3897 * If credit is negative pool operations will always succeed (unlimited pool).
3900 static inline void bnx2x_init_credit_pool(struct bnx2x_credit_pool_obj
*p
,
3901 int base
, int credit
)
3903 /* Zero the object first */
3904 memset(p
, 0, sizeof(*p
));
3906 /* Set the table to all 1s */
3907 memset(&p
->pool_mirror
, 0xff, sizeof(p
->pool_mirror
));
3909 /* Init a pool as full */
3910 atomic_set(&p
->credit
, credit
);
3912 /* The total poll size */
3913 p
->pool_sz
= credit
;
3915 p
->base_pool_offset
= base
;
3917 /* Commit the change */
3920 p
->check
= bnx2x_credit_pool_check
;
3922 /* if pool credit is negative - disable the checks */
3924 p
->put
= bnx2x_credit_pool_put
;
3925 p
->get
= bnx2x_credit_pool_get
;
3926 p
->put_entry
= bnx2x_credit_pool_put_entry
;
3927 p
->get_entry
= bnx2x_credit_pool_get_entry
;
3929 p
->put
= bnx2x_credit_pool_always_true
;
3930 p
->get
= bnx2x_credit_pool_always_true
;
3931 p
->put_entry
= bnx2x_credit_pool_put_entry_always_true
;
3932 p
->get_entry
= bnx2x_credit_pool_get_entry_always_true
;
3935 /* If base is negative - disable entries handling */
3937 p
->put_entry
= bnx2x_credit_pool_put_entry_always_true
;
3938 p
->get_entry
= bnx2x_credit_pool_get_entry_always_true
;
3942 void bnx2x_init_mac_credit_pool(struct bnx2x
*bp
,
3943 struct bnx2x_credit_pool_obj
*p
, u8 func_id
,
3946 /* TODO: this will be defined in consts as well... */
3947 #define BNX2X_CAM_SIZE_EMUL 5
3951 if (CHIP_IS_E1(bp
)) {
3952 /* In E1, Multicast is saved in cam... */
3953 if (!CHIP_REV_IS_SLOW(bp
))
3954 cam_sz
= (MAX_MAC_CREDIT_E1
/ 2) - BNX2X_MAX_MULTICAST
;
3956 cam_sz
= BNX2X_CAM_SIZE_EMUL
- BNX2X_MAX_EMUL_MULTI
;
3958 bnx2x_init_credit_pool(p
, func_id
* cam_sz
, cam_sz
);
3960 } else if (CHIP_IS_E1H(bp
)) {
3961 /* CAM credit is equaly divided between all active functions
3964 if ((func_num
> 0)) {
3965 if (!CHIP_REV_IS_SLOW(bp
))
3966 cam_sz
= (MAX_MAC_CREDIT_E1H
/ (2*func_num
));
3968 cam_sz
= BNX2X_CAM_SIZE_EMUL
;
3969 bnx2x_init_credit_pool(p
, func_id
* cam_sz
, cam_sz
);
3971 /* this should never happen! Block MAC operations. */
3972 bnx2x_init_credit_pool(p
, 0, 0);
3978 * CAM credit is equaly divided between all active functions
3981 if ((func_num
> 0)) {
3982 if (!CHIP_REV_IS_SLOW(bp
))
3983 cam_sz
= (MAX_MAC_CREDIT_E2
/ func_num
);
3985 cam_sz
= BNX2X_CAM_SIZE_EMUL
;
3988 * No need for CAM entries handling for 57712 and
3991 bnx2x_init_credit_pool(p
, -1, cam_sz
);
3993 /* this should never happen! Block MAC operations. */
3994 bnx2x_init_credit_pool(p
, 0, 0);
4000 void bnx2x_init_vlan_credit_pool(struct bnx2x
*bp
,
4001 struct bnx2x_credit_pool_obj
*p
,
4005 if (CHIP_IS_E1x(bp
)) {
4007 * There is no VLAN credit in HW on 57710 and 57711 only
4008 * MAC / MAC-VLAN can be set
4010 bnx2x_init_credit_pool(p
, 0, -1);
4013 * CAM credit is equaly divided between all active functions
4017 int credit
= MAX_VLAN_CREDIT_E2
/ func_num
;
4018 bnx2x_init_credit_pool(p
, func_id
* credit
, credit
);
4020 /* this should never happen! Block VLAN operations. */
4021 bnx2x_init_credit_pool(p
, 0, 0);
4025 /****************** RSS Configuration ******************/
4027 * bnx2x_debug_print_ind_table - prints the indirection table configuration.
4029 * @bp: driver hanlde
4030 * @p: pointer to rss configuration
4032 * Prints it when NETIF_MSG_IFUP debug level is configured.
4034 static inline void bnx2x_debug_print_ind_table(struct bnx2x
*bp
,
4035 struct bnx2x_config_rss_params
*p
)
4039 DP(BNX2X_MSG_SP
, "Setting indirection table to:\n");
4040 DP(BNX2X_MSG_SP
, "0x0000: ");
4041 for (i
= 0; i
< T_ETH_INDIRECTION_TABLE_SIZE
; i
++) {
4042 DP_CONT(BNX2X_MSG_SP
, "0x%02x ", p
->ind_table
[i
]);
4044 /* Print 4 bytes in a line */
4045 if ((i
+ 1 < T_ETH_INDIRECTION_TABLE_SIZE
) &&
4046 (((i
+ 1) & 0x3) == 0)) {
4047 DP_CONT(BNX2X_MSG_SP
, "\n");
4048 DP(BNX2X_MSG_SP
, "0x%04x: ", i
+ 1);
4052 DP_CONT(BNX2X_MSG_SP
, "\n");
4056 * bnx2x_setup_rss - configure RSS
4058 * @bp: device handle
4059 * @p: rss configuration
4061 * sends on UPDATE ramrod for that matter.
4063 static int bnx2x_setup_rss(struct bnx2x
*bp
,
4064 struct bnx2x_config_rss_params
*p
)
4066 struct bnx2x_rss_config_obj
*o
= p
->rss_obj
;
4067 struct bnx2x_raw_obj
*r
= &o
->raw
;
4068 struct eth_rss_update_ramrod_data
*data
=
4069 (struct eth_rss_update_ramrod_data
*)(r
->rdata
);
4073 memset(data
, 0, sizeof(*data
));
4075 DP(BNX2X_MSG_SP
, "Configuring RSS\n");
4077 /* Set an echo field */
4078 data
->echo
= (r
->cid
& BNX2X_SWCID_MASK
) |
4079 (r
->state
<< BNX2X_SWCID_SHIFT
);
4082 if (test_bit(BNX2X_RSS_MODE_DISABLED
, &p
->rss_flags
))
4083 rss_mode
= ETH_RSS_MODE_DISABLED
;
4084 else if (test_bit(BNX2X_RSS_MODE_REGULAR
, &p
->rss_flags
))
4085 rss_mode
= ETH_RSS_MODE_REGULAR
;
4086 else if (test_bit(BNX2X_RSS_MODE_VLAN_PRI
, &p
->rss_flags
))
4087 rss_mode
= ETH_RSS_MODE_VLAN_PRI
;
4088 else if (test_bit(BNX2X_RSS_MODE_E1HOV_PRI
, &p
->rss_flags
))
4089 rss_mode
= ETH_RSS_MODE_E1HOV_PRI
;
4090 else if (test_bit(BNX2X_RSS_MODE_IP_DSCP
, &p
->rss_flags
))
4091 rss_mode
= ETH_RSS_MODE_IP_DSCP
;
4093 data
->rss_mode
= rss_mode
;
4095 DP(BNX2X_MSG_SP
, "rss_mode=%d\n", rss_mode
);
4097 /* RSS capabilities */
4098 if (test_bit(BNX2X_RSS_IPV4
, &p
->rss_flags
))
4099 data
->capabilities
|=
4100 ETH_RSS_UPDATE_RAMROD_DATA_IPV4_CAPABILITY
;
4102 if (test_bit(BNX2X_RSS_IPV4_TCP
, &p
->rss_flags
))
4103 data
->capabilities
|=
4104 ETH_RSS_UPDATE_RAMROD_DATA_IPV4_TCP_CAPABILITY
;
4106 if (test_bit(BNX2X_RSS_IPV6
, &p
->rss_flags
))
4107 data
->capabilities
|=
4108 ETH_RSS_UPDATE_RAMROD_DATA_IPV6_CAPABILITY
;
4110 if (test_bit(BNX2X_RSS_IPV6_TCP
, &p
->rss_flags
))
4111 data
->capabilities
|=
4112 ETH_RSS_UPDATE_RAMROD_DATA_IPV6_TCP_CAPABILITY
;
4115 data
->rss_result_mask
= p
->rss_result_mask
;
4118 data
->rss_engine_id
= o
->engine_id
;
4120 DP(BNX2X_MSG_SP
, "rss_engine_id=%d\n", data
->rss_engine_id
);
4122 /* Indirection table */
4123 memcpy(data
->indirection_table
, p
->ind_table
,
4124 T_ETH_INDIRECTION_TABLE_SIZE
);
4126 /* Remember the last configuration */
4127 memcpy(o
->ind_table
, p
->ind_table
, T_ETH_INDIRECTION_TABLE_SIZE
);
4129 /* Print the indirection table */
4130 if (netif_msg_ifup(bp
))
4131 bnx2x_debug_print_ind_table(bp
, p
);
4134 if (test_bit(BNX2X_RSS_SET_SRCH
, &p
->rss_flags
)) {
4135 memcpy(&data
->rss_key
[0], &p
->rss_key
[0],
4136 sizeof(data
->rss_key
));
4137 data
->capabilities
|= ETH_RSS_UPDATE_RAMROD_DATA_UPDATE_RSS_KEY
;
4141 * No need for an explicit memory barrier here as long we would
4142 * need to ensure the ordering of writing to the SPQ element
4143 * and updating of the SPQ producer which involves a memory
4144 * read and we will have to put a full memory barrier there
4145 * (inside bnx2x_sp_post()).
4149 rc
= bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_RSS_UPDATE
, r
->cid
,
4150 U64_HI(r
->rdata_mapping
),
4151 U64_LO(r
->rdata_mapping
),
4152 ETH_CONNECTION_TYPE
);
4160 void bnx2x_get_rss_ind_table(struct bnx2x_rss_config_obj
*rss_obj
,
4163 memcpy(ind_table
, rss_obj
->ind_table
, sizeof(rss_obj
->ind_table
));
4166 int bnx2x_config_rss(struct bnx2x
*bp
,
4167 struct bnx2x_config_rss_params
*p
)
4170 struct bnx2x_rss_config_obj
*o
= p
->rss_obj
;
4171 struct bnx2x_raw_obj
*r
= &o
->raw
;
4173 /* Do nothing if only driver cleanup was requested */
4174 if (test_bit(RAMROD_DRV_CLR_ONLY
, &p
->ramrod_flags
))
4179 rc
= o
->config_rss(bp
, p
);
4181 r
->clear_pending(r
);
4185 if (test_bit(RAMROD_COMP_WAIT
, &p
->ramrod_flags
))
4186 rc
= r
->wait_comp(bp
, r
);
4192 void bnx2x_init_rss_config_obj(struct bnx2x
*bp
,
4193 struct bnx2x_rss_config_obj
*rss_obj
,
4194 u8 cl_id
, u32 cid
, u8 func_id
, u8 engine_id
,
4195 void *rdata
, dma_addr_t rdata_mapping
,
4196 int state
, unsigned long *pstate
,
4197 bnx2x_obj_type type
)
4199 bnx2x_init_raw_obj(&rss_obj
->raw
, cl_id
, cid
, func_id
, rdata
,
4200 rdata_mapping
, state
, pstate
, type
);
4202 rss_obj
->engine_id
= engine_id
;
4203 rss_obj
->config_rss
= bnx2x_setup_rss
;
4206 /********************** Queue state object ***********************************/
4209 * bnx2x_queue_state_change - perform Queue state change transition
4211 * @bp: device handle
4212 * @params: parameters to perform the transition
4214 * returns 0 in case of successfully completed transition, negative error
4215 * code in case of failure, positive (EBUSY) value if there is a completion
4216 * to that is still pending (possible only if RAMROD_COMP_WAIT is
4217 * not set in params->ramrod_flags for asynchronous commands).
4220 int bnx2x_queue_state_change(struct bnx2x
*bp
,
4221 struct bnx2x_queue_state_params
*params
)
4223 struct bnx2x_queue_sp_obj
*o
= params
->q_obj
;
4224 int rc
, pending_bit
;
4225 unsigned long *pending
= &o
->pending
;
4227 /* Check that the requested transition is legal */
4228 if (o
->check_transition(bp
, o
, params
))
4231 /* Set "pending" bit */
4232 pending_bit
= o
->set_pending(o
, params
);
4234 /* Don't send a command if only driver cleanup was requested */
4235 if (test_bit(RAMROD_DRV_CLR_ONLY
, ¶ms
->ramrod_flags
))
4236 o
->complete_cmd(bp
, o
, pending_bit
);
4239 rc
= o
->send_cmd(bp
, params
);
4241 o
->next_state
= BNX2X_Q_STATE_MAX
;
4242 clear_bit(pending_bit
, pending
);
4243 smp_mb__after_clear_bit();
4247 if (test_bit(RAMROD_COMP_WAIT
, ¶ms
->ramrod_flags
)) {
4248 rc
= o
->wait_comp(bp
, o
, pending_bit
);
4256 return !!test_bit(pending_bit
, pending
);
4260 static int bnx2x_queue_set_pending(struct bnx2x_queue_sp_obj
*obj
,
4261 struct bnx2x_queue_state_params
*params
)
4263 enum bnx2x_queue_cmd cmd
= params
->cmd
, bit
;
4265 /* ACTIVATE and DEACTIVATE commands are implemented on top of
4268 if ((cmd
== BNX2X_Q_CMD_ACTIVATE
) ||
4269 (cmd
== BNX2X_Q_CMD_DEACTIVATE
))
4270 bit
= BNX2X_Q_CMD_UPDATE
;
4274 set_bit(bit
, &obj
->pending
);
4278 static int bnx2x_queue_wait_comp(struct bnx2x
*bp
,
4279 struct bnx2x_queue_sp_obj
*o
,
4280 enum bnx2x_queue_cmd cmd
)
4282 return bnx2x_state_wait(bp
, cmd
, &o
->pending
);
4286 * bnx2x_queue_comp_cmd - complete the state change command.
4288 * @bp: device handle
4292 * Checks that the arrived completion is expected.
4294 static int bnx2x_queue_comp_cmd(struct bnx2x
*bp
,
4295 struct bnx2x_queue_sp_obj
*o
,
4296 enum bnx2x_queue_cmd cmd
)
4298 unsigned long cur_pending
= o
->pending
;
4300 if (!test_and_clear_bit(cmd
, &cur_pending
)) {
4301 BNX2X_ERR("Bad MC reply %d for queue %d in state %d "
4302 "pending 0x%lx, next_state %d\n", cmd
,
4303 o
->cids
[BNX2X_PRIMARY_CID_INDEX
],
4304 o
->state
, cur_pending
, o
->next_state
);
4308 if (o
->next_tx_only
>= o
->max_cos
)
4309 /* >= becuase tx only must always be smaller than cos since the
4310 * primary connection suports COS 0
4312 BNX2X_ERR("illegal value for next tx_only: %d. max cos was %d",
4313 o
->next_tx_only
, o
->max_cos
);
4315 DP(BNX2X_MSG_SP
, "Completing command %d for queue %d, "
4316 "setting state to %d\n", cmd
,
4317 o
->cids
[BNX2X_PRIMARY_CID_INDEX
], o
->next_state
);
4319 if (o
->next_tx_only
) /* print num tx-only if any exist */
4320 DP(BNX2X_MSG_SP
, "primary cid %d: num tx-only cons %d\n",
4321 o
->cids
[BNX2X_PRIMARY_CID_INDEX
], o
->next_tx_only
);
4323 o
->state
= o
->next_state
;
4324 o
->num_tx_only
= o
->next_tx_only
;
4325 o
->next_state
= BNX2X_Q_STATE_MAX
;
4327 /* It's important that o->state and o->next_state are
4328 * updated before o->pending.
4332 clear_bit(cmd
, &o
->pending
);
4333 smp_mb__after_clear_bit();
4338 static void bnx2x_q_fill_setup_data_e2(struct bnx2x
*bp
,
4339 struct bnx2x_queue_state_params
*cmd_params
,
4340 struct client_init_ramrod_data
*data
)
4342 struct bnx2x_queue_setup_params
*params
= &cmd_params
->params
.setup
;
4346 /* IPv6 TPA supported for E2 and above only */
4347 data
->rx
.tpa_en
|= test_bit(BNX2X_Q_FLG_TPA_IPV6
, ¶ms
->flags
) *
4348 CLIENT_INIT_RX_DATA_TPA_EN_IPV6
;
4351 static void bnx2x_q_fill_init_general_data(struct bnx2x
*bp
,
4352 struct bnx2x_queue_sp_obj
*o
,
4353 struct bnx2x_general_setup_params
*params
,
4354 struct client_init_general_data
*gen_data
,
4355 unsigned long *flags
)
4357 gen_data
->client_id
= o
->cl_id
;
4359 if (test_bit(BNX2X_Q_FLG_STATS
, flags
)) {
4360 gen_data
->statistics_counter_id
=
4362 gen_data
->statistics_en_flg
= 1;
4363 gen_data
->statistics_zero_flg
=
4364 test_bit(BNX2X_Q_FLG_ZERO_STATS
, flags
);
4366 gen_data
->statistics_counter_id
=
4367 DISABLE_STATISTIC_COUNTER_ID_VALUE
;
4369 gen_data
->is_fcoe_flg
= test_bit(BNX2X_Q_FLG_FCOE
, flags
);
4370 gen_data
->activate_flg
= test_bit(BNX2X_Q_FLG_ACTIVE
, flags
);
4371 gen_data
->sp_client_id
= params
->spcl_id
;
4372 gen_data
->mtu
= cpu_to_le16(params
->mtu
);
4373 gen_data
->func_id
= o
->func_id
;
4376 gen_data
->cos
= params
->cos
;
4378 gen_data
->traffic_type
=
4379 test_bit(BNX2X_Q_FLG_FCOE
, flags
) ?
4380 LLFC_TRAFFIC_TYPE_FCOE
: LLFC_TRAFFIC_TYPE_NW
;
4382 DP(BNX2X_MSG_SP
, "flags: active %d, cos %d, stats en %d\n",
4383 gen_data
->activate_flg
, gen_data
->cos
, gen_data
->statistics_en_flg
);
4386 static void bnx2x_q_fill_init_tx_data(struct bnx2x_queue_sp_obj
*o
,
4387 struct bnx2x_txq_setup_params
*params
,
4388 struct client_init_tx_data
*tx_data
,
4389 unsigned long *flags
)
4391 tx_data
->enforce_security_flg
=
4392 test_bit(BNX2X_Q_FLG_TX_SEC
, flags
);
4393 tx_data
->default_vlan
=
4394 cpu_to_le16(params
->default_vlan
);
4395 tx_data
->default_vlan_flg
=
4396 test_bit(BNX2X_Q_FLG_DEF_VLAN
, flags
);
4397 tx_data
->tx_switching_flg
=
4398 test_bit(BNX2X_Q_FLG_TX_SWITCH
, flags
);
4399 tx_data
->anti_spoofing_flg
=
4400 test_bit(BNX2X_Q_FLG_ANTI_SPOOF
, flags
);
4401 tx_data
->tx_status_block_id
= params
->fw_sb_id
;
4402 tx_data
->tx_sb_index_number
= params
->sb_cq_index
;
4403 tx_data
->tss_leading_client_id
= params
->tss_leading_cl_id
;
4405 tx_data
->tx_bd_page_base
.lo
=
4406 cpu_to_le32(U64_LO(params
->dscr_map
));
4407 tx_data
->tx_bd_page_base
.hi
=
4408 cpu_to_le32(U64_HI(params
->dscr_map
));
4410 /* Don't configure any Tx switching mode during queue SETUP */
4414 static void bnx2x_q_fill_init_pause_data(struct bnx2x_queue_sp_obj
*o
,
4415 struct rxq_pause_params
*params
,
4416 struct client_init_rx_data
*rx_data
)
4418 /* flow control data */
4419 rx_data
->cqe_pause_thr_low
= cpu_to_le16(params
->rcq_th_lo
);
4420 rx_data
->cqe_pause_thr_high
= cpu_to_le16(params
->rcq_th_hi
);
4421 rx_data
->bd_pause_thr_low
= cpu_to_le16(params
->bd_th_lo
);
4422 rx_data
->bd_pause_thr_high
= cpu_to_le16(params
->bd_th_hi
);
4423 rx_data
->sge_pause_thr_low
= cpu_to_le16(params
->sge_th_lo
);
4424 rx_data
->sge_pause_thr_high
= cpu_to_le16(params
->sge_th_hi
);
4425 rx_data
->rx_cos_mask
= cpu_to_le16(params
->pri_map
);
4428 static void bnx2x_q_fill_init_rx_data(struct bnx2x_queue_sp_obj
*o
,
4429 struct bnx2x_rxq_setup_params
*params
,
4430 struct client_init_rx_data
*rx_data
,
4431 unsigned long *flags
)
4434 rx_data
->tpa_en
= test_bit(BNX2X_Q_FLG_TPA
, flags
) *
4435 CLIENT_INIT_RX_DATA_TPA_EN_IPV4
;
4436 rx_data
->vmqueue_mode_en_flg
= 0;
4438 rx_data
->cache_line_alignment_log_size
=
4439 params
->cache_line_log
;
4440 rx_data
->enable_dynamic_hc
=
4441 test_bit(BNX2X_Q_FLG_DHC
, flags
);
4442 rx_data
->max_sges_for_packet
= params
->max_sges_pkt
;
4443 rx_data
->client_qzone_id
= params
->cl_qzone_id
;
4444 rx_data
->max_agg_size
= cpu_to_le16(params
->tpa_agg_sz
);
4446 /* Always start in DROP_ALL mode */
4447 rx_data
->state
= cpu_to_le16(CLIENT_INIT_RX_DATA_UCAST_DROP_ALL
|
4448 CLIENT_INIT_RX_DATA_MCAST_DROP_ALL
);
4450 /* We don't set drop flags */
4451 rx_data
->drop_ip_cs_err_flg
= 0;
4452 rx_data
->drop_tcp_cs_err_flg
= 0;
4453 rx_data
->drop_ttl0_flg
= 0;
4454 rx_data
->drop_udp_cs_err_flg
= 0;
4455 rx_data
->inner_vlan_removal_enable_flg
=
4456 test_bit(BNX2X_Q_FLG_VLAN
, flags
);
4457 rx_data
->outer_vlan_removal_enable_flg
=
4458 test_bit(BNX2X_Q_FLG_OV
, flags
);
4459 rx_data
->status_block_id
= params
->fw_sb_id
;
4460 rx_data
->rx_sb_index_number
= params
->sb_cq_index
;
4461 rx_data
->max_tpa_queues
= params
->max_tpa_queues
;
4462 rx_data
->max_bytes_on_bd
= cpu_to_le16(params
->buf_sz
);
4463 rx_data
->sge_buff_size
= cpu_to_le16(params
->sge_buf_sz
);
4464 rx_data
->bd_page_base
.lo
=
4465 cpu_to_le32(U64_LO(params
->dscr_map
));
4466 rx_data
->bd_page_base
.hi
=
4467 cpu_to_le32(U64_HI(params
->dscr_map
));
4468 rx_data
->sge_page_base
.lo
=
4469 cpu_to_le32(U64_LO(params
->sge_map
));
4470 rx_data
->sge_page_base
.hi
=
4471 cpu_to_le32(U64_HI(params
->sge_map
));
4472 rx_data
->cqe_page_base
.lo
=
4473 cpu_to_le32(U64_LO(params
->rcq_map
));
4474 rx_data
->cqe_page_base
.hi
=
4475 cpu_to_le32(U64_HI(params
->rcq_map
));
4476 rx_data
->is_leading_rss
= test_bit(BNX2X_Q_FLG_LEADING_RSS
, flags
);
4478 if (test_bit(BNX2X_Q_FLG_MCAST
, flags
)) {
4479 rx_data
->approx_mcast_engine_id
= o
->func_id
;
4480 rx_data
->is_approx_mcast
= 1;
4483 rx_data
->rss_engine_id
= params
->rss_engine_id
;
4485 /* silent vlan removal */
4486 rx_data
->silent_vlan_removal_flg
=
4487 test_bit(BNX2X_Q_FLG_SILENT_VLAN_REM
, flags
);
4488 rx_data
->silent_vlan_value
=
4489 cpu_to_le16(params
->silent_removal_value
);
4490 rx_data
->silent_vlan_mask
=
4491 cpu_to_le16(params
->silent_removal_mask
);
4495 /* initialize the general, tx and rx parts of a queue object */
4496 static void bnx2x_q_fill_setup_data_cmn(struct bnx2x
*bp
,
4497 struct bnx2x_queue_state_params
*cmd_params
,
4498 struct client_init_ramrod_data
*data
)
4500 bnx2x_q_fill_init_general_data(bp
, cmd_params
->q_obj
,
4501 &cmd_params
->params
.setup
.gen_params
,
4503 &cmd_params
->params
.setup
.flags
);
4505 bnx2x_q_fill_init_tx_data(cmd_params
->q_obj
,
4506 &cmd_params
->params
.setup
.txq_params
,
4508 &cmd_params
->params
.setup
.flags
);
4510 bnx2x_q_fill_init_rx_data(cmd_params
->q_obj
,
4511 &cmd_params
->params
.setup
.rxq_params
,
4513 &cmd_params
->params
.setup
.flags
);
4515 bnx2x_q_fill_init_pause_data(cmd_params
->q_obj
,
4516 &cmd_params
->params
.setup
.pause_params
,
4520 /* initialize the general and tx parts of a tx-only queue object */
4521 static void bnx2x_q_fill_setup_tx_only(struct bnx2x
*bp
,
4522 struct bnx2x_queue_state_params
*cmd_params
,
4523 struct tx_queue_init_ramrod_data
*data
)
4525 bnx2x_q_fill_init_general_data(bp
, cmd_params
->q_obj
,
4526 &cmd_params
->params
.tx_only
.gen_params
,
4528 &cmd_params
->params
.tx_only
.flags
);
4530 bnx2x_q_fill_init_tx_data(cmd_params
->q_obj
,
4531 &cmd_params
->params
.tx_only
.txq_params
,
4533 &cmd_params
->params
.tx_only
.flags
);
4535 DP(BNX2X_MSG_SP
, "cid %d, tx bd page lo %x hi %x\n",cmd_params
->q_obj
->cids
[0],
4536 data
->tx
.tx_bd_page_base
.lo
, data
->tx
.tx_bd_page_base
.hi
);
4540 * bnx2x_q_init - init HW/FW queue
4542 * @bp: device handle
4545 * HW/FW initial Queue configuration:
4547 * - CDU context validation
4550 static inline int bnx2x_q_init(struct bnx2x
*bp
,
4551 struct bnx2x_queue_state_params
*params
)
4553 struct bnx2x_queue_sp_obj
*o
= params
->q_obj
;
4554 struct bnx2x_queue_init_params
*init
= ¶ms
->params
.init
;
4558 /* Tx HC configuration */
4559 if (test_bit(BNX2X_Q_TYPE_HAS_TX
, &o
->type
) &&
4560 test_bit(BNX2X_Q_FLG_HC
, &init
->tx
.flags
)) {
4561 hc_usec
= init
->tx
.hc_rate
? 1000000 / init
->tx
.hc_rate
: 0;
4563 bnx2x_update_coalesce_sb_index(bp
, init
->tx
.fw_sb_id
,
4564 init
->tx
.sb_cq_index
,
4565 !test_bit(BNX2X_Q_FLG_HC_EN
, &init
->tx
.flags
),
4569 /* Rx HC configuration */
4570 if (test_bit(BNX2X_Q_TYPE_HAS_RX
, &o
->type
) &&
4571 test_bit(BNX2X_Q_FLG_HC
, &init
->rx
.flags
)) {
4572 hc_usec
= init
->rx
.hc_rate
? 1000000 / init
->rx
.hc_rate
: 0;
4574 bnx2x_update_coalesce_sb_index(bp
, init
->rx
.fw_sb_id
,
4575 init
->rx
.sb_cq_index
,
4576 !test_bit(BNX2X_Q_FLG_HC_EN
, &init
->rx
.flags
),
4580 /* Set CDU context validation values */
4581 for (cos
= 0; cos
< o
->max_cos
; cos
++) {
4582 DP(BNX2X_MSG_SP
, "setting context validation. cid %d, cos %d\n",
4584 DP(BNX2X_MSG_SP
, "context pointer %p\n", init
->cxts
[cos
]);
4585 bnx2x_set_ctx_validation(bp
, init
->cxts
[cos
], o
->cids
[cos
]);
4588 /* As no ramrod is sent, complete the command immediately */
4589 o
->complete_cmd(bp
, o
, BNX2X_Q_CMD_INIT
);
4597 static inline int bnx2x_q_send_setup_e1x(struct bnx2x
*bp
,
4598 struct bnx2x_queue_state_params
*params
)
4600 struct bnx2x_queue_sp_obj
*o
= params
->q_obj
;
4601 struct client_init_ramrod_data
*rdata
=
4602 (struct client_init_ramrod_data
*)o
->rdata
;
4603 dma_addr_t data_mapping
= o
->rdata_mapping
;
4604 int ramrod
= RAMROD_CMD_ID_ETH_CLIENT_SETUP
;
4606 /* Clear the ramrod data */
4607 memset(rdata
, 0, sizeof(*rdata
));
4609 /* Fill the ramrod data */
4610 bnx2x_q_fill_setup_data_cmn(bp
, params
, rdata
);
4613 * No need for an explicit memory barrier here as long we would
4614 * need to ensure the ordering of writing to the SPQ element
4615 * and updating of the SPQ producer which involves a memory
4616 * read and we will have to put a full memory barrier there
4617 * (inside bnx2x_sp_post()).
4620 return bnx2x_sp_post(bp
, ramrod
, o
->cids
[BNX2X_PRIMARY_CID_INDEX
],
4621 U64_HI(data_mapping
),
4622 U64_LO(data_mapping
), ETH_CONNECTION_TYPE
);
4625 static inline int bnx2x_q_send_setup_e2(struct bnx2x
*bp
,
4626 struct bnx2x_queue_state_params
*params
)
4628 struct bnx2x_queue_sp_obj
*o
= params
->q_obj
;
4629 struct client_init_ramrod_data
*rdata
=
4630 (struct client_init_ramrod_data
*)o
->rdata
;
4631 dma_addr_t data_mapping
= o
->rdata_mapping
;
4632 int ramrod
= RAMROD_CMD_ID_ETH_CLIENT_SETUP
;
4634 /* Clear the ramrod data */
4635 memset(rdata
, 0, sizeof(*rdata
));
4637 /* Fill the ramrod data */
4638 bnx2x_q_fill_setup_data_cmn(bp
, params
, rdata
);
4639 bnx2x_q_fill_setup_data_e2(bp
, params
, rdata
);
4642 * No need for an explicit memory barrier here as long we would
4643 * need to ensure the ordering of writing to the SPQ element
4644 * and updating of the SPQ producer which involves a memory
4645 * read and we will have to put a full memory barrier there
4646 * (inside bnx2x_sp_post()).
4649 return bnx2x_sp_post(bp
, ramrod
, o
->cids
[BNX2X_PRIMARY_CID_INDEX
],
4650 U64_HI(data_mapping
),
4651 U64_LO(data_mapping
), ETH_CONNECTION_TYPE
);
4654 static inline int bnx2x_q_send_setup_tx_only(struct bnx2x
*bp
,
4655 struct bnx2x_queue_state_params
*params
)
4657 struct bnx2x_queue_sp_obj
*o
= params
->q_obj
;
4658 struct tx_queue_init_ramrod_data
*rdata
=
4659 (struct tx_queue_init_ramrod_data
*)o
->rdata
;
4660 dma_addr_t data_mapping
= o
->rdata_mapping
;
4661 int ramrod
= RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP
;
4662 struct bnx2x_queue_setup_tx_only_params
*tx_only_params
=
4663 ¶ms
->params
.tx_only
;
4664 u8 cid_index
= tx_only_params
->cid_index
;
4667 if (cid_index
>= o
->max_cos
) {
4668 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4669 o
->cl_id
, cid_index
);
4673 DP(BNX2X_MSG_SP
, "parameters received: cos: %d sp-id: %d\n",
4674 tx_only_params
->gen_params
.cos
,
4675 tx_only_params
->gen_params
.spcl_id
);
4677 /* Clear the ramrod data */
4678 memset(rdata
, 0, sizeof(*rdata
));
4680 /* Fill the ramrod data */
4681 bnx2x_q_fill_setup_tx_only(bp
, params
, rdata
);
4683 DP(BNX2X_MSG_SP
, "sending tx-only ramrod: cid %d, client-id %d,"
4684 "sp-client id %d, cos %d\n",
4686 rdata
->general
.client_id
,
4687 rdata
->general
.sp_client_id
, rdata
->general
.cos
);
4690 * No need for an explicit memory barrier here as long we would
4691 * need to ensure the ordering of writing to the SPQ element
4692 * and updating of the SPQ producer which involves a memory
4693 * read and we will have to put a full memory barrier there
4694 * (inside bnx2x_sp_post()).
4697 return bnx2x_sp_post(bp
, ramrod
, o
->cids
[cid_index
],
4698 U64_HI(data_mapping
),
4699 U64_LO(data_mapping
), ETH_CONNECTION_TYPE
);
4702 static void bnx2x_q_fill_update_data(struct bnx2x
*bp
,
4703 struct bnx2x_queue_sp_obj
*obj
,
4704 struct bnx2x_queue_update_params
*params
,
4705 struct client_update_ramrod_data
*data
)
4707 /* Client ID of the client to update */
4708 data
->client_id
= obj
->cl_id
;
4710 /* Function ID of the client to update */
4711 data
->func_id
= obj
->func_id
;
4713 /* Default VLAN value */
4714 data
->default_vlan
= cpu_to_le16(params
->def_vlan
);
4716 /* Inner VLAN stripping */
4717 data
->inner_vlan_removal_enable_flg
=
4718 test_bit(BNX2X_Q_UPDATE_IN_VLAN_REM
, ¶ms
->update_flags
);
4719 data
->inner_vlan_removal_change_flg
=
4720 test_bit(BNX2X_Q_UPDATE_IN_VLAN_REM_CHNG
,
4721 ¶ms
->update_flags
);
4723 /* Outer VLAN sripping */
4724 data
->outer_vlan_removal_enable_flg
=
4725 test_bit(BNX2X_Q_UPDATE_OUT_VLAN_REM
, ¶ms
->update_flags
);
4726 data
->outer_vlan_removal_change_flg
=
4727 test_bit(BNX2X_Q_UPDATE_OUT_VLAN_REM_CHNG
,
4728 ¶ms
->update_flags
);
4730 /* Drop packets that have source MAC that doesn't belong to this
4733 data
->anti_spoofing_enable_flg
=
4734 test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF
, ¶ms
->update_flags
);
4735 data
->anti_spoofing_change_flg
=
4736 test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF_CHNG
, ¶ms
->update_flags
);
4738 /* Activate/Deactivate */
4739 data
->activate_flg
=
4740 test_bit(BNX2X_Q_UPDATE_ACTIVATE
, ¶ms
->update_flags
);
4741 data
->activate_change_flg
=
4742 test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG
, ¶ms
->update_flags
);
4744 /* Enable default VLAN */
4745 data
->default_vlan_enable_flg
=
4746 test_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN
, ¶ms
->update_flags
);
4747 data
->default_vlan_change_flg
=
4748 test_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN_CHNG
,
4749 ¶ms
->update_flags
);
4751 /* silent vlan removal */
4752 data
->silent_vlan_change_flg
=
4753 test_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG
,
4754 ¶ms
->update_flags
);
4755 data
->silent_vlan_removal_flg
=
4756 test_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM
, ¶ms
->update_flags
);
4757 data
->silent_vlan_value
= cpu_to_le16(params
->silent_removal_value
);
4758 data
->silent_vlan_mask
= cpu_to_le16(params
->silent_removal_mask
);
4761 static inline int bnx2x_q_send_update(struct bnx2x
*bp
,
4762 struct bnx2x_queue_state_params
*params
)
4764 struct bnx2x_queue_sp_obj
*o
= params
->q_obj
;
4765 struct client_update_ramrod_data
*rdata
=
4766 (struct client_update_ramrod_data
*)o
->rdata
;
4767 dma_addr_t data_mapping
= o
->rdata_mapping
;
4768 struct bnx2x_queue_update_params
*update_params
=
4769 ¶ms
->params
.update
;
4770 u8 cid_index
= update_params
->cid_index
;
4772 if (cid_index
>= o
->max_cos
) {
4773 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4774 o
->cl_id
, cid_index
);
4779 /* Clear the ramrod data */
4780 memset(rdata
, 0, sizeof(*rdata
));
4782 /* Fill the ramrod data */
4783 bnx2x_q_fill_update_data(bp
, o
, update_params
, rdata
);
4786 * No need for an explicit memory barrier here as long we would
4787 * need to ensure the ordering of writing to the SPQ element
4788 * and updating of the SPQ producer which involves a memory
4789 * read and we will have to put a full memory barrier there
4790 * (inside bnx2x_sp_post()).
4793 return bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_CLIENT_UPDATE
,
4794 o
->cids
[cid_index
], U64_HI(data_mapping
),
4795 U64_LO(data_mapping
), ETH_CONNECTION_TYPE
);
4799 * bnx2x_q_send_deactivate - send DEACTIVATE command
4801 * @bp: device handle
4804 * implemented using the UPDATE command.
4806 static inline int bnx2x_q_send_deactivate(struct bnx2x
*bp
,
4807 struct bnx2x_queue_state_params
*params
)
4809 struct bnx2x_queue_update_params
*update
= ¶ms
->params
.update
;
4811 memset(update
, 0, sizeof(*update
));
4813 __set_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG
, &update
->update_flags
);
4815 return bnx2x_q_send_update(bp
, params
);
4819 * bnx2x_q_send_activate - send ACTIVATE command
4821 * @bp: device handle
4824 * implemented using the UPDATE command.
4826 static inline int bnx2x_q_send_activate(struct bnx2x
*bp
,
4827 struct bnx2x_queue_state_params
*params
)
4829 struct bnx2x_queue_update_params
*update
= ¶ms
->params
.update
;
4831 memset(update
, 0, sizeof(*update
));
4833 __set_bit(BNX2X_Q_UPDATE_ACTIVATE
, &update
->update_flags
);
4834 __set_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG
, &update
->update_flags
);
4836 return bnx2x_q_send_update(bp
, params
);
4839 static inline int bnx2x_q_send_update_tpa(struct bnx2x
*bp
,
4840 struct bnx2x_queue_state_params
*params
)
4842 /* TODO: Not implemented yet. */
4846 static inline int bnx2x_q_send_halt(struct bnx2x
*bp
,
4847 struct bnx2x_queue_state_params
*params
)
4849 struct bnx2x_queue_sp_obj
*o
= params
->q_obj
;
4851 return bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_HALT
,
4852 o
->cids
[BNX2X_PRIMARY_CID_INDEX
], 0, o
->cl_id
,
4853 ETH_CONNECTION_TYPE
);
4856 static inline int bnx2x_q_send_cfc_del(struct bnx2x
*bp
,
4857 struct bnx2x_queue_state_params
*params
)
4859 struct bnx2x_queue_sp_obj
*o
= params
->q_obj
;
4860 u8 cid_idx
= params
->params
.cfc_del
.cid_index
;
4862 if (cid_idx
>= o
->max_cos
) {
4863 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4868 return bnx2x_sp_post(bp
, RAMROD_CMD_ID_COMMON_CFC_DEL
,
4869 o
->cids
[cid_idx
], 0, 0, NONE_CONNECTION_TYPE
);
4872 static inline int bnx2x_q_send_terminate(struct bnx2x
*bp
,
4873 struct bnx2x_queue_state_params
*params
)
4875 struct bnx2x_queue_sp_obj
*o
= params
->q_obj
;
4876 u8 cid_index
= params
->params
.terminate
.cid_index
;
4878 if (cid_index
>= o
->max_cos
) {
4879 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4880 o
->cl_id
, cid_index
);
4884 return bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_TERMINATE
,
4885 o
->cids
[cid_index
], 0, 0, ETH_CONNECTION_TYPE
);
4888 static inline int bnx2x_q_send_empty(struct bnx2x
*bp
,
4889 struct bnx2x_queue_state_params
*params
)
4891 struct bnx2x_queue_sp_obj
*o
= params
->q_obj
;
4893 return bnx2x_sp_post(bp
, RAMROD_CMD_ID_ETH_EMPTY
,
4894 o
->cids
[BNX2X_PRIMARY_CID_INDEX
], 0, 0,
4895 ETH_CONNECTION_TYPE
);
4898 static inline int bnx2x_queue_send_cmd_cmn(struct bnx2x
*bp
,
4899 struct bnx2x_queue_state_params
*params
)
4901 switch (params
->cmd
) {
4902 case BNX2X_Q_CMD_INIT
:
4903 return bnx2x_q_init(bp
, params
);
4904 case BNX2X_Q_CMD_SETUP_TX_ONLY
:
4905 return bnx2x_q_send_setup_tx_only(bp
, params
);
4906 case BNX2X_Q_CMD_DEACTIVATE
:
4907 return bnx2x_q_send_deactivate(bp
, params
);
4908 case BNX2X_Q_CMD_ACTIVATE
:
4909 return bnx2x_q_send_activate(bp
, params
);
4910 case BNX2X_Q_CMD_UPDATE
:
4911 return bnx2x_q_send_update(bp
, params
);
4912 case BNX2X_Q_CMD_UPDATE_TPA
:
4913 return bnx2x_q_send_update_tpa(bp
, params
);
4914 case BNX2X_Q_CMD_HALT
:
4915 return bnx2x_q_send_halt(bp
, params
);
4916 case BNX2X_Q_CMD_CFC_DEL
:
4917 return bnx2x_q_send_cfc_del(bp
, params
);
4918 case BNX2X_Q_CMD_TERMINATE
:
4919 return bnx2x_q_send_terminate(bp
, params
);
4920 case BNX2X_Q_CMD_EMPTY
:
4921 return bnx2x_q_send_empty(bp
, params
);
4923 BNX2X_ERR("Unknown command: %d\n", params
->cmd
);
4928 static int bnx2x_queue_send_cmd_e1x(struct bnx2x
*bp
,
4929 struct bnx2x_queue_state_params
*params
)
4931 switch (params
->cmd
) {
4932 case BNX2X_Q_CMD_SETUP
:
4933 return bnx2x_q_send_setup_e1x(bp
, params
);
4934 case BNX2X_Q_CMD_INIT
:
4935 case BNX2X_Q_CMD_SETUP_TX_ONLY
:
4936 case BNX2X_Q_CMD_DEACTIVATE
:
4937 case BNX2X_Q_CMD_ACTIVATE
:
4938 case BNX2X_Q_CMD_UPDATE
:
4939 case BNX2X_Q_CMD_UPDATE_TPA
:
4940 case BNX2X_Q_CMD_HALT
:
4941 case BNX2X_Q_CMD_CFC_DEL
:
4942 case BNX2X_Q_CMD_TERMINATE
:
4943 case BNX2X_Q_CMD_EMPTY
:
4944 return bnx2x_queue_send_cmd_cmn(bp
, params
);
4946 BNX2X_ERR("Unknown command: %d\n", params
->cmd
);
4951 static int bnx2x_queue_send_cmd_e2(struct bnx2x
*bp
,
4952 struct bnx2x_queue_state_params
*params
)
4954 switch (params
->cmd
) {
4955 case BNX2X_Q_CMD_SETUP
:
4956 return bnx2x_q_send_setup_e2(bp
, params
);
4957 case BNX2X_Q_CMD_INIT
:
4958 case BNX2X_Q_CMD_SETUP_TX_ONLY
:
4959 case BNX2X_Q_CMD_DEACTIVATE
:
4960 case BNX2X_Q_CMD_ACTIVATE
:
4961 case BNX2X_Q_CMD_UPDATE
:
4962 case BNX2X_Q_CMD_UPDATE_TPA
:
4963 case BNX2X_Q_CMD_HALT
:
4964 case BNX2X_Q_CMD_CFC_DEL
:
4965 case BNX2X_Q_CMD_TERMINATE
:
4966 case BNX2X_Q_CMD_EMPTY
:
4967 return bnx2x_queue_send_cmd_cmn(bp
, params
);
4969 BNX2X_ERR("Unknown command: %d\n", params
->cmd
);
4975 * bnx2x_queue_chk_transition - check state machine of a regular Queue
4977 * @bp: device handle
4982 * It both checks if the requested command is legal in a current
4983 * state and, if it's legal, sets a `next_state' in the object
4984 * that will be used in the completion flow to set the `state'
4987 * returns 0 if a requested command is a legal transition,
4988 * -EINVAL otherwise.
4990 static int bnx2x_queue_chk_transition(struct bnx2x
*bp
,
4991 struct bnx2x_queue_sp_obj
*o
,
4992 struct bnx2x_queue_state_params
*params
)
4994 enum bnx2x_q_state state
= o
->state
, next_state
= BNX2X_Q_STATE_MAX
;
4995 enum bnx2x_queue_cmd cmd
= params
->cmd
;
4996 struct bnx2x_queue_update_params
*update_params
=
4997 ¶ms
->params
.update
;
4998 u8 next_tx_only
= o
->num_tx_only
;
5001 * Forget all pending for completion commands if a driver only state
5002 * transition has been requested.
5004 if (test_bit(RAMROD_DRV_CLR_ONLY
, ¶ms
->ramrod_flags
)) {
5006 o
->next_state
= BNX2X_Q_STATE_MAX
;
5010 * Don't allow a next state transition if we are in the middle of
5017 case BNX2X_Q_STATE_RESET
:
5018 if (cmd
== BNX2X_Q_CMD_INIT
)
5019 next_state
= BNX2X_Q_STATE_INITIALIZED
;
5022 case BNX2X_Q_STATE_INITIALIZED
:
5023 if (cmd
== BNX2X_Q_CMD_SETUP
) {
5024 if (test_bit(BNX2X_Q_FLG_ACTIVE
,
5025 ¶ms
->params
.setup
.flags
))
5026 next_state
= BNX2X_Q_STATE_ACTIVE
;
5028 next_state
= BNX2X_Q_STATE_INACTIVE
;
5032 case BNX2X_Q_STATE_ACTIVE
:
5033 if (cmd
== BNX2X_Q_CMD_DEACTIVATE
)
5034 next_state
= BNX2X_Q_STATE_INACTIVE
;
5036 else if ((cmd
== BNX2X_Q_CMD_EMPTY
) ||
5037 (cmd
== BNX2X_Q_CMD_UPDATE_TPA
))
5038 next_state
= BNX2X_Q_STATE_ACTIVE
;
5040 else if (cmd
== BNX2X_Q_CMD_SETUP_TX_ONLY
) {
5041 next_state
= BNX2X_Q_STATE_MULTI_COS
;
5045 else if (cmd
== BNX2X_Q_CMD_HALT
)
5046 next_state
= BNX2X_Q_STATE_STOPPED
;
5048 else if (cmd
== BNX2X_Q_CMD_UPDATE
) {
5049 /* If "active" state change is requested, update the
5050 * state accordingly.
5052 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG
,
5053 &update_params
->update_flags
) &&
5054 !test_bit(BNX2X_Q_UPDATE_ACTIVATE
,
5055 &update_params
->update_flags
))
5056 next_state
= BNX2X_Q_STATE_INACTIVE
;
5058 next_state
= BNX2X_Q_STATE_ACTIVE
;
5062 case BNX2X_Q_STATE_MULTI_COS
:
5063 if (cmd
== BNX2X_Q_CMD_TERMINATE
)
5064 next_state
= BNX2X_Q_STATE_MCOS_TERMINATED
;
5066 else if (cmd
== BNX2X_Q_CMD_SETUP_TX_ONLY
) {
5067 next_state
= BNX2X_Q_STATE_MULTI_COS
;
5068 next_tx_only
= o
->num_tx_only
+ 1;
5071 else if ((cmd
== BNX2X_Q_CMD_EMPTY
) ||
5072 (cmd
== BNX2X_Q_CMD_UPDATE_TPA
))
5073 next_state
= BNX2X_Q_STATE_MULTI_COS
;
5075 else if (cmd
== BNX2X_Q_CMD_UPDATE
) {
5076 /* If "active" state change is requested, update the
5077 * state accordingly.
5079 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG
,
5080 &update_params
->update_flags
) &&
5081 !test_bit(BNX2X_Q_UPDATE_ACTIVATE
,
5082 &update_params
->update_flags
))
5083 next_state
= BNX2X_Q_STATE_INACTIVE
;
5085 next_state
= BNX2X_Q_STATE_MULTI_COS
;
5089 case BNX2X_Q_STATE_MCOS_TERMINATED
:
5090 if (cmd
== BNX2X_Q_CMD_CFC_DEL
) {
5091 next_tx_only
= o
->num_tx_only
- 1;
5092 if (next_tx_only
== 0)
5093 next_state
= BNX2X_Q_STATE_ACTIVE
;
5095 next_state
= BNX2X_Q_STATE_MULTI_COS
;
5099 case BNX2X_Q_STATE_INACTIVE
:
5100 if (cmd
== BNX2X_Q_CMD_ACTIVATE
)
5101 next_state
= BNX2X_Q_STATE_ACTIVE
;
5103 else if ((cmd
== BNX2X_Q_CMD_EMPTY
) ||
5104 (cmd
== BNX2X_Q_CMD_UPDATE_TPA
))
5105 next_state
= BNX2X_Q_STATE_INACTIVE
;
5107 else if (cmd
== BNX2X_Q_CMD_HALT
)
5108 next_state
= BNX2X_Q_STATE_STOPPED
;
5110 else if (cmd
== BNX2X_Q_CMD_UPDATE
) {
5111 /* If "active" state change is requested, update the
5112 * state accordingly.
5114 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG
,
5115 &update_params
->update_flags
) &&
5116 test_bit(BNX2X_Q_UPDATE_ACTIVATE
,
5117 &update_params
->update_flags
)){
5118 if (o
->num_tx_only
== 0)
5119 next_state
= BNX2X_Q_STATE_ACTIVE
;
5120 else /* tx only queues exist for this queue */
5121 next_state
= BNX2X_Q_STATE_MULTI_COS
;
5123 next_state
= BNX2X_Q_STATE_INACTIVE
;
5127 case BNX2X_Q_STATE_STOPPED
:
5128 if (cmd
== BNX2X_Q_CMD_TERMINATE
)
5129 next_state
= BNX2X_Q_STATE_TERMINATED
;
5132 case BNX2X_Q_STATE_TERMINATED
:
5133 if (cmd
== BNX2X_Q_CMD_CFC_DEL
)
5134 next_state
= BNX2X_Q_STATE_RESET
;
5138 BNX2X_ERR("Illegal state: %d\n", state
);
5141 /* Transition is assured */
5142 if (next_state
!= BNX2X_Q_STATE_MAX
) {
5143 DP(BNX2X_MSG_SP
, "Good state transition: %d(%d)->%d\n",
5144 state
, cmd
, next_state
);
5145 o
->next_state
= next_state
;
5146 o
->next_tx_only
= next_tx_only
;
5150 DP(BNX2X_MSG_SP
, "Bad state transition request: %d %d\n", state
, cmd
);
5155 void bnx2x_init_queue_obj(struct bnx2x
*bp
,
5156 struct bnx2x_queue_sp_obj
*obj
,
5157 u8 cl_id
, u32
*cids
, u8 cid_cnt
, u8 func_id
,
5159 dma_addr_t rdata_mapping
, unsigned long type
)
5161 memset(obj
, 0, sizeof(*obj
));
5163 /* We support only BNX2X_MULTI_TX_COS Tx CoS at the moment */
5164 BUG_ON(BNX2X_MULTI_TX_COS
< cid_cnt
);
5166 memcpy(obj
->cids
, cids
, sizeof(obj
->cids
[0]) * cid_cnt
);
5167 obj
->max_cos
= cid_cnt
;
5169 obj
->func_id
= func_id
;
5171 obj
->rdata_mapping
= rdata_mapping
;
5173 obj
->next_state
= BNX2X_Q_STATE_MAX
;
5175 if (CHIP_IS_E1x(bp
))
5176 obj
->send_cmd
= bnx2x_queue_send_cmd_e1x
;
5178 obj
->send_cmd
= bnx2x_queue_send_cmd_e2
;
5180 obj
->check_transition
= bnx2x_queue_chk_transition
;
5182 obj
->complete_cmd
= bnx2x_queue_comp_cmd
;
5183 obj
->wait_comp
= bnx2x_queue_wait_comp
;
5184 obj
->set_pending
= bnx2x_queue_set_pending
;
5187 void bnx2x_queue_set_cos_cid(struct bnx2x
*bp
,
5188 struct bnx2x_queue_sp_obj
*obj
,
5191 obj
->cids
[index
] = cid
;
5194 /********************** Function state object *********************************/
5195 enum bnx2x_func_state
bnx2x_func_get_state(struct bnx2x
*bp
,
5196 struct bnx2x_func_sp_obj
*o
)
5198 /* in the middle of transaction - return INVALID state */
5200 return BNX2X_F_STATE_MAX
;
5203 * unsure the order of reading of o->pending and o->state
5204 * o->pending should be read first
5211 static int bnx2x_func_wait_comp(struct bnx2x
*bp
,
5212 struct bnx2x_func_sp_obj
*o
,
5213 enum bnx2x_func_cmd cmd
)
5215 return bnx2x_state_wait(bp
, cmd
, &o
->pending
);
5219 * bnx2x_func_state_change_comp - complete the state machine transition
5221 * @bp: device handle
5225 * Called on state change transition. Completes the state
5226 * machine transition only - no HW interaction.
5228 static inline int bnx2x_func_state_change_comp(struct bnx2x
*bp
,
5229 struct bnx2x_func_sp_obj
*o
,
5230 enum bnx2x_func_cmd cmd
)
5232 unsigned long cur_pending
= o
->pending
;
5234 if (!test_and_clear_bit(cmd
, &cur_pending
)) {
5235 BNX2X_ERR("Bad MC reply %d for func %d in state %d "
5236 "pending 0x%lx, next_state %d\n", cmd
, BP_FUNC(bp
),
5237 o
->state
, cur_pending
, o
->next_state
);
5242 "Completing command %d for func %d, setting state to %d\n",
5243 cmd
, BP_FUNC(bp
), o
->next_state
);
5245 o
->state
= o
->next_state
;
5246 o
->next_state
= BNX2X_F_STATE_MAX
;
5248 /* It's important that o->state and o->next_state are
5249 * updated before o->pending.
5253 clear_bit(cmd
, &o
->pending
);
5254 smp_mb__after_clear_bit();
5260 * bnx2x_func_comp_cmd - complete the state change command
5262 * @bp: device handle
5266 * Checks that the arrived completion is expected.
5268 static int bnx2x_func_comp_cmd(struct bnx2x
*bp
,
5269 struct bnx2x_func_sp_obj
*o
,
5270 enum bnx2x_func_cmd cmd
)
5272 /* Complete the state machine part first, check if it's a
5275 int rc
= bnx2x_func_state_change_comp(bp
, o
, cmd
);
5280 * bnx2x_func_chk_transition - perform function state machine transition
5282 * @bp: device handle
5286 * It both checks if the requested command is legal in a current
5287 * state and, if it's legal, sets a `next_state' in the object
5288 * that will be used in the completion flow to set the `state'
5291 * returns 0 if a requested command is a legal transition,
5292 * -EINVAL otherwise.
5294 static int bnx2x_func_chk_transition(struct bnx2x
*bp
,
5295 struct bnx2x_func_sp_obj
*o
,
5296 struct bnx2x_func_state_params
*params
)
5298 enum bnx2x_func_state state
= o
->state
, next_state
= BNX2X_F_STATE_MAX
;
5299 enum bnx2x_func_cmd cmd
= params
->cmd
;
5302 * Forget all pending for completion commands if a driver only state
5303 * transition has been requested.
5305 if (test_bit(RAMROD_DRV_CLR_ONLY
, ¶ms
->ramrod_flags
)) {
5307 o
->next_state
= BNX2X_F_STATE_MAX
;
5311 * Don't allow a next state transition if we are in the middle of
5318 case BNX2X_F_STATE_RESET
:
5319 if (cmd
== BNX2X_F_CMD_HW_INIT
)
5320 next_state
= BNX2X_F_STATE_INITIALIZED
;
5323 case BNX2X_F_STATE_INITIALIZED
:
5324 if (cmd
== BNX2X_F_CMD_START
)
5325 next_state
= BNX2X_F_STATE_STARTED
;
5327 else if (cmd
== BNX2X_F_CMD_HW_RESET
)
5328 next_state
= BNX2X_F_STATE_RESET
;
5331 case BNX2X_F_STATE_STARTED
:
5332 if (cmd
== BNX2X_F_CMD_STOP
)
5333 next_state
= BNX2X_F_STATE_INITIALIZED
;
5334 else if (cmd
== BNX2X_F_CMD_TX_STOP
)
5335 next_state
= BNX2X_F_STATE_TX_STOPPED
;
5338 case BNX2X_F_STATE_TX_STOPPED
:
5339 if (cmd
== BNX2X_F_CMD_TX_START
)
5340 next_state
= BNX2X_F_STATE_STARTED
;
5344 BNX2X_ERR("Unknown state: %d\n", state
);
5347 /* Transition is assured */
5348 if (next_state
!= BNX2X_F_STATE_MAX
) {
5349 DP(BNX2X_MSG_SP
, "Good function state transition: %d(%d)->%d\n",
5350 state
, cmd
, next_state
);
5351 o
->next_state
= next_state
;
5355 DP(BNX2X_MSG_SP
, "Bad function state transition request: %d %d\n",
5362 * bnx2x_func_init_func - performs HW init at function stage
5364 * @bp: device handle
5367 * Init HW when the current phase is
5368 * FW_MSG_CODE_DRV_LOAD_FUNCTION: initialize only FUNCTION-only
5371 static inline int bnx2x_func_init_func(struct bnx2x
*bp
,
5372 const struct bnx2x_func_sp_drv_ops
*drv
)
5374 return drv
->init_hw_func(bp
);
5378 * bnx2x_func_init_port - performs HW init at port stage
5380 * @bp: device handle
5383 * Init HW when the current phase is
5384 * FW_MSG_CODE_DRV_LOAD_PORT: initialize PORT-only and
5385 * FUNCTION-only HW blocks.
5388 static inline int bnx2x_func_init_port(struct bnx2x
*bp
,
5389 const struct bnx2x_func_sp_drv_ops
*drv
)
5391 int rc
= drv
->init_hw_port(bp
);
5395 return bnx2x_func_init_func(bp
, drv
);
5399 * bnx2x_func_init_cmn_chip - performs HW init at chip-common stage
5401 * @bp: device handle
5404 * Init HW when the current phase is
5405 * FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: initialize COMMON_CHIP,
5406 * PORT-only and FUNCTION-only HW blocks.
5408 static inline int bnx2x_func_init_cmn_chip(struct bnx2x
*bp
,
5409 const struct bnx2x_func_sp_drv_ops
*drv
)
5411 int rc
= drv
->init_hw_cmn_chip(bp
);
5415 return bnx2x_func_init_port(bp
, drv
);
5419 * bnx2x_func_init_cmn - performs HW init at common stage
5421 * @bp: device handle
5424 * Init HW when the current phase is
5425 * FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: initialize COMMON,
5426 * PORT-only and FUNCTION-only HW blocks.
5428 static inline int bnx2x_func_init_cmn(struct bnx2x
*bp
,
5429 const struct bnx2x_func_sp_drv_ops
*drv
)
5431 int rc
= drv
->init_hw_cmn(bp
);
5435 return bnx2x_func_init_port(bp
, drv
);
5438 static int bnx2x_func_hw_init(struct bnx2x
*bp
,
5439 struct bnx2x_func_state_params
*params
)
5441 u32 load_code
= params
->params
.hw_init
.load_phase
;
5442 struct bnx2x_func_sp_obj
*o
= params
->f_obj
;
5443 const struct bnx2x_func_sp_drv_ops
*drv
= o
->drv
;
5446 DP(BNX2X_MSG_SP
, "function %d load_code %x\n",
5447 BP_ABS_FUNC(bp
), load_code
);
5449 /* Prepare buffers for unzipping the FW */
5450 rc
= drv
->gunzip_init(bp
);
5455 rc
= drv
->init_fw(bp
);
5457 BNX2X_ERR("Error loading firmware\n");
5461 /* Handle the beginning of COMMON_XXX pases separatelly... */
5462 switch (load_code
) {
5463 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP
:
5464 rc
= bnx2x_func_init_cmn_chip(bp
, drv
);
5469 case FW_MSG_CODE_DRV_LOAD_COMMON
:
5470 rc
= bnx2x_func_init_cmn(bp
, drv
);
5475 case FW_MSG_CODE_DRV_LOAD_PORT
:
5476 rc
= bnx2x_func_init_port(bp
, drv
);
5481 case FW_MSG_CODE_DRV_LOAD_FUNCTION
:
5482 rc
= bnx2x_func_init_func(bp
, drv
);
5488 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code
);
5493 drv
->gunzip_end(bp
);
5495 /* In case of success, complete the comand immediatelly: no ramrods
5499 o
->complete_cmd(bp
, o
, BNX2X_F_CMD_HW_INIT
);
5505 * bnx2x_func_reset_func - reset HW at function stage
5507 * @bp: device handle
5510 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_FUNCTION stage: reset only
5511 * FUNCTION-only HW blocks.
5513 static inline void bnx2x_func_reset_func(struct bnx2x
*bp
,
5514 const struct bnx2x_func_sp_drv_ops
*drv
)
5516 drv
->reset_hw_func(bp
);
5520 * bnx2x_func_reset_port - reser HW at port stage
5522 * @bp: device handle
5525 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_PORT stage: reset
5526 * FUNCTION-only and PORT-only HW blocks.
5530 * It's important to call reset_port before reset_func() as the last thing
5531 * reset_func does is pf_disable() thus disabling PGLUE_B, which
5532 * makes impossible any DMAE transactions.
5534 static inline void bnx2x_func_reset_port(struct bnx2x
*bp
,
5535 const struct bnx2x_func_sp_drv_ops
*drv
)
5537 drv
->reset_hw_port(bp
);
5538 bnx2x_func_reset_func(bp
, drv
);
5542 * bnx2x_func_reset_cmn - reser HW at common stage
5544 * @bp: device handle
5547 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_COMMON and
5548 * FW_MSG_CODE_DRV_UNLOAD_COMMON_CHIP stages: reset COMMON,
5549 * COMMON_CHIP, FUNCTION-only and PORT-only HW blocks.
5551 static inline void bnx2x_func_reset_cmn(struct bnx2x
*bp
,
5552 const struct bnx2x_func_sp_drv_ops
*drv
)
5554 bnx2x_func_reset_port(bp
, drv
);
5555 drv
->reset_hw_cmn(bp
);
5559 static inline int bnx2x_func_hw_reset(struct bnx2x
*bp
,
5560 struct bnx2x_func_state_params
*params
)
5562 u32 reset_phase
= params
->params
.hw_reset
.reset_phase
;
5563 struct bnx2x_func_sp_obj
*o
= params
->f_obj
;
5564 const struct bnx2x_func_sp_drv_ops
*drv
= o
->drv
;
5566 DP(BNX2X_MSG_SP
, "function %d reset_phase %x\n", BP_ABS_FUNC(bp
),
5569 switch (reset_phase
) {
5570 case FW_MSG_CODE_DRV_UNLOAD_COMMON
:
5571 bnx2x_func_reset_cmn(bp
, drv
);
5573 case FW_MSG_CODE_DRV_UNLOAD_PORT
:
5574 bnx2x_func_reset_port(bp
, drv
);
5576 case FW_MSG_CODE_DRV_UNLOAD_FUNCTION
:
5577 bnx2x_func_reset_func(bp
, drv
);
5580 BNX2X_ERR("Unknown reset_phase (0x%x) from MCP\n",
5585 /* Complete the comand immediatelly: no ramrods have been sent. */
5586 o
->complete_cmd(bp
, o
, BNX2X_F_CMD_HW_RESET
);
5591 static inline int bnx2x_func_send_start(struct bnx2x
*bp
,
5592 struct bnx2x_func_state_params
*params
)
5594 struct bnx2x_func_sp_obj
*o
= params
->f_obj
;
5595 struct function_start_data
*rdata
=
5596 (struct function_start_data
*)o
->rdata
;
5597 dma_addr_t data_mapping
= o
->rdata_mapping
;
5598 struct bnx2x_func_start_params
*start_params
= ¶ms
->params
.start
;
5600 memset(rdata
, 0, sizeof(*rdata
));
5602 /* Fill the ramrod data with provided parameters */
5603 rdata
->function_mode
= cpu_to_le16(start_params
->mf_mode
);
5604 rdata
->sd_vlan_tag
= cpu_to_le16(start_params
->sd_vlan_tag
);
5605 rdata
->path_id
= BP_PATH(bp
);
5606 rdata
->network_cos_mode
= start_params
->network_cos_mode
;
5609 * No need for an explicit memory barrier here as long we would
5610 * need to ensure the ordering of writing to the SPQ element
5611 * and updating of the SPQ producer which involves a memory
5612 * read and we will have to put a full memory barrier there
5613 * (inside bnx2x_sp_post()).
5616 return bnx2x_sp_post(bp
, RAMROD_CMD_ID_COMMON_FUNCTION_START
, 0,
5617 U64_HI(data_mapping
),
5618 U64_LO(data_mapping
), NONE_CONNECTION_TYPE
);
5621 static inline int bnx2x_func_send_stop(struct bnx2x
*bp
,
5622 struct bnx2x_func_state_params
*params
)
5624 return bnx2x_sp_post(bp
, RAMROD_CMD_ID_COMMON_FUNCTION_STOP
, 0, 0, 0,
5625 NONE_CONNECTION_TYPE
);
5628 static inline int bnx2x_func_send_tx_stop(struct bnx2x
*bp
,
5629 struct bnx2x_func_state_params
*params
)
5631 return bnx2x_sp_post(bp
, RAMROD_CMD_ID_COMMON_STOP_TRAFFIC
, 0, 0, 0,
5632 NONE_CONNECTION_TYPE
);
5634 static inline int bnx2x_func_send_tx_start(struct bnx2x
*bp
,
5635 struct bnx2x_func_state_params
*params
)
5637 struct bnx2x_func_sp_obj
*o
= params
->f_obj
;
5638 struct flow_control_configuration
*rdata
=
5639 (struct flow_control_configuration
*)o
->rdata
;
5640 dma_addr_t data_mapping
= o
->rdata_mapping
;
5641 struct bnx2x_func_tx_start_params
*tx_start_params
=
5642 ¶ms
->params
.tx_start
;
5645 memset(rdata
, 0, sizeof(*rdata
));
5647 rdata
->dcb_enabled
= tx_start_params
->dcb_enabled
;
5648 rdata
->dcb_version
= tx_start_params
->dcb_version
;
5649 rdata
->dont_add_pri_0_en
= tx_start_params
->dont_add_pri_0_en
;
5651 for (i
= 0; i
< ARRAY_SIZE(rdata
->traffic_type_to_priority_cos
); i
++)
5652 rdata
->traffic_type_to_priority_cos
[i
] =
5653 tx_start_params
->traffic_type_to_priority_cos
[i
];
5655 return bnx2x_sp_post(bp
, RAMROD_CMD_ID_COMMON_START_TRAFFIC
, 0,
5656 U64_HI(data_mapping
),
5657 U64_LO(data_mapping
), NONE_CONNECTION_TYPE
);
5660 static int bnx2x_func_send_cmd(struct bnx2x
*bp
,
5661 struct bnx2x_func_state_params
*params
)
5663 switch (params
->cmd
) {
5664 case BNX2X_F_CMD_HW_INIT
:
5665 return bnx2x_func_hw_init(bp
, params
);
5666 case BNX2X_F_CMD_START
:
5667 return bnx2x_func_send_start(bp
, params
);
5668 case BNX2X_F_CMD_STOP
:
5669 return bnx2x_func_send_stop(bp
, params
);
5670 case BNX2X_F_CMD_HW_RESET
:
5671 return bnx2x_func_hw_reset(bp
, params
);
5672 case BNX2X_F_CMD_TX_STOP
:
5673 return bnx2x_func_send_tx_stop(bp
, params
);
5674 case BNX2X_F_CMD_TX_START
:
5675 return bnx2x_func_send_tx_start(bp
, params
);
5677 BNX2X_ERR("Unknown command: %d\n", params
->cmd
);
5682 void bnx2x_init_func_obj(struct bnx2x
*bp
,
5683 struct bnx2x_func_sp_obj
*obj
,
5684 void *rdata
, dma_addr_t rdata_mapping
,
5685 struct bnx2x_func_sp_drv_ops
*drv_iface
)
5687 memset(obj
, 0, sizeof(*obj
));
5689 mutex_init(&obj
->one_pending_mutex
);
5692 obj
->rdata_mapping
= rdata_mapping
;
5694 obj
->send_cmd
= bnx2x_func_send_cmd
;
5695 obj
->check_transition
= bnx2x_func_chk_transition
;
5696 obj
->complete_cmd
= bnx2x_func_comp_cmd
;
5697 obj
->wait_comp
= bnx2x_func_wait_comp
;
5699 obj
->drv
= drv_iface
;
5703 * bnx2x_func_state_change - perform Function state change transition
5705 * @bp: device handle
5706 * @params: parameters to perform the transaction
5708 * returns 0 in case of successfully completed transition,
5709 * negative error code in case of failure, positive
5710 * (EBUSY) value if there is a completion to that is
5711 * still pending (possible only if RAMROD_COMP_WAIT is
5712 * not set in params->ramrod_flags for asynchronous
5715 int bnx2x_func_state_change(struct bnx2x
*bp
,
5716 struct bnx2x_func_state_params
*params
)
5718 struct bnx2x_func_sp_obj
*o
= params
->f_obj
;
5720 enum bnx2x_func_cmd cmd
= params
->cmd
;
5721 unsigned long *pending
= &o
->pending
;
5723 mutex_lock(&o
->one_pending_mutex
);
5725 /* Check that the requested transition is legal */
5726 if (o
->check_transition(bp
, o
, params
)) {
5727 mutex_unlock(&o
->one_pending_mutex
);
5731 /* Set "pending" bit */
5732 set_bit(cmd
, pending
);
5734 /* Don't send a command if only driver cleanup was requested */
5735 if (test_bit(RAMROD_DRV_CLR_ONLY
, ¶ms
->ramrod_flags
)) {
5736 bnx2x_func_state_change_comp(bp
, o
, cmd
);
5737 mutex_unlock(&o
->one_pending_mutex
);
5740 rc
= o
->send_cmd(bp
, params
);
5742 mutex_unlock(&o
->one_pending_mutex
);
5745 o
->next_state
= BNX2X_F_STATE_MAX
;
5746 clear_bit(cmd
, pending
);
5747 smp_mb__after_clear_bit();
5751 if (test_bit(RAMROD_COMP_WAIT
, ¶ms
->ramrod_flags
)) {
5752 rc
= o
->wait_comp(bp
, o
, cmd
);
5760 return !!test_bit(cmd
, pending
);