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,
53 exe_q_optimize optimize,
57 memset(o, 0, sizeof(*o));
59 INIT_LIST_HEAD(&o->exe_queue);
60 INIT_LIST_HEAD(&o->pending_comp);
62 spin_lock_init(&o->lock);
64 o->exe_chunk_len = exe_len;
67 /* Owner specific callbacks */
68 o->validate = validate;
69 o->optimize = optimize;
73 DP(BNX2X_MSG_SP, "Setup the execution queue with the chunk "
74 "length of %d\n", exe_len);
77 static inline void bnx2x_exe_queue_free_elem(struct bnx2x *bp,
78 struct bnx2x_exeq_elem *elem)
80 DP(BNX2X_MSG_SP, "Deleting an exe_queue element\n");
84 static inline int bnx2x_exe_queue_length(struct bnx2x_exe_queue_obj *o)
86 struct bnx2x_exeq_elem *elem;
89 spin_lock_bh(&o->lock);
91 list_for_each_entry(elem, &o->exe_queue, link)
94 spin_unlock_bh(&o->lock);
100 * bnx2x_exe_queue_add - add a new element to the execution queue
104 * @cmd: new command to add
105 * @restore: true - do not optimize the command
107 * If the element is optimized or is illegal, frees it.
109 static inline int bnx2x_exe_queue_add(struct bnx2x *bp,
110 struct bnx2x_exe_queue_obj *o,
111 struct bnx2x_exeq_elem *elem,
116 spin_lock_bh(&o->lock);
119 /* Try to cancel this element queue */
120 rc = o->optimize(bp, o->owner, elem);
124 /* Check if this request is ok */
125 rc = o->validate(bp, o->owner, elem);
127 BNX2X_ERR("Preamble failed: %d\n", rc);
132 /* If so, add it to the execution queue */
133 list_add_tail(&elem->link, &o->exe_queue);
135 spin_unlock_bh(&o->lock);
140 bnx2x_exe_queue_free_elem(bp, elem);
142 spin_unlock_bh(&o->lock);
148 static inline void __bnx2x_exe_queue_reset_pending(
150 struct bnx2x_exe_queue_obj *o)
152 struct bnx2x_exeq_elem *elem;
154 while (!list_empty(&o->pending_comp)) {
155 elem = list_first_entry(&o->pending_comp,
156 struct bnx2x_exeq_elem, link);
158 list_del(&elem->link);
159 bnx2x_exe_queue_free_elem(bp, elem);
163 static inline void bnx2x_exe_queue_reset_pending(struct bnx2x *bp,
164 struct bnx2x_exe_queue_obj *o)
167 spin_lock_bh(&o->lock);
169 __bnx2x_exe_queue_reset_pending(bp, o);
171 spin_unlock_bh(&o->lock);
176 * bnx2x_exe_queue_step - execute one execution chunk atomically
180 * @ramrod_flags: flags
182 * (Atomicy is ensured using the exe_queue->lock).
184 static inline int bnx2x_exe_queue_step(struct bnx2x *bp,
185 struct bnx2x_exe_queue_obj *o,
186 unsigned long *ramrod_flags)
188 struct bnx2x_exeq_elem *elem, spacer;
191 memset(&spacer, 0, sizeof(spacer));
193 spin_lock_bh(&o->lock);
196 * Next step should not be performed until the current is finished,
197 * unless a DRV_CLEAR_ONLY bit is set. In this case we just want to
198 * properly clear object internals without sending any command to the FW
199 * which also implies there won't be any completion to clear the
202 if (!list_empty(&o->pending_comp)) {
203 if (test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags)) {
204 DP(BNX2X_MSG_SP, "RAMROD_DRV_CLR_ONLY requested: "
205 "resetting pending_comp\n");
206 __bnx2x_exe_queue_reset_pending(bp, o);
208 spin_unlock_bh(&o->lock);
214 * Run through the pending commands list and create a next
217 while (!list_empty(&o->exe_queue)) {
218 elem = list_first_entry(&o->exe_queue, struct bnx2x_exeq_elem,
220 WARN_ON(!elem->cmd_len);
222 if (cur_len + elem->cmd_len <= o->exe_chunk_len) {
223 cur_len += elem->cmd_len;
225 * Prevent from both lists being empty when moving an
226 * element. This will allow the call of
227 * bnx2x_exe_queue_empty() without locking.
229 list_add_tail(&spacer.link, &o->pending_comp);
231 list_del(&elem->link);
232 list_add_tail(&elem->link, &o->pending_comp);
233 list_del(&spacer.link);
240 spin_unlock_bh(&o->lock);
244 rc = o->execute(bp, o->owner, &o->pending_comp, ramrod_flags);
247 * In case of an error return the commands back to the queue
248 * and reset the pending_comp.
250 list_splice_init(&o->pending_comp, &o->exe_queue);
253 * If zero is returned, means there are no outstanding pending
254 * completions and we may dismiss the pending list.
256 __bnx2x_exe_queue_reset_pending(bp, o);
258 spin_unlock_bh(&o->lock);
262 static inline bool bnx2x_exe_queue_empty(struct bnx2x_exe_queue_obj *o)
264 bool empty = list_empty(&o->exe_queue);
266 /* Don't reorder!!! */
269 return empty && list_empty(&o->pending_comp);
272 static inline struct bnx2x_exeq_elem *bnx2x_exe_queue_alloc_elem(
275 DP(BNX2X_MSG_SP, "Allocating a new exe_queue element\n");
276 return kzalloc(sizeof(struct bnx2x_exeq_elem), GFP_ATOMIC);
279 /************************ raw_obj functions ***********************************/
280 static bool bnx2x_raw_check_pending(struct bnx2x_raw_obj *o)
282 return !!test_bit(o->state, o->pstate);
285 static void bnx2x_raw_clear_pending(struct bnx2x_raw_obj *o)
287 smp_mb__before_clear_bit();
288 clear_bit(o->state, o->pstate);
289 smp_mb__after_clear_bit();
292 static void bnx2x_raw_set_pending(struct bnx2x_raw_obj *o)
294 smp_mb__before_clear_bit();
295 set_bit(o->state, o->pstate);
296 smp_mb__after_clear_bit();
300 * bnx2x_state_wait - wait until the given bit(state) is cleared
303 * @state: state which is to be cleared
304 * @state_p: state buffer
307 static inline int bnx2x_state_wait(struct bnx2x *bp, int state,
308 unsigned long *pstate)
310 /* can take a while if any port is running */
314 if (CHIP_REV_IS_EMUL(bp))
317 DP(BNX2X_MSG_SP, "waiting for state to become %d\n", state);
321 if (!test_bit(state, pstate)) {
322 #ifdef BNX2X_STOP_ON_ERROR
323 DP(BNX2X_MSG_SP, "exit (cnt %d)\n", 5000 - cnt);
328 usleep_range(1000, 1000);
335 BNX2X_ERR("timeout waiting for state %d\n", state);
336 #ifdef BNX2X_STOP_ON_ERROR
343 static int bnx2x_raw_wait(struct bnx2x *bp, struct bnx2x_raw_obj *raw)
345 return bnx2x_state_wait(bp, raw->state, raw->pstate);
348 /***************** Classification verbs: Set/Del MAC/VLAN/VLAN-MAC ************/
349 /* credit handling callbacks */
350 static bool bnx2x_get_cam_offset_mac(struct bnx2x_vlan_mac_obj *o, int *offset)
352 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
356 return mp->get_entry(mp, offset);
359 static bool bnx2x_get_credit_mac(struct bnx2x_vlan_mac_obj *o)
361 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
365 return mp->get(mp, 1);
368 static bool bnx2x_get_cam_offset_vlan(struct bnx2x_vlan_mac_obj *o, int *offset)
370 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
374 return vp->get_entry(vp, offset);
377 static bool bnx2x_get_credit_vlan(struct bnx2x_vlan_mac_obj *o)
379 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
383 return vp->get(vp, 1);
386 static bool bnx2x_get_credit_vlan_mac(struct bnx2x_vlan_mac_obj *o)
388 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
389 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
394 if (!vp->get(vp, 1)) {
402 static bool bnx2x_put_cam_offset_mac(struct bnx2x_vlan_mac_obj *o, int offset)
404 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
406 return mp->put_entry(mp, offset);
409 static bool bnx2x_put_credit_mac(struct bnx2x_vlan_mac_obj *o)
411 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
413 return mp->put(mp, 1);
416 static bool bnx2x_put_cam_offset_vlan(struct bnx2x_vlan_mac_obj *o, int offset)
418 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
420 return vp->put_entry(vp, offset);
423 static bool bnx2x_put_credit_vlan(struct bnx2x_vlan_mac_obj *o)
425 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
427 return vp->put(vp, 1);
430 static bool bnx2x_put_credit_vlan_mac(struct bnx2x_vlan_mac_obj *o)
432 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
433 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
438 if (!vp->put(vp, 1)) {
446 static int bnx2x_get_n_elements(struct bnx2x *bp, struct bnx2x_vlan_mac_obj *o,
449 struct bnx2x_vlan_mac_registry_elem *pos;
454 list_for_each_entry(pos, &o->head, link) {
456 /* place leading zeroes in buffer */
457 memset(next, 0, MAC_LEADING_ZERO_CNT);
459 /* place mac after leading zeroes*/
460 memcpy(next + MAC_LEADING_ZERO_CNT, pos->u.mac.mac,
463 /* calculate address of next element and
467 next = buf + counter * ALIGN(ETH_ALEN, sizeof(u32));
469 DP(BNX2X_MSG_SP, "copied element number %d to address %p element was %pM\n",
470 counter, next, pos->u.mac.mac);
473 return counter * ETH_ALEN;
476 /* check_add() callbacks */
477 static int bnx2x_check_mac_add(struct bnx2x_vlan_mac_obj *o,
478 union bnx2x_classification_ramrod_data *data)
480 struct bnx2x_vlan_mac_registry_elem *pos;
482 if (!is_valid_ether_addr(data->mac.mac))
485 /* Check if a requested MAC already exists */
486 list_for_each_entry(pos, &o->head, link)
487 if (!memcmp(data->mac.mac, pos->u.mac.mac, ETH_ALEN))
493 static int bnx2x_check_vlan_add(struct bnx2x_vlan_mac_obj *o,
494 union bnx2x_classification_ramrod_data *data)
496 struct bnx2x_vlan_mac_registry_elem *pos;
498 list_for_each_entry(pos, &o->head, link)
499 if (data->vlan.vlan == pos->u.vlan.vlan)
505 static int bnx2x_check_vlan_mac_add(struct bnx2x_vlan_mac_obj *o,
506 union bnx2x_classification_ramrod_data *data)
508 struct bnx2x_vlan_mac_registry_elem *pos;
510 list_for_each_entry(pos, &o->head, link)
511 if ((data->vlan_mac.vlan == pos->u.vlan_mac.vlan) &&
512 (!memcmp(data->vlan_mac.mac, pos->u.vlan_mac.mac,
520 /* check_del() callbacks */
521 static struct bnx2x_vlan_mac_registry_elem *
522 bnx2x_check_mac_del(struct bnx2x_vlan_mac_obj *o,
523 union bnx2x_classification_ramrod_data *data)
525 struct bnx2x_vlan_mac_registry_elem *pos;
527 list_for_each_entry(pos, &o->head, link)
528 if (!memcmp(data->mac.mac, pos->u.mac.mac, ETH_ALEN))
534 static struct bnx2x_vlan_mac_registry_elem *
535 bnx2x_check_vlan_del(struct bnx2x_vlan_mac_obj *o,
536 union bnx2x_classification_ramrod_data *data)
538 struct bnx2x_vlan_mac_registry_elem *pos;
540 list_for_each_entry(pos, &o->head, link)
541 if (data->vlan.vlan == pos->u.vlan.vlan)
547 static struct bnx2x_vlan_mac_registry_elem *
548 bnx2x_check_vlan_mac_del(struct bnx2x_vlan_mac_obj *o,
549 union bnx2x_classification_ramrod_data *data)
551 struct bnx2x_vlan_mac_registry_elem *pos;
553 list_for_each_entry(pos, &o->head, link)
554 if ((data->vlan_mac.vlan == pos->u.vlan_mac.vlan) &&
555 (!memcmp(data->vlan_mac.mac, pos->u.vlan_mac.mac,
562 /* check_move() callback */
563 static bool bnx2x_check_move(struct bnx2x_vlan_mac_obj *src_o,
564 struct bnx2x_vlan_mac_obj *dst_o,
565 union bnx2x_classification_ramrod_data *data)
567 struct bnx2x_vlan_mac_registry_elem *pos;
570 /* Check if we can delete the requested configuration from the first
573 pos = src_o->check_del(src_o, data);
575 /* check if configuration can be added */
576 rc = dst_o->check_add(dst_o, data);
578 /* If this classification can not be added (is already set)
579 * or can't be deleted - return an error.
587 static bool bnx2x_check_move_always_err(
588 struct bnx2x_vlan_mac_obj *src_o,
589 struct bnx2x_vlan_mac_obj *dst_o,
590 union bnx2x_classification_ramrod_data *data)
596 static inline u8 bnx2x_vlan_mac_get_rx_tx_flag(struct bnx2x_vlan_mac_obj *o)
598 struct bnx2x_raw_obj *raw = &o->raw;
601 if ((raw->obj_type == BNX2X_OBJ_TYPE_TX) ||
602 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
603 rx_tx_flag |= ETH_CLASSIFY_CMD_HEADER_TX_CMD;
605 if ((raw->obj_type == BNX2X_OBJ_TYPE_RX) ||
606 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
607 rx_tx_flag |= ETH_CLASSIFY_CMD_HEADER_RX_CMD;
612 /* LLH CAM line allocations */
614 LLH_CAM_ISCSI_ETH_LINE = 0,
616 LLH_CAM_MAX_PF_LINE = NIG_REG_LLH1_FUNC_MEM_SIZE / 2
619 static inline void bnx2x_set_mac_in_nig(struct bnx2x *bp,
620 bool add, unsigned char *dev_addr, int index)
623 u32 reg_offset = BP_PORT(bp) ? NIG_REG_LLH1_FUNC_MEM :
624 NIG_REG_LLH0_FUNC_MEM;
626 if (!IS_MF_SI(bp) || index > LLH_CAM_MAX_PF_LINE)
629 DP(BNX2X_MSG_SP, "Going to %s LLH configuration at entry %d\n",
630 (add ? "ADD" : "DELETE"), index);
633 /* LLH_FUNC_MEM is a u64 WB register */
634 reg_offset += 8*index;
636 wb_data[0] = ((dev_addr[2] << 24) | (dev_addr[3] << 16) |
637 (dev_addr[4] << 8) | dev_addr[5]);
638 wb_data[1] = ((dev_addr[0] << 8) | dev_addr[1]);
640 REG_WR_DMAE(bp, reg_offset, wb_data, 2);
643 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_FUNC_MEM_ENABLE :
644 NIG_REG_LLH0_FUNC_MEM_ENABLE) + 4*index, add);
648 * bnx2x_vlan_mac_set_cmd_hdr_e2 - set a header in a single classify ramrod
651 * @o: queue for which we want to configure this rule
652 * @add: if true the command is an ADD command, DEL otherwise
653 * @opcode: CLASSIFY_RULE_OPCODE_XXX
654 * @hdr: pointer to a header to setup
657 static inline void bnx2x_vlan_mac_set_cmd_hdr_e2(struct bnx2x *bp,
658 struct bnx2x_vlan_mac_obj *o, bool add, int opcode,
659 struct eth_classify_cmd_header *hdr)
661 struct bnx2x_raw_obj *raw = &o->raw;
663 hdr->client_id = raw->cl_id;
664 hdr->func_id = raw->func_id;
666 /* Rx or/and Tx (internal switching) configuration ? */
667 hdr->cmd_general_data |=
668 bnx2x_vlan_mac_get_rx_tx_flag(o);
671 hdr->cmd_general_data |= ETH_CLASSIFY_CMD_HEADER_IS_ADD;
673 hdr->cmd_general_data |=
674 (opcode << ETH_CLASSIFY_CMD_HEADER_OPCODE_SHIFT);
678 * bnx2x_vlan_mac_set_rdata_hdr_e2 - set the classify ramrod data header
680 * @cid: connection id
681 * @type: BNX2X_FILTER_XXX_PENDING
682 * @hdr: poiter to header to setup
685 * currently we always configure one rule and echo field to contain a CID and an
688 static inline void bnx2x_vlan_mac_set_rdata_hdr_e2(u32 cid, int type,
689 struct eth_classify_header *hdr, int rule_cnt)
691 hdr->echo = (cid & BNX2X_SWCID_MASK) | (type << BNX2X_SWCID_SHIFT);
692 hdr->rule_cnt = (u8)rule_cnt;
696 /* hw_config() callbacks */
697 static void bnx2x_set_one_mac_e2(struct bnx2x *bp,
698 struct bnx2x_vlan_mac_obj *o,
699 struct bnx2x_exeq_elem *elem, int rule_idx,
702 struct bnx2x_raw_obj *raw = &o->raw;
703 struct eth_classify_rules_ramrod_data *data =
704 (struct eth_classify_rules_ramrod_data *)(raw->rdata);
705 int rule_cnt = rule_idx + 1, cmd = elem->cmd_data.vlan_mac.cmd;
706 union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
707 bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
708 unsigned long *vlan_mac_flags = &elem->cmd_data.vlan_mac.vlan_mac_flags;
709 u8 *mac = elem->cmd_data.vlan_mac.u.mac.mac;
712 * Set LLH CAM entry: currently only iSCSI and ETH macs are
713 * relevant. In addition, current implementation is tuned for a
716 * When multiple unicast ETH MACs PF configuration in switch
717 * independent mode is required (NetQ, multiple netdev MACs,
718 * etc.), consider better utilisation of 8 per function MAC
719 * entries in the LLH register. There is also
720 * NIG_REG_P[01]_LLH_FUNC_MEM2 registers that complete the
721 * total number of CAM entries to 16.
723 * Currently we won't configure NIG for MACs other than a primary ETH
724 * MAC and iSCSI L2 MAC.
726 * If this MAC is moving from one Queue to another, no need to change
729 if (cmd != BNX2X_VLAN_MAC_MOVE) {
730 if (test_bit(BNX2X_ISCSI_ETH_MAC, vlan_mac_flags))
731 bnx2x_set_mac_in_nig(bp, add, mac,
732 LLH_CAM_ISCSI_ETH_LINE);
733 else if (test_bit(BNX2X_ETH_MAC, vlan_mac_flags))
734 bnx2x_set_mac_in_nig(bp, add, mac, LLH_CAM_ETH_LINE);
737 /* Reset the ramrod data buffer for the first rule */
739 memset(data, 0, sizeof(*data));
741 /* Setup a command header */
742 bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_MAC,
743 &rule_entry->mac.header);
745 DP(BNX2X_MSG_SP, "About to %s MAC %pM for Queue %d\n",
746 add ? "add" : "delete", mac, raw->cl_id);
748 /* Set a MAC itself */
749 bnx2x_set_fw_mac_addr(&rule_entry->mac.mac_msb,
750 &rule_entry->mac.mac_mid,
751 &rule_entry->mac.mac_lsb, mac);
753 /* MOVE: Add a rule that will add this MAC to the target Queue */
754 if (cmd == BNX2X_VLAN_MAC_MOVE) {
758 /* Setup ramrod data */
759 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
760 elem->cmd_data.vlan_mac.target_obj,
761 true, CLASSIFY_RULE_OPCODE_MAC,
762 &rule_entry->mac.header);
764 /* Set a MAC itself */
765 bnx2x_set_fw_mac_addr(&rule_entry->mac.mac_msb,
766 &rule_entry->mac.mac_mid,
767 &rule_entry->mac.mac_lsb, mac);
770 /* Set the ramrod data header */
771 /* TODO: take this to the higher level in order to prevent multiple
773 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
778 * bnx2x_vlan_mac_set_rdata_hdr_e1x - set a header in a single classify ramrod
783 * @cam_offset: offset in cam memory
784 * @hdr: pointer to a header to setup
788 static inline void bnx2x_vlan_mac_set_rdata_hdr_e1x(struct bnx2x *bp,
789 struct bnx2x_vlan_mac_obj *o, int type, int cam_offset,
790 struct mac_configuration_hdr *hdr)
792 struct bnx2x_raw_obj *r = &o->raw;
795 hdr->offset = (u8)cam_offset;
796 hdr->client_id = 0xff;
797 hdr->echo = ((r->cid & BNX2X_SWCID_MASK) | (type << BNX2X_SWCID_SHIFT));
800 static inline void bnx2x_vlan_mac_set_cfg_entry_e1x(struct bnx2x *bp,
801 struct bnx2x_vlan_mac_obj *o, bool add, int opcode, u8 *mac,
802 u16 vlan_id, struct mac_configuration_entry *cfg_entry)
804 struct bnx2x_raw_obj *r = &o->raw;
805 u32 cl_bit_vec = (1 << r->cl_id);
807 cfg_entry->clients_bit_vector = cpu_to_le32(cl_bit_vec);
808 cfg_entry->pf_id = r->func_id;
809 cfg_entry->vlan_id = cpu_to_le16(vlan_id);
812 SET_FLAG(cfg_entry->flags, MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
813 T_ETH_MAC_COMMAND_SET);
814 SET_FLAG(cfg_entry->flags,
815 MAC_CONFIGURATION_ENTRY_VLAN_FILTERING_MODE, opcode);
817 /* Set a MAC in a ramrod data */
818 bnx2x_set_fw_mac_addr(&cfg_entry->msb_mac_addr,
819 &cfg_entry->middle_mac_addr,
820 &cfg_entry->lsb_mac_addr, mac);
822 SET_FLAG(cfg_entry->flags, MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
823 T_ETH_MAC_COMMAND_INVALIDATE);
826 static inline void bnx2x_vlan_mac_set_rdata_e1x(struct bnx2x *bp,
827 struct bnx2x_vlan_mac_obj *o, int type, int cam_offset, bool add,
828 u8 *mac, u16 vlan_id, int opcode, struct mac_configuration_cmd *config)
830 struct mac_configuration_entry *cfg_entry = &config->config_table[0];
831 struct bnx2x_raw_obj *raw = &o->raw;
833 bnx2x_vlan_mac_set_rdata_hdr_e1x(bp, o, type, cam_offset,
835 bnx2x_vlan_mac_set_cfg_entry_e1x(bp, o, add, opcode, mac, vlan_id,
838 DP(BNX2X_MSG_SP, "%s MAC %pM CLID %d CAM offset %d\n",
839 add ? "setting" : "clearing",
840 mac, raw->cl_id, cam_offset);
844 * bnx2x_set_one_mac_e1x - fill a single MAC rule ramrod data
847 * @o: bnx2x_vlan_mac_obj
848 * @elem: bnx2x_exeq_elem
849 * @rule_idx: rule_idx
850 * @cam_offset: cam_offset
852 static void bnx2x_set_one_mac_e1x(struct bnx2x *bp,
853 struct bnx2x_vlan_mac_obj *o,
854 struct bnx2x_exeq_elem *elem, int rule_idx,
857 struct bnx2x_raw_obj *raw = &o->raw;
858 struct mac_configuration_cmd *config =
859 (struct mac_configuration_cmd *)(raw->rdata);
861 * 57710 and 57711 do not support MOVE command,
862 * so it's either ADD or DEL
864 bool add = (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
867 /* Reset the ramrod data buffer */
868 memset(config, 0, sizeof(*config));
870 bnx2x_vlan_mac_set_rdata_e1x(bp, o, BNX2X_FILTER_MAC_PENDING,
872 elem->cmd_data.vlan_mac.u.mac.mac, 0,
873 ETH_VLAN_FILTER_ANY_VLAN, config);
876 static void bnx2x_set_one_vlan_e2(struct bnx2x *bp,
877 struct bnx2x_vlan_mac_obj *o,
878 struct bnx2x_exeq_elem *elem, int rule_idx,
881 struct bnx2x_raw_obj *raw = &o->raw;
882 struct eth_classify_rules_ramrod_data *data =
883 (struct eth_classify_rules_ramrod_data *)(raw->rdata);
884 int rule_cnt = rule_idx + 1;
885 union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
886 int cmd = elem->cmd_data.vlan_mac.cmd;
887 bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
888 u16 vlan = elem->cmd_data.vlan_mac.u.vlan.vlan;
890 /* Reset the ramrod data buffer for the first rule */
892 memset(data, 0, sizeof(*data));
894 /* Set a rule header */
895 bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_VLAN,
896 &rule_entry->vlan.header);
898 DP(BNX2X_MSG_SP, "About to %s VLAN %d\n", (add ? "add" : "delete"),
901 /* Set a VLAN itself */
902 rule_entry->vlan.vlan = cpu_to_le16(vlan);
904 /* MOVE: Add a rule that will add this MAC to the target Queue */
905 if (cmd == BNX2X_VLAN_MAC_MOVE) {
909 /* Setup ramrod data */
910 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
911 elem->cmd_data.vlan_mac.target_obj,
912 true, CLASSIFY_RULE_OPCODE_VLAN,
913 &rule_entry->vlan.header);
915 /* Set a VLAN itself */
916 rule_entry->vlan.vlan = cpu_to_le16(vlan);
919 /* Set the ramrod data header */
920 /* TODO: take this to the higher level in order to prevent multiple
922 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
926 static void bnx2x_set_one_vlan_mac_e2(struct bnx2x *bp,
927 struct bnx2x_vlan_mac_obj *o,
928 struct bnx2x_exeq_elem *elem,
929 int rule_idx, int cam_offset)
931 struct bnx2x_raw_obj *raw = &o->raw;
932 struct eth_classify_rules_ramrod_data *data =
933 (struct eth_classify_rules_ramrod_data *)(raw->rdata);
934 int rule_cnt = rule_idx + 1;
935 union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
936 int cmd = elem->cmd_data.vlan_mac.cmd;
937 bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
938 u16 vlan = elem->cmd_data.vlan_mac.u.vlan_mac.vlan;
939 u8 *mac = elem->cmd_data.vlan_mac.u.vlan_mac.mac;
942 /* Reset the ramrod data buffer for the first rule */
944 memset(data, 0, sizeof(*data));
946 /* Set a rule header */
947 bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_PAIR,
948 &rule_entry->pair.header);
950 /* Set VLAN and MAC themselvs */
951 rule_entry->pair.vlan = cpu_to_le16(vlan);
952 bnx2x_set_fw_mac_addr(&rule_entry->pair.mac_msb,
953 &rule_entry->pair.mac_mid,
954 &rule_entry->pair.mac_lsb, mac);
956 /* MOVE: Add a rule that will add this MAC to the target Queue */
957 if (cmd == BNX2X_VLAN_MAC_MOVE) {
961 /* Setup ramrod data */
962 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
963 elem->cmd_data.vlan_mac.target_obj,
964 true, CLASSIFY_RULE_OPCODE_PAIR,
965 &rule_entry->pair.header);
967 /* Set a VLAN itself */
968 rule_entry->pair.vlan = cpu_to_le16(vlan);
969 bnx2x_set_fw_mac_addr(&rule_entry->pair.mac_msb,
970 &rule_entry->pair.mac_mid,
971 &rule_entry->pair.mac_lsb, mac);
974 /* Set the ramrod data header */
975 /* TODO: take this to the higher level in order to prevent multiple
977 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
982 * bnx2x_set_one_vlan_mac_e1h -
985 * @o: bnx2x_vlan_mac_obj
986 * @elem: bnx2x_exeq_elem
987 * @rule_idx: rule_idx
988 * @cam_offset: cam_offset
990 static void bnx2x_set_one_vlan_mac_e1h(struct bnx2x *bp,
991 struct bnx2x_vlan_mac_obj *o,
992 struct bnx2x_exeq_elem *elem,
993 int rule_idx, int cam_offset)
995 struct bnx2x_raw_obj *raw = &o->raw;
996 struct mac_configuration_cmd *config =
997 (struct mac_configuration_cmd *)(raw->rdata);
999 * 57710 and 57711 do not support MOVE command,
1000 * so it's either ADD or DEL
1002 bool add = (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
1005 /* Reset the ramrod data buffer */
1006 memset(config, 0, sizeof(*config));
1008 bnx2x_vlan_mac_set_rdata_e1x(bp, o, BNX2X_FILTER_VLAN_MAC_PENDING,
1010 elem->cmd_data.vlan_mac.u.vlan_mac.mac,
1011 elem->cmd_data.vlan_mac.u.vlan_mac.vlan,
1012 ETH_VLAN_FILTER_CLASSIFY, config);
1015 #define list_next_entry(pos, member) \
1016 list_entry((pos)->member.next, typeof(*(pos)), member)
1019 * bnx2x_vlan_mac_restore - reconfigure next MAC/VLAN/VLAN-MAC element
1021 * @bp: device handle
1022 * @p: command parameters
1023 * @ppos: pointer to the cooky
1025 * reconfigure next MAC/VLAN/VLAN-MAC element from the
1026 * previously configured elements list.
1028 * from command parameters only RAMROD_COMP_WAIT bit in ramrod_flags is taken
1031 * pointer to the cooky - that should be given back in the next call to make
1032 * function handle the next element. If *ppos is set to NULL it will restart the
1033 * iterator. If returned *ppos == NULL this means that the last element has been
1037 static int bnx2x_vlan_mac_restore(struct bnx2x *bp,
1038 struct bnx2x_vlan_mac_ramrod_params *p,
1039 struct bnx2x_vlan_mac_registry_elem **ppos)
1041 struct bnx2x_vlan_mac_registry_elem *pos;
1042 struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
1044 /* If list is empty - there is nothing to do here */
1045 if (list_empty(&o->head)) {
1050 /* make a step... */
1052 *ppos = list_first_entry(&o->head,
1053 struct bnx2x_vlan_mac_registry_elem,
1056 *ppos = list_next_entry(*ppos, link);
1060 /* If it's the last step - return NULL */
1061 if (list_is_last(&pos->link, &o->head))
1064 /* Prepare a 'user_req' */
1065 memcpy(&p->user_req.u, &pos->u, sizeof(pos->u));
1067 /* Set the command */
1068 p->user_req.cmd = BNX2X_VLAN_MAC_ADD;
1070 /* Set vlan_mac_flags */
1071 p->user_req.vlan_mac_flags = pos->vlan_mac_flags;
1073 /* Set a restore bit */
1074 __set_bit(RAMROD_RESTORE, &p->ramrod_flags);
1076 return bnx2x_config_vlan_mac(bp, p);
1080 * bnx2x_exeq_get_mac/bnx2x_exeq_get_vlan/bnx2x_exeq_get_vlan_mac return a
1081 * pointer to an element with a specific criteria and NULL if such an element
1082 * hasn't been found.
1084 static struct bnx2x_exeq_elem *bnx2x_exeq_get_mac(
1085 struct bnx2x_exe_queue_obj *o,
1086 struct bnx2x_exeq_elem *elem)
1088 struct bnx2x_exeq_elem *pos;
1089 struct bnx2x_mac_ramrod_data *data = &elem->cmd_data.vlan_mac.u.mac;
1091 /* Check pending for execution commands */
1092 list_for_each_entry(pos, &o->exe_queue, link)
1093 if (!memcmp(&pos->cmd_data.vlan_mac.u.mac, data,
1095 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1101 static struct bnx2x_exeq_elem *bnx2x_exeq_get_vlan(
1102 struct bnx2x_exe_queue_obj *o,
1103 struct bnx2x_exeq_elem *elem)
1105 struct bnx2x_exeq_elem *pos;
1106 struct bnx2x_vlan_ramrod_data *data = &elem->cmd_data.vlan_mac.u.vlan;
1108 /* Check pending for execution commands */
1109 list_for_each_entry(pos, &o->exe_queue, link)
1110 if (!memcmp(&pos->cmd_data.vlan_mac.u.vlan, data,
1112 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1118 static struct bnx2x_exeq_elem *bnx2x_exeq_get_vlan_mac(
1119 struct bnx2x_exe_queue_obj *o,
1120 struct bnx2x_exeq_elem *elem)
1122 struct bnx2x_exeq_elem *pos;
1123 struct bnx2x_vlan_mac_ramrod_data *data =
1124 &elem->cmd_data.vlan_mac.u.vlan_mac;
1126 /* Check pending for execution commands */
1127 list_for_each_entry(pos, &o->exe_queue, link)
1128 if (!memcmp(&pos->cmd_data.vlan_mac.u.vlan_mac, data,
1130 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1137 * bnx2x_validate_vlan_mac_add - check if an ADD command can be executed
1139 * @bp: device handle
1140 * @qo: bnx2x_qable_obj
1141 * @elem: bnx2x_exeq_elem
1143 * Checks that the requested configuration can be added. If yes and if
1144 * requested, consume CAM credit.
1146 * The 'validate' is run after the 'optimize'.
1149 static inline int bnx2x_validate_vlan_mac_add(struct bnx2x *bp,
1150 union bnx2x_qable_obj *qo,
1151 struct bnx2x_exeq_elem *elem)
1153 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
1154 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1157 /* Check the registry */
1158 rc = o->check_add(o, &elem->cmd_data.vlan_mac.u);
1160 DP(BNX2X_MSG_SP, "ADD command is not allowed considering "
1161 "current registry state\n");
1166 * Check if there is a pending ADD command for this
1167 * MAC/VLAN/VLAN-MAC. Return an error if there is.
1169 if (exeq->get(exeq, elem)) {
1170 DP(BNX2X_MSG_SP, "There is a pending ADD command already\n");
1175 * TODO: Check the pending MOVE from other objects where this
1176 * object is a destination object.
1179 /* Consume the credit if not requested not to */
1180 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1181 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1189 * bnx2x_validate_vlan_mac_del - check if the DEL command can be executed
1191 * @bp: device handle
1192 * @qo: quable object to check
1193 * @elem: element that needs to be deleted
1195 * Checks that the requested configuration can be deleted. If yes and if
1196 * requested, returns a CAM credit.
1198 * The 'validate' is run after the 'optimize'.
1200 static inline int bnx2x_validate_vlan_mac_del(struct bnx2x *bp,
1201 union bnx2x_qable_obj *qo,
1202 struct bnx2x_exeq_elem *elem)
1204 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
1205 struct bnx2x_vlan_mac_registry_elem *pos;
1206 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1207 struct bnx2x_exeq_elem query_elem;
1209 /* If this classification can not be deleted (doesn't exist)
1210 * - return a BNX2X_EXIST.
1212 pos = o->check_del(o, &elem->cmd_data.vlan_mac.u);
1214 DP(BNX2X_MSG_SP, "DEL command is not allowed considering "
1215 "current registry state\n");
1220 * Check if there are pending DEL or MOVE commands for this
1221 * MAC/VLAN/VLAN-MAC. Return an error if so.
1223 memcpy(&query_elem, elem, sizeof(query_elem));
1225 /* Check for MOVE commands */
1226 query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_MOVE;
1227 if (exeq->get(exeq, &query_elem)) {
1228 BNX2X_ERR("There is a pending MOVE command already\n");
1232 /* Check for DEL commands */
1233 if (exeq->get(exeq, elem)) {
1234 DP(BNX2X_MSG_SP, "There is a pending DEL command already\n");
1238 /* Return the credit to the credit pool if not requested not to */
1239 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1240 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1241 o->put_credit(o))) {
1242 BNX2X_ERR("Failed to return a credit\n");
1250 * bnx2x_validate_vlan_mac_move - check if the MOVE command can be executed
1252 * @bp: device handle
1253 * @qo: quable object to check (source)
1254 * @elem: element that needs to be moved
1256 * Checks that the requested configuration can be moved. If yes and if
1257 * requested, returns a CAM credit.
1259 * The 'validate' is run after the 'optimize'.
1261 static inline int bnx2x_validate_vlan_mac_move(struct bnx2x *bp,
1262 union bnx2x_qable_obj *qo,
1263 struct bnx2x_exeq_elem *elem)
1265 struct bnx2x_vlan_mac_obj *src_o = &qo->vlan_mac;
1266 struct bnx2x_vlan_mac_obj *dest_o = elem->cmd_data.vlan_mac.target_obj;
1267 struct bnx2x_exeq_elem query_elem;
1268 struct bnx2x_exe_queue_obj *src_exeq = &src_o->exe_queue;
1269 struct bnx2x_exe_queue_obj *dest_exeq = &dest_o->exe_queue;
1272 * Check if we can perform this operation based on the current registry
1275 if (!src_o->check_move(src_o, dest_o, &elem->cmd_data.vlan_mac.u)) {
1276 DP(BNX2X_MSG_SP, "MOVE command is not allowed considering "
1277 "current registry state\n");
1282 * Check if there is an already pending DEL or MOVE command for the
1283 * source object or ADD command for a destination object. Return an
1286 memcpy(&query_elem, elem, sizeof(query_elem));
1288 /* Check DEL on source */
1289 query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_DEL;
1290 if (src_exeq->get(src_exeq, &query_elem)) {
1291 BNX2X_ERR("There is a pending DEL command on the source "
1296 /* Check MOVE on source */
1297 if (src_exeq->get(src_exeq, elem)) {
1298 DP(BNX2X_MSG_SP, "There is a pending MOVE command already\n");
1302 /* Check ADD on destination */
1303 query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_ADD;
1304 if (dest_exeq->get(dest_exeq, &query_elem)) {
1305 BNX2X_ERR("There is a pending ADD command on the "
1306 "destination queue already\n");
1310 /* Consume the credit if not requested not to */
1311 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT_DEST,
1312 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1313 dest_o->get_credit(dest_o)))
1316 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1317 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1318 src_o->put_credit(src_o))) {
1319 /* return the credit taken from dest... */
1320 dest_o->put_credit(dest_o);
1327 static int bnx2x_validate_vlan_mac(struct bnx2x *bp,
1328 union bnx2x_qable_obj *qo,
1329 struct bnx2x_exeq_elem *elem)
1331 switch (elem->cmd_data.vlan_mac.cmd) {
1332 case BNX2X_VLAN_MAC_ADD:
1333 return bnx2x_validate_vlan_mac_add(bp, qo, elem);
1334 case BNX2X_VLAN_MAC_DEL:
1335 return bnx2x_validate_vlan_mac_del(bp, qo, elem);
1336 case BNX2X_VLAN_MAC_MOVE:
1337 return bnx2x_validate_vlan_mac_move(bp, qo, elem);
1344 * bnx2x_wait_vlan_mac - passivly wait for 5 seconds until all work completes.
1346 * @bp: device handle
1347 * @o: bnx2x_vlan_mac_obj
1350 static int bnx2x_wait_vlan_mac(struct bnx2x *bp,
1351 struct bnx2x_vlan_mac_obj *o)
1354 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1355 struct bnx2x_raw_obj *raw = &o->raw;
1358 /* Wait for the current command to complete */
1359 rc = raw->wait_comp(bp, raw);
1363 /* Wait until there are no pending commands */
1364 if (!bnx2x_exe_queue_empty(exeq))
1365 usleep_range(1000, 1000);
1374 * bnx2x_complete_vlan_mac - complete one VLAN-MAC ramrod
1376 * @bp: device handle
1377 * @o: bnx2x_vlan_mac_obj
1379 * @cont: if true schedule next execution chunk
1382 static int bnx2x_complete_vlan_mac(struct bnx2x *bp,
1383 struct bnx2x_vlan_mac_obj *o,
1384 union event_ring_elem *cqe,
1385 unsigned long *ramrod_flags)
1387 struct bnx2x_raw_obj *r = &o->raw;
1390 /* Reset pending list */
1391 bnx2x_exe_queue_reset_pending(bp, &o->exe_queue);
1394 r->clear_pending(r);
1396 /* If ramrod failed this is most likely a SW bug */
1397 if (cqe->message.error)
1400 /* Run the next bulk of pending commands if requeted */
1401 if (test_bit(RAMROD_CONT, ramrod_flags)) {
1402 rc = bnx2x_exe_queue_step(bp, &o->exe_queue, ramrod_flags);
1407 /* If there is more work to do return PENDING */
1408 if (!bnx2x_exe_queue_empty(&o->exe_queue))
1415 * bnx2x_optimize_vlan_mac - optimize ADD and DEL commands.
1417 * @bp: device handle
1418 * @o: bnx2x_qable_obj
1419 * @elem: bnx2x_exeq_elem
1421 static int bnx2x_optimize_vlan_mac(struct bnx2x *bp,
1422 union bnx2x_qable_obj *qo,
1423 struct bnx2x_exeq_elem *elem)
1425 struct bnx2x_exeq_elem query, *pos;
1426 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
1427 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1429 memcpy(&query, elem, sizeof(query));
1431 switch (elem->cmd_data.vlan_mac.cmd) {
1432 case BNX2X_VLAN_MAC_ADD:
1433 query.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_DEL;
1435 case BNX2X_VLAN_MAC_DEL:
1436 query.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_ADD;
1439 /* Don't handle anything other than ADD or DEL */
1443 /* If we found the appropriate element - delete it */
1444 pos = exeq->get(exeq, &query);
1447 /* Return the credit of the optimized command */
1448 if (!test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1449 &pos->cmd_data.vlan_mac.vlan_mac_flags)) {
1450 if ((query.cmd_data.vlan_mac.cmd ==
1451 BNX2X_VLAN_MAC_ADD) && !o->put_credit(o)) {
1452 BNX2X_ERR("Failed to return the credit for the "
1453 "optimized ADD command\n");
1455 } else if (!o->get_credit(o)) { /* VLAN_MAC_DEL */
1456 BNX2X_ERR("Failed to recover the credit from "
1457 "the optimized DEL command\n");
1462 DP(BNX2X_MSG_SP, "Optimizing %s command\n",
1463 (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
1466 list_del(&pos->link);
1467 bnx2x_exe_queue_free_elem(bp, pos);
1475 * bnx2x_vlan_mac_get_registry_elem - prepare a registry element
1477 * @bp: device handle
1483 * prepare a registry element according to the current command request.
1485 static inline int bnx2x_vlan_mac_get_registry_elem(
1487 struct bnx2x_vlan_mac_obj *o,
1488 struct bnx2x_exeq_elem *elem,
1490 struct bnx2x_vlan_mac_registry_elem **re)
1492 int cmd = elem->cmd_data.vlan_mac.cmd;
1493 struct bnx2x_vlan_mac_registry_elem *reg_elem;
1495 /* Allocate a new registry element if needed. */
1497 ((cmd == BNX2X_VLAN_MAC_ADD) || (cmd == BNX2X_VLAN_MAC_MOVE))) {
1498 reg_elem = kzalloc(sizeof(*reg_elem), GFP_ATOMIC);
1502 /* Get a new CAM offset */
1503 if (!o->get_cam_offset(o, ®_elem->cam_offset)) {
1505 * This shell never happen, because we have checked the
1506 * CAM availiability in the 'validate'.
1513 DP(BNX2X_MSG_SP, "Got cam offset %d\n", reg_elem->cam_offset);
1515 /* Set a VLAN-MAC data */
1516 memcpy(®_elem->u, &elem->cmd_data.vlan_mac.u,
1517 sizeof(reg_elem->u));
1519 /* Copy the flags (needed for DEL and RESTORE flows) */
1520 reg_elem->vlan_mac_flags =
1521 elem->cmd_data.vlan_mac.vlan_mac_flags;
1522 } else /* DEL, RESTORE */
1523 reg_elem = o->check_del(o, &elem->cmd_data.vlan_mac.u);
1530 * bnx2x_execute_vlan_mac - execute vlan mac command
1532 * @bp: device handle
1537 * go and send a ramrod!
1539 static int bnx2x_execute_vlan_mac(struct bnx2x *bp,
1540 union bnx2x_qable_obj *qo,
1541 struct list_head *exe_chunk,
1542 unsigned long *ramrod_flags)
1544 struct bnx2x_exeq_elem *elem;
1545 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac, *cam_obj;
1546 struct bnx2x_raw_obj *r = &o->raw;
1548 bool restore = test_bit(RAMROD_RESTORE, ramrod_flags);
1549 bool drv_only = test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags);
1550 struct bnx2x_vlan_mac_registry_elem *reg_elem;
1554 * If DRIVER_ONLY execution is requested, cleanup a registry
1555 * and exit. Otherwise send a ramrod to FW.
1558 WARN_ON(r->check_pending(r));
1563 /* Fill tha ramrod data */
1564 list_for_each_entry(elem, exe_chunk, link) {
1565 cmd = elem->cmd_data.vlan_mac.cmd;
1567 * We will add to the target object in MOVE command, so
1568 * change the object for a CAM search.
1570 if (cmd == BNX2X_VLAN_MAC_MOVE)
1571 cam_obj = elem->cmd_data.vlan_mac.target_obj;
1575 rc = bnx2x_vlan_mac_get_registry_elem(bp, cam_obj,
1583 /* Push a new entry into the registry */
1585 ((cmd == BNX2X_VLAN_MAC_ADD) ||
1586 (cmd == BNX2X_VLAN_MAC_MOVE)))
1587 list_add(®_elem->link, &cam_obj->head);
1589 /* Configure a single command in a ramrod data buffer */
1590 o->set_one_rule(bp, o, elem, idx,
1591 reg_elem->cam_offset);
1593 /* MOVE command consumes 2 entries in the ramrod data */
1594 if (cmd == BNX2X_VLAN_MAC_MOVE)
1601 * No need for an explicit memory barrier here as long we would
1602 * need to ensure the ordering of writing to the SPQ element
1603 * and updating of the SPQ producer which involves a memory
1604 * read and we will have to put a full memory barrier there
1605 * (inside bnx2x_sp_post()).
1608 rc = bnx2x_sp_post(bp, o->ramrod_cmd, r->cid,
1609 U64_HI(r->rdata_mapping),
1610 U64_LO(r->rdata_mapping),
1611 ETH_CONNECTION_TYPE);
1616 /* Now, when we are done with the ramrod - clean up the registry */
1617 list_for_each_entry(elem, exe_chunk, link) {
1618 cmd = elem->cmd_data.vlan_mac.cmd;
1619 if ((cmd == BNX2X_VLAN_MAC_DEL) ||
1620 (cmd == BNX2X_VLAN_MAC_MOVE)) {
1621 reg_elem = o->check_del(o, &elem->cmd_data.vlan_mac.u);
1625 o->put_cam_offset(o, reg_elem->cam_offset);
1626 list_del(®_elem->link);
1637 r->clear_pending(r);
1639 /* Cleanup a registry in case of a failure */
1640 list_for_each_entry(elem, exe_chunk, link) {
1641 cmd = elem->cmd_data.vlan_mac.cmd;
1643 if (cmd == BNX2X_VLAN_MAC_MOVE)
1644 cam_obj = elem->cmd_data.vlan_mac.target_obj;
1648 /* Delete all newly added above entries */
1650 ((cmd == BNX2X_VLAN_MAC_ADD) ||
1651 (cmd == BNX2X_VLAN_MAC_MOVE))) {
1652 reg_elem = o->check_del(cam_obj,
1653 &elem->cmd_data.vlan_mac.u);
1655 list_del(®_elem->link);
1664 static inline int bnx2x_vlan_mac_push_new_cmd(
1666 struct bnx2x_vlan_mac_ramrod_params *p)
1668 struct bnx2x_exeq_elem *elem;
1669 struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
1670 bool restore = test_bit(RAMROD_RESTORE, &p->ramrod_flags);
1672 /* Allocate the execution queue element */
1673 elem = bnx2x_exe_queue_alloc_elem(bp);
1677 /* Set the command 'length' */
1678 switch (p->user_req.cmd) {
1679 case BNX2X_VLAN_MAC_MOVE:
1686 /* Fill the object specific info */
1687 memcpy(&elem->cmd_data.vlan_mac, &p->user_req, sizeof(p->user_req));
1689 /* Try to add a new command to the pending list */
1690 return bnx2x_exe_queue_add(bp, &o->exe_queue, elem, restore);
1694 * bnx2x_config_vlan_mac - configure VLAN/MAC/VLAN_MAC filtering rules.
1696 * @bp: device handle
1700 int bnx2x_config_vlan_mac(
1702 struct bnx2x_vlan_mac_ramrod_params *p)
1705 struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
1706 unsigned long *ramrod_flags = &p->ramrod_flags;
1707 bool cont = test_bit(RAMROD_CONT, ramrod_flags);
1708 struct bnx2x_raw_obj *raw = &o->raw;
1711 * Add new elements to the execution list for commands that require it.
1714 rc = bnx2x_vlan_mac_push_new_cmd(bp, p);
1720 * If nothing will be executed further in this iteration we want to
1721 * return PENDING if there are pending commands
1723 if (!bnx2x_exe_queue_empty(&o->exe_queue))
1726 if (test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags)) {
1727 DP(BNX2X_MSG_SP, "RAMROD_DRV_CLR_ONLY requested: "
1728 "clearing a pending bit.\n");
1729 raw->clear_pending(raw);
1732 /* Execute commands if required */
1733 if (cont || test_bit(RAMROD_EXEC, ramrod_flags) ||
1734 test_bit(RAMROD_COMP_WAIT, ramrod_flags)) {
1735 rc = bnx2x_exe_queue_step(bp, &o->exe_queue, ramrod_flags);
1741 * RAMROD_COMP_WAIT is a superset of RAMROD_EXEC. If it was set
1742 * then user want to wait until the last command is done.
1744 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags)) {
1746 * Wait maximum for the current exe_queue length iterations plus
1747 * one (for the current pending command).
1749 int max_iterations = bnx2x_exe_queue_length(&o->exe_queue) + 1;
1751 while (!bnx2x_exe_queue_empty(&o->exe_queue) &&
1754 /* Wait for the current command to complete */
1755 rc = raw->wait_comp(bp, raw);
1759 /* Make a next step */
1760 rc = bnx2x_exe_queue_step(bp, &o->exe_queue,
1775 * bnx2x_vlan_mac_del_all - delete elements with given vlan_mac_flags spec
1777 * @bp: device handle
1780 * @ramrod_flags: execution flags to be used for this deletion
1782 * if the last operation has completed successfully and there are no
1783 * moreelements left, positive value if the last operation has completed
1784 * successfully and there are more previously configured elements, negative
1785 * value is current operation has failed.
1787 static int bnx2x_vlan_mac_del_all(struct bnx2x *bp,
1788 struct bnx2x_vlan_mac_obj *o,
1789 unsigned long *vlan_mac_flags,
1790 unsigned long *ramrod_flags)
1792 struct bnx2x_vlan_mac_registry_elem *pos = NULL;
1794 struct bnx2x_vlan_mac_ramrod_params p;
1795 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1796 struct bnx2x_exeq_elem *exeq_pos, *exeq_pos_n;
1798 /* Clear pending commands first */
1800 spin_lock_bh(&exeq->lock);
1802 list_for_each_entry_safe(exeq_pos, exeq_pos_n, &exeq->exe_queue, link) {
1803 if (exeq_pos->cmd_data.vlan_mac.vlan_mac_flags ==
1805 list_del(&exeq_pos->link);
1808 spin_unlock_bh(&exeq->lock);
1810 /* Prepare a command request */
1811 memset(&p, 0, sizeof(p));
1813 p.ramrod_flags = *ramrod_flags;
1814 p.user_req.cmd = BNX2X_VLAN_MAC_DEL;
1817 * Add all but the last VLAN-MAC to the execution queue without actually
1818 * execution anything.
1820 __clear_bit(RAMROD_COMP_WAIT, &p.ramrod_flags);
1821 __clear_bit(RAMROD_EXEC, &p.ramrod_flags);
1822 __clear_bit(RAMROD_CONT, &p.ramrod_flags);
1824 list_for_each_entry(pos, &o->head, link) {
1825 if (pos->vlan_mac_flags == *vlan_mac_flags) {
1826 p.user_req.vlan_mac_flags = pos->vlan_mac_flags;
1827 memcpy(&p.user_req.u, &pos->u, sizeof(pos->u));
1828 rc = bnx2x_config_vlan_mac(bp, &p);
1830 BNX2X_ERR("Failed to add a new DEL command\n");
1836 p.ramrod_flags = *ramrod_flags;
1837 __set_bit(RAMROD_CONT, &p.ramrod_flags);
1839 return bnx2x_config_vlan_mac(bp, &p);
1842 static inline void bnx2x_init_raw_obj(struct bnx2x_raw_obj *raw, u8 cl_id,
1843 u32 cid, u8 func_id, void *rdata, dma_addr_t rdata_mapping, int state,
1844 unsigned long *pstate, bnx2x_obj_type type)
1846 raw->func_id = func_id;
1850 raw->rdata_mapping = rdata_mapping;
1852 raw->pstate = pstate;
1853 raw->obj_type = type;
1854 raw->check_pending = bnx2x_raw_check_pending;
1855 raw->clear_pending = bnx2x_raw_clear_pending;
1856 raw->set_pending = bnx2x_raw_set_pending;
1857 raw->wait_comp = bnx2x_raw_wait;
1860 static inline void bnx2x_init_vlan_mac_common(struct bnx2x_vlan_mac_obj *o,
1861 u8 cl_id, u32 cid, u8 func_id, void *rdata, dma_addr_t rdata_mapping,
1862 int state, unsigned long *pstate, bnx2x_obj_type type,
1863 struct bnx2x_credit_pool_obj *macs_pool,
1864 struct bnx2x_credit_pool_obj *vlans_pool)
1866 INIT_LIST_HEAD(&o->head);
1868 o->macs_pool = macs_pool;
1869 o->vlans_pool = vlans_pool;
1871 o->delete_all = bnx2x_vlan_mac_del_all;
1872 o->restore = bnx2x_vlan_mac_restore;
1873 o->complete = bnx2x_complete_vlan_mac;
1874 o->wait = bnx2x_wait_vlan_mac;
1876 bnx2x_init_raw_obj(&o->raw, cl_id, cid, func_id, rdata, rdata_mapping,
1877 state, pstate, type);
1881 void bnx2x_init_mac_obj(struct bnx2x *bp,
1882 struct bnx2x_vlan_mac_obj *mac_obj,
1883 u8 cl_id, u32 cid, u8 func_id, void *rdata,
1884 dma_addr_t rdata_mapping, int state,
1885 unsigned long *pstate, bnx2x_obj_type type,
1886 struct bnx2x_credit_pool_obj *macs_pool)
1888 union bnx2x_qable_obj *qable_obj = (union bnx2x_qable_obj *)mac_obj;
1890 bnx2x_init_vlan_mac_common(mac_obj, cl_id, cid, func_id, rdata,
1891 rdata_mapping, state, pstate, type,
1894 /* CAM credit pool handling */
1895 mac_obj->get_credit = bnx2x_get_credit_mac;
1896 mac_obj->put_credit = bnx2x_put_credit_mac;
1897 mac_obj->get_cam_offset = bnx2x_get_cam_offset_mac;
1898 mac_obj->put_cam_offset = bnx2x_put_cam_offset_mac;
1900 if (CHIP_IS_E1x(bp)) {
1901 mac_obj->set_one_rule = bnx2x_set_one_mac_e1x;
1902 mac_obj->check_del = bnx2x_check_mac_del;
1903 mac_obj->check_add = bnx2x_check_mac_add;
1904 mac_obj->check_move = bnx2x_check_move_always_err;
1905 mac_obj->ramrod_cmd = RAMROD_CMD_ID_ETH_SET_MAC;
1908 bnx2x_exe_queue_init(bp,
1909 &mac_obj->exe_queue, 1, qable_obj,
1910 bnx2x_validate_vlan_mac,
1911 bnx2x_optimize_vlan_mac,
1912 bnx2x_execute_vlan_mac,
1913 bnx2x_exeq_get_mac);
1915 mac_obj->set_one_rule = bnx2x_set_one_mac_e2;
1916 mac_obj->check_del = bnx2x_check_mac_del;
1917 mac_obj->check_add = bnx2x_check_mac_add;
1918 mac_obj->check_move = bnx2x_check_move;
1919 mac_obj->ramrod_cmd =
1920 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
1921 mac_obj->get_n_elements = bnx2x_get_n_elements;
1924 bnx2x_exe_queue_init(bp,
1925 &mac_obj->exe_queue, CLASSIFY_RULES_COUNT,
1926 qable_obj, bnx2x_validate_vlan_mac,
1927 bnx2x_optimize_vlan_mac,
1928 bnx2x_execute_vlan_mac,
1929 bnx2x_exeq_get_mac);
1933 void bnx2x_init_vlan_obj(struct bnx2x *bp,
1934 struct bnx2x_vlan_mac_obj *vlan_obj,
1935 u8 cl_id, u32 cid, u8 func_id, void *rdata,
1936 dma_addr_t rdata_mapping, int state,
1937 unsigned long *pstate, bnx2x_obj_type type,
1938 struct bnx2x_credit_pool_obj *vlans_pool)
1940 union bnx2x_qable_obj *qable_obj = (union bnx2x_qable_obj *)vlan_obj;
1942 bnx2x_init_vlan_mac_common(vlan_obj, cl_id, cid, func_id, rdata,
1943 rdata_mapping, state, pstate, type, NULL,
1946 vlan_obj->get_credit = bnx2x_get_credit_vlan;
1947 vlan_obj->put_credit = bnx2x_put_credit_vlan;
1948 vlan_obj->get_cam_offset = bnx2x_get_cam_offset_vlan;
1949 vlan_obj->put_cam_offset = bnx2x_put_cam_offset_vlan;
1951 if (CHIP_IS_E1x(bp)) {
1952 BNX2X_ERR("Do not support chips others than E2 and newer\n");
1955 vlan_obj->set_one_rule = bnx2x_set_one_vlan_e2;
1956 vlan_obj->check_del = bnx2x_check_vlan_del;
1957 vlan_obj->check_add = bnx2x_check_vlan_add;
1958 vlan_obj->check_move = bnx2x_check_move;
1959 vlan_obj->ramrod_cmd =
1960 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
1963 bnx2x_exe_queue_init(bp,
1964 &vlan_obj->exe_queue, CLASSIFY_RULES_COUNT,
1965 qable_obj, bnx2x_validate_vlan_mac,
1966 bnx2x_optimize_vlan_mac,
1967 bnx2x_execute_vlan_mac,
1968 bnx2x_exeq_get_vlan);
1972 void bnx2x_init_vlan_mac_obj(struct bnx2x *bp,
1973 struct bnx2x_vlan_mac_obj *vlan_mac_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 *macs_pool,
1978 struct bnx2x_credit_pool_obj *vlans_pool)
1980 union bnx2x_qable_obj *qable_obj =
1981 (union bnx2x_qable_obj *)vlan_mac_obj;
1983 bnx2x_init_vlan_mac_common(vlan_mac_obj, cl_id, cid, func_id, rdata,
1984 rdata_mapping, state, pstate, type,
1985 macs_pool, vlans_pool);
1987 /* CAM pool handling */
1988 vlan_mac_obj->get_credit = bnx2x_get_credit_vlan_mac;
1989 vlan_mac_obj->put_credit = bnx2x_put_credit_vlan_mac;
1991 * CAM offset is relevant for 57710 and 57711 chips only which have a
1992 * single CAM for both MACs and VLAN-MAC pairs. So the offset
1993 * will be taken from MACs' pool object only.
1995 vlan_mac_obj->get_cam_offset = bnx2x_get_cam_offset_mac;
1996 vlan_mac_obj->put_cam_offset = bnx2x_put_cam_offset_mac;
1998 if (CHIP_IS_E1(bp)) {
1999 BNX2X_ERR("Do not support chips others than E2\n");
2001 } else if (CHIP_IS_E1H(bp)) {
2002 vlan_mac_obj->set_one_rule = bnx2x_set_one_vlan_mac_e1h;
2003 vlan_mac_obj->check_del = bnx2x_check_vlan_mac_del;
2004 vlan_mac_obj->check_add = bnx2x_check_vlan_mac_add;
2005 vlan_mac_obj->check_move = bnx2x_check_move_always_err;
2006 vlan_mac_obj->ramrod_cmd = RAMROD_CMD_ID_ETH_SET_MAC;
2009 bnx2x_exe_queue_init(bp,
2010 &vlan_mac_obj->exe_queue, 1, qable_obj,
2011 bnx2x_validate_vlan_mac,
2012 bnx2x_optimize_vlan_mac,
2013 bnx2x_execute_vlan_mac,
2014 bnx2x_exeq_get_vlan_mac);
2016 vlan_mac_obj->set_one_rule = bnx2x_set_one_vlan_mac_e2;
2017 vlan_mac_obj->check_del = bnx2x_check_vlan_mac_del;
2018 vlan_mac_obj->check_add = bnx2x_check_vlan_mac_add;
2019 vlan_mac_obj->check_move = bnx2x_check_move;
2020 vlan_mac_obj->ramrod_cmd =
2021 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
2024 bnx2x_exe_queue_init(bp,
2025 &vlan_mac_obj->exe_queue,
2026 CLASSIFY_RULES_COUNT,
2027 qable_obj, bnx2x_validate_vlan_mac,
2028 bnx2x_optimize_vlan_mac,
2029 bnx2x_execute_vlan_mac,
2030 bnx2x_exeq_get_vlan_mac);
2035 /* RX_MODE verbs: DROP_ALL/ACCEPT_ALL/ACCEPT_ALL_MULTI/ACCEPT_ALL_VLAN/NORMAL */
2036 static inline void __storm_memset_mac_filters(struct bnx2x *bp,
2037 struct tstorm_eth_mac_filter_config *mac_filters,
2040 size_t size = sizeof(struct tstorm_eth_mac_filter_config);
2042 u32 addr = BAR_TSTRORM_INTMEM +
2043 TSTORM_MAC_FILTER_CONFIG_OFFSET(pf_id);
2045 __storm_memset_struct(bp, addr, size, (u32 *)mac_filters);
2048 static int bnx2x_set_rx_mode_e1x(struct bnx2x *bp,
2049 struct bnx2x_rx_mode_ramrod_params *p)
2051 /* update the bp MAC filter structure */
2052 u32 mask = (1 << p->cl_id);
2054 struct tstorm_eth_mac_filter_config *mac_filters =
2055 (struct tstorm_eth_mac_filter_config *)p->rdata;
2057 /* initial seeting is drop-all */
2058 u8 drop_all_ucast = 1, drop_all_mcast = 1;
2059 u8 accp_all_ucast = 0, accp_all_bcast = 0, accp_all_mcast = 0;
2060 u8 unmatched_unicast = 0;
2062 /* In e1x there we only take into account rx acceot flag since tx switching
2064 if (test_bit(BNX2X_ACCEPT_UNICAST, &p->rx_accept_flags))
2065 /* accept matched ucast */
2068 if (test_bit(BNX2X_ACCEPT_MULTICAST, &p->rx_accept_flags))
2069 /* accept matched mcast */
2072 if (test_bit(BNX2X_ACCEPT_ALL_UNICAST, &p->rx_accept_flags)) {
2073 /* accept all mcast */
2077 if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST, &p->rx_accept_flags)) {
2078 /* accept all mcast */
2082 if (test_bit(BNX2X_ACCEPT_BROADCAST, &p->rx_accept_flags))
2083 /* accept (all) bcast */
2085 if (test_bit(BNX2X_ACCEPT_UNMATCHED, &p->rx_accept_flags))
2086 /* accept unmatched unicasts */
2087 unmatched_unicast = 1;
2089 mac_filters->ucast_drop_all = drop_all_ucast ?
2090 mac_filters->ucast_drop_all | mask :
2091 mac_filters->ucast_drop_all & ~mask;
2093 mac_filters->mcast_drop_all = drop_all_mcast ?
2094 mac_filters->mcast_drop_all | mask :
2095 mac_filters->mcast_drop_all & ~mask;
2097 mac_filters->ucast_accept_all = accp_all_ucast ?
2098 mac_filters->ucast_accept_all | mask :
2099 mac_filters->ucast_accept_all & ~mask;
2101 mac_filters->mcast_accept_all = accp_all_mcast ?
2102 mac_filters->mcast_accept_all | mask :
2103 mac_filters->mcast_accept_all & ~mask;
2105 mac_filters->bcast_accept_all = accp_all_bcast ?
2106 mac_filters->bcast_accept_all | mask :
2107 mac_filters->bcast_accept_all & ~mask;
2109 mac_filters->unmatched_unicast = unmatched_unicast ?
2110 mac_filters->unmatched_unicast | mask :
2111 mac_filters->unmatched_unicast & ~mask;
2113 DP(BNX2X_MSG_SP, "drop_ucast 0x%x\ndrop_mcast 0x%x\n accp_ucast 0x%x\n"
2114 "accp_mcast 0x%x\naccp_bcast 0x%x\n",
2115 mac_filters->ucast_drop_all,
2116 mac_filters->mcast_drop_all,
2117 mac_filters->ucast_accept_all,
2118 mac_filters->mcast_accept_all,
2119 mac_filters->bcast_accept_all);
2121 /* write the MAC filter structure*/
2122 __storm_memset_mac_filters(bp, mac_filters, p->func_id);
2124 /* The operation is completed */
2125 clear_bit(p->state, p->pstate);
2126 smp_mb__after_clear_bit();
2131 /* Setup ramrod data */
2132 static inline void bnx2x_rx_mode_set_rdata_hdr_e2(u32 cid,
2133 struct eth_classify_header *hdr,
2137 hdr->rule_cnt = rule_cnt;
2140 static inline void bnx2x_rx_mode_set_cmd_state_e2(struct bnx2x *bp,
2141 unsigned long accept_flags,
2142 struct eth_filter_rules_cmd *cmd,
2143 bool clear_accept_all)
2147 /* start with 'drop-all' */
2148 state = ETH_FILTER_RULES_CMD_UCAST_DROP_ALL |
2149 ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
2152 if (test_bit(BNX2X_ACCEPT_UNICAST, &accept_flags))
2153 state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
2155 if (test_bit(BNX2X_ACCEPT_MULTICAST, &accept_flags))
2156 state &= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
2158 if (test_bit(BNX2X_ACCEPT_ALL_UNICAST, &accept_flags)) {
2159 state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
2160 state |= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL;
2163 if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags)) {
2164 state |= ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL;
2165 state &= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
2167 if (test_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags))
2168 state |= ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL;
2170 if (test_bit(BNX2X_ACCEPT_UNMATCHED, &accept_flags)) {
2171 state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
2172 state |= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED;
2174 if (test_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags))
2175 state |= ETH_FILTER_RULES_CMD_ACCEPT_ANY_VLAN;
2178 /* Clear ACCEPT_ALL_XXX flags for FCoE L2 Queue */
2179 if (clear_accept_all) {
2180 state &= ~ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL;
2181 state &= ~ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL;
2182 state &= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL;
2183 state &= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED;
2186 cmd->state = cpu_to_le16(state);
2190 static int bnx2x_set_rx_mode_e2(struct bnx2x *bp,
2191 struct bnx2x_rx_mode_ramrod_params *p)
2193 struct eth_filter_rules_ramrod_data *data = p->rdata;
2197 /* Reset the ramrod data buffer */
2198 memset(data, 0, sizeof(*data));
2200 /* Setup ramrod data */
2202 /* Tx (internal switching) */
2203 if (test_bit(RAMROD_TX, &p->ramrod_flags)) {
2204 data->rules[rule_idx].client_id = p->cl_id;
2205 data->rules[rule_idx].func_id = p->func_id;
2207 data->rules[rule_idx].cmd_general_data =
2208 ETH_FILTER_RULES_CMD_TX_CMD;
2210 bnx2x_rx_mode_set_cmd_state_e2(bp, p->tx_accept_flags,
2211 &(data->rules[rule_idx++]), false);
2215 if (test_bit(RAMROD_RX, &p->ramrod_flags)) {
2216 data->rules[rule_idx].client_id = p->cl_id;
2217 data->rules[rule_idx].func_id = p->func_id;
2219 data->rules[rule_idx].cmd_general_data =
2220 ETH_FILTER_RULES_CMD_RX_CMD;
2222 bnx2x_rx_mode_set_cmd_state_e2(bp, p->rx_accept_flags,
2223 &(data->rules[rule_idx++]), false);
2228 * If FCoE Queue configuration has been requested configure the Rx and
2229 * internal switching modes for this queue in separate rules.
2231 * FCoE queue shell never be set to ACCEPT_ALL packets of any sort:
2232 * MCAST_ALL, UCAST_ALL, BCAST_ALL and UNMATCHED.
2234 if (test_bit(BNX2X_RX_MODE_FCOE_ETH, &p->rx_mode_flags)) {
2235 /* Tx (internal switching) */
2236 if (test_bit(RAMROD_TX, &p->ramrod_flags)) {
2237 data->rules[rule_idx].client_id = bnx2x_fcoe(bp, cl_id);
2238 data->rules[rule_idx].func_id = p->func_id;
2240 data->rules[rule_idx].cmd_general_data =
2241 ETH_FILTER_RULES_CMD_TX_CMD;
2243 bnx2x_rx_mode_set_cmd_state_e2(bp, p->tx_accept_flags,
2244 &(data->rules[rule_idx++]),
2249 if (test_bit(RAMROD_RX, &p->ramrod_flags)) {
2250 data->rules[rule_idx].client_id = bnx2x_fcoe(bp, cl_id);
2251 data->rules[rule_idx].func_id = p->func_id;
2253 data->rules[rule_idx].cmd_general_data =
2254 ETH_FILTER_RULES_CMD_RX_CMD;
2256 bnx2x_rx_mode_set_cmd_state_e2(bp, p->rx_accept_flags,
2257 &(data->rules[rule_idx++]),
2263 * Set the ramrod header (most importantly - number of rules to
2266 bnx2x_rx_mode_set_rdata_hdr_e2(p->cid, &data->header, rule_idx);
2268 DP(BNX2X_MSG_SP, "About to configure %d rules, rx_accept_flags 0x%lx, "
2269 "tx_accept_flags 0x%lx\n",
2270 data->header.rule_cnt, p->rx_accept_flags,
2271 p->tx_accept_flags);
2274 * No need for an explicit memory barrier here as long we would
2275 * need to ensure the ordering of writing to the SPQ element
2276 * and updating of the SPQ producer which involves a memory
2277 * read and we will have to put a full memory barrier there
2278 * (inside bnx2x_sp_post()).
2282 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_FILTER_RULES, p->cid,
2283 U64_HI(p->rdata_mapping),
2284 U64_LO(p->rdata_mapping),
2285 ETH_CONNECTION_TYPE);
2289 /* Ramrod completion is pending */
2293 static int bnx2x_wait_rx_mode_comp_e2(struct bnx2x *bp,
2294 struct bnx2x_rx_mode_ramrod_params *p)
2296 return bnx2x_state_wait(bp, p->state, p->pstate);
2299 static int bnx2x_empty_rx_mode_wait(struct bnx2x *bp,
2300 struct bnx2x_rx_mode_ramrod_params *p)
2306 int bnx2x_config_rx_mode(struct bnx2x *bp,
2307 struct bnx2x_rx_mode_ramrod_params *p)
2311 /* Configure the new classification in the chip */
2312 rc = p->rx_mode_obj->config_rx_mode(bp, p);
2316 /* Wait for a ramrod completion if was requested */
2317 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags)) {
2318 rc = p->rx_mode_obj->wait_comp(bp, p);
2326 void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
2327 struct bnx2x_rx_mode_obj *o)
2329 if (CHIP_IS_E1x(bp)) {
2330 o->wait_comp = bnx2x_empty_rx_mode_wait;
2331 o->config_rx_mode = bnx2x_set_rx_mode_e1x;
2333 o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
2334 o->config_rx_mode = bnx2x_set_rx_mode_e2;
2338 /********************* Multicast verbs: SET, CLEAR ****************************/
2339 static inline u8 bnx2x_mcast_bin_from_mac(u8 *mac)
2341 return (crc32c_le(0, mac, ETH_ALEN) >> 24) & 0xff;
2344 struct bnx2x_mcast_mac_elem {
2345 struct list_head link;
2347 u8 pad[2]; /* For a natural alignment of the following buffer */
2350 struct bnx2x_pending_mcast_cmd {
2351 struct list_head link;
2352 int type; /* BNX2X_MCAST_CMD_X */
2354 struct list_head macs_head;
2355 u32 macs_num; /* Needed for DEL command */
2356 int next_bin; /* Needed for RESTORE flow with aprox match */
2359 bool done; /* set to true, when the command has been handled,
2360 * practically used in 57712 handling only, where one pending
2361 * command may be handled in a few operations. As long as for
2362 * other chips every operation handling is completed in a
2363 * single ramrod, there is no need to utilize this field.
2367 static int bnx2x_mcast_wait(struct bnx2x *bp,
2368 struct bnx2x_mcast_obj *o)
2370 if (bnx2x_state_wait(bp, o->sched_state, o->raw.pstate) ||
2371 o->raw.wait_comp(bp, &o->raw))
2377 static int bnx2x_mcast_enqueue_cmd(struct bnx2x *bp,
2378 struct bnx2x_mcast_obj *o,
2379 struct bnx2x_mcast_ramrod_params *p,
2383 struct bnx2x_pending_mcast_cmd *new_cmd;
2384 struct bnx2x_mcast_mac_elem *cur_mac = NULL;
2385 struct bnx2x_mcast_list_elem *pos;
2386 int macs_list_len = ((cmd == BNX2X_MCAST_CMD_ADD) ?
2387 p->mcast_list_len : 0);
2389 /* If the command is empty ("handle pending commands only"), break */
2390 if (!p->mcast_list_len)
2393 total_sz = sizeof(*new_cmd) +
2394 macs_list_len * sizeof(struct bnx2x_mcast_mac_elem);
2396 /* Add mcast is called under spin_lock, thus calling with GFP_ATOMIC */
2397 new_cmd = kzalloc(total_sz, GFP_ATOMIC);
2402 DP(BNX2X_MSG_SP, "About to enqueue a new %d command. "
2403 "macs_list_len=%d\n", cmd, macs_list_len);
2405 INIT_LIST_HEAD(&new_cmd->data.macs_head);
2407 new_cmd->type = cmd;
2408 new_cmd->done = false;
2411 case BNX2X_MCAST_CMD_ADD:
2412 cur_mac = (struct bnx2x_mcast_mac_elem *)
2413 ((u8 *)new_cmd + sizeof(*new_cmd));
2415 /* Push the MACs of the current command into the pendig command
2418 list_for_each_entry(pos, &p->mcast_list, link) {
2419 memcpy(cur_mac->mac, pos->mac, ETH_ALEN);
2420 list_add_tail(&cur_mac->link, &new_cmd->data.macs_head);
2426 case BNX2X_MCAST_CMD_DEL:
2427 new_cmd->data.macs_num = p->mcast_list_len;
2430 case BNX2X_MCAST_CMD_RESTORE:
2431 new_cmd->data.next_bin = 0;
2435 BNX2X_ERR("Unknown command: %d\n", cmd);
2439 /* Push the new pending command to the tail of the pending list: FIFO */
2440 list_add_tail(&new_cmd->link, &o->pending_cmds_head);
2448 * bnx2x_mcast_get_next_bin - get the next set bin (index)
2451 * @last: index to start looking from (including)
2453 * returns the next found (set) bin or a negative value if none is found.
2455 static inline int bnx2x_mcast_get_next_bin(struct bnx2x_mcast_obj *o, int last)
2457 int i, j, inner_start = last % BIT_VEC64_ELEM_SZ;
2459 for (i = last / BIT_VEC64_ELEM_SZ; i < BNX2X_MCAST_VEC_SZ; i++) {
2460 if (o->registry.aprox_match.vec[i])
2461 for (j = inner_start; j < BIT_VEC64_ELEM_SZ; j++) {
2462 int cur_bit = j + BIT_VEC64_ELEM_SZ * i;
2463 if (BIT_VEC64_TEST_BIT(o->registry.aprox_match.
2476 * bnx2x_mcast_clear_first_bin - find the first set bin and clear it
2480 * returns the index of the found bin or -1 if none is found
2482 static inline int bnx2x_mcast_clear_first_bin(struct bnx2x_mcast_obj *o)
2484 int cur_bit = bnx2x_mcast_get_next_bin(o, 0);
2487 BIT_VEC64_CLEAR_BIT(o->registry.aprox_match.vec, cur_bit);
2492 static inline u8 bnx2x_mcast_get_rx_tx_flag(struct bnx2x_mcast_obj *o)
2494 struct bnx2x_raw_obj *raw = &o->raw;
2497 if ((raw->obj_type == BNX2X_OBJ_TYPE_TX) ||
2498 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
2499 rx_tx_flag |= ETH_MULTICAST_RULES_CMD_TX_CMD;
2501 if ((raw->obj_type == BNX2X_OBJ_TYPE_RX) ||
2502 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
2503 rx_tx_flag |= ETH_MULTICAST_RULES_CMD_RX_CMD;
2508 static void bnx2x_mcast_set_one_rule_e2(struct bnx2x *bp,
2509 struct bnx2x_mcast_obj *o, int idx,
2510 union bnx2x_mcast_config_data *cfg_data,
2513 struct bnx2x_raw_obj *r = &o->raw;
2514 struct eth_multicast_rules_ramrod_data *data =
2515 (struct eth_multicast_rules_ramrod_data *)(r->rdata);
2516 u8 func_id = r->func_id;
2517 u8 rx_tx_add_flag = bnx2x_mcast_get_rx_tx_flag(o);
2520 if ((cmd == BNX2X_MCAST_CMD_ADD) || (cmd == BNX2X_MCAST_CMD_RESTORE))
2521 rx_tx_add_flag |= ETH_MULTICAST_RULES_CMD_IS_ADD;
2523 data->rules[idx].cmd_general_data |= rx_tx_add_flag;
2525 /* Get a bin and update a bins' vector */
2527 case BNX2X_MCAST_CMD_ADD:
2528 bin = bnx2x_mcast_bin_from_mac(cfg_data->mac);
2529 BIT_VEC64_SET_BIT(o->registry.aprox_match.vec, bin);
2532 case BNX2X_MCAST_CMD_DEL:
2533 /* If there were no more bins to clear
2534 * (bnx2x_mcast_clear_first_bin() returns -1) then we would
2535 * clear any (0xff) bin.
2536 * See bnx2x_mcast_validate_e2() for explanation when it may
2539 bin = bnx2x_mcast_clear_first_bin(o);
2542 case BNX2X_MCAST_CMD_RESTORE:
2543 bin = cfg_data->bin;
2547 BNX2X_ERR("Unknown command: %d\n", cmd);
2551 DP(BNX2X_MSG_SP, "%s bin %d\n",
2552 ((rx_tx_add_flag & ETH_MULTICAST_RULES_CMD_IS_ADD) ?
2553 "Setting" : "Clearing"), bin);
2555 data->rules[idx].bin_id = (u8)bin;
2556 data->rules[idx].func_id = func_id;
2557 data->rules[idx].engine_id = o->engine_id;
2561 * bnx2x_mcast_handle_restore_cmd_e2 - restore configuration from the registry
2563 * @bp: device handle
2565 * @start_bin: index in the registry to start from (including)
2566 * @rdata_idx: index in the ramrod data to start from
2568 * returns last handled bin index or -1 if all bins have been handled
2570 static inline int bnx2x_mcast_handle_restore_cmd_e2(
2571 struct bnx2x *bp, struct bnx2x_mcast_obj *o , int start_bin,
2574 int cur_bin, cnt = *rdata_idx;
2575 union bnx2x_mcast_config_data cfg_data = {0};
2577 /* go through the registry and configure the bins from it */
2578 for (cur_bin = bnx2x_mcast_get_next_bin(o, start_bin); cur_bin >= 0;
2579 cur_bin = bnx2x_mcast_get_next_bin(o, cur_bin + 1)) {
2581 cfg_data.bin = (u8)cur_bin;
2582 o->set_one_rule(bp, o, cnt, &cfg_data,
2583 BNX2X_MCAST_CMD_RESTORE);
2587 DP(BNX2X_MSG_SP, "About to configure a bin %d\n", cur_bin);
2589 /* Break if we reached the maximum number
2592 if (cnt >= o->max_cmd_len)
2601 static inline void bnx2x_mcast_hdl_pending_add_e2(struct bnx2x *bp,
2602 struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
2605 struct bnx2x_mcast_mac_elem *pmac_pos, *pmac_pos_n;
2606 int cnt = *line_idx;
2607 union bnx2x_mcast_config_data cfg_data = {0};
2609 list_for_each_entry_safe(pmac_pos, pmac_pos_n, &cmd_pos->data.macs_head,
2612 cfg_data.mac = &pmac_pos->mac[0];
2613 o->set_one_rule(bp, o, cnt, &cfg_data, cmd_pos->type);
2617 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
2620 list_del(&pmac_pos->link);
2622 /* Break if we reached the maximum number
2625 if (cnt >= o->max_cmd_len)
2631 /* if no more MACs to configure - we are done */
2632 if (list_empty(&cmd_pos->data.macs_head))
2633 cmd_pos->done = true;
2636 static inline void bnx2x_mcast_hdl_pending_del_e2(struct bnx2x *bp,
2637 struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
2640 int cnt = *line_idx;
2642 while (cmd_pos->data.macs_num) {
2643 o->set_one_rule(bp, o, cnt, NULL, cmd_pos->type);
2647 cmd_pos->data.macs_num--;
2649 DP(BNX2X_MSG_SP, "Deleting MAC. %d left,cnt is %d\n",
2650 cmd_pos->data.macs_num, cnt);
2652 /* Break if we reached the maximum
2655 if (cnt >= o->max_cmd_len)
2661 /* If we cleared all bins - we are done */
2662 if (!cmd_pos->data.macs_num)
2663 cmd_pos->done = true;
2666 static inline void bnx2x_mcast_hdl_pending_restore_e2(struct bnx2x *bp,
2667 struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
2670 cmd_pos->data.next_bin = o->hdl_restore(bp, o, cmd_pos->data.next_bin,
2673 if (cmd_pos->data.next_bin < 0)
2674 /* If o->set_restore returned -1 we are done */
2675 cmd_pos->done = true;
2677 /* Start from the next bin next time */
2678 cmd_pos->data.next_bin++;
2681 static inline int bnx2x_mcast_handle_pending_cmds_e2(struct bnx2x *bp,
2682 struct bnx2x_mcast_ramrod_params *p)
2684 struct bnx2x_pending_mcast_cmd *cmd_pos, *cmd_pos_n;
2686 struct bnx2x_mcast_obj *o = p->mcast_obj;
2688 list_for_each_entry_safe(cmd_pos, cmd_pos_n, &o->pending_cmds_head,
2690 switch (cmd_pos->type) {
2691 case BNX2X_MCAST_CMD_ADD:
2692 bnx2x_mcast_hdl_pending_add_e2(bp, o, cmd_pos, &cnt);
2695 case BNX2X_MCAST_CMD_DEL:
2696 bnx2x_mcast_hdl_pending_del_e2(bp, o, cmd_pos, &cnt);
2699 case BNX2X_MCAST_CMD_RESTORE:
2700 bnx2x_mcast_hdl_pending_restore_e2(bp, o, cmd_pos,
2705 BNX2X_ERR("Unknown command: %d\n", cmd_pos->type);
2709 /* If the command has been completed - remove it from the list
2710 * and free the memory
2712 if (cmd_pos->done) {
2713 list_del(&cmd_pos->link);
2717 /* Break if we reached the maximum number of rules */
2718 if (cnt >= o->max_cmd_len)
2725 static inline void bnx2x_mcast_hdl_add(struct bnx2x *bp,
2726 struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
2729 struct bnx2x_mcast_list_elem *mlist_pos;
2730 union bnx2x_mcast_config_data cfg_data = {0};
2731 int cnt = *line_idx;
2733 list_for_each_entry(mlist_pos, &p->mcast_list, link) {
2734 cfg_data.mac = mlist_pos->mac;
2735 o->set_one_rule(bp, o, cnt, &cfg_data, BNX2X_MCAST_CMD_ADD);
2739 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
2746 static inline void bnx2x_mcast_hdl_del(struct bnx2x *bp,
2747 struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
2750 int cnt = *line_idx, i;
2752 for (i = 0; i < p->mcast_list_len; i++) {
2753 o->set_one_rule(bp, o, cnt, NULL, BNX2X_MCAST_CMD_DEL);
2757 DP(BNX2X_MSG_SP, "Deleting MAC. %d left\n",
2758 p->mcast_list_len - i - 1);
2765 * bnx2x_mcast_handle_current_cmd -
2767 * @bp: device handle
2770 * @start_cnt: first line in the ramrod data that may be used
2772 * This function is called iff there is enough place for the current command in
2774 * Returns number of lines filled in the ramrod data in total.
2776 static inline int bnx2x_mcast_handle_current_cmd(struct bnx2x *bp,
2777 struct bnx2x_mcast_ramrod_params *p, int cmd,
2780 struct bnx2x_mcast_obj *o = p->mcast_obj;
2781 int cnt = start_cnt;
2783 DP(BNX2X_MSG_SP, "p->mcast_list_len=%d\n", p->mcast_list_len);
2786 case BNX2X_MCAST_CMD_ADD:
2787 bnx2x_mcast_hdl_add(bp, o, p, &cnt);
2790 case BNX2X_MCAST_CMD_DEL:
2791 bnx2x_mcast_hdl_del(bp, o, p, &cnt);
2794 case BNX2X_MCAST_CMD_RESTORE:
2795 o->hdl_restore(bp, o, 0, &cnt);
2799 BNX2X_ERR("Unknown command: %d\n", cmd);
2803 /* The current command has been handled */
2804 p->mcast_list_len = 0;
2809 static int bnx2x_mcast_validate_e2(struct bnx2x *bp,
2810 struct bnx2x_mcast_ramrod_params *p,
2813 struct bnx2x_mcast_obj *o = p->mcast_obj;
2814 int reg_sz = o->get_registry_size(o);
2817 /* DEL command deletes all currently configured MACs */
2818 case BNX2X_MCAST_CMD_DEL:
2819 o->set_registry_size(o, 0);
2822 /* RESTORE command will restore the entire multicast configuration */
2823 case BNX2X_MCAST_CMD_RESTORE:
2824 /* Here we set the approximate amount of work to do, which in
2825 * fact may be only less as some MACs in postponed ADD
2826 * command(s) scheduled before this command may fall into
2827 * the same bin and the actual number of bins set in the
2828 * registry would be less than we estimated here. See
2829 * bnx2x_mcast_set_one_rule_e2() for further details.
2831 p->mcast_list_len = reg_sz;
2834 case BNX2X_MCAST_CMD_ADD:
2835 case BNX2X_MCAST_CMD_CONT:
2836 /* Here we assume that all new MACs will fall into new bins.
2837 * However we will correct the real registry size after we
2838 * handle all pending commands.
2840 o->set_registry_size(o, reg_sz + p->mcast_list_len);
2844 BNX2X_ERR("Unknown command: %d\n", cmd);
2849 /* Increase the total number of MACs pending to be configured */
2850 o->total_pending_num += p->mcast_list_len;
2855 static void bnx2x_mcast_revert_e2(struct bnx2x *bp,
2856 struct bnx2x_mcast_ramrod_params *p,
2859 struct bnx2x_mcast_obj *o = p->mcast_obj;
2861 o->set_registry_size(o, old_num_bins);
2862 o->total_pending_num -= p->mcast_list_len;
2866 * bnx2x_mcast_set_rdata_hdr_e2 - sets a header values
2868 * @bp: device handle
2870 * @len: number of rules to handle
2872 static inline void bnx2x_mcast_set_rdata_hdr_e2(struct bnx2x *bp,
2873 struct bnx2x_mcast_ramrod_params *p,
2876 struct bnx2x_raw_obj *r = &p->mcast_obj->raw;
2877 struct eth_multicast_rules_ramrod_data *data =
2878 (struct eth_multicast_rules_ramrod_data *)(r->rdata);
2880 data->header.echo = ((r->cid & BNX2X_SWCID_MASK) |
2881 (BNX2X_FILTER_MCAST_PENDING << BNX2X_SWCID_SHIFT));
2882 data->header.rule_cnt = len;
2886 * bnx2x_mcast_refresh_registry_e2 - recalculate the actual number of set bins
2888 * @bp: device handle
2891 * Recalculate the actual number of set bins in the registry using Brian
2892 * Kernighan's algorithm: it's execution complexity is as a number of set bins.
2894 * returns 0 for the compliance with bnx2x_mcast_refresh_registry_e1().
2896 static inline int bnx2x_mcast_refresh_registry_e2(struct bnx2x *bp,
2897 struct bnx2x_mcast_obj *o)
2902 for (i = 0; i < BNX2X_MCAST_VEC_SZ; i++) {
2903 elem = o->registry.aprox_match.vec[i];
2908 o->set_registry_size(o, cnt);
2913 static int bnx2x_mcast_setup_e2(struct bnx2x *bp,
2914 struct bnx2x_mcast_ramrod_params *p,
2917 struct bnx2x_raw_obj *raw = &p->mcast_obj->raw;
2918 struct bnx2x_mcast_obj *o = p->mcast_obj;
2919 struct eth_multicast_rules_ramrod_data *data =
2920 (struct eth_multicast_rules_ramrod_data *)(raw->rdata);
2923 /* Reset the ramrod data buffer */
2924 memset(data, 0, sizeof(*data));
2926 cnt = bnx2x_mcast_handle_pending_cmds_e2(bp, p);
2928 /* If there are no more pending commands - clear SCHEDULED state */
2929 if (list_empty(&o->pending_cmds_head))
2932 /* The below may be true iff there was enough room in ramrod
2933 * data for all pending commands and for the current
2934 * command. Otherwise the current command would have been added
2935 * to the pending commands and p->mcast_list_len would have been
2938 if (p->mcast_list_len > 0)
2939 cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, cnt);
2941 /* We've pulled out some MACs - update the total number of
2944 o->total_pending_num -= cnt;
2947 WARN_ON(o->total_pending_num < 0);
2948 WARN_ON(cnt > o->max_cmd_len);
2950 bnx2x_mcast_set_rdata_hdr_e2(bp, p, (u8)cnt);
2952 /* Update a registry size if there are no more pending operations.
2954 * We don't want to change the value of the registry size if there are
2955 * pending operations because we want it to always be equal to the
2956 * exact or the approximate number (see bnx2x_mcast_validate_e2()) of
2957 * set bins after the last requested operation in order to properly
2958 * evaluate the size of the next DEL/RESTORE operation.
2960 * Note that we update the registry itself during command(s) handling
2961 * - see bnx2x_mcast_set_one_rule_e2(). That's because for 57712 we
2962 * aggregate multiple commands (ADD/DEL/RESTORE) into one ramrod but
2963 * with a limited amount of update commands (per MAC/bin) and we don't
2964 * know in this scope what the actual state of bins configuration is
2965 * going to be after this ramrod.
2967 if (!o->total_pending_num)
2968 bnx2x_mcast_refresh_registry_e2(bp, o);
2971 * If CLEAR_ONLY was requested - don't send a ramrod and clear
2972 * RAMROD_PENDING status immediately.
2974 if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
2975 raw->clear_pending(raw);
2979 * No need for an explicit memory barrier here as long we would
2980 * need to ensure the ordering of writing to the SPQ element
2981 * and updating of the SPQ producer which involves a memory
2982 * read and we will have to put a full memory barrier there
2983 * (inside bnx2x_sp_post()).
2987 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_MULTICAST_RULES,
2988 raw->cid, U64_HI(raw->rdata_mapping),
2989 U64_LO(raw->rdata_mapping),
2990 ETH_CONNECTION_TYPE);
2994 /* Ramrod completion is pending */
2999 static int bnx2x_mcast_validate_e1h(struct bnx2x *bp,
3000 struct bnx2x_mcast_ramrod_params *p,
3003 /* Mark, that there is a work to do */
3004 if ((cmd == BNX2X_MCAST_CMD_DEL) || (cmd == BNX2X_MCAST_CMD_RESTORE))
3005 p->mcast_list_len = 1;
3010 static void bnx2x_mcast_revert_e1h(struct bnx2x *bp,
3011 struct bnx2x_mcast_ramrod_params *p,
3017 #define BNX2X_57711_SET_MC_FILTER(filter, bit) \
3019 (filter)[(bit) >> 5] |= (1 << ((bit) & 0x1f)); \
3022 static inline void bnx2x_mcast_hdl_add_e1h(struct bnx2x *bp,
3023 struct bnx2x_mcast_obj *o,
3024 struct bnx2x_mcast_ramrod_params *p,
3027 struct bnx2x_mcast_list_elem *mlist_pos;
3030 list_for_each_entry(mlist_pos, &p->mcast_list, link) {
3031 bit = bnx2x_mcast_bin_from_mac(mlist_pos->mac);
3032 BNX2X_57711_SET_MC_FILTER(mc_filter, bit);
3034 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC, bin %d\n",
3035 mlist_pos->mac, bit);
3037 /* bookkeeping... */
3038 BIT_VEC64_SET_BIT(o->registry.aprox_match.vec,
3043 static inline void bnx2x_mcast_hdl_restore_e1h(struct bnx2x *bp,
3044 struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
3049 for (bit = bnx2x_mcast_get_next_bin(o, 0);
3051 bit = bnx2x_mcast_get_next_bin(o, bit + 1)) {
3052 BNX2X_57711_SET_MC_FILTER(mc_filter, bit);
3053 DP(BNX2X_MSG_SP, "About to set bin %d\n", bit);
3057 /* On 57711 we write the multicast MACs' aproximate match
3058 * table by directly into the TSTORM's internal RAM. So we don't
3059 * really need to handle any tricks to make it work.
3061 static int bnx2x_mcast_setup_e1h(struct bnx2x *bp,
3062 struct bnx2x_mcast_ramrod_params *p,
3066 struct bnx2x_mcast_obj *o = p->mcast_obj;
3067 struct bnx2x_raw_obj *r = &o->raw;
3069 /* If CLEAR_ONLY has been requested - clear the registry
3070 * and clear a pending bit.
3072 if (!test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
3073 u32 mc_filter[MC_HASH_SIZE] = {0};
3075 /* Set the multicast filter bits before writing it into
3076 * the internal memory.
3079 case BNX2X_MCAST_CMD_ADD:
3080 bnx2x_mcast_hdl_add_e1h(bp, o, p, mc_filter);
3083 case BNX2X_MCAST_CMD_DEL:
3085 "Invalidating multicast MACs configuration\n");
3087 /* clear the registry */
3088 memset(o->registry.aprox_match.vec, 0,
3089 sizeof(o->registry.aprox_match.vec));
3092 case BNX2X_MCAST_CMD_RESTORE:
3093 bnx2x_mcast_hdl_restore_e1h(bp, o, p, mc_filter);
3097 BNX2X_ERR("Unknown command: %d\n", cmd);
3101 /* Set the mcast filter in the internal memory */
3102 for (i = 0; i < MC_HASH_SIZE; i++)
3103 REG_WR(bp, MC_HASH_OFFSET(bp, i), mc_filter[i]);
3105 /* clear the registry */
3106 memset(o->registry.aprox_match.vec, 0,
3107 sizeof(o->registry.aprox_match.vec));
3110 r->clear_pending(r);
3115 static int bnx2x_mcast_validate_e1(struct bnx2x *bp,
3116 struct bnx2x_mcast_ramrod_params *p,
3119 struct bnx2x_mcast_obj *o = p->mcast_obj;
3120 int reg_sz = o->get_registry_size(o);
3123 /* DEL command deletes all currently configured MACs */
3124 case BNX2X_MCAST_CMD_DEL:
3125 o->set_registry_size(o, 0);
3128 /* RESTORE command will restore the entire multicast configuration */
3129 case BNX2X_MCAST_CMD_RESTORE:
3130 p->mcast_list_len = reg_sz;
3131 DP(BNX2X_MSG_SP, "Command %d, p->mcast_list_len=%d\n",
3132 cmd, p->mcast_list_len);
3135 case BNX2X_MCAST_CMD_ADD:
3136 case BNX2X_MCAST_CMD_CONT:
3137 /* Multicast MACs on 57710 are configured as unicast MACs and
3138 * there is only a limited number of CAM entries for that
3141 if (p->mcast_list_len > o->max_cmd_len) {
3142 BNX2X_ERR("Can't configure more than %d multicast MACs"
3143 "on 57710\n", o->max_cmd_len);
3146 /* Every configured MAC should be cleared if DEL command is
3147 * called. Only the last ADD command is relevant as long as
3148 * every ADD commands overrides the previous configuration.
3150 DP(BNX2X_MSG_SP, "p->mcast_list_len=%d\n", p->mcast_list_len);
3151 if (p->mcast_list_len > 0)
3152 o->set_registry_size(o, p->mcast_list_len);
3157 BNX2X_ERR("Unknown command: %d\n", cmd);
3162 /* We want to ensure that commands are executed one by one for 57710.
3163 * Therefore each none-empty command will consume o->max_cmd_len.
3165 if (p->mcast_list_len)
3166 o->total_pending_num += o->max_cmd_len;
3171 static void bnx2x_mcast_revert_e1(struct bnx2x *bp,
3172 struct bnx2x_mcast_ramrod_params *p,
3175 struct bnx2x_mcast_obj *o = p->mcast_obj;
3177 o->set_registry_size(o, old_num_macs);
3179 /* If current command hasn't been handled yet and we are
3180 * here means that it's meant to be dropped and we have to
3181 * update the number of outstandling MACs accordingly.
3183 if (p->mcast_list_len)
3184 o->total_pending_num -= o->max_cmd_len;
3187 static void bnx2x_mcast_set_one_rule_e1(struct bnx2x *bp,
3188 struct bnx2x_mcast_obj *o, int idx,
3189 union bnx2x_mcast_config_data *cfg_data,
3192 struct bnx2x_raw_obj *r = &o->raw;
3193 struct mac_configuration_cmd *data =
3194 (struct mac_configuration_cmd *)(r->rdata);
3197 if ((cmd == BNX2X_MCAST_CMD_ADD) || (cmd == BNX2X_MCAST_CMD_RESTORE)) {
3198 bnx2x_set_fw_mac_addr(&data->config_table[idx].msb_mac_addr,
3199 &data->config_table[idx].middle_mac_addr,
3200 &data->config_table[idx].lsb_mac_addr,
3203 data->config_table[idx].vlan_id = 0;
3204 data->config_table[idx].pf_id = r->func_id;
3205 data->config_table[idx].clients_bit_vector =
3206 cpu_to_le32(1 << r->cl_id);
3208 SET_FLAG(data->config_table[idx].flags,
3209 MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
3210 T_ETH_MAC_COMMAND_SET);
3215 * bnx2x_mcast_set_rdata_hdr_e1 - set header values in mac_configuration_cmd
3217 * @bp: device handle
3219 * @len: number of rules to handle
3221 static inline void bnx2x_mcast_set_rdata_hdr_e1(struct bnx2x *bp,
3222 struct bnx2x_mcast_ramrod_params *p,
3225 struct bnx2x_raw_obj *r = &p->mcast_obj->raw;
3226 struct mac_configuration_cmd *data =
3227 (struct mac_configuration_cmd *)(r->rdata);
3229 u8 offset = (CHIP_REV_IS_SLOW(bp) ?
3230 BNX2X_MAX_EMUL_MULTI*(1 + r->func_id) :
3231 BNX2X_MAX_MULTICAST*(1 + r->func_id));
3233 data->hdr.offset = offset;
3234 data->hdr.client_id = 0xff;
3235 data->hdr.echo = ((r->cid & BNX2X_SWCID_MASK) |
3236 (BNX2X_FILTER_MCAST_PENDING << BNX2X_SWCID_SHIFT));
3237 data->hdr.length = len;
3241 * bnx2x_mcast_handle_restore_cmd_e1 - restore command for 57710
3243 * @bp: device handle
3245 * @start_idx: index in the registry to start from
3246 * @rdata_idx: index in the ramrod data to start from
3248 * restore command for 57710 is like all other commands - always a stand alone
3249 * command - start_idx and rdata_idx will always be 0. This function will always
3251 * returns -1 to comply with 57712 variant.
3253 static inline int bnx2x_mcast_handle_restore_cmd_e1(
3254 struct bnx2x *bp, struct bnx2x_mcast_obj *o , int start_idx,
3257 struct bnx2x_mcast_mac_elem *elem;
3259 union bnx2x_mcast_config_data cfg_data = {0};
3261 /* go through the registry and configure the MACs from it. */
3262 list_for_each_entry(elem, &o->registry.exact_match.macs, link) {
3263 cfg_data.mac = &elem->mac[0];
3264 o->set_one_rule(bp, o, i, &cfg_data, BNX2X_MCAST_CMD_RESTORE);
3268 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
3278 static inline int bnx2x_mcast_handle_pending_cmds_e1(
3279 struct bnx2x *bp, struct bnx2x_mcast_ramrod_params *p)
3281 struct bnx2x_pending_mcast_cmd *cmd_pos;
3282 struct bnx2x_mcast_mac_elem *pmac_pos;
3283 struct bnx2x_mcast_obj *o = p->mcast_obj;
3284 union bnx2x_mcast_config_data cfg_data = {0};
3288 /* If nothing to be done - return */
3289 if (list_empty(&o->pending_cmds_head))
3292 /* Handle the first command */
3293 cmd_pos = list_first_entry(&o->pending_cmds_head,
3294 struct bnx2x_pending_mcast_cmd, link);
3296 switch (cmd_pos->type) {
3297 case BNX2X_MCAST_CMD_ADD:
3298 list_for_each_entry(pmac_pos, &cmd_pos->data.macs_head, link) {
3299 cfg_data.mac = &pmac_pos->mac[0];
3300 o->set_one_rule(bp, o, cnt, &cfg_data, cmd_pos->type);
3304 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
3309 case BNX2X_MCAST_CMD_DEL:
3310 cnt = cmd_pos->data.macs_num;
3311 DP(BNX2X_MSG_SP, "About to delete %d multicast MACs\n", cnt);
3314 case BNX2X_MCAST_CMD_RESTORE:
3315 o->hdl_restore(bp, o, 0, &cnt);
3319 BNX2X_ERR("Unknown command: %d\n", cmd_pos->type);
3323 list_del(&cmd_pos->link);
3330 * bnx2x_get_fw_mac_addr - revert the bnx2x_set_fw_mac_addr().
3337 static inline void bnx2x_get_fw_mac_addr(__le16 *fw_hi, __le16 *fw_mid,
3338 __le16 *fw_lo, u8 *mac)
3340 mac[1] = ((u8 *)fw_hi)[0];
3341 mac[0] = ((u8 *)fw_hi)[1];
3342 mac[3] = ((u8 *)fw_mid)[0];
3343 mac[2] = ((u8 *)fw_mid)[1];
3344 mac[5] = ((u8 *)fw_lo)[0];
3345 mac[4] = ((u8 *)fw_lo)[1];
3349 * bnx2x_mcast_refresh_registry_e1 -
3351 * @bp: device handle
3354 * Check the ramrod data first entry flag to see if it's a DELETE or ADD command
3355 * and update the registry correspondingly: if ADD - allocate a memory and add
3356 * the entries to the registry (list), if DELETE - clear the registry and free
3359 static inline int bnx2x_mcast_refresh_registry_e1(struct bnx2x *bp,
3360 struct bnx2x_mcast_obj *o)
3362 struct bnx2x_raw_obj *raw = &o->raw;
3363 struct bnx2x_mcast_mac_elem *elem;
3364 struct mac_configuration_cmd *data =
3365 (struct mac_configuration_cmd *)(raw->rdata);
3367 /* If first entry contains a SET bit - the command was ADD,
3368 * otherwise - DEL_ALL
3370 if (GET_FLAG(data->config_table[0].flags,
3371 MAC_CONFIGURATION_ENTRY_ACTION_TYPE)) {
3372 int i, len = data->hdr.length;
3374 /* Break if it was a RESTORE command */
3375 if (!list_empty(&o->registry.exact_match.macs))
3378 elem = kcalloc(len, sizeof(*elem), GFP_ATOMIC);
3380 BNX2X_ERR("Failed to allocate registry memory\n");
3384 for (i = 0; i < len; i++, elem++) {
3385 bnx2x_get_fw_mac_addr(
3386 &data->config_table[i].msb_mac_addr,
3387 &data->config_table[i].middle_mac_addr,
3388 &data->config_table[i].lsb_mac_addr,
3390 DP(BNX2X_MSG_SP, "Adding registry entry for [%pM]\n",
3392 list_add_tail(&elem->link,
3393 &o->registry.exact_match.macs);
3396 elem = list_first_entry(&o->registry.exact_match.macs,
3397 struct bnx2x_mcast_mac_elem, link);
3398 DP(BNX2X_MSG_SP, "Deleting a registry\n");
3400 INIT_LIST_HEAD(&o->registry.exact_match.macs);
3406 static int bnx2x_mcast_setup_e1(struct bnx2x *bp,
3407 struct bnx2x_mcast_ramrod_params *p,
3410 struct bnx2x_mcast_obj *o = p->mcast_obj;
3411 struct bnx2x_raw_obj *raw = &o->raw;
3412 struct mac_configuration_cmd *data =
3413 (struct mac_configuration_cmd *)(raw->rdata);
3416 /* Reset the ramrod data buffer */
3417 memset(data, 0, sizeof(*data));
3419 /* First set all entries as invalid */
3420 for (i = 0; i < o->max_cmd_len ; i++)
3421 SET_FLAG(data->config_table[i].flags,
3422 MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
3423 T_ETH_MAC_COMMAND_INVALIDATE);
3425 /* Handle pending commands first */
3426 cnt = bnx2x_mcast_handle_pending_cmds_e1(bp, p);
3428 /* If there are no more pending commands - clear SCHEDULED state */
3429 if (list_empty(&o->pending_cmds_head))
3432 /* The below may be true iff there were no pending commands */
3434 cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, 0);
3436 /* For 57710 every command has o->max_cmd_len length to ensure that
3437 * commands are done one at a time.
3439 o->total_pending_num -= o->max_cmd_len;
3443 WARN_ON(cnt > o->max_cmd_len);
3445 /* Set ramrod header (in particular, a number of entries to update) */
3446 bnx2x_mcast_set_rdata_hdr_e1(bp, p, (u8)cnt);
3448 /* update a registry: we need the registry contents to be always up
3449 * to date in order to be able to execute a RESTORE opcode. Here
3450 * we use the fact that for 57710 we sent one command at a time
3451 * hence we may take the registry update out of the command handling
3452 * and do it in a simpler way here.
3454 rc = bnx2x_mcast_refresh_registry_e1(bp, o);
3459 * If CLEAR_ONLY was requested - don't send a ramrod and clear
3460 * RAMROD_PENDING status immediately.
3462 if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
3463 raw->clear_pending(raw);
3467 * No need for an explicit memory barrier here as long we would
3468 * need to ensure the ordering of writing to the SPQ element
3469 * and updating of the SPQ producer which involves a memory
3470 * read and we will have to put a full memory barrier there
3471 * (inside bnx2x_sp_post()).
3475 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, raw->cid,
3476 U64_HI(raw->rdata_mapping),
3477 U64_LO(raw->rdata_mapping),
3478 ETH_CONNECTION_TYPE);
3482 /* Ramrod completion is pending */
3488 static int bnx2x_mcast_get_registry_size_exact(struct bnx2x_mcast_obj *o)
3490 return o->registry.exact_match.num_macs_set;
3493 static int bnx2x_mcast_get_registry_size_aprox(struct bnx2x_mcast_obj *o)
3495 return o->registry.aprox_match.num_bins_set;
3498 static void bnx2x_mcast_set_registry_size_exact(struct bnx2x_mcast_obj *o,
3501 o->registry.exact_match.num_macs_set = n;
3504 static void bnx2x_mcast_set_registry_size_aprox(struct bnx2x_mcast_obj *o,
3507 o->registry.aprox_match.num_bins_set = n;
3510 int bnx2x_config_mcast(struct bnx2x *bp,
3511 struct bnx2x_mcast_ramrod_params *p,
3514 struct bnx2x_mcast_obj *o = p->mcast_obj;
3515 struct bnx2x_raw_obj *r = &o->raw;
3516 int rc = 0, old_reg_size;
3518 /* This is needed to recover number of currently configured mcast macs
3519 * in case of failure.
3521 old_reg_size = o->get_registry_size(o);
3523 /* Do some calculations and checks */
3524 rc = o->validate(bp, p, cmd);
3528 /* Return if there is no work to do */
3529 if ((!p->mcast_list_len) && (!o->check_sched(o)))
3532 DP(BNX2X_MSG_SP, "o->total_pending_num=%d p->mcast_list_len=%d "
3533 "o->max_cmd_len=%d\n", o->total_pending_num,
3534 p->mcast_list_len, o->max_cmd_len);
3536 /* Enqueue the current command to the pending list if we can't complete
3537 * it in the current iteration
3539 if (r->check_pending(r) ||
3540 ((o->max_cmd_len > 0) && (o->total_pending_num > o->max_cmd_len))) {
3541 rc = o->enqueue_cmd(bp, p->mcast_obj, p, cmd);
3545 /* As long as the current command is in a command list we
3546 * don't need to handle it separately.
3548 p->mcast_list_len = 0;
3551 if (!r->check_pending(r)) {
3553 /* Set 'pending' state */
3556 /* Configure the new classification in the chip */
3557 rc = o->config_mcast(bp, p, cmd);
3561 /* Wait for a ramrod completion if was requested */
3562 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags))
3563 rc = o->wait_comp(bp, o);
3569 r->clear_pending(r);
3572 o->revert(bp, p, old_reg_size);
3577 static void bnx2x_mcast_clear_sched(struct bnx2x_mcast_obj *o)
3579 smp_mb__before_clear_bit();
3580 clear_bit(o->sched_state, o->raw.pstate);
3581 smp_mb__after_clear_bit();
3584 static void bnx2x_mcast_set_sched(struct bnx2x_mcast_obj *o)
3586 smp_mb__before_clear_bit();
3587 set_bit(o->sched_state, o->raw.pstate);
3588 smp_mb__after_clear_bit();
3591 static bool bnx2x_mcast_check_sched(struct bnx2x_mcast_obj *o)
3593 return !!test_bit(o->sched_state, o->raw.pstate);
3596 static bool bnx2x_mcast_check_pending(struct bnx2x_mcast_obj *o)
3598 return o->raw.check_pending(&o->raw) || o->check_sched(o);
3601 void bnx2x_init_mcast_obj(struct bnx2x *bp,
3602 struct bnx2x_mcast_obj *mcast_obj,
3603 u8 mcast_cl_id, u32 mcast_cid, u8 func_id,
3604 u8 engine_id, void *rdata, dma_addr_t rdata_mapping,
3605 int state, unsigned long *pstate, bnx2x_obj_type type)
3607 memset(mcast_obj, 0, sizeof(*mcast_obj));
3609 bnx2x_init_raw_obj(&mcast_obj->raw, mcast_cl_id, mcast_cid, func_id,
3610 rdata, rdata_mapping, state, pstate, type);
3612 mcast_obj->engine_id = engine_id;
3614 INIT_LIST_HEAD(&mcast_obj->pending_cmds_head);
3616 mcast_obj->sched_state = BNX2X_FILTER_MCAST_SCHED;
3617 mcast_obj->check_sched = bnx2x_mcast_check_sched;
3618 mcast_obj->set_sched = bnx2x_mcast_set_sched;
3619 mcast_obj->clear_sched = bnx2x_mcast_clear_sched;
3621 if (CHIP_IS_E1(bp)) {
3622 mcast_obj->config_mcast = bnx2x_mcast_setup_e1;
3623 mcast_obj->enqueue_cmd = bnx2x_mcast_enqueue_cmd;
3624 mcast_obj->hdl_restore =
3625 bnx2x_mcast_handle_restore_cmd_e1;
3626 mcast_obj->check_pending = bnx2x_mcast_check_pending;
3628 if (CHIP_REV_IS_SLOW(bp))
3629 mcast_obj->max_cmd_len = BNX2X_MAX_EMUL_MULTI;
3631 mcast_obj->max_cmd_len = BNX2X_MAX_MULTICAST;
3633 mcast_obj->wait_comp = bnx2x_mcast_wait;
3634 mcast_obj->set_one_rule = bnx2x_mcast_set_one_rule_e1;
3635 mcast_obj->validate = bnx2x_mcast_validate_e1;
3636 mcast_obj->revert = bnx2x_mcast_revert_e1;
3637 mcast_obj->get_registry_size =
3638 bnx2x_mcast_get_registry_size_exact;
3639 mcast_obj->set_registry_size =
3640 bnx2x_mcast_set_registry_size_exact;
3642 /* 57710 is the only chip that uses the exact match for mcast
3645 INIT_LIST_HEAD(&mcast_obj->registry.exact_match.macs);
3647 } else if (CHIP_IS_E1H(bp)) {
3648 mcast_obj->config_mcast = bnx2x_mcast_setup_e1h;
3649 mcast_obj->enqueue_cmd = NULL;
3650 mcast_obj->hdl_restore = NULL;
3651 mcast_obj->check_pending = bnx2x_mcast_check_pending;
3653 /* 57711 doesn't send a ramrod, so it has unlimited credit
3656 mcast_obj->max_cmd_len = -1;
3657 mcast_obj->wait_comp = bnx2x_mcast_wait;
3658 mcast_obj->set_one_rule = NULL;
3659 mcast_obj->validate = bnx2x_mcast_validate_e1h;
3660 mcast_obj->revert = bnx2x_mcast_revert_e1h;
3661 mcast_obj->get_registry_size =
3662 bnx2x_mcast_get_registry_size_aprox;
3663 mcast_obj->set_registry_size =
3664 bnx2x_mcast_set_registry_size_aprox;
3666 mcast_obj->config_mcast = bnx2x_mcast_setup_e2;
3667 mcast_obj->enqueue_cmd = bnx2x_mcast_enqueue_cmd;
3668 mcast_obj->hdl_restore =
3669 bnx2x_mcast_handle_restore_cmd_e2;
3670 mcast_obj->check_pending = bnx2x_mcast_check_pending;
3671 /* TODO: There should be a proper HSI define for this number!!!
3673 mcast_obj->max_cmd_len = 16;
3674 mcast_obj->wait_comp = bnx2x_mcast_wait;
3675 mcast_obj->set_one_rule = bnx2x_mcast_set_one_rule_e2;
3676 mcast_obj->validate = bnx2x_mcast_validate_e2;
3677 mcast_obj->revert = bnx2x_mcast_revert_e2;
3678 mcast_obj->get_registry_size =
3679 bnx2x_mcast_get_registry_size_aprox;
3680 mcast_obj->set_registry_size =
3681 bnx2x_mcast_set_registry_size_aprox;
3685 /*************************** Credit handling **********************************/
3688 * atomic_add_ifless - add if the result is less than a given value.
3690 * @v: pointer of type atomic_t
3691 * @a: the amount to add to v...
3692 * @u: ...if (v + a) is less than u.
3694 * returns true if (v + a) was less than u, and false otherwise.
3697 static inline bool __atomic_add_ifless(atomic_t *v, int a, int u)
3703 if (unlikely(c + a >= u))
3706 old = atomic_cmpxchg((v), c, c + a);
3707 if (likely(old == c))
3716 * atomic_dec_ifmoe - dec if the result is more or equal than a given value.
3718 * @v: pointer of type atomic_t
3719 * @a: the amount to dec from v...
3720 * @u: ...if (v - a) is more or equal than u.
3722 * returns true if (v - a) was more or equal than u, and false
3725 static inline bool __atomic_dec_ifmoe(atomic_t *v, int a, int u)
3731 if (unlikely(c - a < u))
3734 old = atomic_cmpxchg((v), c, c - a);
3735 if (likely(old == c))
3743 static bool bnx2x_credit_pool_get(struct bnx2x_credit_pool_obj *o, int cnt)
3748 rc = __atomic_dec_ifmoe(&o->credit, cnt, 0);
3754 static bool bnx2x_credit_pool_put(struct bnx2x_credit_pool_obj *o, int cnt)
3760 /* Don't let to refill if credit + cnt > pool_sz */
3761 rc = __atomic_add_ifless(&o->credit, cnt, o->pool_sz + 1);
3768 static int bnx2x_credit_pool_check(struct bnx2x_credit_pool_obj *o)
3773 cur_credit = atomic_read(&o->credit);
3778 static bool bnx2x_credit_pool_always_true(struct bnx2x_credit_pool_obj *o,
3785 static bool bnx2x_credit_pool_get_entry(
3786 struct bnx2x_credit_pool_obj *o,
3793 /* Find "internal cam-offset" then add to base for this object... */
3794 for (vec = 0; vec < BNX2X_POOL_VEC_SIZE; vec++) {
3796 /* Skip the current vector if there are no free entries in it */
3797 if (!o->pool_mirror[vec])
3800 /* If we've got here we are going to find a free entry */
3801 for (idx = vec * BNX2X_POOL_VEC_SIZE, i = 0;
3802 i < BIT_VEC64_ELEM_SZ; idx++, i++)
3804 if (BIT_VEC64_TEST_BIT(o->pool_mirror, idx)) {
3806 BIT_VEC64_CLEAR_BIT(o->pool_mirror, idx);
3807 *offset = o->base_pool_offset + idx;
3815 static bool bnx2x_credit_pool_put_entry(
3816 struct bnx2x_credit_pool_obj *o,
3819 if (offset < o->base_pool_offset)
3822 offset -= o->base_pool_offset;
3824 if (offset >= o->pool_sz)
3827 /* Return the entry to the pool */
3828 BIT_VEC64_SET_BIT(o->pool_mirror, offset);
3833 static bool bnx2x_credit_pool_put_entry_always_true(
3834 struct bnx2x_credit_pool_obj *o,
3840 static bool bnx2x_credit_pool_get_entry_always_true(
3841 struct bnx2x_credit_pool_obj *o,
3848 * bnx2x_init_credit_pool - initialize credit pool internals.
3851 * @base: Base entry in the CAM to use.
3852 * @credit: pool size.
3854 * If base is negative no CAM entries handling will be performed.
3855 * If credit is negative pool operations will always succeed (unlimited pool).
3858 static inline void bnx2x_init_credit_pool(struct bnx2x_credit_pool_obj *p,
3859 int base, int credit)
3861 /* Zero the object first */
3862 memset(p, 0, sizeof(*p));
3864 /* Set the table to all 1s */
3865 memset(&p->pool_mirror, 0xff, sizeof(p->pool_mirror));
3867 /* Init a pool as full */
3868 atomic_set(&p->credit, credit);
3870 /* The total poll size */
3871 p->pool_sz = credit;
3873 p->base_pool_offset = base;
3875 /* Commit the change */
3878 p->check = bnx2x_credit_pool_check;
3880 /* if pool credit is negative - disable the checks */
3882 p->put = bnx2x_credit_pool_put;
3883 p->get = bnx2x_credit_pool_get;
3884 p->put_entry = bnx2x_credit_pool_put_entry;
3885 p->get_entry = bnx2x_credit_pool_get_entry;
3887 p->put = bnx2x_credit_pool_always_true;
3888 p->get = bnx2x_credit_pool_always_true;
3889 p->put_entry = bnx2x_credit_pool_put_entry_always_true;
3890 p->get_entry = bnx2x_credit_pool_get_entry_always_true;
3893 /* If base is negative - disable entries handling */
3895 p->put_entry = bnx2x_credit_pool_put_entry_always_true;
3896 p->get_entry = bnx2x_credit_pool_get_entry_always_true;
3900 void bnx2x_init_mac_credit_pool(struct bnx2x *bp,
3901 struct bnx2x_credit_pool_obj *p, u8 func_id,
3904 /* TODO: this will be defined in consts as well... */
3905 #define BNX2X_CAM_SIZE_EMUL 5
3909 if (CHIP_IS_E1(bp)) {
3910 /* In E1, Multicast is saved in cam... */
3911 if (!CHIP_REV_IS_SLOW(bp))
3912 cam_sz = (MAX_MAC_CREDIT_E1 / 2) - BNX2X_MAX_MULTICAST;
3914 cam_sz = BNX2X_CAM_SIZE_EMUL - BNX2X_MAX_EMUL_MULTI;
3916 bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
3918 } else if (CHIP_IS_E1H(bp)) {
3919 /* CAM credit is equaly divided between all active functions
3922 if ((func_num > 0)) {
3923 if (!CHIP_REV_IS_SLOW(bp))
3924 cam_sz = (MAX_MAC_CREDIT_E1H / (2*func_num));
3926 cam_sz = BNX2X_CAM_SIZE_EMUL;
3927 bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
3929 /* this should never happen! Block MAC operations. */
3930 bnx2x_init_credit_pool(p, 0, 0);
3936 * CAM credit is equaly divided between all active functions
3939 if ((func_num > 0)) {
3940 if (!CHIP_REV_IS_SLOW(bp))
3941 cam_sz = (MAX_MAC_CREDIT_E2 / func_num);
3943 cam_sz = BNX2X_CAM_SIZE_EMUL;
3946 * No need for CAM entries handling for 57712 and
3949 bnx2x_init_credit_pool(p, -1, cam_sz);
3951 /* this should never happen! Block MAC operations. */
3952 bnx2x_init_credit_pool(p, 0, 0);
3958 void bnx2x_init_vlan_credit_pool(struct bnx2x *bp,
3959 struct bnx2x_credit_pool_obj *p,
3963 if (CHIP_IS_E1x(bp)) {
3965 * There is no VLAN credit in HW on 57710 and 57711 only
3966 * MAC / MAC-VLAN can be set
3968 bnx2x_init_credit_pool(p, 0, -1);
3971 * CAM credit is equaly divided between all active functions
3975 int credit = MAX_VLAN_CREDIT_E2 / func_num;
3976 bnx2x_init_credit_pool(p, func_id * credit, credit);
3978 /* this should never happen! Block VLAN operations. */
3979 bnx2x_init_credit_pool(p, 0, 0);
3983 /****************** RSS Configuration ******************/
3985 * bnx2x_debug_print_ind_table - prints the indirection table configuration.
3987 * @bp: driver hanlde
3988 * @p: pointer to rss configuration
3990 * Prints it when NETIF_MSG_IFUP debug level is configured.
3992 static inline void bnx2x_debug_print_ind_table(struct bnx2x *bp,
3993 struct bnx2x_config_rss_params *p)
3997 DP(BNX2X_MSG_SP, "Setting indirection table to:\n");
3998 DP(BNX2X_MSG_SP, "0x0000: ");
3999 for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++) {
4000 DP_CONT(BNX2X_MSG_SP, "0x%02x ", p->ind_table[i]);
4002 /* Print 4 bytes in a line */
4003 if ((i + 1 < T_ETH_INDIRECTION_TABLE_SIZE) &&
4004 (((i + 1) & 0x3) == 0)) {
4005 DP_CONT(BNX2X_MSG_SP, "\n");
4006 DP(BNX2X_MSG_SP, "0x%04x: ", i + 1);
4010 DP_CONT(BNX2X_MSG_SP, "\n");
4014 * bnx2x_setup_rss - configure RSS
4016 * @bp: device handle
4017 * @p: rss configuration
4019 * sends on UPDATE ramrod for that matter.
4021 static int bnx2x_setup_rss(struct bnx2x *bp,
4022 struct bnx2x_config_rss_params *p)
4024 struct bnx2x_rss_config_obj *o = p->rss_obj;
4025 struct bnx2x_raw_obj *r = &o->raw;
4026 struct eth_rss_update_ramrod_data *data =
4027 (struct eth_rss_update_ramrod_data *)(r->rdata);
4031 memset(data, 0, sizeof(*data));
4033 DP(BNX2X_MSG_SP, "Configuring RSS\n");
4035 /* Set an echo field */
4036 data->echo = (r->cid & BNX2X_SWCID_MASK) |
4037 (r->state << BNX2X_SWCID_SHIFT);
4040 if (test_bit(BNX2X_RSS_MODE_DISABLED, &p->rss_flags))
4041 rss_mode = ETH_RSS_MODE_DISABLED;
4042 else if (test_bit(BNX2X_RSS_MODE_REGULAR, &p->rss_flags))
4043 rss_mode = ETH_RSS_MODE_REGULAR;
4044 else if (test_bit(BNX2X_RSS_MODE_VLAN_PRI, &p->rss_flags))
4045 rss_mode = ETH_RSS_MODE_VLAN_PRI;
4046 else if (test_bit(BNX2X_RSS_MODE_E1HOV_PRI, &p->rss_flags))
4047 rss_mode = ETH_RSS_MODE_E1HOV_PRI;
4048 else if (test_bit(BNX2X_RSS_MODE_IP_DSCP, &p->rss_flags))
4049 rss_mode = ETH_RSS_MODE_IP_DSCP;
4051 data->rss_mode = rss_mode;
4053 DP(BNX2X_MSG_SP, "rss_mode=%d\n", rss_mode);
4055 /* RSS capabilities */
4056 if (test_bit(BNX2X_RSS_IPV4, &p->rss_flags))
4057 data->capabilities |=
4058 ETH_RSS_UPDATE_RAMROD_DATA_IPV4_CAPABILITY;
4060 if (test_bit(BNX2X_RSS_IPV4_TCP, &p->rss_flags))
4061 data->capabilities |=
4062 ETH_RSS_UPDATE_RAMROD_DATA_IPV4_TCP_CAPABILITY;
4064 if (test_bit(BNX2X_RSS_IPV6, &p->rss_flags))
4065 data->capabilities |=
4066 ETH_RSS_UPDATE_RAMROD_DATA_IPV6_CAPABILITY;
4068 if (test_bit(BNX2X_RSS_IPV6_TCP, &p->rss_flags))
4069 data->capabilities |=
4070 ETH_RSS_UPDATE_RAMROD_DATA_IPV6_TCP_CAPABILITY;
4073 data->rss_result_mask = p->rss_result_mask;
4076 data->rss_engine_id = o->engine_id;
4078 DP(BNX2X_MSG_SP, "rss_engine_id=%d\n", data->rss_engine_id);
4080 /* Indirection table */
4081 memcpy(data->indirection_table, p->ind_table,
4082 T_ETH_INDIRECTION_TABLE_SIZE);
4084 /* Remember the last configuration */
4085 memcpy(o->ind_table, p->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
4087 /* Print the indirection table */
4088 if (netif_msg_ifup(bp))
4089 bnx2x_debug_print_ind_table(bp, p);
4092 if (test_bit(BNX2X_RSS_SET_SRCH, &p->rss_flags)) {
4093 memcpy(&data->rss_key[0], &p->rss_key[0],
4094 sizeof(data->rss_key));
4095 data->capabilities |= ETH_RSS_UPDATE_RAMROD_DATA_UPDATE_RSS_KEY;
4099 * No need for an explicit memory barrier here as long we would
4100 * need to ensure the ordering of writing to the SPQ element
4101 * and updating of the SPQ producer which involves a memory
4102 * read and we will have to put a full memory barrier there
4103 * (inside bnx2x_sp_post()).
4107 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_RSS_UPDATE, r->cid,
4108 U64_HI(r->rdata_mapping),
4109 U64_LO(r->rdata_mapping),
4110 ETH_CONNECTION_TYPE);
4118 void bnx2x_get_rss_ind_table(struct bnx2x_rss_config_obj *rss_obj,
4121 memcpy(ind_table, rss_obj->ind_table, sizeof(rss_obj->ind_table));
4124 int bnx2x_config_rss(struct bnx2x *bp,
4125 struct bnx2x_config_rss_params *p)
4128 struct bnx2x_rss_config_obj *o = p->rss_obj;
4129 struct bnx2x_raw_obj *r = &o->raw;
4131 /* Do nothing if only driver cleanup was requested */
4132 if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags))
4137 rc = o->config_rss(bp, p);
4139 r->clear_pending(r);
4143 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags))
4144 rc = r->wait_comp(bp, r);
4150 void bnx2x_init_rss_config_obj(struct bnx2x *bp,
4151 struct bnx2x_rss_config_obj *rss_obj,
4152 u8 cl_id, u32 cid, u8 func_id, u8 engine_id,
4153 void *rdata, dma_addr_t rdata_mapping,
4154 int state, unsigned long *pstate,
4155 bnx2x_obj_type type)
4157 bnx2x_init_raw_obj(&rss_obj->raw, cl_id, cid, func_id, rdata,
4158 rdata_mapping, state, pstate, type);
4160 rss_obj->engine_id = engine_id;
4161 rss_obj->config_rss = bnx2x_setup_rss;
4164 /********************** Queue state object ***********************************/
4167 * bnx2x_queue_state_change - perform Queue state change transition
4169 * @bp: device handle
4170 * @params: parameters to perform the transition
4172 * returns 0 in case of successfully completed transition, negative error
4173 * code in case of failure, positive (EBUSY) value if there is a completion
4174 * to that is still pending (possible only if RAMROD_COMP_WAIT is
4175 * not set in params->ramrod_flags for asynchronous commands).
4178 int bnx2x_queue_state_change(struct bnx2x *bp,
4179 struct bnx2x_queue_state_params *params)
4181 struct bnx2x_queue_sp_obj *o = params->q_obj;
4182 int rc, pending_bit;
4183 unsigned long *pending = &o->pending;
4185 /* Check that the requested transition is legal */
4186 if (o->check_transition(bp, o, params))
4189 /* Set "pending" bit */
4190 pending_bit = o->set_pending(o, params);
4192 /* Don't send a command if only driver cleanup was requested */
4193 if (test_bit(RAMROD_DRV_CLR_ONLY, ¶ms->ramrod_flags))
4194 o->complete_cmd(bp, o, pending_bit);
4197 rc = o->send_cmd(bp, params);
4199 o->next_state = BNX2X_Q_STATE_MAX;
4200 clear_bit(pending_bit, pending);
4201 smp_mb__after_clear_bit();
4205 if (test_bit(RAMROD_COMP_WAIT, ¶ms->ramrod_flags)) {
4206 rc = o->wait_comp(bp, o, pending_bit);
4214 return !!test_bit(pending_bit, pending);
4218 static int bnx2x_queue_set_pending(struct bnx2x_queue_sp_obj *obj,
4219 struct bnx2x_queue_state_params *params)
4221 enum bnx2x_queue_cmd cmd = params->cmd, bit;
4223 /* ACTIVATE and DEACTIVATE commands are implemented on top of
4226 if ((cmd == BNX2X_Q_CMD_ACTIVATE) ||
4227 (cmd == BNX2X_Q_CMD_DEACTIVATE))
4228 bit = BNX2X_Q_CMD_UPDATE;
4232 set_bit(bit, &obj->pending);
4236 static int bnx2x_queue_wait_comp(struct bnx2x *bp,
4237 struct bnx2x_queue_sp_obj *o,
4238 enum bnx2x_queue_cmd cmd)
4240 return bnx2x_state_wait(bp, cmd, &o->pending);
4244 * bnx2x_queue_comp_cmd - complete the state change command.
4246 * @bp: device handle
4250 * Checks that the arrived completion is expected.
4252 static int bnx2x_queue_comp_cmd(struct bnx2x *bp,
4253 struct bnx2x_queue_sp_obj *o,
4254 enum bnx2x_queue_cmd cmd)
4256 unsigned long cur_pending = o->pending;
4258 if (!test_and_clear_bit(cmd, &cur_pending)) {
4259 BNX2X_ERR("Bad MC reply %d for queue %d in state %d "
4260 "pending 0x%lx, next_state %d\n", cmd,
4261 o->cids[BNX2X_PRIMARY_CID_INDEX],
4262 o->state, cur_pending, o->next_state);
4266 if (o->next_tx_only >= o->max_cos)
4267 /* >= becuase tx only must always be smaller than cos since the
4268 * primary connection suports COS 0
4270 BNX2X_ERR("illegal value for next tx_only: %d. max cos was %d",
4271 o->next_tx_only, o->max_cos);
4273 DP(BNX2X_MSG_SP, "Completing command %d for queue %d, "
4274 "setting state to %d\n", cmd,
4275 o->cids[BNX2X_PRIMARY_CID_INDEX], o->next_state);
4277 if (o->next_tx_only) /* print num tx-only if any exist */
4278 DP(BNX2X_MSG_SP, "primary cid %d: num tx-only cons %d\n",
4279 o->cids[BNX2X_PRIMARY_CID_INDEX], o->next_tx_only);
4281 o->state = o->next_state;
4282 o->num_tx_only = o->next_tx_only;
4283 o->next_state = BNX2X_Q_STATE_MAX;
4285 /* It's important that o->state and o->next_state are
4286 * updated before o->pending.
4290 clear_bit(cmd, &o->pending);
4291 smp_mb__after_clear_bit();
4296 static void bnx2x_q_fill_setup_data_e2(struct bnx2x *bp,
4297 struct bnx2x_queue_state_params *cmd_params,
4298 struct client_init_ramrod_data *data)
4300 struct bnx2x_queue_setup_params *params = &cmd_params->params.setup;
4304 /* IPv6 TPA supported for E2 and above only */
4305 data->rx.tpa_en |= test_bit(BNX2X_Q_FLG_TPA_IPV6, ¶ms->flags) *
4306 CLIENT_INIT_RX_DATA_TPA_EN_IPV6;
4309 static void bnx2x_q_fill_init_general_data(struct bnx2x *bp,
4310 struct bnx2x_queue_sp_obj *o,
4311 struct bnx2x_general_setup_params *params,
4312 struct client_init_general_data *gen_data,
4313 unsigned long *flags)
4315 gen_data->client_id = o->cl_id;
4317 if (test_bit(BNX2X_Q_FLG_STATS, flags)) {
4318 gen_data->statistics_counter_id =
4320 gen_data->statistics_en_flg = 1;
4321 gen_data->statistics_zero_flg =
4322 test_bit(BNX2X_Q_FLG_ZERO_STATS, flags);
4324 gen_data->statistics_counter_id =
4325 DISABLE_STATISTIC_COUNTER_ID_VALUE;
4327 gen_data->is_fcoe_flg = test_bit(BNX2X_Q_FLG_FCOE, flags);
4328 gen_data->activate_flg = test_bit(BNX2X_Q_FLG_ACTIVE, flags);
4329 gen_data->sp_client_id = params->spcl_id;
4330 gen_data->mtu = cpu_to_le16(params->mtu);
4331 gen_data->func_id = o->func_id;
4334 gen_data->cos = params->cos;
4336 gen_data->traffic_type =
4337 test_bit(BNX2X_Q_FLG_FCOE, flags) ?
4338 LLFC_TRAFFIC_TYPE_FCOE : LLFC_TRAFFIC_TYPE_NW;
4340 DP(BNX2X_MSG_SP, "flags: active %d, cos %d, stats en %d\n",
4341 gen_data->activate_flg, gen_data->cos, gen_data->statistics_en_flg);
4344 static void bnx2x_q_fill_init_tx_data(struct bnx2x_queue_sp_obj *o,
4345 struct bnx2x_txq_setup_params *params,
4346 struct client_init_tx_data *tx_data,
4347 unsigned long *flags)
4349 tx_data->enforce_security_flg =
4350 test_bit(BNX2X_Q_FLG_TX_SEC, flags);
4351 tx_data->default_vlan =
4352 cpu_to_le16(params->default_vlan);
4353 tx_data->default_vlan_flg =
4354 test_bit(BNX2X_Q_FLG_DEF_VLAN, flags);
4355 tx_data->tx_switching_flg =
4356 test_bit(BNX2X_Q_FLG_TX_SWITCH, flags);
4357 tx_data->anti_spoofing_flg =
4358 test_bit(BNX2X_Q_FLG_ANTI_SPOOF, flags);
4359 tx_data->tx_status_block_id = params->fw_sb_id;
4360 tx_data->tx_sb_index_number = params->sb_cq_index;
4361 tx_data->tss_leading_client_id = params->tss_leading_cl_id;
4363 tx_data->tx_bd_page_base.lo =
4364 cpu_to_le32(U64_LO(params->dscr_map));
4365 tx_data->tx_bd_page_base.hi =
4366 cpu_to_le32(U64_HI(params->dscr_map));
4368 /* Don't configure any Tx switching mode during queue SETUP */
4372 static void bnx2x_q_fill_init_pause_data(struct bnx2x_queue_sp_obj *o,
4373 struct rxq_pause_params *params,
4374 struct client_init_rx_data *rx_data)
4376 /* flow control data */
4377 rx_data->cqe_pause_thr_low = cpu_to_le16(params->rcq_th_lo);
4378 rx_data->cqe_pause_thr_high = cpu_to_le16(params->rcq_th_hi);
4379 rx_data->bd_pause_thr_low = cpu_to_le16(params->bd_th_lo);
4380 rx_data->bd_pause_thr_high = cpu_to_le16(params->bd_th_hi);
4381 rx_data->sge_pause_thr_low = cpu_to_le16(params->sge_th_lo);
4382 rx_data->sge_pause_thr_high = cpu_to_le16(params->sge_th_hi);
4383 rx_data->rx_cos_mask = cpu_to_le16(params->pri_map);
4386 static void bnx2x_q_fill_init_rx_data(struct bnx2x_queue_sp_obj *o,
4387 struct bnx2x_rxq_setup_params *params,
4388 struct client_init_rx_data *rx_data,
4389 unsigned long *flags)
4392 rx_data->tpa_en = test_bit(BNX2X_Q_FLG_TPA, flags) *
4393 CLIENT_INIT_RX_DATA_TPA_EN_IPV4;
4394 rx_data->vmqueue_mode_en_flg = 0;
4396 rx_data->cache_line_alignment_log_size =
4397 params->cache_line_log;
4398 rx_data->enable_dynamic_hc =
4399 test_bit(BNX2X_Q_FLG_DHC, flags);
4400 rx_data->max_sges_for_packet = params->max_sges_pkt;
4401 rx_data->client_qzone_id = params->cl_qzone_id;
4402 rx_data->max_agg_size = cpu_to_le16(params->tpa_agg_sz);
4404 /* Always start in DROP_ALL mode */
4405 rx_data->state = cpu_to_le16(CLIENT_INIT_RX_DATA_UCAST_DROP_ALL |
4406 CLIENT_INIT_RX_DATA_MCAST_DROP_ALL);
4408 /* We don't set drop flags */
4409 rx_data->drop_ip_cs_err_flg = 0;
4410 rx_data->drop_tcp_cs_err_flg = 0;
4411 rx_data->drop_ttl0_flg = 0;
4412 rx_data->drop_udp_cs_err_flg = 0;
4413 rx_data->inner_vlan_removal_enable_flg =
4414 test_bit(BNX2X_Q_FLG_VLAN, flags);
4415 rx_data->outer_vlan_removal_enable_flg =
4416 test_bit(BNX2X_Q_FLG_OV, flags);
4417 rx_data->status_block_id = params->fw_sb_id;
4418 rx_data->rx_sb_index_number = params->sb_cq_index;
4419 rx_data->max_tpa_queues = params->max_tpa_queues;
4420 rx_data->max_bytes_on_bd = cpu_to_le16(params->buf_sz);
4421 rx_data->sge_buff_size = cpu_to_le16(params->sge_buf_sz);
4422 rx_data->bd_page_base.lo =
4423 cpu_to_le32(U64_LO(params->dscr_map));
4424 rx_data->bd_page_base.hi =
4425 cpu_to_le32(U64_HI(params->dscr_map));
4426 rx_data->sge_page_base.lo =
4427 cpu_to_le32(U64_LO(params->sge_map));
4428 rx_data->sge_page_base.hi =
4429 cpu_to_le32(U64_HI(params->sge_map));
4430 rx_data->cqe_page_base.lo =
4431 cpu_to_le32(U64_LO(params->rcq_map));
4432 rx_data->cqe_page_base.hi =
4433 cpu_to_le32(U64_HI(params->rcq_map));
4434 rx_data->is_leading_rss = test_bit(BNX2X_Q_FLG_LEADING_RSS, flags);
4436 if (test_bit(BNX2X_Q_FLG_MCAST, flags)) {
4437 rx_data->approx_mcast_engine_id = o->func_id;
4438 rx_data->is_approx_mcast = 1;
4441 rx_data->rss_engine_id = params->rss_engine_id;
4443 /* silent vlan removal */
4444 rx_data->silent_vlan_removal_flg =
4445 test_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, flags);
4446 rx_data->silent_vlan_value =
4447 cpu_to_le16(params->silent_removal_value);
4448 rx_data->silent_vlan_mask =
4449 cpu_to_le16(params->silent_removal_mask);
4453 /* initialize the general, tx and rx parts of a queue object */
4454 static void bnx2x_q_fill_setup_data_cmn(struct bnx2x *bp,
4455 struct bnx2x_queue_state_params *cmd_params,
4456 struct client_init_ramrod_data *data)
4458 bnx2x_q_fill_init_general_data(bp, cmd_params->q_obj,
4459 &cmd_params->params.setup.gen_params,
4461 &cmd_params->params.setup.flags);
4463 bnx2x_q_fill_init_tx_data(cmd_params->q_obj,
4464 &cmd_params->params.setup.txq_params,
4466 &cmd_params->params.setup.flags);
4468 bnx2x_q_fill_init_rx_data(cmd_params->q_obj,
4469 &cmd_params->params.setup.rxq_params,
4471 &cmd_params->params.setup.flags);
4473 bnx2x_q_fill_init_pause_data(cmd_params->q_obj,
4474 &cmd_params->params.setup.pause_params,
4478 /* initialize the general and tx parts of a tx-only queue object */
4479 static void bnx2x_q_fill_setup_tx_only(struct bnx2x *bp,
4480 struct bnx2x_queue_state_params *cmd_params,
4481 struct tx_queue_init_ramrod_data *data)
4483 bnx2x_q_fill_init_general_data(bp, cmd_params->q_obj,
4484 &cmd_params->params.tx_only.gen_params,
4486 &cmd_params->params.tx_only.flags);
4488 bnx2x_q_fill_init_tx_data(cmd_params->q_obj,
4489 &cmd_params->params.tx_only.txq_params,
4491 &cmd_params->params.tx_only.flags);
4493 DP(BNX2X_MSG_SP, "cid %d, tx bd page lo %x hi %x\n",cmd_params->q_obj->cids[0],
4494 data->tx.tx_bd_page_base.lo, data->tx.tx_bd_page_base.hi);
4498 * bnx2x_q_init - init HW/FW queue
4500 * @bp: device handle
4503 * HW/FW initial Queue configuration:
4505 * - CDU context validation
4508 static inline int bnx2x_q_init(struct bnx2x *bp,
4509 struct bnx2x_queue_state_params *params)
4511 struct bnx2x_queue_sp_obj *o = params->q_obj;
4512 struct bnx2x_queue_init_params *init = ¶ms->params.init;
4516 /* Tx HC configuration */
4517 if (test_bit(BNX2X_Q_TYPE_HAS_TX, &o->type) &&
4518 test_bit(BNX2X_Q_FLG_HC, &init->tx.flags)) {
4519 hc_usec = init->tx.hc_rate ? 1000000 / init->tx.hc_rate : 0;
4521 bnx2x_update_coalesce_sb_index(bp, init->tx.fw_sb_id,
4522 init->tx.sb_cq_index,
4523 !test_bit(BNX2X_Q_FLG_HC_EN, &init->tx.flags),
4527 /* Rx HC configuration */
4528 if (test_bit(BNX2X_Q_TYPE_HAS_RX, &o->type) &&
4529 test_bit(BNX2X_Q_FLG_HC, &init->rx.flags)) {
4530 hc_usec = init->rx.hc_rate ? 1000000 / init->rx.hc_rate : 0;
4532 bnx2x_update_coalesce_sb_index(bp, init->rx.fw_sb_id,
4533 init->rx.sb_cq_index,
4534 !test_bit(BNX2X_Q_FLG_HC_EN, &init->rx.flags),
4538 /* Set CDU context validation values */
4539 for (cos = 0; cos < o->max_cos; cos++) {
4540 DP(BNX2X_MSG_SP, "setting context validation. cid %d, cos %d\n",
4542 DP(BNX2X_MSG_SP, "context pointer %p\n", init->cxts[cos]);
4543 bnx2x_set_ctx_validation(bp, init->cxts[cos], o->cids[cos]);
4546 /* As no ramrod is sent, complete the command immediately */
4547 o->complete_cmd(bp, o, BNX2X_Q_CMD_INIT);
4555 static inline int bnx2x_q_send_setup_e1x(struct bnx2x *bp,
4556 struct bnx2x_queue_state_params *params)
4558 struct bnx2x_queue_sp_obj *o = params->q_obj;
4559 struct client_init_ramrod_data *rdata =
4560 (struct client_init_ramrod_data *)o->rdata;
4561 dma_addr_t data_mapping = o->rdata_mapping;
4562 int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP;
4564 /* Clear the ramrod data */
4565 memset(rdata, 0, sizeof(*rdata));
4567 /* Fill the ramrod data */
4568 bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
4571 * No need for an explicit memory barrier here as long we would
4572 * need to ensure the ordering of writing to the SPQ element
4573 * and updating of the SPQ producer which involves a memory
4574 * read and we will have to put a full memory barrier there
4575 * (inside bnx2x_sp_post()).
4578 return bnx2x_sp_post(bp, ramrod, o->cids[BNX2X_PRIMARY_CID_INDEX],
4579 U64_HI(data_mapping),
4580 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4583 static inline int bnx2x_q_send_setup_e2(struct bnx2x *bp,
4584 struct bnx2x_queue_state_params *params)
4586 struct bnx2x_queue_sp_obj *o = params->q_obj;
4587 struct client_init_ramrod_data *rdata =
4588 (struct client_init_ramrod_data *)o->rdata;
4589 dma_addr_t data_mapping = o->rdata_mapping;
4590 int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP;
4592 /* Clear the ramrod data */
4593 memset(rdata, 0, sizeof(*rdata));
4595 /* Fill the ramrod data */
4596 bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
4597 bnx2x_q_fill_setup_data_e2(bp, params, rdata);
4600 * No need for an explicit memory barrier here as long we would
4601 * need to ensure the ordering of writing to the SPQ element
4602 * and updating of the SPQ producer which involves a memory
4603 * read and we will have to put a full memory barrier there
4604 * (inside bnx2x_sp_post()).
4607 return bnx2x_sp_post(bp, ramrod, o->cids[BNX2X_PRIMARY_CID_INDEX],
4608 U64_HI(data_mapping),
4609 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4612 static inline int bnx2x_q_send_setup_tx_only(struct bnx2x *bp,
4613 struct bnx2x_queue_state_params *params)
4615 struct bnx2x_queue_sp_obj *o = params->q_obj;
4616 struct tx_queue_init_ramrod_data *rdata =
4617 (struct tx_queue_init_ramrod_data *)o->rdata;
4618 dma_addr_t data_mapping = o->rdata_mapping;
4619 int ramrod = RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP;
4620 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
4621 ¶ms->params.tx_only;
4622 u8 cid_index = tx_only_params->cid_index;
4625 if (cid_index >= o->max_cos) {
4626 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4627 o->cl_id, cid_index);
4631 DP(BNX2X_MSG_SP, "parameters received: cos: %d sp-id: %d\n",
4632 tx_only_params->gen_params.cos,
4633 tx_only_params->gen_params.spcl_id);
4635 /* Clear the ramrod data */
4636 memset(rdata, 0, sizeof(*rdata));
4638 /* Fill the ramrod data */
4639 bnx2x_q_fill_setup_tx_only(bp, params, rdata);
4641 DP(BNX2X_MSG_SP, "sending tx-only ramrod: cid %d, client-id %d,"
4642 "sp-client id %d, cos %d\n",
4644 rdata->general.client_id,
4645 rdata->general.sp_client_id, rdata->general.cos);
4648 * No need for an explicit memory barrier here as long we would
4649 * need to ensure the ordering of writing to the SPQ element
4650 * and updating of the SPQ producer which involves a memory
4651 * read and we will have to put a full memory barrier there
4652 * (inside bnx2x_sp_post()).
4655 return bnx2x_sp_post(bp, ramrod, o->cids[cid_index],
4656 U64_HI(data_mapping),
4657 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4660 static void bnx2x_q_fill_update_data(struct bnx2x *bp,
4661 struct bnx2x_queue_sp_obj *obj,
4662 struct bnx2x_queue_update_params *params,
4663 struct client_update_ramrod_data *data)
4665 /* Client ID of the client to update */
4666 data->client_id = obj->cl_id;
4668 /* Function ID of the client to update */
4669 data->func_id = obj->func_id;
4671 /* Default VLAN value */
4672 data->default_vlan = cpu_to_le16(params->def_vlan);
4674 /* Inner VLAN stripping */
4675 data->inner_vlan_removal_enable_flg =
4676 test_bit(BNX2X_Q_UPDATE_IN_VLAN_REM, ¶ms->update_flags);
4677 data->inner_vlan_removal_change_flg =
4678 test_bit(BNX2X_Q_UPDATE_IN_VLAN_REM_CHNG,
4679 ¶ms->update_flags);
4681 /* Outer VLAN sripping */
4682 data->outer_vlan_removal_enable_flg =
4683 test_bit(BNX2X_Q_UPDATE_OUT_VLAN_REM, ¶ms->update_flags);
4684 data->outer_vlan_removal_change_flg =
4685 test_bit(BNX2X_Q_UPDATE_OUT_VLAN_REM_CHNG,
4686 ¶ms->update_flags);
4688 /* Drop packets that have source MAC that doesn't belong to this
4691 data->anti_spoofing_enable_flg =
4692 test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF, ¶ms->update_flags);
4693 data->anti_spoofing_change_flg =
4694 test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF_CHNG, ¶ms->update_flags);
4696 /* Activate/Deactivate */
4697 data->activate_flg =
4698 test_bit(BNX2X_Q_UPDATE_ACTIVATE, ¶ms->update_flags);
4699 data->activate_change_flg =
4700 test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, ¶ms->update_flags);
4702 /* Enable default VLAN */
4703 data->default_vlan_enable_flg =
4704 test_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN, ¶ms->update_flags);
4705 data->default_vlan_change_flg =
4706 test_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN_CHNG,
4707 ¶ms->update_flags);
4709 /* silent vlan removal */
4710 data->silent_vlan_change_flg =
4711 test_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
4712 ¶ms->update_flags);
4713 data->silent_vlan_removal_flg =
4714 test_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM, ¶ms->update_flags);
4715 data->silent_vlan_value = cpu_to_le16(params->silent_removal_value);
4716 data->silent_vlan_mask = cpu_to_le16(params->silent_removal_mask);
4719 static inline int bnx2x_q_send_update(struct bnx2x *bp,
4720 struct bnx2x_queue_state_params *params)
4722 struct bnx2x_queue_sp_obj *o = params->q_obj;
4723 struct client_update_ramrod_data *rdata =
4724 (struct client_update_ramrod_data *)o->rdata;
4725 dma_addr_t data_mapping = o->rdata_mapping;
4726 struct bnx2x_queue_update_params *update_params =
4727 ¶ms->params.update;
4728 u8 cid_index = update_params->cid_index;
4730 if (cid_index >= o->max_cos) {
4731 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4732 o->cl_id, cid_index);
4737 /* Clear the ramrod data */
4738 memset(rdata, 0, sizeof(*rdata));
4740 /* Fill the ramrod data */
4741 bnx2x_q_fill_update_data(bp, o, update_params, rdata);
4744 * No need for an explicit memory barrier here as long we would
4745 * need to ensure the ordering of writing to the SPQ element
4746 * and updating of the SPQ producer which involves a memory
4747 * read and we will have to put a full memory barrier there
4748 * (inside bnx2x_sp_post()).
4751 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_UPDATE,
4752 o->cids[cid_index], U64_HI(data_mapping),
4753 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4757 * bnx2x_q_send_deactivate - send DEACTIVATE command
4759 * @bp: device handle
4762 * implemented using the UPDATE command.
4764 static inline int bnx2x_q_send_deactivate(struct bnx2x *bp,
4765 struct bnx2x_queue_state_params *params)
4767 struct bnx2x_queue_update_params *update = ¶ms->params.update;
4769 memset(update, 0, sizeof(*update));
4771 __set_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &update->update_flags);
4773 return bnx2x_q_send_update(bp, params);
4777 * bnx2x_q_send_activate - send ACTIVATE command
4779 * @bp: device handle
4782 * implemented using the UPDATE command.
4784 static inline int bnx2x_q_send_activate(struct bnx2x *bp,
4785 struct bnx2x_queue_state_params *params)
4787 struct bnx2x_queue_update_params *update = ¶ms->params.update;
4789 memset(update, 0, sizeof(*update));
4791 __set_bit(BNX2X_Q_UPDATE_ACTIVATE, &update->update_flags);
4792 __set_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &update->update_flags);
4794 return bnx2x_q_send_update(bp, params);
4797 static inline int bnx2x_q_send_update_tpa(struct bnx2x *bp,
4798 struct bnx2x_queue_state_params *params)
4800 /* TODO: Not implemented yet. */
4804 static inline int bnx2x_q_send_halt(struct bnx2x *bp,
4805 struct bnx2x_queue_state_params *params)
4807 struct bnx2x_queue_sp_obj *o = params->q_obj;
4809 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT,
4810 o->cids[BNX2X_PRIMARY_CID_INDEX], 0, o->cl_id,
4811 ETH_CONNECTION_TYPE);
4814 static inline int bnx2x_q_send_cfc_del(struct bnx2x *bp,
4815 struct bnx2x_queue_state_params *params)
4817 struct bnx2x_queue_sp_obj *o = params->q_obj;
4818 u8 cid_idx = params->params.cfc_del.cid_index;
4820 if (cid_idx >= o->max_cos) {
4821 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4826 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_CFC_DEL,
4827 o->cids[cid_idx], 0, 0, NONE_CONNECTION_TYPE);
4830 static inline int bnx2x_q_send_terminate(struct bnx2x *bp,
4831 struct bnx2x_queue_state_params *params)
4833 struct bnx2x_queue_sp_obj *o = params->q_obj;
4834 u8 cid_index = params->params.terminate.cid_index;
4836 if (cid_index >= o->max_cos) {
4837 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4838 o->cl_id, cid_index);
4842 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_TERMINATE,
4843 o->cids[cid_index], 0, 0, ETH_CONNECTION_TYPE);
4846 static inline int bnx2x_q_send_empty(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_EMPTY,
4852 o->cids[BNX2X_PRIMARY_CID_INDEX], 0, 0,
4853 ETH_CONNECTION_TYPE);
4856 static inline int bnx2x_queue_send_cmd_cmn(struct bnx2x *bp,
4857 struct bnx2x_queue_state_params *params)
4859 switch (params->cmd) {
4860 case BNX2X_Q_CMD_INIT:
4861 return bnx2x_q_init(bp, params);
4862 case BNX2X_Q_CMD_SETUP_TX_ONLY:
4863 return bnx2x_q_send_setup_tx_only(bp, params);
4864 case BNX2X_Q_CMD_DEACTIVATE:
4865 return bnx2x_q_send_deactivate(bp, params);
4866 case BNX2X_Q_CMD_ACTIVATE:
4867 return bnx2x_q_send_activate(bp, params);
4868 case BNX2X_Q_CMD_UPDATE:
4869 return bnx2x_q_send_update(bp, params);
4870 case BNX2X_Q_CMD_UPDATE_TPA:
4871 return bnx2x_q_send_update_tpa(bp, params);
4872 case BNX2X_Q_CMD_HALT:
4873 return bnx2x_q_send_halt(bp, params);
4874 case BNX2X_Q_CMD_CFC_DEL:
4875 return bnx2x_q_send_cfc_del(bp, params);
4876 case BNX2X_Q_CMD_TERMINATE:
4877 return bnx2x_q_send_terminate(bp, params);
4878 case BNX2X_Q_CMD_EMPTY:
4879 return bnx2x_q_send_empty(bp, params);
4881 BNX2X_ERR("Unknown command: %d\n", params->cmd);
4886 static int bnx2x_queue_send_cmd_e1x(struct bnx2x *bp,
4887 struct bnx2x_queue_state_params *params)
4889 switch (params->cmd) {
4890 case BNX2X_Q_CMD_SETUP:
4891 return bnx2x_q_send_setup_e1x(bp, params);
4892 case BNX2X_Q_CMD_INIT:
4893 case BNX2X_Q_CMD_SETUP_TX_ONLY:
4894 case BNX2X_Q_CMD_DEACTIVATE:
4895 case BNX2X_Q_CMD_ACTIVATE:
4896 case BNX2X_Q_CMD_UPDATE:
4897 case BNX2X_Q_CMD_UPDATE_TPA:
4898 case BNX2X_Q_CMD_HALT:
4899 case BNX2X_Q_CMD_CFC_DEL:
4900 case BNX2X_Q_CMD_TERMINATE:
4901 case BNX2X_Q_CMD_EMPTY:
4902 return bnx2x_queue_send_cmd_cmn(bp, params);
4904 BNX2X_ERR("Unknown command: %d\n", params->cmd);
4909 static int bnx2x_queue_send_cmd_e2(struct bnx2x *bp,
4910 struct bnx2x_queue_state_params *params)
4912 switch (params->cmd) {
4913 case BNX2X_Q_CMD_SETUP:
4914 return bnx2x_q_send_setup_e2(bp, params);
4915 case BNX2X_Q_CMD_INIT:
4916 case BNX2X_Q_CMD_SETUP_TX_ONLY:
4917 case BNX2X_Q_CMD_DEACTIVATE:
4918 case BNX2X_Q_CMD_ACTIVATE:
4919 case BNX2X_Q_CMD_UPDATE:
4920 case BNX2X_Q_CMD_UPDATE_TPA:
4921 case BNX2X_Q_CMD_HALT:
4922 case BNX2X_Q_CMD_CFC_DEL:
4923 case BNX2X_Q_CMD_TERMINATE:
4924 case BNX2X_Q_CMD_EMPTY:
4925 return bnx2x_queue_send_cmd_cmn(bp, params);
4927 BNX2X_ERR("Unknown command: %d\n", params->cmd);
4933 * bnx2x_queue_chk_transition - check state machine of a regular Queue
4935 * @bp: device handle
4940 * It both checks if the requested command is legal in a current
4941 * state and, if it's legal, sets a `next_state' in the object
4942 * that will be used in the completion flow to set the `state'
4945 * returns 0 if a requested command is a legal transition,
4946 * -EINVAL otherwise.
4948 static int bnx2x_queue_chk_transition(struct bnx2x *bp,
4949 struct bnx2x_queue_sp_obj *o,
4950 struct bnx2x_queue_state_params *params)
4952 enum bnx2x_q_state state = o->state, next_state = BNX2X_Q_STATE_MAX;
4953 enum bnx2x_queue_cmd cmd = params->cmd;
4954 struct bnx2x_queue_update_params *update_params =
4955 ¶ms->params.update;
4956 u8 next_tx_only = o->num_tx_only;
4959 * Forget all pending for completion commands if a driver only state
4960 * transition has been requested.
4962 if (test_bit(RAMROD_DRV_CLR_ONLY, ¶ms->ramrod_flags)) {
4964 o->next_state = BNX2X_Q_STATE_MAX;
4968 * Don't allow a next state transition if we are in the middle of
4975 case BNX2X_Q_STATE_RESET:
4976 if (cmd == BNX2X_Q_CMD_INIT)
4977 next_state = BNX2X_Q_STATE_INITIALIZED;
4980 case BNX2X_Q_STATE_INITIALIZED:
4981 if (cmd == BNX2X_Q_CMD_SETUP) {
4982 if (test_bit(BNX2X_Q_FLG_ACTIVE,
4983 ¶ms->params.setup.flags))
4984 next_state = BNX2X_Q_STATE_ACTIVE;
4986 next_state = BNX2X_Q_STATE_INACTIVE;
4990 case BNX2X_Q_STATE_ACTIVE:
4991 if (cmd == BNX2X_Q_CMD_DEACTIVATE)
4992 next_state = BNX2X_Q_STATE_INACTIVE;
4994 else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
4995 (cmd == BNX2X_Q_CMD_UPDATE_TPA))
4996 next_state = BNX2X_Q_STATE_ACTIVE;
4998 else if (cmd == BNX2X_Q_CMD_SETUP_TX_ONLY) {
4999 next_state = BNX2X_Q_STATE_MULTI_COS;
5003 else if (cmd == BNX2X_Q_CMD_HALT)
5004 next_state = BNX2X_Q_STATE_STOPPED;
5006 else if (cmd == BNX2X_Q_CMD_UPDATE) {
5007 /* If "active" state change is requested, update the
5008 * state accordingly.
5010 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
5011 &update_params->update_flags) &&
5012 !test_bit(BNX2X_Q_UPDATE_ACTIVATE,
5013 &update_params->update_flags))
5014 next_state = BNX2X_Q_STATE_INACTIVE;
5016 next_state = BNX2X_Q_STATE_ACTIVE;
5020 case BNX2X_Q_STATE_MULTI_COS:
5021 if (cmd == BNX2X_Q_CMD_TERMINATE)
5022 next_state = BNX2X_Q_STATE_MCOS_TERMINATED;
5024 else if (cmd == BNX2X_Q_CMD_SETUP_TX_ONLY) {
5025 next_state = BNX2X_Q_STATE_MULTI_COS;
5026 next_tx_only = o->num_tx_only + 1;
5029 else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
5030 (cmd == BNX2X_Q_CMD_UPDATE_TPA))
5031 next_state = BNX2X_Q_STATE_MULTI_COS;
5033 else if (cmd == BNX2X_Q_CMD_UPDATE) {
5034 /* If "active" state change is requested, update the
5035 * state accordingly.
5037 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
5038 &update_params->update_flags) &&
5039 !test_bit(BNX2X_Q_UPDATE_ACTIVATE,
5040 &update_params->update_flags))
5041 next_state = BNX2X_Q_STATE_INACTIVE;
5043 next_state = BNX2X_Q_STATE_MULTI_COS;
5047 case BNX2X_Q_STATE_MCOS_TERMINATED:
5048 if (cmd == BNX2X_Q_CMD_CFC_DEL) {
5049 next_tx_only = o->num_tx_only - 1;
5050 if (next_tx_only == 0)
5051 next_state = BNX2X_Q_STATE_ACTIVE;
5053 next_state = BNX2X_Q_STATE_MULTI_COS;
5057 case BNX2X_Q_STATE_INACTIVE:
5058 if (cmd == BNX2X_Q_CMD_ACTIVATE)
5059 next_state = BNX2X_Q_STATE_ACTIVE;
5061 else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
5062 (cmd == BNX2X_Q_CMD_UPDATE_TPA))
5063 next_state = BNX2X_Q_STATE_INACTIVE;
5065 else if (cmd == BNX2X_Q_CMD_HALT)
5066 next_state = BNX2X_Q_STATE_STOPPED;
5068 else if (cmd == BNX2X_Q_CMD_UPDATE) {
5069 /* If "active" state change is requested, update the
5070 * state accordingly.
5072 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
5073 &update_params->update_flags) &&
5074 test_bit(BNX2X_Q_UPDATE_ACTIVATE,
5075 &update_params->update_flags)){
5076 if (o->num_tx_only == 0)
5077 next_state = BNX2X_Q_STATE_ACTIVE;
5078 else /* tx only queues exist for this queue */
5079 next_state = BNX2X_Q_STATE_MULTI_COS;
5081 next_state = BNX2X_Q_STATE_INACTIVE;
5085 case BNX2X_Q_STATE_STOPPED:
5086 if (cmd == BNX2X_Q_CMD_TERMINATE)
5087 next_state = BNX2X_Q_STATE_TERMINATED;
5090 case BNX2X_Q_STATE_TERMINATED:
5091 if (cmd == BNX2X_Q_CMD_CFC_DEL)
5092 next_state = BNX2X_Q_STATE_RESET;
5096 BNX2X_ERR("Illegal state: %d\n", state);
5099 /* Transition is assured */
5100 if (next_state != BNX2X_Q_STATE_MAX) {
5101 DP(BNX2X_MSG_SP, "Good state transition: %d(%d)->%d\n",
5102 state, cmd, next_state);
5103 o->next_state = next_state;
5104 o->next_tx_only = next_tx_only;
5108 DP(BNX2X_MSG_SP, "Bad state transition request: %d %d\n", state, cmd);
5113 void bnx2x_init_queue_obj(struct bnx2x *bp,
5114 struct bnx2x_queue_sp_obj *obj,
5115 u8 cl_id, u32 *cids, u8 cid_cnt, u8 func_id,
5117 dma_addr_t rdata_mapping, unsigned long type)
5119 memset(obj, 0, sizeof(*obj));
5121 /* We support only BNX2X_MULTI_TX_COS Tx CoS at the moment */
5122 BUG_ON(BNX2X_MULTI_TX_COS < cid_cnt);
5124 memcpy(obj->cids, cids, sizeof(obj->cids[0]) * cid_cnt);
5125 obj->max_cos = cid_cnt;
5127 obj->func_id = func_id;
5129 obj->rdata_mapping = rdata_mapping;
5131 obj->next_state = BNX2X_Q_STATE_MAX;
5133 if (CHIP_IS_E1x(bp))
5134 obj->send_cmd = bnx2x_queue_send_cmd_e1x;
5136 obj->send_cmd = bnx2x_queue_send_cmd_e2;
5138 obj->check_transition = bnx2x_queue_chk_transition;
5140 obj->complete_cmd = bnx2x_queue_comp_cmd;
5141 obj->wait_comp = bnx2x_queue_wait_comp;
5142 obj->set_pending = bnx2x_queue_set_pending;
5145 void bnx2x_queue_set_cos_cid(struct bnx2x *bp,
5146 struct bnx2x_queue_sp_obj *obj,
5149 obj->cids[index] = cid;
5152 /********************** Function state object *********************************/
5153 enum bnx2x_func_state bnx2x_func_get_state(struct bnx2x *bp,
5154 struct bnx2x_func_sp_obj *o)
5156 /* in the middle of transaction - return INVALID state */
5158 return BNX2X_F_STATE_MAX;
5161 * unsure the order of reading of o->pending and o->state
5162 * o->pending should be read first
5169 static int bnx2x_func_wait_comp(struct bnx2x *bp,
5170 struct bnx2x_func_sp_obj *o,
5171 enum bnx2x_func_cmd cmd)
5173 return bnx2x_state_wait(bp, cmd, &o->pending);
5177 * bnx2x_func_state_change_comp - complete the state machine transition
5179 * @bp: device handle
5183 * Called on state change transition. Completes the state
5184 * machine transition only - no HW interaction.
5186 static inline int bnx2x_func_state_change_comp(struct bnx2x *bp,
5187 struct bnx2x_func_sp_obj *o,
5188 enum bnx2x_func_cmd cmd)
5190 unsigned long cur_pending = o->pending;
5192 if (!test_and_clear_bit(cmd, &cur_pending)) {
5193 BNX2X_ERR("Bad MC reply %d for func %d in state %d "
5194 "pending 0x%lx, next_state %d\n", cmd, BP_FUNC(bp),
5195 o->state, cur_pending, o->next_state);
5200 "Completing command %d for func %d, setting state to %d\n",
5201 cmd, BP_FUNC(bp), o->next_state);
5203 o->state = o->next_state;
5204 o->next_state = BNX2X_F_STATE_MAX;
5206 /* It's important that o->state and o->next_state are
5207 * updated before o->pending.
5211 clear_bit(cmd, &o->pending);
5212 smp_mb__after_clear_bit();
5218 * bnx2x_func_comp_cmd - complete the state change command
5220 * @bp: device handle
5224 * Checks that the arrived completion is expected.
5226 static int bnx2x_func_comp_cmd(struct bnx2x *bp,
5227 struct bnx2x_func_sp_obj *o,
5228 enum bnx2x_func_cmd cmd)
5230 /* Complete the state machine part first, check if it's a
5233 int rc = bnx2x_func_state_change_comp(bp, o, cmd);
5238 * bnx2x_func_chk_transition - perform function state machine transition
5240 * @bp: device handle
5244 * It both checks if the requested command is legal in a current
5245 * state and, if it's legal, sets a `next_state' in the object
5246 * that will be used in the completion flow to set the `state'
5249 * returns 0 if a requested command is a legal transition,
5250 * -EINVAL otherwise.
5252 static int bnx2x_func_chk_transition(struct bnx2x *bp,
5253 struct bnx2x_func_sp_obj *o,
5254 struct bnx2x_func_state_params *params)
5256 enum bnx2x_func_state state = o->state, next_state = BNX2X_F_STATE_MAX;
5257 enum bnx2x_func_cmd cmd = params->cmd;
5260 * Forget all pending for completion commands if a driver only state
5261 * transition has been requested.
5263 if (test_bit(RAMROD_DRV_CLR_ONLY, ¶ms->ramrod_flags)) {
5265 o->next_state = BNX2X_F_STATE_MAX;
5269 * Don't allow a next state transition if we are in the middle of
5276 case BNX2X_F_STATE_RESET:
5277 if (cmd == BNX2X_F_CMD_HW_INIT)
5278 next_state = BNX2X_F_STATE_INITIALIZED;
5281 case BNX2X_F_STATE_INITIALIZED:
5282 if (cmd == BNX2X_F_CMD_START)
5283 next_state = BNX2X_F_STATE_STARTED;
5285 else if (cmd == BNX2X_F_CMD_HW_RESET)
5286 next_state = BNX2X_F_STATE_RESET;
5289 case BNX2X_F_STATE_STARTED:
5290 if (cmd == BNX2X_F_CMD_STOP)
5291 next_state = BNX2X_F_STATE_INITIALIZED;
5292 else if (cmd == BNX2X_F_CMD_TX_STOP)
5293 next_state = BNX2X_F_STATE_TX_STOPPED;
5296 case BNX2X_F_STATE_TX_STOPPED:
5297 if (cmd == BNX2X_F_CMD_TX_START)
5298 next_state = BNX2X_F_STATE_STARTED;
5302 BNX2X_ERR("Unknown state: %d\n", state);
5305 /* Transition is assured */
5306 if (next_state != BNX2X_F_STATE_MAX) {
5307 DP(BNX2X_MSG_SP, "Good function state transition: %d(%d)->%d\n",
5308 state, cmd, next_state);
5309 o->next_state = next_state;
5313 DP(BNX2X_MSG_SP, "Bad function state transition request: %d %d\n",
5320 * bnx2x_func_init_func - performs HW init at function stage
5322 * @bp: device handle
5325 * Init HW when the current phase is
5326 * FW_MSG_CODE_DRV_LOAD_FUNCTION: initialize only FUNCTION-only
5329 static inline int bnx2x_func_init_func(struct bnx2x *bp,
5330 const struct bnx2x_func_sp_drv_ops *drv)
5332 return drv->init_hw_func(bp);
5336 * bnx2x_func_init_port - performs HW init at port stage
5338 * @bp: device handle
5341 * Init HW when the current phase is
5342 * FW_MSG_CODE_DRV_LOAD_PORT: initialize PORT-only and
5343 * FUNCTION-only HW blocks.
5346 static inline int bnx2x_func_init_port(struct bnx2x *bp,
5347 const struct bnx2x_func_sp_drv_ops *drv)
5349 int rc = drv->init_hw_port(bp);
5353 return bnx2x_func_init_func(bp, drv);
5357 * bnx2x_func_init_cmn_chip - performs HW init at chip-common stage
5359 * @bp: device handle
5362 * Init HW when the current phase is
5363 * FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: initialize COMMON_CHIP,
5364 * PORT-only and FUNCTION-only HW blocks.
5366 static inline int bnx2x_func_init_cmn_chip(struct bnx2x *bp,
5367 const struct bnx2x_func_sp_drv_ops *drv)
5369 int rc = drv->init_hw_cmn_chip(bp);
5373 return bnx2x_func_init_port(bp, drv);
5377 * bnx2x_func_init_cmn - performs HW init at common stage
5379 * @bp: device handle
5382 * Init HW when the current phase is
5383 * FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: initialize COMMON,
5384 * PORT-only and FUNCTION-only HW blocks.
5386 static inline int bnx2x_func_init_cmn(struct bnx2x *bp,
5387 const struct bnx2x_func_sp_drv_ops *drv)
5389 int rc = drv->init_hw_cmn(bp);
5393 return bnx2x_func_init_port(bp, drv);
5396 static int bnx2x_func_hw_init(struct bnx2x *bp,
5397 struct bnx2x_func_state_params *params)
5399 u32 load_code = params->params.hw_init.load_phase;
5400 struct bnx2x_func_sp_obj *o = params->f_obj;
5401 const struct bnx2x_func_sp_drv_ops *drv = o->drv;
5404 DP(BNX2X_MSG_SP, "function %d load_code %x\n",
5405 BP_ABS_FUNC(bp), load_code);
5407 /* Prepare buffers for unzipping the FW */
5408 rc = drv->gunzip_init(bp);
5413 rc = drv->init_fw(bp);
5415 BNX2X_ERR("Error loading firmware\n");
5419 /* Handle the beginning of COMMON_XXX pases separatelly... */
5420 switch (load_code) {
5421 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
5422 rc = bnx2x_func_init_cmn_chip(bp, drv);
5427 case FW_MSG_CODE_DRV_LOAD_COMMON:
5428 rc = bnx2x_func_init_cmn(bp, drv);
5433 case FW_MSG_CODE_DRV_LOAD_PORT:
5434 rc = bnx2x_func_init_port(bp, drv);
5439 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
5440 rc = bnx2x_func_init_func(bp, drv);
5446 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5451 drv->gunzip_end(bp);
5453 /* In case of success, complete the comand immediatelly: no ramrods
5457 o->complete_cmd(bp, o, BNX2X_F_CMD_HW_INIT);
5463 * bnx2x_func_reset_func - reset HW at function stage
5465 * @bp: device handle
5468 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_FUNCTION stage: reset only
5469 * FUNCTION-only HW blocks.
5471 static inline void bnx2x_func_reset_func(struct bnx2x *bp,
5472 const struct bnx2x_func_sp_drv_ops *drv)
5474 drv->reset_hw_func(bp);
5478 * bnx2x_func_reset_port - reser HW at port stage
5480 * @bp: device handle
5483 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_PORT stage: reset
5484 * FUNCTION-only and PORT-only HW blocks.
5488 * It's important to call reset_port before reset_func() as the last thing
5489 * reset_func does is pf_disable() thus disabling PGLUE_B, which
5490 * makes impossible any DMAE transactions.
5492 static inline void bnx2x_func_reset_port(struct bnx2x *bp,
5493 const struct bnx2x_func_sp_drv_ops *drv)
5495 drv->reset_hw_port(bp);
5496 bnx2x_func_reset_func(bp, drv);
5500 * bnx2x_func_reset_cmn - reser HW at common stage
5502 * @bp: device handle
5505 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_COMMON and
5506 * FW_MSG_CODE_DRV_UNLOAD_COMMON_CHIP stages: reset COMMON,
5507 * COMMON_CHIP, FUNCTION-only and PORT-only HW blocks.
5509 static inline void bnx2x_func_reset_cmn(struct bnx2x *bp,
5510 const struct bnx2x_func_sp_drv_ops *drv)
5512 bnx2x_func_reset_port(bp, drv);
5513 drv->reset_hw_cmn(bp);
5517 static inline int bnx2x_func_hw_reset(struct bnx2x *bp,
5518 struct bnx2x_func_state_params *params)
5520 u32 reset_phase = params->params.hw_reset.reset_phase;
5521 struct bnx2x_func_sp_obj *o = params->f_obj;
5522 const struct bnx2x_func_sp_drv_ops *drv = o->drv;
5524 DP(BNX2X_MSG_SP, "function %d reset_phase %x\n", BP_ABS_FUNC(bp),
5527 switch (reset_phase) {
5528 case FW_MSG_CODE_DRV_UNLOAD_COMMON:
5529 bnx2x_func_reset_cmn(bp, drv);
5531 case FW_MSG_CODE_DRV_UNLOAD_PORT:
5532 bnx2x_func_reset_port(bp, drv);
5534 case FW_MSG_CODE_DRV_UNLOAD_FUNCTION:
5535 bnx2x_func_reset_func(bp, drv);
5538 BNX2X_ERR("Unknown reset_phase (0x%x) from MCP\n",
5543 /* Complete the comand immediatelly: no ramrods have been sent. */
5544 o->complete_cmd(bp, o, BNX2X_F_CMD_HW_RESET);
5549 static inline int bnx2x_func_send_start(struct bnx2x *bp,
5550 struct bnx2x_func_state_params *params)
5552 struct bnx2x_func_sp_obj *o = params->f_obj;
5553 struct function_start_data *rdata =
5554 (struct function_start_data *)o->rdata;
5555 dma_addr_t data_mapping = o->rdata_mapping;
5556 struct bnx2x_func_start_params *start_params = ¶ms->params.start;
5558 memset(rdata, 0, sizeof(*rdata));
5560 /* Fill the ramrod data with provided parameters */
5561 rdata->function_mode = cpu_to_le16(start_params->mf_mode);
5562 rdata->sd_vlan_tag = start_params->sd_vlan_tag;
5563 rdata->path_id = BP_PATH(bp);
5564 rdata->network_cos_mode = start_params->network_cos_mode;
5567 * No need for an explicit memory barrier here as long we would
5568 * need to ensure the ordering of writing to the SPQ element
5569 * and updating of the SPQ producer which involves a memory
5570 * read and we will have to put a full memory barrier there
5571 * (inside bnx2x_sp_post()).
5574 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_START, 0,
5575 U64_HI(data_mapping),
5576 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5579 static inline int bnx2x_func_send_stop(struct bnx2x *bp,
5580 struct bnx2x_func_state_params *params)
5582 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_STOP, 0, 0, 0,
5583 NONE_CONNECTION_TYPE);
5586 static inline int bnx2x_func_send_tx_stop(struct bnx2x *bp,
5587 struct bnx2x_func_state_params *params)
5589 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_STOP_TRAFFIC, 0, 0, 0,
5590 NONE_CONNECTION_TYPE);
5592 static inline int bnx2x_func_send_tx_start(struct bnx2x *bp,
5593 struct bnx2x_func_state_params *params)
5595 struct bnx2x_func_sp_obj *o = params->f_obj;
5596 struct flow_control_configuration *rdata =
5597 (struct flow_control_configuration *)o->rdata;
5598 dma_addr_t data_mapping = o->rdata_mapping;
5599 struct bnx2x_func_tx_start_params *tx_start_params =
5600 ¶ms->params.tx_start;
5603 memset(rdata, 0, sizeof(*rdata));
5605 rdata->dcb_enabled = tx_start_params->dcb_enabled;
5606 rdata->dcb_version = tx_start_params->dcb_version;
5607 rdata->dont_add_pri_0_en = tx_start_params->dont_add_pri_0_en;
5609 for (i = 0; i < ARRAY_SIZE(rdata->traffic_type_to_priority_cos); i++)
5610 rdata->traffic_type_to_priority_cos[i] =
5611 tx_start_params->traffic_type_to_priority_cos[i];
5613 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_START_TRAFFIC, 0,
5614 U64_HI(data_mapping),
5615 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5618 static int bnx2x_func_send_cmd(struct bnx2x *bp,
5619 struct bnx2x_func_state_params *params)
5621 switch (params->cmd) {
5622 case BNX2X_F_CMD_HW_INIT:
5623 return bnx2x_func_hw_init(bp, params);
5624 case BNX2X_F_CMD_START:
5625 return bnx2x_func_send_start(bp, params);
5626 case BNX2X_F_CMD_STOP:
5627 return bnx2x_func_send_stop(bp, params);
5628 case BNX2X_F_CMD_HW_RESET:
5629 return bnx2x_func_hw_reset(bp, params);
5630 case BNX2X_F_CMD_TX_STOP:
5631 return bnx2x_func_send_tx_stop(bp, params);
5632 case BNX2X_F_CMD_TX_START:
5633 return bnx2x_func_send_tx_start(bp, params);
5635 BNX2X_ERR("Unknown command: %d\n", params->cmd);
5640 void bnx2x_init_func_obj(struct bnx2x *bp,
5641 struct bnx2x_func_sp_obj *obj,
5642 void *rdata, dma_addr_t rdata_mapping,
5643 struct bnx2x_func_sp_drv_ops *drv_iface)
5645 memset(obj, 0, sizeof(*obj));
5647 mutex_init(&obj->one_pending_mutex);
5650 obj->rdata_mapping = rdata_mapping;
5652 obj->send_cmd = bnx2x_func_send_cmd;
5653 obj->check_transition = bnx2x_func_chk_transition;
5654 obj->complete_cmd = bnx2x_func_comp_cmd;
5655 obj->wait_comp = bnx2x_func_wait_comp;
5657 obj->drv = drv_iface;
5661 * bnx2x_func_state_change - perform Function state change transition
5663 * @bp: device handle
5664 * @params: parameters to perform the transaction
5666 * returns 0 in case of successfully completed transition,
5667 * negative error code in case of failure, positive
5668 * (EBUSY) value if there is a completion to that is
5669 * still pending (possible only if RAMROD_COMP_WAIT is
5670 * not set in params->ramrod_flags for asynchronous
5673 int bnx2x_func_state_change(struct bnx2x *bp,
5674 struct bnx2x_func_state_params *params)
5676 struct bnx2x_func_sp_obj *o = params->f_obj;
5678 enum bnx2x_func_cmd cmd = params->cmd;
5679 unsigned long *pending = &o->pending;
5681 mutex_lock(&o->one_pending_mutex);
5683 /* Check that the requested transition is legal */
5684 if (o->check_transition(bp, o, params)) {
5685 mutex_unlock(&o->one_pending_mutex);
5689 /* Set "pending" bit */
5690 set_bit(cmd, pending);
5692 /* Don't send a command if only driver cleanup was requested */
5693 if (test_bit(RAMROD_DRV_CLR_ONLY, ¶ms->ramrod_flags)) {
5694 bnx2x_func_state_change_comp(bp, o, cmd);
5695 mutex_unlock(&o->one_pending_mutex);
5698 rc = o->send_cmd(bp, params);
5700 mutex_unlock(&o->one_pending_mutex);
5703 o->next_state = BNX2X_F_STATE_MAX;
5704 clear_bit(cmd, pending);
5705 smp_mb__after_clear_bit();
5709 if (test_bit(RAMROD_COMP_WAIT, ¶ms->ramrod_flags)) {
5710 rc = o->wait_comp(bp, o, cmd);
5718 return !!test_bit(cmd, pending);