1 /* bnx2x_sp.c: Qlogic Everest network driver.
3 * Copyright 2011-2013 Broadcom Corporation
4 * Copyright (c) 2014 QLogic Corporation
7 * Unless you and Qlogic execute a separate written software license
8 * agreement governing use of this software, this software is licensed to you
9 * under the terms of the GNU General Public License version 2, available
10 * at http://www.gnu.org/licenses/gpl-2.0.html (the "GPL").
12 * Notwithstanding the above, under no circumstances may you combine this
13 * software in any way with any other Qlogic software provided under a
14 * license other than the GPL, without Qlogic's express prior written
17 * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
18 * Written by: Vladislav Zolotarov
22 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24 #include <linux/module.h>
25 #include <linux/crc32.h>
26 #include <linux/netdevice.h>
27 #include <linux/etherdevice.h>
28 #include <linux/crc32c.h>
30 #include "bnx2x_cmn.h"
33 #define BNX2X_MAX_EMUL_MULTI 16
35 /**** Exe Queue interfaces ****/
38 * bnx2x_exe_queue_init - init the Exe Queue object
40 * @o: pointer to the object
42 * @owner: pointer to the owner
43 * @validate: validate function pointer
44 * @optimize: optimize function pointer
45 * @exec: execute function pointer
46 * @get: get function pointer
48 static inline void bnx2x_exe_queue_init(struct bnx2x *bp,
49 struct bnx2x_exe_queue_obj *o,
51 union bnx2x_qable_obj *owner,
52 exe_q_validate validate,
54 exe_q_optimize optimize,
58 memset(o, 0, sizeof(*o));
60 INIT_LIST_HEAD(&o->exe_queue);
61 INIT_LIST_HEAD(&o->pending_comp);
63 spin_lock_init(&o->lock);
65 o->exe_chunk_len = exe_len;
68 /* Owner specific callbacks */
69 o->validate = validate;
71 o->optimize = optimize;
75 DP(BNX2X_MSG_SP, "Setup the execution queue with the chunk length of %d\n",
79 static inline void bnx2x_exe_queue_free_elem(struct bnx2x *bp,
80 struct bnx2x_exeq_elem *elem)
82 DP(BNX2X_MSG_SP, "Deleting an exe_queue element\n");
86 static inline int bnx2x_exe_queue_length(struct bnx2x_exe_queue_obj *o)
88 struct bnx2x_exeq_elem *elem;
91 spin_lock_bh(&o->lock);
93 list_for_each_entry(elem, &o->exe_queue, link)
96 spin_unlock_bh(&o->lock);
102 * bnx2x_exe_queue_add - add a new element to the execution queue
106 * @cmd: new command to add
107 * @restore: true - do not optimize the command
109 * If the element is optimized or is illegal, frees it.
111 static inline int bnx2x_exe_queue_add(struct bnx2x *bp,
112 struct bnx2x_exe_queue_obj *o,
113 struct bnx2x_exeq_elem *elem,
118 spin_lock_bh(&o->lock);
121 /* Try to cancel this element queue */
122 rc = o->optimize(bp, o->owner, elem);
126 /* Check if this request is ok */
127 rc = o->validate(bp, o->owner, elem);
129 DP(BNX2X_MSG_SP, "Preamble failed: %d\n", rc);
134 /* If so, add it to the execution queue */
135 list_add_tail(&elem->link, &o->exe_queue);
137 spin_unlock_bh(&o->lock);
142 bnx2x_exe_queue_free_elem(bp, elem);
144 spin_unlock_bh(&o->lock);
149 static inline void __bnx2x_exe_queue_reset_pending(
151 struct bnx2x_exe_queue_obj *o)
153 struct bnx2x_exeq_elem *elem;
155 while (!list_empty(&o->pending_comp)) {
156 elem = list_first_entry(&o->pending_comp,
157 struct bnx2x_exeq_elem, link);
159 list_del(&elem->link);
160 bnx2x_exe_queue_free_elem(bp, elem);
165 * bnx2x_exe_queue_step - execute one execution chunk atomically
169 * @ramrod_flags: flags
171 * (Should be called while holding the exe_queue->lock).
173 static inline int bnx2x_exe_queue_step(struct bnx2x *bp,
174 struct bnx2x_exe_queue_obj *o,
175 unsigned long *ramrod_flags)
177 struct bnx2x_exeq_elem *elem, spacer;
180 memset(&spacer, 0, sizeof(spacer));
182 /* Next step should not be performed until the current is finished,
183 * unless a DRV_CLEAR_ONLY bit is set. In this case we just want to
184 * properly clear object internals without sending any command to the FW
185 * which also implies there won't be any completion to clear the
188 if (!list_empty(&o->pending_comp)) {
189 if (test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags)) {
190 DP(BNX2X_MSG_SP, "RAMROD_DRV_CLR_ONLY requested: resetting a pending_comp list\n");
191 __bnx2x_exe_queue_reset_pending(bp, o);
197 /* Run through the pending commands list and create a next
200 while (!list_empty(&o->exe_queue)) {
201 elem = list_first_entry(&o->exe_queue, struct bnx2x_exeq_elem,
203 WARN_ON(!elem->cmd_len);
205 if (cur_len + elem->cmd_len <= o->exe_chunk_len) {
206 cur_len += elem->cmd_len;
207 /* Prevent from both lists being empty when moving an
208 * element. This will allow the call of
209 * bnx2x_exe_queue_empty() without locking.
211 list_add_tail(&spacer.link, &o->pending_comp);
213 list_move_tail(&elem->link, &o->pending_comp);
214 list_del(&spacer.link);
223 rc = o->execute(bp, o->owner, &o->pending_comp, ramrod_flags);
225 /* In case of an error return the commands back to the queue
226 * and reset the pending_comp.
228 list_splice_init(&o->pending_comp, &o->exe_queue);
230 /* If zero is returned, means there are no outstanding pending
231 * completions and we may dismiss the pending list.
233 __bnx2x_exe_queue_reset_pending(bp, o);
238 static inline bool bnx2x_exe_queue_empty(struct bnx2x_exe_queue_obj *o)
240 bool empty = list_empty(&o->exe_queue);
242 /* Don't reorder!!! */
245 return empty && list_empty(&o->pending_comp);
248 static inline struct bnx2x_exeq_elem *bnx2x_exe_queue_alloc_elem(
251 DP(BNX2X_MSG_SP, "Allocating a new exe_queue element\n");
252 return kzalloc(sizeof(struct bnx2x_exeq_elem), GFP_ATOMIC);
255 /************************ raw_obj functions ***********************************/
256 static bool bnx2x_raw_check_pending(struct bnx2x_raw_obj *o)
258 return !!test_bit(o->state, o->pstate);
261 static void bnx2x_raw_clear_pending(struct bnx2x_raw_obj *o)
263 smp_mb__before_atomic();
264 clear_bit(o->state, o->pstate);
265 smp_mb__after_atomic();
268 static void bnx2x_raw_set_pending(struct bnx2x_raw_obj *o)
270 smp_mb__before_atomic();
271 set_bit(o->state, o->pstate);
272 smp_mb__after_atomic();
276 * bnx2x_state_wait - wait until the given bit(state) is cleared
279 * @state: state which is to be cleared
280 * @state_p: state buffer
283 static inline int bnx2x_state_wait(struct bnx2x *bp, int state,
284 unsigned long *pstate)
286 /* can take a while if any port is running */
289 if (CHIP_REV_IS_EMUL(bp))
292 DP(BNX2X_MSG_SP, "waiting for state to become %d\n", state);
296 if (!test_bit(state, pstate)) {
297 #ifdef BNX2X_STOP_ON_ERROR
298 DP(BNX2X_MSG_SP, "exit (cnt %d)\n", 5000 - cnt);
303 usleep_range(1000, 2000);
310 BNX2X_ERR("timeout waiting for state %d\n", state);
311 #ifdef BNX2X_STOP_ON_ERROR
318 static int bnx2x_raw_wait(struct bnx2x *bp, struct bnx2x_raw_obj *raw)
320 return bnx2x_state_wait(bp, raw->state, raw->pstate);
323 /***************** Classification verbs: Set/Del MAC/VLAN/VLAN-MAC ************/
324 /* credit handling callbacks */
325 static bool bnx2x_get_cam_offset_mac(struct bnx2x_vlan_mac_obj *o, int *offset)
327 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
331 return mp->get_entry(mp, offset);
334 static bool bnx2x_get_credit_mac(struct bnx2x_vlan_mac_obj *o)
336 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
340 return mp->get(mp, 1);
343 static bool bnx2x_get_cam_offset_vlan(struct bnx2x_vlan_mac_obj *o, int *offset)
345 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
349 return vp->get_entry(vp, offset);
352 static bool bnx2x_get_credit_vlan(struct bnx2x_vlan_mac_obj *o)
354 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
358 return vp->get(vp, 1);
360 static bool bnx2x_put_cam_offset_mac(struct bnx2x_vlan_mac_obj *o, int offset)
362 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
364 return mp->put_entry(mp, offset);
367 static bool bnx2x_put_credit_mac(struct bnx2x_vlan_mac_obj *o)
369 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
371 return mp->put(mp, 1);
374 static bool bnx2x_put_cam_offset_vlan(struct bnx2x_vlan_mac_obj *o, int offset)
376 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
378 return vp->put_entry(vp, offset);
381 static bool bnx2x_put_credit_vlan(struct bnx2x_vlan_mac_obj *o)
383 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
385 return vp->put(vp, 1);
389 * __bnx2x_vlan_mac_h_write_trylock - try getting the vlan mac writer lock
392 * @o: vlan_mac object
394 * @details: Non-blocking implementation; should be called under execution
397 static int __bnx2x_vlan_mac_h_write_trylock(struct bnx2x *bp,
398 struct bnx2x_vlan_mac_obj *o)
400 if (o->head_reader) {
401 DP(BNX2X_MSG_SP, "vlan_mac_lock writer - There are readers; Busy\n");
405 DP(BNX2X_MSG_SP, "vlan_mac_lock writer - Taken\n");
410 * __bnx2x_vlan_mac_h_exec_pending - execute step instead of a previous step
413 * @o: vlan_mac object
415 * @details Should be called under execution queue lock; notice it might release
416 * and reclaim it during its run.
418 static void __bnx2x_vlan_mac_h_exec_pending(struct bnx2x *bp,
419 struct bnx2x_vlan_mac_obj *o)
422 unsigned long ramrod_flags = o->saved_ramrod_flags;
424 DP(BNX2X_MSG_SP, "vlan_mac_lock execute pending command with ramrod flags %lu\n",
426 o->head_exe_request = false;
427 o->saved_ramrod_flags = 0;
428 rc = bnx2x_exe_queue_step(bp, &o->exe_queue, &ramrod_flags);
429 if ((rc != 0) && (rc != 1)) {
430 BNX2X_ERR("execution of pending commands failed with rc %d\n",
432 #ifdef BNX2X_STOP_ON_ERROR
439 * __bnx2x_vlan_mac_h_pend - Pend an execution step which couldn't run
442 * @o: vlan_mac object
443 * @ramrod_flags: ramrod flags of missed execution
445 * @details Should be called under execution queue lock.
447 static void __bnx2x_vlan_mac_h_pend(struct bnx2x *bp,
448 struct bnx2x_vlan_mac_obj *o,
449 unsigned long ramrod_flags)
451 o->head_exe_request = true;
452 o->saved_ramrod_flags = ramrod_flags;
453 DP(BNX2X_MSG_SP, "Placing pending execution with ramrod flags %lu\n",
458 * __bnx2x_vlan_mac_h_write_unlock - unlock the vlan mac head list writer lock
461 * @o: vlan_mac object
463 * @details Should be called under execution queue lock. Notice if a pending
464 * execution exists, it would perform it - possibly releasing and
465 * reclaiming the execution queue lock.
467 static void __bnx2x_vlan_mac_h_write_unlock(struct bnx2x *bp,
468 struct bnx2x_vlan_mac_obj *o)
470 /* It's possible a new pending execution was added since this writer
471 * executed. If so, execute again. [Ad infinitum]
473 while (o->head_exe_request) {
474 DP(BNX2X_MSG_SP, "vlan_mac_lock - writer release encountered a pending request\n");
475 __bnx2x_vlan_mac_h_exec_pending(bp, o);
481 * __bnx2x_vlan_mac_h_read_lock - lock the vlan mac head list reader lock
484 * @o: vlan_mac object
486 * @details Should be called under the execution queue lock. May sleep. May
487 * release and reclaim execution queue lock during its run.
489 static int __bnx2x_vlan_mac_h_read_lock(struct bnx2x *bp,
490 struct bnx2x_vlan_mac_obj *o)
492 /* If we got here, we're holding lock --> no WRITER exists */
494 DP(BNX2X_MSG_SP, "vlan_mac_lock - locked reader - number %d\n",
501 * bnx2x_vlan_mac_h_read_lock - lock the vlan mac head list reader lock
504 * @o: vlan_mac object
506 * @details May sleep. Claims and releases execution queue lock during its run.
508 int bnx2x_vlan_mac_h_read_lock(struct bnx2x *bp,
509 struct bnx2x_vlan_mac_obj *o)
513 spin_lock_bh(&o->exe_queue.lock);
514 rc = __bnx2x_vlan_mac_h_read_lock(bp, o);
515 spin_unlock_bh(&o->exe_queue.lock);
521 * __bnx2x_vlan_mac_h_read_unlock - unlock the vlan mac head list reader lock
524 * @o: vlan_mac object
526 * @details Should be called under execution queue lock. Notice if a pending
527 * execution exists, it would be performed if this was the last
528 * reader. possibly releasing and reclaiming the execution queue lock.
530 static void __bnx2x_vlan_mac_h_read_unlock(struct bnx2x *bp,
531 struct bnx2x_vlan_mac_obj *o)
533 if (!o->head_reader) {
534 BNX2X_ERR("Need to release vlan mac reader lock, but lock isn't taken\n");
535 #ifdef BNX2X_STOP_ON_ERROR
540 DP(BNX2X_MSG_SP, "vlan_mac_lock - decreased readers to %d\n",
544 /* It's possible a new pending execution was added, and that this reader
545 * was last - if so we need to execute the command.
547 if (!o->head_reader && o->head_exe_request) {
548 DP(BNX2X_MSG_SP, "vlan_mac_lock - reader release encountered a pending request\n");
550 /* Writer release will do the trick */
551 __bnx2x_vlan_mac_h_write_unlock(bp, o);
556 * bnx2x_vlan_mac_h_read_unlock - unlock the vlan mac head list reader lock
559 * @o: vlan_mac object
561 * @details Notice if a pending execution exists, it would be performed if this
562 * was the last reader. Claims and releases the execution queue lock
565 void bnx2x_vlan_mac_h_read_unlock(struct bnx2x *bp,
566 struct bnx2x_vlan_mac_obj *o)
568 spin_lock_bh(&o->exe_queue.lock);
569 __bnx2x_vlan_mac_h_read_unlock(bp, o);
570 spin_unlock_bh(&o->exe_queue.lock);
573 static int bnx2x_get_n_elements(struct bnx2x *bp, struct bnx2x_vlan_mac_obj *o,
574 int n, u8 *base, u8 stride, u8 size)
576 struct bnx2x_vlan_mac_registry_elem *pos;
581 DP(BNX2X_MSG_SP, "get_n_elements - taking vlan_mac_lock (reader)\n");
582 read_lock = bnx2x_vlan_mac_h_read_lock(bp, o);
584 BNX2X_ERR("get_n_elements failed to get vlan mac reader lock; Access without lock\n");
587 list_for_each_entry(pos, &o->head, link) {
589 memcpy(next, &pos->u, size);
591 DP(BNX2X_MSG_SP, "copied element number %d to address %p element was:\n",
593 next += stride + size;
597 if (read_lock == 0) {
598 DP(BNX2X_MSG_SP, "get_n_elements - releasing vlan_mac_lock (reader)\n");
599 bnx2x_vlan_mac_h_read_unlock(bp, o);
602 return counter * ETH_ALEN;
605 /* check_add() callbacks */
606 static int bnx2x_check_mac_add(struct bnx2x *bp,
607 struct bnx2x_vlan_mac_obj *o,
608 union bnx2x_classification_ramrod_data *data)
610 struct bnx2x_vlan_mac_registry_elem *pos;
612 DP(BNX2X_MSG_SP, "Checking MAC %pM for ADD command\n", data->mac.mac);
614 if (!is_valid_ether_addr(data->mac.mac))
617 /* Check if a requested MAC already exists */
618 list_for_each_entry(pos, &o->head, link)
619 if (ether_addr_equal(data->mac.mac, pos->u.mac.mac) &&
620 (data->mac.is_inner_mac == pos->u.mac.is_inner_mac))
626 static int bnx2x_check_vlan_add(struct bnx2x *bp,
627 struct bnx2x_vlan_mac_obj *o,
628 union bnx2x_classification_ramrod_data *data)
630 struct bnx2x_vlan_mac_registry_elem *pos;
632 DP(BNX2X_MSG_SP, "Checking VLAN %d for ADD command\n", data->vlan.vlan);
634 list_for_each_entry(pos, &o->head, link)
635 if (data->vlan.vlan == pos->u.vlan.vlan)
641 /* check_del() callbacks */
642 static struct bnx2x_vlan_mac_registry_elem *
643 bnx2x_check_mac_del(struct bnx2x *bp,
644 struct bnx2x_vlan_mac_obj *o,
645 union bnx2x_classification_ramrod_data *data)
647 struct bnx2x_vlan_mac_registry_elem *pos;
649 DP(BNX2X_MSG_SP, "Checking MAC %pM for DEL command\n", data->mac.mac);
651 list_for_each_entry(pos, &o->head, link)
652 if (ether_addr_equal(data->mac.mac, pos->u.mac.mac) &&
653 (data->mac.is_inner_mac == pos->u.mac.is_inner_mac))
659 static struct bnx2x_vlan_mac_registry_elem *
660 bnx2x_check_vlan_del(struct bnx2x *bp,
661 struct bnx2x_vlan_mac_obj *o,
662 union bnx2x_classification_ramrod_data *data)
664 struct bnx2x_vlan_mac_registry_elem *pos;
666 DP(BNX2X_MSG_SP, "Checking VLAN %d for DEL command\n", data->vlan.vlan);
668 list_for_each_entry(pos, &o->head, link)
669 if (data->vlan.vlan == pos->u.vlan.vlan)
675 /* check_move() callback */
676 static bool bnx2x_check_move(struct bnx2x *bp,
677 struct bnx2x_vlan_mac_obj *src_o,
678 struct bnx2x_vlan_mac_obj *dst_o,
679 union bnx2x_classification_ramrod_data *data)
681 struct bnx2x_vlan_mac_registry_elem *pos;
684 /* Check if we can delete the requested configuration from the first
687 pos = src_o->check_del(bp, src_o, data);
689 /* check if configuration can be added */
690 rc = dst_o->check_add(bp, dst_o, data);
692 /* If this classification can not be added (is already set)
693 * or can't be deleted - return an error.
701 static bool bnx2x_check_move_always_err(
703 struct bnx2x_vlan_mac_obj *src_o,
704 struct bnx2x_vlan_mac_obj *dst_o,
705 union bnx2x_classification_ramrod_data *data)
710 static inline u8 bnx2x_vlan_mac_get_rx_tx_flag(struct bnx2x_vlan_mac_obj *o)
712 struct bnx2x_raw_obj *raw = &o->raw;
715 if ((raw->obj_type == BNX2X_OBJ_TYPE_TX) ||
716 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
717 rx_tx_flag |= ETH_CLASSIFY_CMD_HEADER_TX_CMD;
719 if ((raw->obj_type == BNX2X_OBJ_TYPE_RX) ||
720 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
721 rx_tx_flag |= ETH_CLASSIFY_CMD_HEADER_RX_CMD;
726 static void bnx2x_set_mac_in_nig(struct bnx2x *bp,
727 bool add, unsigned char *dev_addr, int index)
730 u32 reg_offset = BP_PORT(bp) ? NIG_REG_LLH1_FUNC_MEM :
731 NIG_REG_LLH0_FUNC_MEM;
733 if (!IS_MF_SI(bp) && !IS_MF_AFEX(bp))
736 if (index > BNX2X_LLH_CAM_MAX_PF_LINE)
739 DP(BNX2X_MSG_SP, "Going to %s LLH configuration at entry %d\n",
740 (add ? "ADD" : "DELETE"), index);
743 /* LLH_FUNC_MEM is a u64 WB register */
744 reg_offset += 8*index;
746 wb_data[0] = ((dev_addr[2] << 24) | (dev_addr[3] << 16) |
747 (dev_addr[4] << 8) | dev_addr[5]);
748 wb_data[1] = ((dev_addr[0] << 8) | dev_addr[1]);
750 REG_WR_DMAE(bp, reg_offset, wb_data, 2);
753 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_FUNC_MEM_ENABLE :
754 NIG_REG_LLH0_FUNC_MEM_ENABLE) + 4*index, add);
758 * bnx2x_vlan_mac_set_cmd_hdr_e2 - set a header in a single classify ramrod
761 * @o: queue for which we want to configure this rule
762 * @add: if true the command is an ADD command, DEL otherwise
763 * @opcode: CLASSIFY_RULE_OPCODE_XXX
764 * @hdr: pointer to a header to setup
767 static inline void bnx2x_vlan_mac_set_cmd_hdr_e2(struct bnx2x *bp,
768 struct bnx2x_vlan_mac_obj *o, bool add, int opcode,
769 struct eth_classify_cmd_header *hdr)
771 struct bnx2x_raw_obj *raw = &o->raw;
773 hdr->client_id = raw->cl_id;
774 hdr->func_id = raw->func_id;
776 /* Rx or/and Tx (internal switching) configuration ? */
777 hdr->cmd_general_data |=
778 bnx2x_vlan_mac_get_rx_tx_flag(o);
781 hdr->cmd_general_data |= ETH_CLASSIFY_CMD_HEADER_IS_ADD;
783 hdr->cmd_general_data |=
784 (opcode << ETH_CLASSIFY_CMD_HEADER_OPCODE_SHIFT);
788 * bnx2x_vlan_mac_set_rdata_hdr_e2 - set the classify ramrod data header
790 * @cid: connection id
791 * @type: BNX2X_FILTER_XXX_PENDING
792 * @hdr: pointer to header to setup
795 * currently we always configure one rule and echo field to contain a CID and an
798 static inline void bnx2x_vlan_mac_set_rdata_hdr_e2(u32 cid, int type,
799 struct eth_classify_header *hdr, int rule_cnt)
801 hdr->echo = cpu_to_le32((cid & BNX2X_SWCID_MASK) |
802 (type << BNX2X_SWCID_SHIFT));
803 hdr->rule_cnt = (u8)rule_cnt;
806 /* hw_config() callbacks */
807 static void bnx2x_set_one_mac_e2(struct bnx2x *bp,
808 struct bnx2x_vlan_mac_obj *o,
809 struct bnx2x_exeq_elem *elem, int rule_idx,
812 struct bnx2x_raw_obj *raw = &o->raw;
813 struct eth_classify_rules_ramrod_data *data =
814 (struct eth_classify_rules_ramrod_data *)(raw->rdata);
815 int rule_cnt = rule_idx + 1, cmd = elem->cmd_data.vlan_mac.cmd;
816 union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
817 bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
818 unsigned long *vlan_mac_flags = &elem->cmd_data.vlan_mac.vlan_mac_flags;
819 u8 *mac = elem->cmd_data.vlan_mac.u.mac.mac;
821 /* Set LLH CAM entry: currently only iSCSI and ETH macs are
822 * relevant. In addition, current implementation is tuned for a
825 * When multiple unicast ETH MACs PF configuration in switch
826 * independent mode is required (NetQ, multiple netdev MACs,
827 * etc.), consider better utilisation of 8 per function MAC
828 * entries in the LLH register. There is also
829 * NIG_REG_P[01]_LLH_FUNC_MEM2 registers that complete the
830 * total number of CAM entries to 16.
832 * Currently we won't configure NIG for MACs other than a primary ETH
833 * MAC and iSCSI L2 MAC.
835 * If this MAC is moving from one Queue to another, no need to change
838 if (cmd != BNX2X_VLAN_MAC_MOVE) {
839 if (test_bit(BNX2X_ISCSI_ETH_MAC, vlan_mac_flags))
840 bnx2x_set_mac_in_nig(bp, add, mac,
841 BNX2X_LLH_CAM_ISCSI_ETH_LINE);
842 else if (test_bit(BNX2X_ETH_MAC, vlan_mac_flags))
843 bnx2x_set_mac_in_nig(bp, add, mac,
844 BNX2X_LLH_CAM_ETH_LINE);
847 /* Reset the ramrod data buffer for the first rule */
849 memset(data, 0, sizeof(*data));
851 /* Setup a command header */
852 bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_MAC,
853 &rule_entry->mac.header);
855 DP(BNX2X_MSG_SP, "About to %s MAC %pM for Queue %d\n",
856 (add ? "add" : "delete"), mac, raw->cl_id);
858 /* Set a MAC itself */
859 bnx2x_set_fw_mac_addr(&rule_entry->mac.mac_msb,
860 &rule_entry->mac.mac_mid,
861 &rule_entry->mac.mac_lsb, mac);
862 rule_entry->mac.inner_mac =
863 cpu_to_le16(elem->cmd_data.vlan_mac.u.mac.is_inner_mac);
865 /* MOVE: Add a rule that will add this MAC to the target Queue */
866 if (cmd == BNX2X_VLAN_MAC_MOVE) {
870 /* Setup ramrod data */
871 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
872 elem->cmd_data.vlan_mac.target_obj,
873 true, CLASSIFY_RULE_OPCODE_MAC,
874 &rule_entry->mac.header);
876 /* Set a MAC itself */
877 bnx2x_set_fw_mac_addr(&rule_entry->mac.mac_msb,
878 &rule_entry->mac.mac_mid,
879 &rule_entry->mac.mac_lsb, mac);
880 rule_entry->mac.inner_mac =
881 cpu_to_le16(elem->cmd_data.vlan_mac.
885 /* Set the ramrod data header */
886 /* TODO: take this to the higher level in order to prevent multiple
888 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
893 * bnx2x_vlan_mac_set_rdata_hdr_e1x - set a header in a single classify ramrod
898 * @cam_offset: offset in cam memory
899 * @hdr: pointer to a header to setup
903 static inline void bnx2x_vlan_mac_set_rdata_hdr_e1x(struct bnx2x *bp,
904 struct bnx2x_vlan_mac_obj *o, int type, int cam_offset,
905 struct mac_configuration_hdr *hdr)
907 struct bnx2x_raw_obj *r = &o->raw;
910 hdr->offset = (u8)cam_offset;
911 hdr->client_id = cpu_to_le16(0xff);
912 hdr->echo = cpu_to_le32((r->cid & BNX2X_SWCID_MASK) |
913 (type << BNX2X_SWCID_SHIFT));
916 static inline void bnx2x_vlan_mac_set_cfg_entry_e1x(struct bnx2x *bp,
917 struct bnx2x_vlan_mac_obj *o, bool add, int opcode, u8 *mac,
918 u16 vlan_id, struct mac_configuration_entry *cfg_entry)
920 struct bnx2x_raw_obj *r = &o->raw;
921 u32 cl_bit_vec = (1 << r->cl_id);
923 cfg_entry->clients_bit_vector = cpu_to_le32(cl_bit_vec);
924 cfg_entry->pf_id = r->func_id;
925 cfg_entry->vlan_id = cpu_to_le16(vlan_id);
928 SET_FLAG(cfg_entry->flags, MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
929 T_ETH_MAC_COMMAND_SET);
930 SET_FLAG(cfg_entry->flags,
931 MAC_CONFIGURATION_ENTRY_VLAN_FILTERING_MODE, opcode);
933 /* Set a MAC in a ramrod data */
934 bnx2x_set_fw_mac_addr(&cfg_entry->msb_mac_addr,
935 &cfg_entry->middle_mac_addr,
936 &cfg_entry->lsb_mac_addr, mac);
938 SET_FLAG(cfg_entry->flags, MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
939 T_ETH_MAC_COMMAND_INVALIDATE);
942 static inline void bnx2x_vlan_mac_set_rdata_e1x(struct bnx2x *bp,
943 struct bnx2x_vlan_mac_obj *o, int type, int cam_offset, bool add,
944 u8 *mac, u16 vlan_id, int opcode, struct mac_configuration_cmd *config)
946 struct mac_configuration_entry *cfg_entry = &config->config_table[0];
947 struct bnx2x_raw_obj *raw = &o->raw;
949 bnx2x_vlan_mac_set_rdata_hdr_e1x(bp, o, type, cam_offset,
951 bnx2x_vlan_mac_set_cfg_entry_e1x(bp, o, add, opcode, mac, vlan_id,
954 DP(BNX2X_MSG_SP, "%s MAC %pM CLID %d CAM offset %d\n",
955 (add ? "setting" : "clearing"),
956 mac, raw->cl_id, cam_offset);
960 * bnx2x_set_one_mac_e1x - fill a single MAC rule ramrod data
963 * @o: bnx2x_vlan_mac_obj
964 * @elem: bnx2x_exeq_elem
965 * @rule_idx: rule_idx
966 * @cam_offset: cam_offset
968 static void bnx2x_set_one_mac_e1x(struct bnx2x *bp,
969 struct bnx2x_vlan_mac_obj *o,
970 struct bnx2x_exeq_elem *elem, int rule_idx,
973 struct bnx2x_raw_obj *raw = &o->raw;
974 struct mac_configuration_cmd *config =
975 (struct mac_configuration_cmd *)(raw->rdata);
976 /* 57710 and 57711 do not support MOVE command,
977 * so it's either ADD or DEL
979 bool add = (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
982 /* Reset the ramrod data buffer */
983 memset(config, 0, sizeof(*config));
985 bnx2x_vlan_mac_set_rdata_e1x(bp, o, raw->state,
987 elem->cmd_data.vlan_mac.u.mac.mac, 0,
988 ETH_VLAN_FILTER_ANY_VLAN, config);
991 static void bnx2x_set_one_vlan_e2(struct bnx2x *bp,
992 struct bnx2x_vlan_mac_obj *o,
993 struct bnx2x_exeq_elem *elem, int rule_idx,
996 struct bnx2x_raw_obj *raw = &o->raw;
997 struct eth_classify_rules_ramrod_data *data =
998 (struct eth_classify_rules_ramrod_data *)(raw->rdata);
999 int rule_cnt = rule_idx + 1;
1000 union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
1001 enum bnx2x_vlan_mac_cmd cmd = elem->cmd_data.vlan_mac.cmd;
1002 bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
1003 u16 vlan = elem->cmd_data.vlan_mac.u.vlan.vlan;
1005 /* Reset the ramrod data buffer for the first rule */
1007 memset(data, 0, sizeof(*data));
1009 /* Set a rule header */
1010 bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_VLAN,
1011 &rule_entry->vlan.header);
1013 DP(BNX2X_MSG_SP, "About to %s VLAN %d\n", (add ? "add" : "delete"),
1016 /* Set a VLAN itself */
1017 rule_entry->vlan.vlan = cpu_to_le16(vlan);
1019 /* MOVE: Add a rule that will add this MAC to the target Queue */
1020 if (cmd == BNX2X_VLAN_MAC_MOVE) {
1024 /* Setup ramrod data */
1025 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
1026 elem->cmd_data.vlan_mac.target_obj,
1027 true, CLASSIFY_RULE_OPCODE_VLAN,
1028 &rule_entry->vlan.header);
1030 /* Set a VLAN itself */
1031 rule_entry->vlan.vlan = cpu_to_le16(vlan);
1034 /* Set the ramrod data header */
1035 /* TODO: take this to the higher level in order to prevent multiple
1037 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
1042 * bnx2x_vlan_mac_restore - reconfigure next MAC/VLAN/VLAN-MAC element
1044 * @bp: device handle
1045 * @p: command parameters
1046 * @ppos: pointer to the cookie
1048 * reconfigure next MAC/VLAN/VLAN-MAC element from the
1049 * previously configured elements list.
1051 * from command parameters only RAMROD_COMP_WAIT bit in ramrod_flags is taken
1054 * pointer to the cookie - that should be given back in the next call to make
1055 * function handle the next element. If *ppos is set to NULL it will restart the
1056 * iterator. If returned *ppos == NULL this means that the last element has been
1060 static int bnx2x_vlan_mac_restore(struct bnx2x *bp,
1061 struct bnx2x_vlan_mac_ramrod_params *p,
1062 struct bnx2x_vlan_mac_registry_elem **ppos)
1064 struct bnx2x_vlan_mac_registry_elem *pos;
1065 struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
1067 /* If list is empty - there is nothing to do here */
1068 if (list_empty(&o->head)) {
1073 /* make a step... */
1075 *ppos = list_first_entry(&o->head,
1076 struct bnx2x_vlan_mac_registry_elem,
1079 *ppos = list_next_entry(*ppos, link);
1083 /* If it's the last step - return NULL */
1084 if (list_is_last(&pos->link, &o->head))
1087 /* Prepare a 'user_req' */
1088 memcpy(&p->user_req.u, &pos->u, sizeof(pos->u));
1090 /* Set the command */
1091 p->user_req.cmd = BNX2X_VLAN_MAC_ADD;
1093 /* Set vlan_mac_flags */
1094 p->user_req.vlan_mac_flags = pos->vlan_mac_flags;
1096 /* Set a restore bit */
1097 __set_bit(RAMROD_RESTORE, &p->ramrod_flags);
1099 return bnx2x_config_vlan_mac(bp, p);
1102 /* bnx2x_exeq_get_mac/bnx2x_exeq_get_vlan/bnx2x_exeq_get_vlan_mac return a
1103 * pointer to an element with a specific criteria and NULL if such an element
1104 * hasn't been found.
1106 static struct bnx2x_exeq_elem *bnx2x_exeq_get_mac(
1107 struct bnx2x_exe_queue_obj *o,
1108 struct bnx2x_exeq_elem *elem)
1110 struct bnx2x_exeq_elem *pos;
1111 struct bnx2x_mac_ramrod_data *data = &elem->cmd_data.vlan_mac.u.mac;
1113 /* Check pending for execution commands */
1114 list_for_each_entry(pos, &o->exe_queue, link)
1115 if (!memcmp(&pos->cmd_data.vlan_mac.u.mac, data,
1117 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1123 static struct bnx2x_exeq_elem *bnx2x_exeq_get_vlan(
1124 struct bnx2x_exe_queue_obj *o,
1125 struct bnx2x_exeq_elem *elem)
1127 struct bnx2x_exeq_elem *pos;
1128 struct bnx2x_vlan_ramrod_data *data = &elem->cmd_data.vlan_mac.u.vlan;
1130 /* Check pending for execution commands */
1131 list_for_each_entry(pos, &o->exe_queue, link)
1132 if (!memcmp(&pos->cmd_data.vlan_mac.u.vlan, data,
1134 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1141 * bnx2x_validate_vlan_mac_add - check if an ADD command can be executed
1143 * @bp: device handle
1144 * @qo: bnx2x_qable_obj
1145 * @elem: bnx2x_exeq_elem
1147 * Checks that the requested configuration can be added. If yes and if
1148 * requested, consume CAM credit.
1150 * The 'validate' is run after the 'optimize'.
1153 static inline int bnx2x_validate_vlan_mac_add(struct bnx2x *bp,
1154 union bnx2x_qable_obj *qo,
1155 struct bnx2x_exeq_elem *elem)
1157 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
1158 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1161 /* Check the registry */
1162 rc = o->check_add(bp, o, &elem->cmd_data.vlan_mac.u);
1164 DP(BNX2X_MSG_SP, "ADD command is not allowed considering current registry state.\n");
1168 /* Check if there is a pending ADD command for this
1169 * MAC/VLAN/VLAN-MAC. Return an error if there is.
1171 if (exeq->get(exeq, elem)) {
1172 DP(BNX2X_MSG_SP, "There is a pending ADD command already\n");
1176 /* TODO: Check the pending MOVE from other objects where this
1177 * object is a destination object.
1180 /* Consume the credit if not requested not to */
1181 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1182 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1190 * bnx2x_validate_vlan_mac_del - check if the DEL command can be executed
1192 * @bp: device handle
1193 * @qo: quable object to check
1194 * @elem: element that needs to be deleted
1196 * Checks that the requested configuration can be deleted. If yes and if
1197 * requested, returns a CAM credit.
1199 * The 'validate' is run after the 'optimize'.
1201 static inline int bnx2x_validate_vlan_mac_del(struct bnx2x *bp,
1202 union bnx2x_qable_obj *qo,
1203 struct bnx2x_exeq_elem *elem)
1205 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
1206 struct bnx2x_vlan_mac_registry_elem *pos;
1207 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1208 struct bnx2x_exeq_elem query_elem;
1210 /* If this classification can not be deleted (doesn't exist)
1211 * - return a BNX2X_EXIST.
1213 pos = o->check_del(bp, o, &elem->cmd_data.vlan_mac.u);
1215 DP(BNX2X_MSG_SP, "DEL command is not allowed considering current registry state\n");
1219 /* Check if there are pending DEL or MOVE commands for this
1220 * MAC/VLAN/VLAN-MAC. Return an error if so.
1222 memcpy(&query_elem, elem, sizeof(query_elem));
1224 /* Check for MOVE commands */
1225 query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_MOVE;
1226 if (exeq->get(exeq, &query_elem)) {
1227 BNX2X_ERR("There is a pending MOVE command already\n");
1231 /* Check for DEL commands */
1232 if (exeq->get(exeq, elem)) {
1233 DP(BNX2X_MSG_SP, "There is a pending DEL command already\n");
1237 /* Return the credit to the credit pool if not requested not to */
1238 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1239 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1240 o->put_credit(o))) {
1241 BNX2X_ERR("Failed to return a credit\n");
1249 * bnx2x_validate_vlan_mac_move - check if the MOVE command can be executed
1251 * @bp: device handle
1252 * @qo: quable object to check (source)
1253 * @elem: element that needs to be moved
1255 * Checks that the requested configuration can be moved. If yes and if
1256 * requested, returns a CAM credit.
1258 * The 'validate' is run after the 'optimize'.
1260 static inline int bnx2x_validate_vlan_mac_move(struct bnx2x *bp,
1261 union bnx2x_qable_obj *qo,
1262 struct bnx2x_exeq_elem *elem)
1264 struct bnx2x_vlan_mac_obj *src_o = &qo->vlan_mac;
1265 struct bnx2x_vlan_mac_obj *dest_o = elem->cmd_data.vlan_mac.target_obj;
1266 struct bnx2x_exeq_elem query_elem;
1267 struct bnx2x_exe_queue_obj *src_exeq = &src_o->exe_queue;
1268 struct bnx2x_exe_queue_obj *dest_exeq = &dest_o->exe_queue;
1270 /* Check if we can perform this operation based on the current registry
1273 if (!src_o->check_move(bp, src_o, dest_o,
1274 &elem->cmd_data.vlan_mac.u)) {
1275 DP(BNX2X_MSG_SP, "MOVE command is not allowed considering current registry state\n");
1279 /* Check if there is an already pending DEL or MOVE command for the
1280 * source object or ADD command for a destination object. Return an
1283 memcpy(&query_elem, elem, sizeof(query_elem));
1285 /* Check DEL on source */
1286 query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_DEL;
1287 if (src_exeq->get(src_exeq, &query_elem)) {
1288 BNX2X_ERR("There is a pending DEL command on the source queue already\n");
1292 /* Check MOVE on source */
1293 if (src_exeq->get(src_exeq, elem)) {
1294 DP(BNX2X_MSG_SP, "There is a pending MOVE command already\n");
1298 /* Check ADD on destination */
1299 query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_ADD;
1300 if (dest_exeq->get(dest_exeq, &query_elem)) {
1301 BNX2X_ERR("There is a pending ADD command on the destination queue already\n");
1305 /* Consume the credit if not requested not to */
1306 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT_DEST,
1307 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1308 dest_o->get_credit(dest_o)))
1311 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1312 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1313 src_o->put_credit(src_o))) {
1314 /* return the credit taken from dest... */
1315 dest_o->put_credit(dest_o);
1322 static int bnx2x_validate_vlan_mac(struct bnx2x *bp,
1323 union bnx2x_qable_obj *qo,
1324 struct bnx2x_exeq_elem *elem)
1326 switch (elem->cmd_data.vlan_mac.cmd) {
1327 case BNX2X_VLAN_MAC_ADD:
1328 return bnx2x_validate_vlan_mac_add(bp, qo, elem);
1329 case BNX2X_VLAN_MAC_DEL:
1330 return bnx2x_validate_vlan_mac_del(bp, qo, elem);
1331 case BNX2X_VLAN_MAC_MOVE:
1332 return bnx2x_validate_vlan_mac_move(bp, qo, elem);
1338 static int bnx2x_remove_vlan_mac(struct bnx2x *bp,
1339 union bnx2x_qable_obj *qo,
1340 struct bnx2x_exeq_elem *elem)
1344 /* If consumption wasn't required, nothing to do */
1345 if (test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1346 &elem->cmd_data.vlan_mac.vlan_mac_flags))
1349 switch (elem->cmd_data.vlan_mac.cmd) {
1350 case BNX2X_VLAN_MAC_ADD:
1351 case BNX2X_VLAN_MAC_MOVE:
1352 rc = qo->vlan_mac.put_credit(&qo->vlan_mac);
1354 case BNX2X_VLAN_MAC_DEL:
1355 rc = qo->vlan_mac.get_credit(&qo->vlan_mac);
1368 * bnx2x_wait_vlan_mac - passively wait for 5 seconds until all work completes.
1370 * @bp: device handle
1371 * @o: bnx2x_vlan_mac_obj
1374 static int bnx2x_wait_vlan_mac(struct bnx2x *bp,
1375 struct bnx2x_vlan_mac_obj *o)
1378 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1379 struct bnx2x_raw_obj *raw = &o->raw;
1382 /* Wait for the current command to complete */
1383 rc = raw->wait_comp(bp, raw);
1387 /* Wait until there are no pending commands */
1388 if (!bnx2x_exe_queue_empty(exeq))
1389 usleep_range(1000, 2000);
1397 static int __bnx2x_vlan_mac_execute_step(struct bnx2x *bp,
1398 struct bnx2x_vlan_mac_obj *o,
1399 unsigned long *ramrod_flags)
1403 spin_lock_bh(&o->exe_queue.lock);
1405 DP(BNX2X_MSG_SP, "vlan_mac_execute_step - trying to take writer lock\n");
1406 rc = __bnx2x_vlan_mac_h_write_trylock(bp, o);
1409 __bnx2x_vlan_mac_h_pend(bp, o, *ramrod_flags);
1411 /* Calling function should not diffrentiate between this case
1412 * and the case in which there is already a pending ramrod
1416 rc = bnx2x_exe_queue_step(bp, &o->exe_queue, ramrod_flags);
1418 spin_unlock_bh(&o->exe_queue.lock);
1424 * bnx2x_complete_vlan_mac - complete one VLAN-MAC ramrod
1426 * @bp: device handle
1427 * @o: bnx2x_vlan_mac_obj
1429 * @cont: if true schedule next execution chunk
1432 static int bnx2x_complete_vlan_mac(struct bnx2x *bp,
1433 struct bnx2x_vlan_mac_obj *o,
1434 union event_ring_elem *cqe,
1435 unsigned long *ramrod_flags)
1437 struct bnx2x_raw_obj *r = &o->raw;
1440 /* Clearing the pending list & raw state should be made
1441 * atomically (as execution flow assumes they represent the same).
1443 spin_lock_bh(&o->exe_queue.lock);
1445 /* Reset pending list */
1446 __bnx2x_exe_queue_reset_pending(bp, &o->exe_queue);
1449 r->clear_pending(r);
1451 spin_unlock_bh(&o->exe_queue.lock);
1453 /* If ramrod failed this is most likely a SW bug */
1454 if (cqe->message.error)
1457 /* Run the next bulk of pending commands if requested */
1458 if (test_bit(RAMROD_CONT, ramrod_flags)) {
1459 rc = __bnx2x_vlan_mac_execute_step(bp, o, ramrod_flags);
1465 /* If there is more work to do return PENDING */
1466 if (!bnx2x_exe_queue_empty(&o->exe_queue))
1473 * bnx2x_optimize_vlan_mac - optimize ADD and DEL commands.
1475 * @bp: device handle
1476 * @o: bnx2x_qable_obj
1477 * @elem: bnx2x_exeq_elem
1479 static int bnx2x_optimize_vlan_mac(struct bnx2x *bp,
1480 union bnx2x_qable_obj *qo,
1481 struct bnx2x_exeq_elem *elem)
1483 struct bnx2x_exeq_elem query, *pos;
1484 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
1485 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1487 memcpy(&query, elem, sizeof(query));
1489 switch (elem->cmd_data.vlan_mac.cmd) {
1490 case BNX2X_VLAN_MAC_ADD:
1491 query.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_DEL;
1493 case BNX2X_VLAN_MAC_DEL:
1494 query.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_ADD;
1497 /* Don't handle anything other than ADD or DEL */
1501 /* If we found the appropriate element - delete it */
1502 pos = exeq->get(exeq, &query);
1505 /* Return the credit of the optimized command */
1506 if (!test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1507 &pos->cmd_data.vlan_mac.vlan_mac_flags)) {
1508 if ((query.cmd_data.vlan_mac.cmd ==
1509 BNX2X_VLAN_MAC_ADD) && !o->put_credit(o)) {
1510 BNX2X_ERR("Failed to return the credit for the optimized ADD command\n");
1512 } else if (!o->get_credit(o)) { /* VLAN_MAC_DEL */
1513 BNX2X_ERR("Failed to recover the credit from the optimized DEL command\n");
1518 DP(BNX2X_MSG_SP, "Optimizing %s command\n",
1519 (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
1522 list_del(&pos->link);
1523 bnx2x_exe_queue_free_elem(bp, pos);
1531 * bnx2x_vlan_mac_get_registry_elem - prepare a registry element
1533 * @bp: device handle
1539 * prepare a registry element according to the current command request.
1541 static inline int bnx2x_vlan_mac_get_registry_elem(
1543 struct bnx2x_vlan_mac_obj *o,
1544 struct bnx2x_exeq_elem *elem,
1546 struct bnx2x_vlan_mac_registry_elem **re)
1548 enum bnx2x_vlan_mac_cmd cmd = elem->cmd_data.vlan_mac.cmd;
1549 struct bnx2x_vlan_mac_registry_elem *reg_elem;
1551 /* Allocate a new registry element if needed. */
1553 ((cmd == BNX2X_VLAN_MAC_ADD) || (cmd == BNX2X_VLAN_MAC_MOVE))) {
1554 reg_elem = kzalloc(sizeof(*reg_elem), GFP_ATOMIC);
1558 /* Get a new CAM offset */
1559 if (!o->get_cam_offset(o, ®_elem->cam_offset)) {
1560 /* This shall never happen, because we have checked the
1561 * CAM availability in the 'validate'.
1568 DP(BNX2X_MSG_SP, "Got cam offset %d\n", reg_elem->cam_offset);
1570 /* Set a VLAN-MAC data */
1571 memcpy(®_elem->u, &elem->cmd_data.vlan_mac.u,
1572 sizeof(reg_elem->u));
1574 /* Copy the flags (needed for DEL and RESTORE flows) */
1575 reg_elem->vlan_mac_flags =
1576 elem->cmd_data.vlan_mac.vlan_mac_flags;
1577 } else /* DEL, RESTORE */
1578 reg_elem = o->check_del(bp, o, &elem->cmd_data.vlan_mac.u);
1585 * bnx2x_execute_vlan_mac - execute vlan mac command
1587 * @bp: device handle
1592 * go and send a ramrod!
1594 static int bnx2x_execute_vlan_mac(struct bnx2x *bp,
1595 union bnx2x_qable_obj *qo,
1596 struct list_head *exe_chunk,
1597 unsigned long *ramrod_flags)
1599 struct bnx2x_exeq_elem *elem;
1600 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac, *cam_obj;
1601 struct bnx2x_raw_obj *r = &o->raw;
1603 bool restore = test_bit(RAMROD_RESTORE, ramrod_flags);
1604 bool drv_only = test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags);
1605 struct bnx2x_vlan_mac_registry_elem *reg_elem;
1606 enum bnx2x_vlan_mac_cmd cmd;
1608 /* If DRIVER_ONLY execution is requested, cleanup a registry
1609 * and exit. Otherwise send a ramrod to FW.
1612 WARN_ON(r->check_pending(r));
1617 /* Fill the ramrod data */
1618 list_for_each_entry(elem, exe_chunk, link) {
1619 cmd = elem->cmd_data.vlan_mac.cmd;
1620 /* We will add to the target object in MOVE command, so
1621 * change the object for a CAM search.
1623 if (cmd == BNX2X_VLAN_MAC_MOVE)
1624 cam_obj = elem->cmd_data.vlan_mac.target_obj;
1628 rc = bnx2x_vlan_mac_get_registry_elem(bp, cam_obj,
1636 /* Push a new entry into the registry */
1638 ((cmd == BNX2X_VLAN_MAC_ADD) ||
1639 (cmd == BNX2X_VLAN_MAC_MOVE)))
1640 list_add(®_elem->link, &cam_obj->head);
1642 /* Configure a single command in a ramrod data buffer */
1643 o->set_one_rule(bp, o, elem, idx,
1644 reg_elem->cam_offset);
1646 /* MOVE command consumes 2 entries in the ramrod data */
1647 if (cmd == BNX2X_VLAN_MAC_MOVE)
1653 /* No need for an explicit memory barrier here as long we would
1654 * need to ensure the ordering of writing to the SPQ element
1655 * and updating of the SPQ producer which involves a memory
1656 * read and we will have to put a full memory barrier there
1657 * (inside bnx2x_sp_post()).
1660 rc = bnx2x_sp_post(bp, o->ramrod_cmd, r->cid,
1661 U64_HI(r->rdata_mapping),
1662 U64_LO(r->rdata_mapping),
1663 ETH_CONNECTION_TYPE);
1668 /* Now, when we are done with the ramrod - clean up the registry */
1669 list_for_each_entry(elem, exe_chunk, link) {
1670 cmd = elem->cmd_data.vlan_mac.cmd;
1671 if ((cmd == BNX2X_VLAN_MAC_DEL) ||
1672 (cmd == BNX2X_VLAN_MAC_MOVE)) {
1673 reg_elem = o->check_del(bp, o,
1674 &elem->cmd_data.vlan_mac.u);
1678 o->put_cam_offset(o, reg_elem->cam_offset);
1679 list_del(®_elem->link);
1690 r->clear_pending(r);
1692 /* Cleanup a registry in case of a failure */
1693 list_for_each_entry(elem, exe_chunk, link) {
1694 cmd = elem->cmd_data.vlan_mac.cmd;
1696 if (cmd == BNX2X_VLAN_MAC_MOVE)
1697 cam_obj = elem->cmd_data.vlan_mac.target_obj;
1701 /* Delete all newly added above entries */
1703 ((cmd == BNX2X_VLAN_MAC_ADD) ||
1704 (cmd == BNX2X_VLAN_MAC_MOVE))) {
1705 reg_elem = o->check_del(bp, cam_obj,
1706 &elem->cmd_data.vlan_mac.u);
1708 list_del(®_elem->link);
1717 static inline int bnx2x_vlan_mac_push_new_cmd(
1719 struct bnx2x_vlan_mac_ramrod_params *p)
1721 struct bnx2x_exeq_elem *elem;
1722 struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
1723 bool restore = test_bit(RAMROD_RESTORE, &p->ramrod_flags);
1725 /* Allocate the execution queue element */
1726 elem = bnx2x_exe_queue_alloc_elem(bp);
1730 /* Set the command 'length' */
1731 switch (p->user_req.cmd) {
1732 case BNX2X_VLAN_MAC_MOVE:
1739 /* Fill the object specific info */
1740 memcpy(&elem->cmd_data.vlan_mac, &p->user_req, sizeof(p->user_req));
1742 /* Try to add a new command to the pending list */
1743 return bnx2x_exe_queue_add(bp, &o->exe_queue, elem, restore);
1747 * bnx2x_config_vlan_mac - configure VLAN/MAC/VLAN_MAC filtering rules.
1749 * @bp: device handle
1753 int bnx2x_config_vlan_mac(struct bnx2x *bp,
1754 struct bnx2x_vlan_mac_ramrod_params *p)
1757 struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
1758 unsigned long *ramrod_flags = &p->ramrod_flags;
1759 bool cont = test_bit(RAMROD_CONT, ramrod_flags);
1760 struct bnx2x_raw_obj *raw = &o->raw;
1763 * Add new elements to the execution list for commands that require it.
1766 rc = bnx2x_vlan_mac_push_new_cmd(bp, p);
1771 /* If nothing will be executed further in this iteration we want to
1772 * return PENDING if there are pending commands
1774 if (!bnx2x_exe_queue_empty(&o->exe_queue))
1777 if (test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags)) {
1778 DP(BNX2X_MSG_SP, "RAMROD_DRV_CLR_ONLY requested: clearing a pending bit.\n");
1779 raw->clear_pending(raw);
1782 /* Execute commands if required */
1783 if (cont || test_bit(RAMROD_EXEC, ramrod_flags) ||
1784 test_bit(RAMROD_COMP_WAIT, ramrod_flags)) {
1785 rc = __bnx2x_vlan_mac_execute_step(bp, p->vlan_mac_obj,
1791 /* RAMROD_COMP_WAIT is a superset of RAMROD_EXEC. If it was set
1792 * then user want to wait until the last command is done.
1794 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags)) {
1795 /* Wait maximum for the current exe_queue length iterations plus
1796 * one (for the current pending command).
1798 int max_iterations = bnx2x_exe_queue_length(&o->exe_queue) + 1;
1800 while (!bnx2x_exe_queue_empty(&o->exe_queue) &&
1803 /* Wait for the current command to complete */
1804 rc = raw->wait_comp(bp, raw);
1808 /* Make a next step */
1809 rc = __bnx2x_vlan_mac_execute_step(bp,
1823 * bnx2x_vlan_mac_del_all - delete elements with given vlan_mac_flags spec
1825 * @bp: device handle
1828 * @ramrod_flags: execution flags to be used for this deletion
1830 * if the last operation has completed successfully and there are no
1831 * more elements left, positive value if the last operation has completed
1832 * successfully and there are more previously configured elements, negative
1833 * value is current operation has failed.
1835 static int bnx2x_vlan_mac_del_all(struct bnx2x *bp,
1836 struct bnx2x_vlan_mac_obj *o,
1837 unsigned long *vlan_mac_flags,
1838 unsigned long *ramrod_flags)
1840 struct bnx2x_vlan_mac_registry_elem *pos = NULL;
1841 struct bnx2x_vlan_mac_ramrod_params p;
1842 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1843 struct bnx2x_exeq_elem *exeq_pos, *exeq_pos_n;
1844 unsigned long flags;
1848 /* Clear pending commands first */
1850 spin_lock_bh(&exeq->lock);
1852 list_for_each_entry_safe(exeq_pos, exeq_pos_n, &exeq->exe_queue, link) {
1853 flags = exeq_pos->cmd_data.vlan_mac.vlan_mac_flags;
1854 if (BNX2X_VLAN_MAC_CMP_FLAGS(flags) ==
1855 BNX2X_VLAN_MAC_CMP_FLAGS(*vlan_mac_flags)) {
1856 rc = exeq->remove(bp, exeq->owner, exeq_pos);
1858 BNX2X_ERR("Failed to remove command\n");
1859 spin_unlock_bh(&exeq->lock);
1862 list_del(&exeq_pos->link);
1863 bnx2x_exe_queue_free_elem(bp, exeq_pos);
1867 spin_unlock_bh(&exeq->lock);
1869 /* Prepare a command request */
1870 memset(&p, 0, sizeof(p));
1872 p.ramrod_flags = *ramrod_flags;
1873 p.user_req.cmd = BNX2X_VLAN_MAC_DEL;
1875 /* Add all but the last VLAN-MAC to the execution queue without actually
1876 * execution anything.
1878 __clear_bit(RAMROD_COMP_WAIT, &p.ramrod_flags);
1879 __clear_bit(RAMROD_EXEC, &p.ramrod_flags);
1880 __clear_bit(RAMROD_CONT, &p.ramrod_flags);
1882 DP(BNX2X_MSG_SP, "vlan_mac_del_all -- taking vlan_mac_lock (reader)\n");
1883 read_lock = bnx2x_vlan_mac_h_read_lock(bp, o);
1887 list_for_each_entry(pos, &o->head, link) {
1888 flags = pos->vlan_mac_flags;
1889 if (BNX2X_VLAN_MAC_CMP_FLAGS(flags) ==
1890 BNX2X_VLAN_MAC_CMP_FLAGS(*vlan_mac_flags)) {
1891 p.user_req.vlan_mac_flags = pos->vlan_mac_flags;
1892 memcpy(&p.user_req.u, &pos->u, sizeof(pos->u));
1893 rc = bnx2x_config_vlan_mac(bp, &p);
1895 BNX2X_ERR("Failed to add a new DEL command\n");
1896 bnx2x_vlan_mac_h_read_unlock(bp, o);
1902 DP(BNX2X_MSG_SP, "vlan_mac_del_all -- releasing vlan_mac_lock (reader)\n");
1903 bnx2x_vlan_mac_h_read_unlock(bp, o);
1905 p.ramrod_flags = *ramrod_flags;
1906 __set_bit(RAMROD_CONT, &p.ramrod_flags);
1908 return bnx2x_config_vlan_mac(bp, &p);
1911 static inline void bnx2x_init_raw_obj(struct bnx2x_raw_obj *raw, u8 cl_id,
1912 u32 cid, u8 func_id, void *rdata, dma_addr_t rdata_mapping, int state,
1913 unsigned long *pstate, bnx2x_obj_type type)
1915 raw->func_id = func_id;
1919 raw->rdata_mapping = rdata_mapping;
1921 raw->pstate = pstate;
1922 raw->obj_type = type;
1923 raw->check_pending = bnx2x_raw_check_pending;
1924 raw->clear_pending = bnx2x_raw_clear_pending;
1925 raw->set_pending = bnx2x_raw_set_pending;
1926 raw->wait_comp = bnx2x_raw_wait;
1929 static inline void bnx2x_init_vlan_mac_common(struct bnx2x_vlan_mac_obj *o,
1930 u8 cl_id, u32 cid, u8 func_id, void *rdata, dma_addr_t rdata_mapping,
1931 int state, unsigned long *pstate, bnx2x_obj_type type,
1932 struct bnx2x_credit_pool_obj *macs_pool,
1933 struct bnx2x_credit_pool_obj *vlans_pool)
1935 INIT_LIST_HEAD(&o->head);
1937 o->head_exe_request = false;
1938 o->saved_ramrod_flags = 0;
1940 o->macs_pool = macs_pool;
1941 o->vlans_pool = vlans_pool;
1943 o->delete_all = bnx2x_vlan_mac_del_all;
1944 o->restore = bnx2x_vlan_mac_restore;
1945 o->complete = bnx2x_complete_vlan_mac;
1946 o->wait = bnx2x_wait_vlan_mac;
1948 bnx2x_init_raw_obj(&o->raw, cl_id, cid, func_id, rdata, rdata_mapping,
1949 state, pstate, type);
1952 void bnx2x_init_mac_obj(struct bnx2x *bp,
1953 struct bnx2x_vlan_mac_obj *mac_obj,
1954 u8 cl_id, u32 cid, u8 func_id, void *rdata,
1955 dma_addr_t rdata_mapping, int state,
1956 unsigned long *pstate, bnx2x_obj_type type,
1957 struct bnx2x_credit_pool_obj *macs_pool)
1959 union bnx2x_qable_obj *qable_obj = (union bnx2x_qable_obj *)mac_obj;
1961 bnx2x_init_vlan_mac_common(mac_obj, cl_id, cid, func_id, rdata,
1962 rdata_mapping, state, pstate, type,
1965 /* CAM credit pool handling */
1966 mac_obj->get_credit = bnx2x_get_credit_mac;
1967 mac_obj->put_credit = bnx2x_put_credit_mac;
1968 mac_obj->get_cam_offset = bnx2x_get_cam_offset_mac;
1969 mac_obj->put_cam_offset = bnx2x_put_cam_offset_mac;
1971 if (CHIP_IS_E1x(bp)) {
1972 mac_obj->set_one_rule = bnx2x_set_one_mac_e1x;
1973 mac_obj->check_del = bnx2x_check_mac_del;
1974 mac_obj->check_add = bnx2x_check_mac_add;
1975 mac_obj->check_move = bnx2x_check_move_always_err;
1976 mac_obj->ramrod_cmd = RAMROD_CMD_ID_ETH_SET_MAC;
1979 bnx2x_exe_queue_init(bp,
1980 &mac_obj->exe_queue, 1, qable_obj,
1981 bnx2x_validate_vlan_mac,
1982 bnx2x_remove_vlan_mac,
1983 bnx2x_optimize_vlan_mac,
1984 bnx2x_execute_vlan_mac,
1985 bnx2x_exeq_get_mac);
1987 mac_obj->set_one_rule = bnx2x_set_one_mac_e2;
1988 mac_obj->check_del = bnx2x_check_mac_del;
1989 mac_obj->check_add = bnx2x_check_mac_add;
1990 mac_obj->check_move = bnx2x_check_move;
1991 mac_obj->ramrod_cmd =
1992 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
1993 mac_obj->get_n_elements = bnx2x_get_n_elements;
1996 bnx2x_exe_queue_init(bp,
1997 &mac_obj->exe_queue, CLASSIFY_RULES_COUNT,
1998 qable_obj, bnx2x_validate_vlan_mac,
1999 bnx2x_remove_vlan_mac,
2000 bnx2x_optimize_vlan_mac,
2001 bnx2x_execute_vlan_mac,
2002 bnx2x_exeq_get_mac);
2006 void bnx2x_init_vlan_obj(struct bnx2x *bp,
2007 struct bnx2x_vlan_mac_obj *vlan_obj,
2008 u8 cl_id, u32 cid, u8 func_id, void *rdata,
2009 dma_addr_t rdata_mapping, int state,
2010 unsigned long *pstate, bnx2x_obj_type type,
2011 struct bnx2x_credit_pool_obj *vlans_pool)
2013 union bnx2x_qable_obj *qable_obj = (union bnx2x_qable_obj *)vlan_obj;
2015 bnx2x_init_vlan_mac_common(vlan_obj, cl_id, cid, func_id, rdata,
2016 rdata_mapping, state, pstate, type, NULL,
2019 vlan_obj->get_credit = bnx2x_get_credit_vlan;
2020 vlan_obj->put_credit = bnx2x_put_credit_vlan;
2021 vlan_obj->get_cam_offset = bnx2x_get_cam_offset_vlan;
2022 vlan_obj->put_cam_offset = bnx2x_put_cam_offset_vlan;
2024 if (CHIP_IS_E1x(bp)) {
2025 BNX2X_ERR("Do not support chips others than E2 and newer\n");
2028 vlan_obj->set_one_rule = bnx2x_set_one_vlan_e2;
2029 vlan_obj->check_del = bnx2x_check_vlan_del;
2030 vlan_obj->check_add = bnx2x_check_vlan_add;
2031 vlan_obj->check_move = bnx2x_check_move;
2032 vlan_obj->ramrod_cmd =
2033 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
2034 vlan_obj->get_n_elements = bnx2x_get_n_elements;
2037 bnx2x_exe_queue_init(bp,
2038 &vlan_obj->exe_queue, CLASSIFY_RULES_COUNT,
2039 qable_obj, bnx2x_validate_vlan_mac,
2040 bnx2x_remove_vlan_mac,
2041 bnx2x_optimize_vlan_mac,
2042 bnx2x_execute_vlan_mac,
2043 bnx2x_exeq_get_vlan);
2047 /* RX_MODE verbs: DROP_ALL/ACCEPT_ALL/ACCEPT_ALL_MULTI/ACCEPT_ALL_VLAN/NORMAL */
2048 static inline void __storm_memset_mac_filters(struct bnx2x *bp,
2049 struct tstorm_eth_mac_filter_config *mac_filters,
2052 size_t size = sizeof(struct tstorm_eth_mac_filter_config);
2054 u32 addr = BAR_TSTRORM_INTMEM +
2055 TSTORM_MAC_FILTER_CONFIG_OFFSET(pf_id);
2057 __storm_memset_struct(bp, addr, size, (u32 *)mac_filters);
2060 static int bnx2x_set_rx_mode_e1x(struct bnx2x *bp,
2061 struct bnx2x_rx_mode_ramrod_params *p)
2063 /* update the bp MAC filter structure */
2064 u32 mask = (1 << p->cl_id);
2066 struct tstorm_eth_mac_filter_config *mac_filters =
2067 (struct tstorm_eth_mac_filter_config *)p->rdata;
2069 /* initial setting is drop-all */
2070 u8 drop_all_ucast = 1, drop_all_mcast = 1;
2071 u8 accp_all_ucast = 0, accp_all_bcast = 0, accp_all_mcast = 0;
2072 u8 unmatched_unicast = 0;
2074 /* In e1x there we only take into account rx accept flag since tx switching
2076 if (test_bit(BNX2X_ACCEPT_UNICAST, &p->rx_accept_flags))
2077 /* accept matched ucast */
2080 if (test_bit(BNX2X_ACCEPT_MULTICAST, &p->rx_accept_flags))
2081 /* accept matched mcast */
2084 if (test_bit(BNX2X_ACCEPT_ALL_UNICAST, &p->rx_accept_flags)) {
2085 /* accept all mcast */
2089 if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST, &p->rx_accept_flags)) {
2090 /* accept all mcast */
2094 if (test_bit(BNX2X_ACCEPT_BROADCAST, &p->rx_accept_flags))
2095 /* accept (all) bcast */
2097 if (test_bit(BNX2X_ACCEPT_UNMATCHED, &p->rx_accept_flags))
2098 /* accept unmatched unicasts */
2099 unmatched_unicast = 1;
2101 mac_filters->ucast_drop_all = drop_all_ucast ?
2102 mac_filters->ucast_drop_all | mask :
2103 mac_filters->ucast_drop_all & ~mask;
2105 mac_filters->mcast_drop_all = drop_all_mcast ?
2106 mac_filters->mcast_drop_all | mask :
2107 mac_filters->mcast_drop_all & ~mask;
2109 mac_filters->ucast_accept_all = accp_all_ucast ?
2110 mac_filters->ucast_accept_all | mask :
2111 mac_filters->ucast_accept_all & ~mask;
2113 mac_filters->mcast_accept_all = accp_all_mcast ?
2114 mac_filters->mcast_accept_all | mask :
2115 mac_filters->mcast_accept_all & ~mask;
2117 mac_filters->bcast_accept_all = accp_all_bcast ?
2118 mac_filters->bcast_accept_all | mask :
2119 mac_filters->bcast_accept_all & ~mask;
2121 mac_filters->unmatched_unicast = unmatched_unicast ?
2122 mac_filters->unmatched_unicast | mask :
2123 mac_filters->unmatched_unicast & ~mask;
2125 DP(BNX2X_MSG_SP, "drop_ucast 0x%x\ndrop_mcast 0x%x\n accp_ucast 0x%x\n"
2126 "accp_mcast 0x%x\naccp_bcast 0x%x\n",
2127 mac_filters->ucast_drop_all, mac_filters->mcast_drop_all,
2128 mac_filters->ucast_accept_all, mac_filters->mcast_accept_all,
2129 mac_filters->bcast_accept_all);
2131 /* write the MAC filter structure*/
2132 __storm_memset_mac_filters(bp, mac_filters, p->func_id);
2134 /* The operation is completed */
2135 clear_bit(p->state, p->pstate);
2136 smp_mb__after_atomic();
2141 /* Setup ramrod data */
2142 static inline void bnx2x_rx_mode_set_rdata_hdr_e2(u32 cid,
2143 struct eth_classify_header *hdr,
2146 hdr->echo = cpu_to_le32(cid);
2147 hdr->rule_cnt = rule_cnt;
2150 static inline void bnx2x_rx_mode_set_cmd_state_e2(struct bnx2x *bp,
2151 unsigned long *accept_flags,
2152 struct eth_filter_rules_cmd *cmd,
2153 bool clear_accept_all)
2157 /* start with 'drop-all' */
2158 state = ETH_FILTER_RULES_CMD_UCAST_DROP_ALL |
2159 ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
2161 if (test_bit(BNX2X_ACCEPT_UNICAST, accept_flags))
2162 state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
2164 if (test_bit(BNX2X_ACCEPT_MULTICAST, accept_flags))
2165 state &= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
2167 if (test_bit(BNX2X_ACCEPT_ALL_UNICAST, accept_flags)) {
2168 state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
2169 state |= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL;
2172 if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST, accept_flags)) {
2173 state |= ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL;
2174 state &= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
2177 if (test_bit(BNX2X_ACCEPT_BROADCAST, accept_flags))
2178 state |= ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL;
2180 if (test_bit(BNX2X_ACCEPT_UNMATCHED, accept_flags)) {
2181 state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
2182 state |= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED;
2185 if (test_bit(BNX2X_ACCEPT_ANY_VLAN, accept_flags))
2186 state |= ETH_FILTER_RULES_CMD_ACCEPT_ANY_VLAN;
2188 /* Clear ACCEPT_ALL_XXX flags for FCoE L2 Queue */
2189 if (clear_accept_all) {
2190 state &= ~ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL;
2191 state &= ~ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL;
2192 state &= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL;
2193 state &= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED;
2196 cmd->state = cpu_to_le16(state);
2199 static int bnx2x_set_rx_mode_e2(struct bnx2x *bp,
2200 struct bnx2x_rx_mode_ramrod_params *p)
2202 struct eth_filter_rules_ramrod_data *data = p->rdata;
2206 /* Reset the ramrod data buffer */
2207 memset(data, 0, sizeof(*data));
2209 /* Setup ramrod data */
2211 /* Tx (internal switching) */
2212 if (test_bit(RAMROD_TX, &p->ramrod_flags)) {
2213 data->rules[rule_idx].client_id = p->cl_id;
2214 data->rules[rule_idx].func_id = p->func_id;
2216 data->rules[rule_idx].cmd_general_data =
2217 ETH_FILTER_RULES_CMD_TX_CMD;
2219 bnx2x_rx_mode_set_cmd_state_e2(bp, &p->tx_accept_flags,
2220 &(data->rules[rule_idx++]),
2225 if (test_bit(RAMROD_RX, &p->ramrod_flags)) {
2226 data->rules[rule_idx].client_id = p->cl_id;
2227 data->rules[rule_idx].func_id = p->func_id;
2229 data->rules[rule_idx].cmd_general_data =
2230 ETH_FILTER_RULES_CMD_RX_CMD;
2232 bnx2x_rx_mode_set_cmd_state_e2(bp, &p->rx_accept_flags,
2233 &(data->rules[rule_idx++]),
2237 /* If FCoE Queue configuration has been requested configure the Rx and
2238 * internal switching modes for this queue in separate rules.
2240 * FCoE queue shell never be set to ACCEPT_ALL packets of any sort:
2241 * MCAST_ALL, UCAST_ALL, BCAST_ALL and UNMATCHED.
2243 if (test_bit(BNX2X_RX_MODE_FCOE_ETH, &p->rx_mode_flags)) {
2244 /* Tx (internal switching) */
2245 if (test_bit(RAMROD_TX, &p->ramrod_flags)) {
2246 data->rules[rule_idx].client_id = bnx2x_fcoe(bp, cl_id);
2247 data->rules[rule_idx].func_id = p->func_id;
2249 data->rules[rule_idx].cmd_general_data =
2250 ETH_FILTER_RULES_CMD_TX_CMD;
2252 bnx2x_rx_mode_set_cmd_state_e2(bp, &p->tx_accept_flags,
2253 &(data->rules[rule_idx]),
2259 if (test_bit(RAMROD_RX, &p->ramrod_flags)) {
2260 data->rules[rule_idx].client_id = bnx2x_fcoe(bp, cl_id);
2261 data->rules[rule_idx].func_id = p->func_id;
2263 data->rules[rule_idx].cmd_general_data =
2264 ETH_FILTER_RULES_CMD_RX_CMD;
2266 bnx2x_rx_mode_set_cmd_state_e2(bp, &p->rx_accept_flags,
2267 &(data->rules[rule_idx]),
2273 /* Set the ramrod header (most importantly - number of rules to
2276 bnx2x_rx_mode_set_rdata_hdr_e2(p->cid, &data->header, rule_idx);
2278 DP(BNX2X_MSG_SP, "About to configure %d rules, rx_accept_flags 0x%lx, tx_accept_flags 0x%lx\n",
2279 data->header.rule_cnt, p->rx_accept_flags,
2280 p->tx_accept_flags);
2282 /* No need for an explicit memory barrier here as long as we
2283 * ensure the ordering of writing to the SPQ element
2284 * and updating of the SPQ producer which involves a memory
2285 * read. If the memory read is removed we will have to put a
2286 * full memory barrier there (inside bnx2x_sp_post()).
2290 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_FILTER_RULES, p->cid,
2291 U64_HI(p->rdata_mapping),
2292 U64_LO(p->rdata_mapping),
2293 ETH_CONNECTION_TYPE);
2297 /* Ramrod completion is pending */
2301 static int bnx2x_wait_rx_mode_comp_e2(struct bnx2x *bp,
2302 struct bnx2x_rx_mode_ramrod_params *p)
2304 return bnx2x_state_wait(bp, p->state, p->pstate);
2307 static int bnx2x_empty_rx_mode_wait(struct bnx2x *bp,
2308 struct bnx2x_rx_mode_ramrod_params *p)
2314 int bnx2x_config_rx_mode(struct bnx2x *bp,
2315 struct bnx2x_rx_mode_ramrod_params *p)
2319 /* Configure the new classification in the chip */
2320 rc = p->rx_mode_obj->config_rx_mode(bp, p);
2324 /* Wait for a ramrod completion if was requested */
2325 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags)) {
2326 rc = p->rx_mode_obj->wait_comp(bp, p);
2334 void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
2335 struct bnx2x_rx_mode_obj *o)
2337 if (CHIP_IS_E1x(bp)) {
2338 o->wait_comp = bnx2x_empty_rx_mode_wait;
2339 o->config_rx_mode = bnx2x_set_rx_mode_e1x;
2341 o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
2342 o->config_rx_mode = bnx2x_set_rx_mode_e2;
2346 /********************* Multicast verbs: SET, CLEAR ****************************/
2347 static inline u8 bnx2x_mcast_bin_from_mac(u8 *mac)
2349 return (crc32c_le(0, mac, ETH_ALEN) >> 24) & 0xff;
2352 struct bnx2x_mcast_mac_elem {
2353 struct list_head link;
2355 u8 pad[2]; /* For a natural alignment of the following buffer */
2358 struct bnx2x_pending_mcast_cmd {
2359 struct list_head link;
2360 int type; /* BNX2X_MCAST_CMD_X */
2362 struct list_head macs_head;
2363 u32 macs_num; /* Needed for DEL command */
2364 int next_bin; /* Needed for RESTORE flow with aprox match */
2367 bool done; /* set to true, when the command has been handled,
2368 * practically used in 57712 handling only, where one pending
2369 * command may be handled in a few operations. As long as for
2370 * other chips every operation handling is completed in a
2371 * single ramrod, there is no need to utilize this field.
2375 static int bnx2x_mcast_wait(struct bnx2x *bp,
2376 struct bnx2x_mcast_obj *o)
2378 if (bnx2x_state_wait(bp, o->sched_state, o->raw.pstate) ||
2379 o->raw.wait_comp(bp, &o->raw))
2385 static int bnx2x_mcast_enqueue_cmd(struct bnx2x *bp,
2386 struct bnx2x_mcast_obj *o,
2387 struct bnx2x_mcast_ramrod_params *p,
2388 enum bnx2x_mcast_cmd cmd)
2391 struct bnx2x_pending_mcast_cmd *new_cmd;
2392 struct bnx2x_mcast_mac_elem *cur_mac = NULL;
2393 struct bnx2x_mcast_list_elem *pos;
2394 int macs_list_len = ((cmd == BNX2X_MCAST_CMD_ADD) ?
2395 p->mcast_list_len : 0);
2397 /* If the command is empty ("handle pending commands only"), break */
2398 if (!p->mcast_list_len)
2401 total_sz = sizeof(*new_cmd) +
2402 macs_list_len * sizeof(struct bnx2x_mcast_mac_elem);
2404 /* Add mcast is called under spin_lock, thus calling with GFP_ATOMIC */
2405 new_cmd = kzalloc(total_sz, GFP_ATOMIC);
2410 DP(BNX2X_MSG_SP, "About to enqueue a new %d command. macs_list_len=%d\n",
2411 cmd, macs_list_len);
2413 INIT_LIST_HEAD(&new_cmd->data.macs_head);
2415 new_cmd->type = cmd;
2416 new_cmd->done = false;
2419 case BNX2X_MCAST_CMD_ADD:
2420 cur_mac = (struct bnx2x_mcast_mac_elem *)
2421 ((u8 *)new_cmd + sizeof(*new_cmd));
2423 /* Push the MACs of the current command into the pending command
2426 list_for_each_entry(pos, &p->mcast_list, link) {
2427 memcpy(cur_mac->mac, pos->mac, ETH_ALEN);
2428 list_add_tail(&cur_mac->link, &new_cmd->data.macs_head);
2434 case BNX2X_MCAST_CMD_DEL:
2435 new_cmd->data.macs_num = p->mcast_list_len;
2438 case BNX2X_MCAST_CMD_RESTORE:
2439 new_cmd->data.next_bin = 0;
2444 BNX2X_ERR("Unknown command: %d\n", cmd);
2448 /* Push the new pending command to the tail of the pending list: FIFO */
2449 list_add_tail(&new_cmd->link, &o->pending_cmds_head);
2457 * bnx2x_mcast_get_next_bin - get the next set bin (index)
2460 * @last: index to start looking from (including)
2462 * returns the next found (set) bin or a negative value if none is found.
2464 static inline int bnx2x_mcast_get_next_bin(struct bnx2x_mcast_obj *o, int last)
2466 int i, j, inner_start = last % BIT_VEC64_ELEM_SZ;
2468 for (i = last / BIT_VEC64_ELEM_SZ; i < BNX2X_MCAST_VEC_SZ; i++) {
2469 if (o->registry.aprox_match.vec[i])
2470 for (j = inner_start; j < BIT_VEC64_ELEM_SZ; j++) {
2471 int cur_bit = j + BIT_VEC64_ELEM_SZ * i;
2472 if (BIT_VEC64_TEST_BIT(o->registry.aprox_match.
2485 * bnx2x_mcast_clear_first_bin - find the first set bin and clear it
2489 * returns the index of the found bin or -1 if none is found
2491 static inline int bnx2x_mcast_clear_first_bin(struct bnx2x_mcast_obj *o)
2493 int cur_bit = bnx2x_mcast_get_next_bin(o, 0);
2496 BIT_VEC64_CLEAR_BIT(o->registry.aprox_match.vec, cur_bit);
2501 static inline u8 bnx2x_mcast_get_rx_tx_flag(struct bnx2x_mcast_obj *o)
2503 struct bnx2x_raw_obj *raw = &o->raw;
2506 if ((raw->obj_type == BNX2X_OBJ_TYPE_TX) ||
2507 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
2508 rx_tx_flag |= ETH_MULTICAST_RULES_CMD_TX_CMD;
2510 if ((raw->obj_type == BNX2X_OBJ_TYPE_RX) ||
2511 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
2512 rx_tx_flag |= ETH_MULTICAST_RULES_CMD_RX_CMD;
2517 static void bnx2x_mcast_set_one_rule_e2(struct bnx2x *bp,
2518 struct bnx2x_mcast_obj *o, int idx,
2519 union bnx2x_mcast_config_data *cfg_data,
2520 enum bnx2x_mcast_cmd cmd)
2522 struct bnx2x_raw_obj *r = &o->raw;
2523 struct eth_multicast_rules_ramrod_data *data =
2524 (struct eth_multicast_rules_ramrod_data *)(r->rdata);
2525 u8 func_id = r->func_id;
2526 u8 rx_tx_add_flag = bnx2x_mcast_get_rx_tx_flag(o);
2529 if ((cmd == BNX2X_MCAST_CMD_ADD) || (cmd == BNX2X_MCAST_CMD_RESTORE))
2530 rx_tx_add_flag |= ETH_MULTICAST_RULES_CMD_IS_ADD;
2532 data->rules[idx].cmd_general_data |= rx_tx_add_flag;
2534 /* Get a bin and update a bins' vector */
2536 case BNX2X_MCAST_CMD_ADD:
2537 bin = bnx2x_mcast_bin_from_mac(cfg_data->mac);
2538 BIT_VEC64_SET_BIT(o->registry.aprox_match.vec, bin);
2541 case BNX2X_MCAST_CMD_DEL:
2542 /* If there were no more bins to clear
2543 * (bnx2x_mcast_clear_first_bin() returns -1) then we would
2544 * clear any (0xff) bin.
2545 * See bnx2x_mcast_validate_e2() for explanation when it may
2548 bin = bnx2x_mcast_clear_first_bin(o);
2551 case BNX2X_MCAST_CMD_RESTORE:
2552 bin = cfg_data->bin;
2556 BNX2X_ERR("Unknown command: %d\n", cmd);
2560 DP(BNX2X_MSG_SP, "%s bin %d\n",
2561 ((rx_tx_add_flag & ETH_MULTICAST_RULES_CMD_IS_ADD) ?
2562 "Setting" : "Clearing"), bin);
2564 data->rules[idx].bin_id = (u8)bin;
2565 data->rules[idx].func_id = func_id;
2566 data->rules[idx].engine_id = o->engine_id;
2570 * bnx2x_mcast_handle_restore_cmd_e2 - restore configuration from the registry
2572 * @bp: device handle
2574 * @start_bin: index in the registry to start from (including)
2575 * @rdata_idx: index in the ramrod data to start from
2577 * returns last handled bin index or -1 if all bins have been handled
2579 static inline int bnx2x_mcast_handle_restore_cmd_e2(
2580 struct bnx2x *bp, struct bnx2x_mcast_obj *o , int start_bin,
2583 int cur_bin, cnt = *rdata_idx;
2584 union bnx2x_mcast_config_data cfg_data = {NULL};
2586 /* go through the registry and configure the bins from it */
2587 for (cur_bin = bnx2x_mcast_get_next_bin(o, start_bin); cur_bin >= 0;
2588 cur_bin = bnx2x_mcast_get_next_bin(o, cur_bin + 1)) {
2590 cfg_data.bin = (u8)cur_bin;
2591 o->set_one_rule(bp, o, cnt, &cfg_data,
2592 BNX2X_MCAST_CMD_RESTORE);
2596 DP(BNX2X_MSG_SP, "About to configure a bin %d\n", cur_bin);
2598 /* Break if we reached the maximum number
2601 if (cnt >= o->max_cmd_len)
2610 static inline void bnx2x_mcast_hdl_pending_add_e2(struct bnx2x *bp,
2611 struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
2614 struct bnx2x_mcast_mac_elem *pmac_pos, *pmac_pos_n;
2615 int cnt = *line_idx;
2616 union bnx2x_mcast_config_data cfg_data = {NULL};
2618 list_for_each_entry_safe(pmac_pos, pmac_pos_n, &cmd_pos->data.macs_head,
2621 cfg_data.mac = &pmac_pos->mac[0];
2622 o->set_one_rule(bp, o, cnt, &cfg_data, cmd_pos->type);
2626 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
2629 list_del(&pmac_pos->link);
2631 /* Break if we reached the maximum number
2634 if (cnt >= o->max_cmd_len)
2640 /* if no more MACs to configure - we are done */
2641 if (list_empty(&cmd_pos->data.macs_head))
2642 cmd_pos->done = true;
2645 static inline void bnx2x_mcast_hdl_pending_del_e2(struct bnx2x *bp,
2646 struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
2649 int cnt = *line_idx;
2651 while (cmd_pos->data.macs_num) {
2652 o->set_one_rule(bp, o, cnt, NULL, cmd_pos->type);
2656 cmd_pos->data.macs_num--;
2658 DP(BNX2X_MSG_SP, "Deleting MAC. %d left,cnt is %d\n",
2659 cmd_pos->data.macs_num, cnt);
2661 /* Break if we reached the maximum
2664 if (cnt >= o->max_cmd_len)
2670 /* If we cleared all bins - we are done */
2671 if (!cmd_pos->data.macs_num)
2672 cmd_pos->done = true;
2675 static inline void bnx2x_mcast_hdl_pending_restore_e2(struct bnx2x *bp,
2676 struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
2679 cmd_pos->data.next_bin = o->hdl_restore(bp, o, cmd_pos->data.next_bin,
2682 if (cmd_pos->data.next_bin < 0)
2683 /* If o->set_restore returned -1 we are done */
2684 cmd_pos->done = true;
2686 /* Start from the next bin next time */
2687 cmd_pos->data.next_bin++;
2690 static inline int bnx2x_mcast_handle_pending_cmds_e2(struct bnx2x *bp,
2691 struct bnx2x_mcast_ramrod_params *p)
2693 struct bnx2x_pending_mcast_cmd *cmd_pos, *cmd_pos_n;
2695 struct bnx2x_mcast_obj *o = p->mcast_obj;
2697 list_for_each_entry_safe(cmd_pos, cmd_pos_n, &o->pending_cmds_head,
2699 switch (cmd_pos->type) {
2700 case BNX2X_MCAST_CMD_ADD:
2701 bnx2x_mcast_hdl_pending_add_e2(bp, o, cmd_pos, &cnt);
2704 case BNX2X_MCAST_CMD_DEL:
2705 bnx2x_mcast_hdl_pending_del_e2(bp, o, cmd_pos, &cnt);
2708 case BNX2X_MCAST_CMD_RESTORE:
2709 bnx2x_mcast_hdl_pending_restore_e2(bp, o, cmd_pos,
2714 BNX2X_ERR("Unknown command: %d\n", cmd_pos->type);
2718 /* If the command has been completed - remove it from the list
2719 * and free the memory
2721 if (cmd_pos->done) {
2722 list_del(&cmd_pos->link);
2726 /* Break if we reached the maximum number of rules */
2727 if (cnt >= o->max_cmd_len)
2734 static inline void bnx2x_mcast_hdl_add(struct bnx2x *bp,
2735 struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
2738 struct bnx2x_mcast_list_elem *mlist_pos;
2739 union bnx2x_mcast_config_data cfg_data = {NULL};
2740 int cnt = *line_idx;
2742 list_for_each_entry(mlist_pos, &p->mcast_list, link) {
2743 cfg_data.mac = mlist_pos->mac;
2744 o->set_one_rule(bp, o, cnt, &cfg_data, BNX2X_MCAST_CMD_ADD);
2748 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
2755 static inline void bnx2x_mcast_hdl_del(struct bnx2x *bp,
2756 struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
2759 int cnt = *line_idx, i;
2761 for (i = 0; i < p->mcast_list_len; i++) {
2762 o->set_one_rule(bp, o, cnt, NULL, BNX2X_MCAST_CMD_DEL);
2766 DP(BNX2X_MSG_SP, "Deleting MAC. %d left\n",
2767 p->mcast_list_len - i - 1);
2774 * bnx2x_mcast_handle_current_cmd -
2776 * @bp: device handle
2779 * @start_cnt: first line in the ramrod data that may be used
2781 * This function is called iff there is enough place for the current command in
2783 * Returns number of lines filled in the ramrod data in total.
2785 static inline int bnx2x_mcast_handle_current_cmd(struct bnx2x *bp,
2786 struct bnx2x_mcast_ramrod_params *p,
2787 enum bnx2x_mcast_cmd cmd,
2790 struct bnx2x_mcast_obj *o = p->mcast_obj;
2791 int cnt = start_cnt;
2793 DP(BNX2X_MSG_SP, "p->mcast_list_len=%d\n", p->mcast_list_len);
2796 case BNX2X_MCAST_CMD_ADD:
2797 bnx2x_mcast_hdl_add(bp, o, p, &cnt);
2800 case BNX2X_MCAST_CMD_DEL:
2801 bnx2x_mcast_hdl_del(bp, o, p, &cnt);
2804 case BNX2X_MCAST_CMD_RESTORE:
2805 o->hdl_restore(bp, o, 0, &cnt);
2809 BNX2X_ERR("Unknown command: %d\n", cmd);
2813 /* The current command has been handled */
2814 p->mcast_list_len = 0;
2819 static int bnx2x_mcast_validate_e2(struct bnx2x *bp,
2820 struct bnx2x_mcast_ramrod_params *p,
2821 enum bnx2x_mcast_cmd cmd)
2823 struct bnx2x_mcast_obj *o = p->mcast_obj;
2824 int reg_sz = o->get_registry_size(o);
2827 /* DEL command deletes all currently configured MACs */
2828 case BNX2X_MCAST_CMD_DEL:
2829 o->set_registry_size(o, 0);
2832 /* RESTORE command will restore the entire multicast configuration */
2833 case BNX2X_MCAST_CMD_RESTORE:
2834 /* Here we set the approximate amount of work to do, which in
2835 * fact may be only less as some MACs in postponed ADD
2836 * command(s) scheduled before this command may fall into
2837 * the same bin and the actual number of bins set in the
2838 * registry would be less than we estimated here. See
2839 * bnx2x_mcast_set_one_rule_e2() for further details.
2841 p->mcast_list_len = reg_sz;
2844 case BNX2X_MCAST_CMD_ADD:
2845 case BNX2X_MCAST_CMD_CONT:
2846 /* Here we assume that all new MACs will fall into new bins.
2847 * However we will correct the real registry size after we
2848 * handle all pending commands.
2850 o->set_registry_size(o, reg_sz + p->mcast_list_len);
2854 BNX2X_ERR("Unknown command: %d\n", cmd);
2858 /* Increase the total number of MACs pending to be configured */
2859 o->total_pending_num += p->mcast_list_len;
2864 static void bnx2x_mcast_revert_e2(struct bnx2x *bp,
2865 struct bnx2x_mcast_ramrod_params *p,
2868 struct bnx2x_mcast_obj *o = p->mcast_obj;
2870 o->set_registry_size(o, old_num_bins);
2871 o->total_pending_num -= p->mcast_list_len;
2875 * bnx2x_mcast_set_rdata_hdr_e2 - sets a header values
2877 * @bp: device handle
2879 * @len: number of rules to handle
2881 static inline void bnx2x_mcast_set_rdata_hdr_e2(struct bnx2x *bp,
2882 struct bnx2x_mcast_ramrod_params *p,
2885 struct bnx2x_raw_obj *r = &p->mcast_obj->raw;
2886 struct eth_multicast_rules_ramrod_data *data =
2887 (struct eth_multicast_rules_ramrod_data *)(r->rdata);
2889 data->header.echo = cpu_to_le32((r->cid & BNX2X_SWCID_MASK) |
2890 (BNX2X_FILTER_MCAST_PENDING <<
2891 BNX2X_SWCID_SHIFT));
2892 data->header.rule_cnt = len;
2896 * bnx2x_mcast_refresh_registry_e2 - recalculate the actual number of set bins
2898 * @bp: device handle
2901 * Recalculate the actual number of set bins in the registry using Brian
2902 * Kernighan's algorithm: it's execution complexity is as a number of set bins.
2904 * returns 0 for the compliance with bnx2x_mcast_refresh_registry_e1().
2906 static inline int bnx2x_mcast_refresh_registry_e2(struct bnx2x *bp,
2907 struct bnx2x_mcast_obj *o)
2912 for (i = 0; i < BNX2X_MCAST_VEC_SZ; i++) {
2913 elem = o->registry.aprox_match.vec[i];
2918 o->set_registry_size(o, cnt);
2923 static int bnx2x_mcast_setup_e2(struct bnx2x *bp,
2924 struct bnx2x_mcast_ramrod_params *p,
2925 enum bnx2x_mcast_cmd cmd)
2927 struct bnx2x_raw_obj *raw = &p->mcast_obj->raw;
2928 struct bnx2x_mcast_obj *o = p->mcast_obj;
2929 struct eth_multicast_rules_ramrod_data *data =
2930 (struct eth_multicast_rules_ramrod_data *)(raw->rdata);
2933 /* Reset the ramrod data buffer */
2934 memset(data, 0, sizeof(*data));
2936 cnt = bnx2x_mcast_handle_pending_cmds_e2(bp, p);
2938 /* If there are no more pending commands - clear SCHEDULED state */
2939 if (list_empty(&o->pending_cmds_head))
2942 /* The below may be true iff there was enough room in ramrod
2943 * data for all pending commands and for the current
2944 * command. Otherwise the current command would have been added
2945 * to the pending commands and p->mcast_list_len would have been
2948 if (p->mcast_list_len > 0)
2949 cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, cnt);
2951 /* We've pulled out some MACs - update the total number of
2954 o->total_pending_num -= cnt;
2957 WARN_ON(o->total_pending_num < 0);
2958 WARN_ON(cnt > o->max_cmd_len);
2960 bnx2x_mcast_set_rdata_hdr_e2(bp, p, (u8)cnt);
2962 /* Update a registry size if there are no more pending operations.
2964 * We don't want to change the value of the registry size if there are
2965 * pending operations because we want it to always be equal to the
2966 * exact or the approximate number (see bnx2x_mcast_validate_e2()) of
2967 * set bins after the last requested operation in order to properly
2968 * evaluate the size of the next DEL/RESTORE operation.
2970 * Note that we update the registry itself during command(s) handling
2971 * - see bnx2x_mcast_set_one_rule_e2(). That's because for 57712 we
2972 * aggregate multiple commands (ADD/DEL/RESTORE) into one ramrod but
2973 * with a limited amount of update commands (per MAC/bin) and we don't
2974 * know in this scope what the actual state of bins configuration is
2975 * going to be after this ramrod.
2977 if (!o->total_pending_num)
2978 bnx2x_mcast_refresh_registry_e2(bp, o);
2980 /* If CLEAR_ONLY was requested - don't send a ramrod and clear
2981 * RAMROD_PENDING status immediately.
2983 if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
2984 raw->clear_pending(raw);
2987 /* No need for an explicit memory barrier here as long as we
2988 * ensure the ordering of writing to the SPQ element
2989 * and updating of the SPQ producer which involves a memory
2990 * read. If the memory read is removed we will have to put a
2991 * full memory barrier there (inside bnx2x_sp_post()).
2995 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_MULTICAST_RULES,
2996 raw->cid, U64_HI(raw->rdata_mapping),
2997 U64_LO(raw->rdata_mapping),
2998 ETH_CONNECTION_TYPE);
3002 /* Ramrod completion is pending */
3007 static int bnx2x_mcast_validate_e1h(struct bnx2x *bp,
3008 struct bnx2x_mcast_ramrod_params *p,
3009 enum bnx2x_mcast_cmd cmd)
3011 /* Mark, that there is a work to do */
3012 if ((cmd == BNX2X_MCAST_CMD_DEL) || (cmd == BNX2X_MCAST_CMD_RESTORE))
3013 p->mcast_list_len = 1;
3018 static void bnx2x_mcast_revert_e1h(struct bnx2x *bp,
3019 struct bnx2x_mcast_ramrod_params *p,
3025 #define BNX2X_57711_SET_MC_FILTER(filter, bit) \
3027 (filter)[(bit) >> 5] |= (1 << ((bit) & 0x1f)); \
3030 static inline void bnx2x_mcast_hdl_add_e1h(struct bnx2x *bp,
3031 struct bnx2x_mcast_obj *o,
3032 struct bnx2x_mcast_ramrod_params *p,
3035 struct bnx2x_mcast_list_elem *mlist_pos;
3038 list_for_each_entry(mlist_pos, &p->mcast_list, link) {
3039 bit = bnx2x_mcast_bin_from_mac(mlist_pos->mac);
3040 BNX2X_57711_SET_MC_FILTER(mc_filter, bit);
3042 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC, bin %d\n",
3043 mlist_pos->mac, bit);
3045 /* bookkeeping... */
3046 BIT_VEC64_SET_BIT(o->registry.aprox_match.vec,
3051 static inline void bnx2x_mcast_hdl_restore_e1h(struct bnx2x *bp,
3052 struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
3057 for (bit = bnx2x_mcast_get_next_bin(o, 0);
3059 bit = bnx2x_mcast_get_next_bin(o, bit + 1)) {
3060 BNX2X_57711_SET_MC_FILTER(mc_filter, bit);
3061 DP(BNX2X_MSG_SP, "About to set bin %d\n", bit);
3065 /* On 57711 we write the multicast MACs' approximate match
3066 * table by directly into the TSTORM's internal RAM. So we don't
3067 * really need to handle any tricks to make it work.
3069 static int bnx2x_mcast_setup_e1h(struct bnx2x *bp,
3070 struct bnx2x_mcast_ramrod_params *p,
3071 enum bnx2x_mcast_cmd cmd)
3074 struct bnx2x_mcast_obj *o = p->mcast_obj;
3075 struct bnx2x_raw_obj *r = &o->raw;
3077 /* If CLEAR_ONLY has been requested - clear the registry
3078 * and clear a pending bit.
3080 if (!test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
3081 u32 mc_filter[MC_HASH_SIZE] = {0};
3083 /* Set the multicast filter bits before writing it into
3084 * the internal memory.
3087 case BNX2X_MCAST_CMD_ADD:
3088 bnx2x_mcast_hdl_add_e1h(bp, o, p, mc_filter);
3091 case BNX2X_MCAST_CMD_DEL:
3093 "Invalidating multicast MACs configuration\n");
3095 /* clear the registry */
3096 memset(o->registry.aprox_match.vec, 0,
3097 sizeof(o->registry.aprox_match.vec));
3100 case BNX2X_MCAST_CMD_RESTORE:
3101 bnx2x_mcast_hdl_restore_e1h(bp, o, p, mc_filter);
3105 BNX2X_ERR("Unknown command: %d\n", cmd);
3109 /* Set the mcast filter in the internal memory */
3110 for (i = 0; i < MC_HASH_SIZE; i++)
3111 REG_WR(bp, MC_HASH_OFFSET(bp, i), mc_filter[i]);
3113 /* clear the registry */
3114 memset(o->registry.aprox_match.vec, 0,
3115 sizeof(o->registry.aprox_match.vec));
3118 r->clear_pending(r);
3123 static int bnx2x_mcast_validate_e1(struct bnx2x *bp,
3124 struct bnx2x_mcast_ramrod_params *p,
3125 enum bnx2x_mcast_cmd cmd)
3127 struct bnx2x_mcast_obj *o = p->mcast_obj;
3128 int reg_sz = o->get_registry_size(o);
3131 /* DEL command deletes all currently configured MACs */
3132 case BNX2X_MCAST_CMD_DEL:
3133 o->set_registry_size(o, 0);
3136 /* RESTORE command will restore the entire multicast configuration */
3137 case BNX2X_MCAST_CMD_RESTORE:
3138 p->mcast_list_len = reg_sz;
3139 DP(BNX2X_MSG_SP, "Command %d, p->mcast_list_len=%d\n",
3140 cmd, p->mcast_list_len);
3143 case BNX2X_MCAST_CMD_ADD:
3144 case BNX2X_MCAST_CMD_CONT:
3145 /* Multicast MACs on 57710 are configured as unicast MACs and
3146 * there is only a limited number of CAM entries for that
3149 if (p->mcast_list_len > o->max_cmd_len) {
3150 BNX2X_ERR("Can't configure more than %d multicast MACs on 57710\n",
3154 /* Every configured MAC should be cleared if DEL command is
3155 * called. Only the last ADD command is relevant as long as
3156 * every ADD commands overrides the previous configuration.
3158 DP(BNX2X_MSG_SP, "p->mcast_list_len=%d\n", p->mcast_list_len);
3159 if (p->mcast_list_len > 0)
3160 o->set_registry_size(o, p->mcast_list_len);
3165 BNX2X_ERR("Unknown command: %d\n", cmd);
3169 /* We want to ensure that commands are executed one by one for 57710.
3170 * Therefore each none-empty command will consume o->max_cmd_len.
3172 if (p->mcast_list_len)
3173 o->total_pending_num += o->max_cmd_len;
3178 static void bnx2x_mcast_revert_e1(struct bnx2x *bp,
3179 struct bnx2x_mcast_ramrod_params *p,
3182 struct bnx2x_mcast_obj *o = p->mcast_obj;
3184 o->set_registry_size(o, old_num_macs);
3186 /* If current command hasn't been handled yet and we are
3187 * here means that it's meant to be dropped and we have to
3188 * update the number of outstanding MACs accordingly.
3190 if (p->mcast_list_len)
3191 o->total_pending_num -= o->max_cmd_len;
3194 static void bnx2x_mcast_set_one_rule_e1(struct bnx2x *bp,
3195 struct bnx2x_mcast_obj *o, int idx,
3196 union bnx2x_mcast_config_data *cfg_data,
3197 enum bnx2x_mcast_cmd cmd)
3199 struct bnx2x_raw_obj *r = &o->raw;
3200 struct mac_configuration_cmd *data =
3201 (struct mac_configuration_cmd *)(r->rdata);
3204 if ((cmd == BNX2X_MCAST_CMD_ADD) || (cmd == BNX2X_MCAST_CMD_RESTORE)) {
3205 bnx2x_set_fw_mac_addr(&data->config_table[idx].msb_mac_addr,
3206 &data->config_table[idx].middle_mac_addr,
3207 &data->config_table[idx].lsb_mac_addr,
3210 data->config_table[idx].vlan_id = 0;
3211 data->config_table[idx].pf_id = r->func_id;
3212 data->config_table[idx].clients_bit_vector =
3213 cpu_to_le32(1 << r->cl_id);
3215 SET_FLAG(data->config_table[idx].flags,
3216 MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
3217 T_ETH_MAC_COMMAND_SET);
3222 * bnx2x_mcast_set_rdata_hdr_e1 - set header values in mac_configuration_cmd
3224 * @bp: device handle
3226 * @len: number of rules to handle
3228 static inline void bnx2x_mcast_set_rdata_hdr_e1(struct bnx2x *bp,
3229 struct bnx2x_mcast_ramrod_params *p,
3232 struct bnx2x_raw_obj *r = &p->mcast_obj->raw;
3233 struct mac_configuration_cmd *data =
3234 (struct mac_configuration_cmd *)(r->rdata);
3236 u8 offset = (CHIP_REV_IS_SLOW(bp) ?
3237 BNX2X_MAX_EMUL_MULTI*(1 + r->func_id) :
3238 BNX2X_MAX_MULTICAST*(1 + r->func_id));
3240 data->hdr.offset = offset;
3241 data->hdr.client_id = cpu_to_le16(0xff);
3242 data->hdr.echo = cpu_to_le32((r->cid & BNX2X_SWCID_MASK) |
3243 (BNX2X_FILTER_MCAST_PENDING <<
3244 BNX2X_SWCID_SHIFT));
3245 data->hdr.length = len;
3249 * bnx2x_mcast_handle_restore_cmd_e1 - restore command for 57710
3251 * @bp: device handle
3253 * @start_idx: index in the registry to start from
3254 * @rdata_idx: index in the ramrod data to start from
3256 * restore command for 57710 is like all other commands - always a stand alone
3257 * command - start_idx and rdata_idx will always be 0. This function will always
3259 * returns -1 to comply with 57712 variant.
3261 static inline int bnx2x_mcast_handle_restore_cmd_e1(
3262 struct bnx2x *bp, struct bnx2x_mcast_obj *o , int start_idx,
3265 struct bnx2x_mcast_mac_elem *elem;
3267 union bnx2x_mcast_config_data cfg_data = {NULL};
3269 /* go through the registry and configure the MACs from it. */
3270 list_for_each_entry(elem, &o->registry.exact_match.macs, link) {
3271 cfg_data.mac = &elem->mac[0];
3272 o->set_one_rule(bp, o, i, &cfg_data, BNX2X_MCAST_CMD_RESTORE);
3276 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
3285 static inline int bnx2x_mcast_handle_pending_cmds_e1(
3286 struct bnx2x *bp, struct bnx2x_mcast_ramrod_params *p)
3288 struct bnx2x_pending_mcast_cmd *cmd_pos;
3289 struct bnx2x_mcast_mac_elem *pmac_pos;
3290 struct bnx2x_mcast_obj *o = p->mcast_obj;
3291 union bnx2x_mcast_config_data cfg_data = {NULL};
3294 /* If nothing to be done - return */
3295 if (list_empty(&o->pending_cmds_head))
3298 /* Handle the first command */
3299 cmd_pos = list_first_entry(&o->pending_cmds_head,
3300 struct bnx2x_pending_mcast_cmd, link);
3302 switch (cmd_pos->type) {
3303 case BNX2X_MCAST_CMD_ADD:
3304 list_for_each_entry(pmac_pos, &cmd_pos->data.macs_head, link) {
3305 cfg_data.mac = &pmac_pos->mac[0];
3306 o->set_one_rule(bp, o, cnt, &cfg_data, cmd_pos->type);
3310 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
3315 case BNX2X_MCAST_CMD_DEL:
3316 cnt = cmd_pos->data.macs_num;
3317 DP(BNX2X_MSG_SP, "About to delete %d multicast MACs\n", cnt);
3320 case BNX2X_MCAST_CMD_RESTORE:
3321 o->hdl_restore(bp, o, 0, &cnt);
3325 BNX2X_ERR("Unknown command: %d\n", cmd_pos->type);
3329 list_del(&cmd_pos->link);
3336 * bnx2x_get_fw_mac_addr - revert the bnx2x_set_fw_mac_addr().
3343 static inline void bnx2x_get_fw_mac_addr(__le16 *fw_hi, __le16 *fw_mid,
3344 __le16 *fw_lo, u8 *mac)
3346 mac[1] = ((u8 *)fw_hi)[0];
3347 mac[0] = ((u8 *)fw_hi)[1];
3348 mac[3] = ((u8 *)fw_mid)[0];
3349 mac[2] = ((u8 *)fw_mid)[1];
3350 mac[5] = ((u8 *)fw_lo)[0];
3351 mac[4] = ((u8 *)fw_lo)[1];
3355 * bnx2x_mcast_refresh_registry_e1 -
3357 * @bp: device handle
3360 * Check the ramrod data first entry flag to see if it's a DELETE or ADD command
3361 * and update the registry correspondingly: if ADD - allocate a memory and add
3362 * the entries to the registry (list), if DELETE - clear the registry and free
3365 static inline int bnx2x_mcast_refresh_registry_e1(struct bnx2x *bp,
3366 struct bnx2x_mcast_obj *o)
3368 struct bnx2x_raw_obj *raw = &o->raw;
3369 struct bnx2x_mcast_mac_elem *elem;
3370 struct mac_configuration_cmd *data =
3371 (struct mac_configuration_cmd *)(raw->rdata);
3373 /* If first entry contains a SET bit - the command was ADD,
3374 * otherwise - DEL_ALL
3376 if (GET_FLAG(data->config_table[0].flags,
3377 MAC_CONFIGURATION_ENTRY_ACTION_TYPE)) {
3378 int i, len = data->hdr.length;
3380 /* Break if it was a RESTORE command */
3381 if (!list_empty(&o->registry.exact_match.macs))
3384 elem = kcalloc(len, sizeof(*elem), GFP_ATOMIC);
3386 BNX2X_ERR("Failed to allocate registry memory\n");
3390 for (i = 0; i < len; i++, elem++) {
3391 bnx2x_get_fw_mac_addr(
3392 &data->config_table[i].msb_mac_addr,
3393 &data->config_table[i].middle_mac_addr,
3394 &data->config_table[i].lsb_mac_addr,
3396 DP(BNX2X_MSG_SP, "Adding registry entry for [%pM]\n",
3398 list_add_tail(&elem->link,
3399 &o->registry.exact_match.macs);
3402 elem = list_first_entry(&o->registry.exact_match.macs,
3403 struct bnx2x_mcast_mac_elem, link);
3404 DP(BNX2X_MSG_SP, "Deleting a registry\n");
3406 INIT_LIST_HEAD(&o->registry.exact_match.macs);
3412 static int bnx2x_mcast_setup_e1(struct bnx2x *bp,
3413 struct bnx2x_mcast_ramrod_params *p,
3414 enum bnx2x_mcast_cmd cmd)
3416 struct bnx2x_mcast_obj *o = p->mcast_obj;
3417 struct bnx2x_raw_obj *raw = &o->raw;
3418 struct mac_configuration_cmd *data =
3419 (struct mac_configuration_cmd *)(raw->rdata);
3422 /* Reset the ramrod data buffer */
3423 memset(data, 0, sizeof(*data));
3425 /* First set all entries as invalid */
3426 for (i = 0; i < o->max_cmd_len ; i++)
3427 SET_FLAG(data->config_table[i].flags,
3428 MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
3429 T_ETH_MAC_COMMAND_INVALIDATE);
3431 /* Handle pending commands first */
3432 cnt = bnx2x_mcast_handle_pending_cmds_e1(bp, p);
3434 /* If there are no more pending commands - clear SCHEDULED state */
3435 if (list_empty(&o->pending_cmds_head))
3438 /* The below may be true iff there were no pending commands */
3440 cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, 0);
3442 /* For 57710 every command has o->max_cmd_len length to ensure that
3443 * commands are done one at a time.
3445 o->total_pending_num -= o->max_cmd_len;
3449 WARN_ON(cnt > o->max_cmd_len);
3451 /* Set ramrod header (in particular, a number of entries to update) */
3452 bnx2x_mcast_set_rdata_hdr_e1(bp, p, (u8)cnt);
3454 /* update a registry: we need the registry contents to be always up
3455 * to date in order to be able to execute a RESTORE opcode. Here
3456 * we use the fact that for 57710 we sent one command at a time
3457 * hence we may take the registry update out of the command handling
3458 * and do it in a simpler way here.
3460 rc = bnx2x_mcast_refresh_registry_e1(bp, o);
3464 /* If CLEAR_ONLY was requested - don't send a ramrod and clear
3465 * RAMROD_PENDING status immediately.
3467 if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
3468 raw->clear_pending(raw);
3471 /* No need for an explicit memory barrier here as long as we
3472 * ensure the ordering of writing to the SPQ element
3473 * and updating of the SPQ producer which involves a memory
3474 * read. If the memory read is removed we will have to put a
3475 * full memory barrier there (inside bnx2x_sp_post()).
3479 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, raw->cid,
3480 U64_HI(raw->rdata_mapping),
3481 U64_LO(raw->rdata_mapping),
3482 ETH_CONNECTION_TYPE);
3486 /* Ramrod completion is pending */
3491 static int bnx2x_mcast_get_registry_size_exact(struct bnx2x_mcast_obj *o)
3493 return o->registry.exact_match.num_macs_set;
3496 static int bnx2x_mcast_get_registry_size_aprox(struct bnx2x_mcast_obj *o)
3498 return o->registry.aprox_match.num_bins_set;
3501 static void bnx2x_mcast_set_registry_size_exact(struct bnx2x_mcast_obj *o,
3504 o->registry.exact_match.num_macs_set = n;
3507 static void bnx2x_mcast_set_registry_size_aprox(struct bnx2x_mcast_obj *o,
3510 o->registry.aprox_match.num_bins_set = n;
3513 int bnx2x_config_mcast(struct bnx2x *bp,
3514 struct bnx2x_mcast_ramrod_params *p,
3515 enum bnx2x_mcast_cmd cmd)
3517 struct bnx2x_mcast_obj *o = p->mcast_obj;
3518 struct bnx2x_raw_obj *r = &o->raw;
3519 int rc = 0, old_reg_size;
3521 /* This is needed to recover number of currently configured mcast macs
3522 * in case of failure.
3524 old_reg_size = o->get_registry_size(o);
3526 /* Do some calculations and checks */
3527 rc = o->validate(bp, p, cmd);
3531 /* Return if there is no work to do */
3532 if ((!p->mcast_list_len) && (!o->check_sched(o)))
3535 DP(BNX2X_MSG_SP, "o->total_pending_num=%d p->mcast_list_len=%d o->max_cmd_len=%d\n",
3536 o->total_pending_num, p->mcast_list_len, o->max_cmd_len);
3538 /* Enqueue the current command to the pending list if we can't complete
3539 * it in the current iteration
3541 if (r->check_pending(r) ||
3542 ((o->max_cmd_len > 0) && (o->total_pending_num > o->max_cmd_len))) {
3543 rc = o->enqueue_cmd(bp, p->mcast_obj, p, cmd);
3547 /* As long as the current command is in a command list we
3548 * don't need to handle it separately.
3550 p->mcast_list_len = 0;
3553 if (!r->check_pending(r)) {
3555 /* Set 'pending' state */
3558 /* Configure the new classification in the chip */
3559 rc = o->config_mcast(bp, p, cmd);
3563 /* Wait for a ramrod completion if was requested */
3564 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags))
3565 rc = o->wait_comp(bp, o);
3571 r->clear_pending(r);
3574 o->revert(bp, p, old_reg_size);
3579 static void bnx2x_mcast_clear_sched(struct bnx2x_mcast_obj *o)
3581 smp_mb__before_atomic();
3582 clear_bit(o->sched_state, o->raw.pstate);
3583 smp_mb__after_atomic();
3586 static void bnx2x_mcast_set_sched(struct bnx2x_mcast_obj *o)
3588 smp_mb__before_atomic();
3589 set_bit(o->sched_state, o->raw.pstate);
3590 smp_mb__after_atomic();
3593 static bool bnx2x_mcast_check_sched(struct bnx2x_mcast_obj *o)
3595 return !!test_bit(o->sched_state, o->raw.pstate);
3598 static bool bnx2x_mcast_check_pending(struct bnx2x_mcast_obj *o)
3600 return o->raw.check_pending(&o->raw) || o->check_sched(o);
3603 void bnx2x_init_mcast_obj(struct bnx2x *bp,
3604 struct bnx2x_mcast_obj *mcast_obj,
3605 u8 mcast_cl_id, u32 mcast_cid, u8 func_id,
3606 u8 engine_id, void *rdata, dma_addr_t rdata_mapping,
3607 int state, unsigned long *pstate, bnx2x_obj_type type)
3609 memset(mcast_obj, 0, sizeof(*mcast_obj));
3611 bnx2x_init_raw_obj(&mcast_obj->raw, mcast_cl_id, mcast_cid, func_id,
3612 rdata, rdata_mapping, state, pstate, type);
3614 mcast_obj->engine_id = engine_id;
3616 INIT_LIST_HEAD(&mcast_obj->pending_cmds_head);
3618 mcast_obj->sched_state = BNX2X_FILTER_MCAST_SCHED;
3619 mcast_obj->check_sched = bnx2x_mcast_check_sched;
3620 mcast_obj->set_sched = bnx2x_mcast_set_sched;
3621 mcast_obj->clear_sched = bnx2x_mcast_clear_sched;
3623 if (CHIP_IS_E1(bp)) {
3624 mcast_obj->config_mcast = bnx2x_mcast_setup_e1;
3625 mcast_obj->enqueue_cmd = bnx2x_mcast_enqueue_cmd;
3626 mcast_obj->hdl_restore =
3627 bnx2x_mcast_handle_restore_cmd_e1;
3628 mcast_obj->check_pending = bnx2x_mcast_check_pending;
3630 if (CHIP_REV_IS_SLOW(bp))
3631 mcast_obj->max_cmd_len = BNX2X_MAX_EMUL_MULTI;
3633 mcast_obj->max_cmd_len = BNX2X_MAX_MULTICAST;
3635 mcast_obj->wait_comp = bnx2x_mcast_wait;
3636 mcast_obj->set_one_rule = bnx2x_mcast_set_one_rule_e1;
3637 mcast_obj->validate = bnx2x_mcast_validate_e1;
3638 mcast_obj->revert = bnx2x_mcast_revert_e1;
3639 mcast_obj->get_registry_size =
3640 bnx2x_mcast_get_registry_size_exact;
3641 mcast_obj->set_registry_size =
3642 bnx2x_mcast_set_registry_size_exact;
3644 /* 57710 is the only chip that uses the exact match for mcast
3647 INIT_LIST_HEAD(&mcast_obj->registry.exact_match.macs);
3649 } else if (CHIP_IS_E1H(bp)) {
3650 mcast_obj->config_mcast = bnx2x_mcast_setup_e1h;
3651 mcast_obj->enqueue_cmd = NULL;
3652 mcast_obj->hdl_restore = NULL;
3653 mcast_obj->check_pending = bnx2x_mcast_check_pending;
3655 /* 57711 doesn't send a ramrod, so it has unlimited credit
3658 mcast_obj->max_cmd_len = -1;
3659 mcast_obj->wait_comp = bnx2x_mcast_wait;
3660 mcast_obj->set_one_rule = NULL;
3661 mcast_obj->validate = bnx2x_mcast_validate_e1h;
3662 mcast_obj->revert = bnx2x_mcast_revert_e1h;
3663 mcast_obj->get_registry_size =
3664 bnx2x_mcast_get_registry_size_aprox;
3665 mcast_obj->set_registry_size =
3666 bnx2x_mcast_set_registry_size_aprox;
3668 mcast_obj->config_mcast = bnx2x_mcast_setup_e2;
3669 mcast_obj->enqueue_cmd = bnx2x_mcast_enqueue_cmd;
3670 mcast_obj->hdl_restore =
3671 bnx2x_mcast_handle_restore_cmd_e2;
3672 mcast_obj->check_pending = bnx2x_mcast_check_pending;
3673 /* TODO: There should be a proper HSI define for this number!!!
3675 mcast_obj->max_cmd_len = 16;
3676 mcast_obj->wait_comp = bnx2x_mcast_wait;
3677 mcast_obj->set_one_rule = bnx2x_mcast_set_one_rule_e2;
3678 mcast_obj->validate = bnx2x_mcast_validate_e2;
3679 mcast_obj->revert = bnx2x_mcast_revert_e2;
3680 mcast_obj->get_registry_size =
3681 bnx2x_mcast_get_registry_size_aprox;
3682 mcast_obj->set_registry_size =
3683 bnx2x_mcast_set_registry_size_aprox;
3687 /*************************** Credit handling **********************************/
3690 * atomic_add_ifless - add if the result is less than a given value.
3692 * @v: pointer of type atomic_t
3693 * @a: the amount to add to v...
3694 * @u: ...if (v + a) is less than u.
3696 * returns true if (v + a) was less than u, and false otherwise.
3699 static inline bool __atomic_add_ifless(atomic_t *v, int a, int u)
3705 if (unlikely(c + a >= u))
3708 old = atomic_cmpxchg((v), c, c + a);
3709 if (likely(old == c))
3718 * atomic_dec_ifmoe - dec if the result is more or equal than a given value.
3720 * @v: pointer of type atomic_t
3721 * @a: the amount to dec from v...
3722 * @u: ...if (v - a) is more or equal than u.
3724 * returns true if (v - a) was more or equal than u, and false
3727 static inline bool __atomic_dec_ifmoe(atomic_t *v, int a, int u)
3733 if (unlikely(c - a < u))
3736 old = atomic_cmpxchg((v), c, c - a);
3737 if (likely(old == c))
3745 static bool bnx2x_credit_pool_get(struct bnx2x_credit_pool_obj *o, int cnt)
3750 rc = __atomic_dec_ifmoe(&o->credit, cnt, 0);
3756 static bool bnx2x_credit_pool_put(struct bnx2x_credit_pool_obj *o, int cnt)
3762 /* Don't let to refill if credit + cnt > pool_sz */
3763 rc = __atomic_add_ifless(&o->credit, cnt, o->pool_sz + 1);
3770 static int bnx2x_credit_pool_check(struct bnx2x_credit_pool_obj *o)
3775 cur_credit = atomic_read(&o->credit);
3780 static bool bnx2x_credit_pool_always_true(struct bnx2x_credit_pool_obj *o,
3786 static bool bnx2x_credit_pool_get_entry(
3787 struct bnx2x_credit_pool_obj *o,
3794 /* Find "internal cam-offset" then add to base for this object... */
3795 for (vec = 0; vec < BNX2X_POOL_VEC_SIZE; vec++) {
3797 /* Skip the current vector if there are no free entries in it */
3798 if (!o->pool_mirror[vec])
3801 /* If we've got here we are going to find a free entry */
3802 for (idx = vec * BIT_VEC64_ELEM_SZ, i = 0;
3803 i < BIT_VEC64_ELEM_SZ; idx++, i++)
3805 if (BIT_VEC64_TEST_BIT(o->pool_mirror, idx)) {
3807 BIT_VEC64_CLEAR_BIT(o->pool_mirror, idx);
3808 *offset = o->base_pool_offset + idx;
3816 static bool bnx2x_credit_pool_put_entry(
3817 struct bnx2x_credit_pool_obj *o,
3820 if (offset < o->base_pool_offset)
3823 offset -= o->base_pool_offset;
3825 if (offset >= o->pool_sz)
3828 /* Return the entry to the pool */
3829 BIT_VEC64_SET_BIT(o->pool_mirror, offset);
3834 static bool bnx2x_credit_pool_put_entry_always_true(
3835 struct bnx2x_credit_pool_obj *o,
3841 static bool bnx2x_credit_pool_get_entry_always_true(
3842 struct bnx2x_credit_pool_obj *o,
3849 * bnx2x_init_credit_pool - initialize credit pool internals.
3852 * @base: Base entry in the CAM to use.
3853 * @credit: pool size.
3855 * If base is negative no CAM entries handling will be performed.
3856 * If credit is negative pool operations will always succeed (unlimited pool).
3859 static inline void bnx2x_init_credit_pool(struct bnx2x_credit_pool_obj *p,
3860 int base, int credit)
3862 /* Zero the object first */
3863 memset(p, 0, sizeof(*p));
3865 /* Set the table to all 1s */
3866 memset(&p->pool_mirror, 0xff, sizeof(p->pool_mirror));
3868 /* Init a pool as full */
3869 atomic_set(&p->credit, credit);
3871 /* The total poll size */
3872 p->pool_sz = credit;
3874 p->base_pool_offset = base;
3876 /* Commit the change */
3879 p->check = bnx2x_credit_pool_check;
3881 /* if pool credit is negative - disable the checks */
3883 p->put = bnx2x_credit_pool_put;
3884 p->get = bnx2x_credit_pool_get;
3885 p->put_entry = bnx2x_credit_pool_put_entry;
3886 p->get_entry = bnx2x_credit_pool_get_entry;
3888 p->put = bnx2x_credit_pool_always_true;
3889 p->get = bnx2x_credit_pool_always_true;
3890 p->put_entry = bnx2x_credit_pool_put_entry_always_true;
3891 p->get_entry = bnx2x_credit_pool_get_entry_always_true;
3894 /* If base is negative - disable entries handling */
3896 p->put_entry = bnx2x_credit_pool_put_entry_always_true;
3897 p->get_entry = bnx2x_credit_pool_get_entry_always_true;
3901 void bnx2x_init_mac_credit_pool(struct bnx2x *bp,
3902 struct bnx2x_credit_pool_obj *p, u8 func_id,
3905 /* TODO: this will be defined in consts as well... */
3906 #define BNX2X_CAM_SIZE_EMUL 5
3910 if (CHIP_IS_E1(bp)) {
3911 /* In E1, Multicast is saved in cam... */
3912 if (!CHIP_REV_IS_SLOW(bp))
3913 cam_sz = (MAX_MAC_CREDIT_E1 / 2) - BNX2X_MAX_MULTICAST;
3915 cam_sz = BNX2X_CAM_SIZE_EMUL - BNX2X_MAX_EMUL_MULTI;
3917 bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
3919 } else if (CHIP_IS_E1H(bp)) {
3920 /* CAM credit is equaly divided between all active functions
3923 if ((func_num > 0)) {
3924 if (!CHIP_REV_IS_SLOW(bp))
3925 cam_sz = (MAX_MAC_CREDIT_E1H / (2*func_num));
3927 cam_sz = BNX2X_CAM_SIZE_EMUL;
3928 bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
3930 /* this should never happen! Block MAC operations. */
3931 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;
3945 /* No need for CAM entries handling for 57712 and
3948 bnx2x_init_credit_pool(p, -1, cam_sz);
3950 /* this should never happen! Block MAC operations. */
3951 bnx2x_init_credit_pool(p, 0, 0);
3956 void bnx2x_init_vlan_credit_pool(struct bnx2x *bp,
3957 struct bnx2x_credit_pool_obj *p,
3961 if (CHIP_IS_E1x(bp)) {
3962 /* There is no VLAN credit in HW on 57710 and 57711 only
3963 * MAC / MAC-VLAN can be set
3965 bnx2x_init_credit_pool(p, 0, -1);
3967 /* CAM credit is equally divided between all active functions
3971 int credit = MAX_VLAN_CREDIT_E2 / func_num;
3972 bnx2x_init_credit_pool(p, func_id * credit, credit);
3974 /* this should never happen! Block VLAN operations. */
3975 bnx2x_init_credit_pool(p, 0, 0);
3979 /****************** RSS Configuration ******************/
3981 * bnx2x_debug_print_ind_table - prints the indirection table configuration.
3983 * @bp: driver handle
3984 * @p: pointer to rss configuration
3986 * Prints it when NETIF_MSG_IFUP debug level is configured.
3988 static inline void bnx2x_debug_print_ind_table(struct bnx2x *bp,
3989 struct bnx2x_config_rss_params *p)
3993 DP(BNX2X_MSG_SP, "Setting indirection table to:\n");
3994 DP(BNX2X_MSG_SP, "0x0000: ");
3995 for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++) {
3996 DP_CONT(BNX2X_MSG_SP, "0x%02x ", p->ind_table[i]);
3998 /* Print 4 bytes in a line */
3999 if ((i + 1 < T_ETH_INDIRECTION_TABLE_SIZE) &&
4000 (((i + 1) & 0x3) == 0)) {
4001 DP_CONT(BNX2X_MSG_SP, "\n");
4002 DP(BNX2X_MSG_SP, "0x%04x: ", i + 1);
4006 DP_CONT(BNX2X_MSG_SP, "\n");
4010 * bnx2x_setup_rss - configure RSS
4012 * @bp: device handle
4013 * @p: rss configuration
4015 * sends on UPDATE ramrod for that matter.
4017 static int bnx2x_setup_rss(struct bnx2x *bp,
4018 struct bnx2x_config_rss_params *p)
4020 struct bnx2x_rss_config_obj *o = p->rss_obj;
4021 struct bnx2x_raw_obj *r = &o->raw;
4022 struct eth_rss_update_ramrod_data *data =
4023 (struct eth_rss_update_ramrod_data *)(r->rdata);
4028 memset(data, 0, sizeof(*data));
4030 DP(BNX2X_MSG_SP, "Configuring RSS\n");
4032 /* Set an echo field */
4033 data->echo = cpu_to_le32((r->cid & BNX2X_SWCID_MASK) |
4034 (r->state << BNX2X_SWCID_SHIFT));
4037 if (test_bit(BNX2X_RSS_MODE_DISABLED, &p->rss_flags))
4038 rss_mode = ETH_RSS_MODE_DISABLED;
4039 else if (test_bit(BNX2X_RSS_MODE_REGULAR, &p->rss_flags))
4040 rss_mode = ETH_RSS_MODE_REGULAR;
4042 data->rss_mode = rss_mode;
4044 DP(BNX2X_MSG_SP, "rss_mode=%d\n", rss_mode);
4046 /* RSS capabilities */
4047 if (test_bit(BNX2X_RSS_IPV4, &p->rss_flags))
4048 caps |= ETH_RSS_UPDATE_RAMROD_DATA_IPV4_CAPABILITY;
4050 if (test_bit(BNX2X_RSS_IPV4_TCP, &p->rss_flags))
4051 caps |= ETH_RSS_UPDATE_RAMROD_DATA_IPV4_TCP_CAPABILITY;
4053 if (test_bit(BNX2X_RSS_IPV4_UDP, &p->rss_flags))
4054 caps |= ETH_RSS_UPDATE_RAMROD_DATA_IPV4_UDP_CAPABILITY;
4056 if (test_bit(BNX2X_RSS_IPV6, &p->rss_flags))
4057 caps |= ETH_RSS_UPDATE_RAMROD_DATA_IPV6_CAPABILITY;
4059 if (test_bit(BNX2X_RSS_IPV6_TCP, &p->rss_flags))
4060 caps |= ETH_RSS_UPDATE_RAMROD_DATA_IPV6_TCP_CAPABILITY;
4062 if (test_bit(BNX2X_RSS_IPV6_UDP, &p->rss_flags))
4063 caps |= ETH_RSS_UPDATE_RAMROD_DATA_IPV6_UDP_CAPABILITY;
4065 if (test_bit(BNX2X_RSS_IPV4_VXLAN, &p->rss_flags))
4066 caps |= ETH_RSS_UPDATE_RAMROD_DATA_IPV4_VXLAN_CAPABILITY;
4068 if (test_bit(BNX2X_RSS_IPV6_VXLAN, &p->rss_flags))
4069 caps |= ETH_RSS_UPDATE_RAMROD_DATA_IPV6_VXLAN_CAPABILITY;
4071 if (test_bit(BNX2X_RSS_TUNN_INNER_HDRS, &p->rss_flags))
4072 caps |= ETH_RSS_UPDATE_RAMROD_DATA_TUNN_INNER_HDRS_CAPABILITY;
4075 if (test_bit(BNX2X_RSS_SET_SRCH, &p->rss_flags)) {
4076 memcpy(&data->rss_key[0], &p->rss_key[0],
4077 sizeof(data->rss_key));
4078 caps |= ETH_RSS_UPDATE_RAMROD_DATA_UPDATE_RSS_KEY;
4081 data->capabilities = cpu_to_le16(caps);
4084 data->rss_result_mask = p->rss_result_mask;
4087 data->rss_engine_id = o->engine_id;
4089 DP(BNX2X_MSG_SP, "rss_engine_id=%d\n", data->rss_engine_id);
4091 /* Indirection table */
4092 memcpy(data->indirection_table, p->ind_table,
4093 T_ETH_INDIRECTION_TABLE_SIZE);
4095 /* Remember the last configuration */
4096 memcpy(o->ind_table, p->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
4098 /* Print the indirection table */
4099 if (netif_msg_ifup(bp))
4100 bnx2x_debug_print_ind_table(bp, p);
4102 /* No need for an explicit memory barrier here as long as we
4103 * ensure the ordering of writing to the SPQ element
4104 * and updating of the SPQ producer which involves a memory
4105 * read. If the memory read is removed we will have to put a
4106 * full memory barrier there (inside bnx2x_sp_post()).
4110 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_RSS_UPDATE, r->cid,
4111 U64_HI(r->rdata_mapping),
4112 U64_LO(r->rdata_mapping),
4113 ETH_CONNECTION_TYPE);
4121 void bnx2x_get_rss_ind_table(struct bnx2x_rss_config_obj *rss_obj,
4124 memcpy(ind_table, rss_obj->ind_table, sizeof(rss_obj->ind_table));
4127 int bnx2x_config_rss(struct bnx2x *bp,
4128 struct bnx2x_config_rss_params *p)
4131 struct bnx2x_rss_config_obj *o = p->rss_obj;
4132 struct bnx2x_raw_obj *r = &o->raw;
4134 /* Do nothing if only driver cleanup was requested */
4135 if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
4136 DP(BNX2X_MSG_SP, "Not configuring RSS ramrod_flags=%lx\n",
4143 rc = o->config_rss(bp, p);
4145 r->clear_pending(r);
4149 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags))
4150 rc = r->wait_comp(bp, r);
4155 void bnx2x_init_rss_config_obj(struct bnx2x *bp,
4156 struct bnx2x_rss_config_obj *rss_obj,
4157 u8 cl_id, u32 cid, u8 func_id, u8 engine_id,
4158 void *rdata, dma_addr_t rdata_mapping,
4159 int state, unsigned long *pstate,
4160 bnx2x_obj_type type)
4162 bnx2x_init_raw_obj(&rss_obj->raw, cl_id, cid, func_id, rdata,
4163 rdata_mapping, state, pstate, type);
4165 rss_obj->engine_id = engine_id;
4166 rss_obj->config_rss = bnx2x_setup_rss;
4169 /********************** Queue state object ***********************************/
4172 * bnx2x_queue_state_change - perform Queue state change transition
4174 * @bp: device handle
4175 * @params: parameters to perform the transition
4177 * returns 0 in case of successfully completed transition, negative error
4178 * code in case of failure, positive (EBUSY) value if there is a completion
4179 * to that is still pending (possible only if RAMROD_COMP_WAIT is
4180 * not set in params->ramrod_flags for asynchronous commands).
4183 int bnx2x_queue_state_change(struct bnx2x *bp,
4184 struct bnx2x_queue_state_params *params)
4186 struct bnx2x_queue_sp_obj *o = params->q_obj;
4187 int rc, pending_bit;
4188 unsigned long *pending = &o->pending;
4190 /* Check that the requested transition is legal */
4191 rc = o->check_transition(bp, o, params);
4193 BNX2X_ERR("check transition returned an error. rc %d\n", rc);
4197 /* Set "pending" bit */
4198 DP(BNX2X_MSG_SP, "pending bit was=%lx\n", o->pending);
4199 pending_bit = o->set_pending(o, params);
4200 DP(BNX2X_MSG_SP, "pending bit now=%lx\n", o->pending);
4202 /* Don't send a command if only driver cleanup was requested */
4203 if (test_bit(RAMROD_DRV_CLR_ONLY, ¶ms->ramrod_flags))
4204 o->complete_cmd(bp, o, pending_bit);
4207 rc = o->send_cmd(bp, params);
4209 o->next_state = BNX2X_Q_STATE_MAX;
4210 clear_bit(pending_bit, pending);
4211 smp_mb__after_atomic();
4215 if (test_bit(RAMROD_COMP_WAIT, ¶ms->ramrod_flags)) {
4216 rc = o->wait_comp(bp, o, pending_bit);
4224 return !!test_bit(pending_bit, pending);
4227 static int bnx2x_queue_set_pending(struct bnx2x_queue_sp_obj *obj,
4228 struct bnx2x_queue_state_params *params)
4230 enum bnx2x_queue_cmd cmd = params->cmd, bit;
4232 /* ACTIVATE and DEACTIVATE commands are implemented on top of
4235 if ((cmd == BNX2X_Q_CMD_ACTIVATE) ||
4236 (cmd == BNX2X_Q_CMD_DEACTIVATE))
4237 bit = BNX2X_Q_CMD_UPDATE;
4241 set_bit(bit, &obj->pending);
4245 static int bnx2x_queue_wait_comp(struct bnx2x *bp,
4246 struct bnx2x_queue_sp_obj *o,
4247 enum bnx2x_queue_cmd cmd)
4249 return bnx2x_state_wait(bp, cmd, &o->pending);
4253 * bnx2x_queue_comp_cmd - complete the state change command.
4255 * @bp: device handle
4259 * Checks that the arrived completion is expected.
4261 static int bnx2x_queue_comp_cmd(struct bnx2x *bp,
4262 struct bnx2x_queue_sp_obj *o,
4263 enum bnx2x_queue_cmd cmd)
4265 unsigned long cur_pending = o->pending;
4267 if (!test_and_clear_bit(cmd, &cur_pending)) {
4268 BNX2X_ERR("Bad MC reply %d for queue %d in state %d pending 0x%lx, next_state %d\n",
4269 cmd, o->cids[BNX2X_PRIMARY_CID_INDEX],
4270 o->state, cur_pending, o->next_state);
4274 if (o->next_tx_only >= o->max_cos)
4275 /* >= because tx only must always be smaller than cos since the
4276 * primary connection supports COS 0
4278 BNX2X_ERR("illegal value for next tx_only: %d. max cos was %d",
4279 o->next_tx_only, o->max_cos);
4282 "Completing command %d for queue %d, setting state to %d\n",
4283 cmd, o->cids[BNX2X_PRIMARY_CID_INDEX], o->next_state);
4285 if (o->next_tx_only) /* print num tx-only if any exist */
4286 DP(BNX2X_MSG_SP, "primary cid %d: num tx-only cons %d\n",
4287 o->cids[BNX2X_PRIMARY_CID_INDEX], o->next_tx_only);
4289 o->state = o->next_state;
4290 o->num_tx_only = o->next_tx_only;
4291 o->next_state = BNX2X_Q_STATE_MAX;
4293 /* It's important that o->state and o->next_state are
4294 * updated before o->pending.
4298 clear_bit(cmd, &o->pending);
4299 smp_mb__after_atomic();
4304 static void bnx2x_q_fill_setup_data_e2(struct bnx2x *bp,
4305 struct bnx2x_queue_state_params *cmd_params,
4306 struct client_init_ramrod_data *data)
4308 struct bnx2x_queue_setup_params *params = &cmd_params->params.setup;
4312 /* IPv6 TPA supported for E2 and above only */
4313 data->rx.tpa_en |= test_bit(BNX2X_Q_FLG_TPA_IPV6, ¶ms->flags) *
4314 CLIENT_INIT_RX_DATA_TPA_EN_IPV6;
4317 static void bnx2x_q_fill_init_general_data(struct bnx2x *bp,
4318 struct bnx2x_queue_sp_obj *o,
4319 struct bnx2x_general_setup_params *params,
4320 struct client_init_general_data *gen_data,
4321 unsigned long *flags)
4323 gen_data->client_id = o->cl_id;
4325 if (test_bit(BNX2X_Q_FLG_STATS, flags)) {
4326 gen_data->statistics_counter_id =
4328 gen_data->statistics_en_flg = 1;
4329 gen_data->statistics_zero_flg =
4330 test_bit(BNX2X_Q_FLG_ZERO_STATS, flags);
4332 gen_data->statistics_counter_id =
4333 DISABLE_STATISTIC_COUNTER_ID_VALUE;
4335 gen_data->is_fcoe_flg = test_bit(BNX2X_Q_FLG_FCOE, flags);
4336 gen_data->activate_flg = test_bit(BNX2X_Q_FLG_ACTIVE, flags);
4337 gen_data->sp_client_id = params->spcl_id;
4338 gen_data->mtu = cpu_to_le16(params->mtu);
4339 gen_data->func_id = o->func_id;
4341 gen_data->cos = params->cos;
4343 gen_data->traffic_type =
4344 test_bit(BNX2X_Q_FLG_FCOE, flags) ?
4345 LLFC_TRAFFIC_TYPE_FCOE : LLFC_TRAFFIC_TYPE_NW;
4347 gen_data->fp_hsi_ver = params->fp_hsi;
4349 DP(BNX2X_MSG_SP, "flags: active %d, cos %d, stats en %d\n",
4350 gen_data->activate_flg, gen_data->cos, gen_data->statistics_en_flg);
4353 static void bnx2x_q_fill_init_tx_data(struct bnx2x_queue_sp_obj *o,
4354 struct bnx2x_txq_setup_params *params,
4355 struct client_init_tx_data *tx_data,
4356 unsigned long *flags)
4358 tx_data->enforce_security_flg =
4359 test_bit(BNX2X_Q_FLG_TX_SEC, flags);
4360 tx_data->default_vlan =
4361 cpu_to_le16(params->default_vlan);
4362 tx_data->default_vlan_flg =
4363 test_bit(BNX2X_Q_FLG_DEF_VLAN, flags);
4364 tx_data->tx_switching_flg =
4365 test_bit(BNX2X_Q_FLG_TX_SWITCH, flags);
4366 tx_data->anti_spoofing_flg =
4367 test_bit(BNX2X_Q_FLG_ANTI_SPOOF, flags);
4368 tx_data->force_default_pri_flg =
4369 test_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, flags);
4370 tx_data->refuse_outband_vlan_flg =
4371 test_bit(BNX2X_Q_FLG_REFUSE_OUTBAND_VLAN, flags);
4372 tx_data->tunnel_lso_inc_ip_id =
4373 test_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, flags);
4374 tx_data->tunnel_non_lso_pcsum_location =
4375 test_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, flags) ? CSUM_ON_PKT :
4378 tx_data->tx_status_block_id = params->fw_sb_id;
4379 tx_data->tx_sb_index_number = params->sb_cq_index;
4380 tx_data->tss_leading_client_id = params->tss_leading_cl_id;
4382 tx_data->tx_bd_page_base.lo =
4383 cpu_to_le32(U64_LO(params->dscr_map));
4384 tx_data->tx_bd_page_base.hi =
4385 cpu_to_le32(U64_HI(params->dscr_map));
4387 /* Don't configure any Tx switching mode during queue SETUP */
4391 static void bnx2x_q_fill_init_pause_data(struct bnx2x_queue_sp_obj *o,
4392 struct rxq_pause_params *params,
4393 struct client_init_rx_data *rx_data)
4395 /* flow control data */
4396 rx_data->cqe_pause_thr_low = cpu_to_le16(params->rcq_th_lo);
4397 rx_data->cqe_pause_thr_high = cpu_to_le16(params->rcq_th_hi);
4398 rx_data->bd_pause_thr_low = cpu_to_le16(params->bd_th_lo);
4399 rx_data->bd_pause_thr_high = cpu_to_le16(params->bd_th_hi);
4400 rx_data->sge_pause_thr_low = cpu_to_le16(params->sge_th_lo);
4401 rx_data->sge_pause_thr_high = cpu_to_le16(params->sge_th_hi);
4402 rx_data->rx_cos_mask = cpu_to_le16(params->pri_map);
4405 static void bnx2x_q_fill_init_rx_data(struct bnx2x_queue_sp_obj *o,
4406 struct bnx2x_rxq_setup_params *params,
4407 struct client_init_rx_data *rx_data,
4408 unsigned long *flags)
4410 rx_data->tpa_en = test_bit(BNX2X_Q_FLG_TPA, flags) *
4411 CLIENT_INIT_RX_DATA_TPA_EN_IPV4;
4412 rx_data->tpa_en |= test_bit(BNX2X_Q_FLG_TPA_GRO, flags) *
4413 CLIENT_INIT_RX_DATA_TPA_MODE;
4414 rx_data->vmqueue_mode_en_flg = 0;
4416 rx_data->cache_line_alignment_log_size =
4417 params->cache_line_log;
4418 rx_data->enable_dynamic_hc =
4419 test_bit(BNX2X_Q_FLG_DHC, flags);
4420 rx_data->max_sges_for_packet = params->max_sges_pkt;
4421 rx_data->client_qzone_id = params->cl_qzone_id;
4422 rx_data->max_agg_size = cpu_to_le16(params->tpa_agg_sz);
4424 /* Always start in DROP_ALL mode */
4425 rx_data->state = cpu_to_le16(CLIENT_INIT_RX_DATA_UCAST_DROP_ALL |
4426 CLIENT_INIT_RX_DATA_MCAST_DROP_ALL);
4428 /* We don't set drop flags */
4429 rx_data->drop_ip_cs_err_flg = 0;
4430 rx_data->drop_tcp_cs_err_flg = 0;
4431 rx_data->drop_ttl0_flg = 0;
4432 rx_data->drop_udp_cs_err_flg = 0;
4433 rx_data->inner_vlan_removal_enable_flg =
4434 test_bit(BNX2X_Q_FLG_VLAN, flags);
4435 rx_data->outer_vlan_removal_enable_flg =
4436 test_bit(BNX2X_Q_FLG_OV, flags);
4437 rx_data->status_block_id = params->fw_sb_id;
4438 rx_data->rx_sb_index_number = params->sb_cq_index;
4439 rx_data->max_tpa_queues = params->max_tpa_queues;
4440 rx_data->max_bytes_on_bd = cpu_to_le16(params->buf_sz);
4441 rx_data->sge_buff_size = cpu_to_le16(params->sge_buf_sz);
4442 rx_data->bd_page_base.lo =
4443 cpu_to_le32(U64_LO(params->dscr_map));
4444 rx_data->bd_page_base.hi =
4445 cpu_to_le32(U64_HI(params->dscr_map));
4446 rx_data->sge_page_base.lo =
4447 cpu_to_le32(U64_LO(params->sge_map));
4448 rx_data->sge_page_base.hi =
4449 cpu_to_le32(U64_HI(params->sge_map));
4450 rx_data->cqe_page_base.lo =
4451 cpu_to_le32(U64_LO(params->rcq_map));
4452 rx_data->cqe_page_base.hi =
4453 cpu_to_le32(U64_HI(params->rcq_map));
4454 rx_data->is_leading_rss = test_bit(BNX2X_Q_FLG_LEADING_RSS, flags);
4456 if (test_bit(BNX2X_Q_FLG_MCAST, flags)) {
4457 rx_data->approx_mcast_engine_id = params->mcast_engine_id;
4458 rx_data->is_approx_mcast = 1;
4461 rx_data->rss_engine_id = params->rss_engine_id;
4463 /* silent vlan removal */
4464 rx_data->silent_vlan_removal_flg =
4465 test_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, flags);
4466 rx_data->silent_vlan_value =
4467 cpu_to_le16(params->silent_removal_value);
4468 rx_data->silent_vlan_mask =
4469 cpu_to_le16(params->silent_removal_mask);
4472 /* initialize the general, tx and rx parts of a queue object */
4473 static void bnx2x_q_fill_setup_data_cmn(struct bnx2x *bp,
4474 struct bnx2x_queue_state_params *cmd_params,
4475 struct client_init_ramrod_data *data)
4477 bnx2x_q_fill_init_general_data(bp, cmd_params->q_obj,
4478 &cmd_params->params.setup.gen_params,
4480 &cmd_params->params.setup.flags);
4482 bnx2x_q_fill_init_tx_data(cmd_params->q_obj,
4483 &cmd_params->params.setup.txq_params,
4485 &cmd_params->params.setup.flags);
4487 bnx2x_q_fill_init_rx_data(cmd_params->q_obj,
4488 &cmd_params->params.setup.rxq_params,
4490 &cmd_params->params.setup.flags);
4492 bnx2x_q_fill_init_pause_data(cmd_params->q_obj,
4493 &cmd_params->params.setup.pause_params,
4497 /* initialize the general and tx parts of a tx-only queue object */
4498 static void bnx2x_q_fill_setup_tx_only(struct bnx2x *bp,
4499 struct bnx2x_queue_state_params *cmd_params,
4500 struct tx_queue_init_ramrod_data *data)
4502 bnx2x_q_fill_init_general_data(bp, cmd_params->q_obj,
4503 &cmd_params->params.tx_only.gen_params,
4505 &cmd_params->params.tx_only.flags);
4507 bnx2x_q_fill_init_tx_data(cmd_params->q_obj,
4508 &cmd_params->params.tx_only.txq_params,
4510 &cmd_params->params.tx_only.flags);
4512 DP(BNX2X_MSG_SP, "cid %d, tx bd page lo %x hi %x",
4513 cmd_params->q_obj->cids[0],
4514 data->tx.tx_bd_page_base.lo,
4515 data->tx.tx_bd_page_base.hi);
4519 * bnx2x_q_init - init HW/FW queue
4521 * @bp: device handle
4524 * HW/FW initial Queue configuration:
4526 * - CDU context validation
4529 static inline int bnx2x_q_init(struct bnx2x *bp,
4530 struct bnx2x_queue_state_params *params)
4532 struct bnx2x_queue_sp_obj *o = params->q_obj;
4533 struct bnx2x_queue_init_params *init = ¶ms->params.init;
4537 /* Tx HC configuration */
4538 if (test_bit(BNX2X_Q_TYPE_HAS_TX, &o->type) &&
4539 test_bit(BNX2X_Q_FLG_HC, &init->tx.flags)) {
4540 hc_usec = init->tx.hc_rate ? 1000000 / init->tx.hc_rate : 0;
4542 bnx2x_update_coalesce_sb_index(bp, init->tx.fw_sb_id,
4543 init->tx.sb_cq_index,
4544 !test_bit(BNX2X_Q_FLG_HC_EN, &init->tx.flags),
4548 /* Rx HC configuration */
4549 if (test_bit(BNX2X_Q_TYPE_HAS_RX, &o->type) &&
4550 test_bit(BNX2X_Q_FLG_HC, &init->rx.flags)) {
4551 hc_usec = init->rx.hc_rate ? 1000000 / init->rx.hc_rate : 0;
4553 bnx2x_update_coalesce_sb_index(bp, init->rx.fw_sb_id,
4554 init->rx.sb_cq_index,
4555 !test_bit(BNX2X_Q_FLG_HC_EN, &init->rx.flags),
4559 /* Set CDU context validation values */
4560 for (cos = 0; cos < o->max_cos; cos++) {
4561 DP(BNX2X_MSG_SP, "setting context validation. cid %d, cos %d\n",
4563 DP(BNX2X_MSG_SP, "context pointer %p\n", init->cxts[cos]);
4564 bnx2x_set_ctx_validation(bp, init->cxts[cos], o->cids[cos]);
4567 /* As no ramrod is sent, complete the command immediately */
4568 o->complete_cmd(bp, o, BNX2X_Q_CMD_INIT);
4576 static inline int bnx2x_q_send_setup_e1x(struct bnx2x *bp,
4577 struct bnx2x_queue_state_params *params)
4579 struct bnx2x_queue_sp_obj *o = params->q_obj;
4580 struct client_init_ramrod_data *rdata =
4581 (struct client_init_ramrod_data *)o->rdata;
4582 dma_addr_t data_mapping = o->rdata_mapping;
4583 int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP;
4585 /* Clear the ramrod data */
4586 memset(rdata, 0, sizeof(*rdata));
4588 /* Fill the ramrod data */
4589 bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
4591 /* No need for an explicit memory barrier here as long as we
4592 * ensure the ordering of writing to the SPQ element
4593 * and updating of the SPQ producer which involves a memory
4594 * read. If the memory read is removed we will have to put a
4595 * full memory barrier there (inside bnx2x_sp_post()).
4597 return bnx2x_sp_post(bp, ramrod, o->cids[BNX2X_PRIMARY_CID_INDEX],
4598 U64_HI(data_mapping),
4599 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4602 static inline int bnx2x_q_send_setup_e2(struct bnx2x *bp,
4603 struct bnx2x_queue_state_params *params)
4605 struct bnx2x_queue_sp_obj *o = params->q_obj;
4606 struct client_init_ramrod_data *rdata =
4607 (struct client_init_ramrod_data *)o->rdata;
4608 dma_addr_t data_mapping = o->rdata_mapping;
4609 int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP;
4611 /* Clear the ramrod data */
4612 memset(rdata, 0, sizeof(*rdata));
4614 /* Fill the ramrod data */
4615 bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
4616 bnx2x_q_fill_setup_data_e2(bp, params, rdata);
4618 /* No need for an explicit memory barrier here as long as we
4619 * ensure the ordering of writing to the SPQ element
4620 * and updating of the SPQ producer which involves a memory
4621 * read. If the memory read is removed we will have to put a
4622 * full memory barrier there (inside bnx2x_sp_post()).
4624 return bnx2x_sp_post(bp, ramrod, o->cids[BNX2X_PRIMARY_CID_INDEX],
4625 U64_HI(data_mapping),
4626 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4629 static inline int bnx2x_q_send_setup_tx_only(struct bnx2x *bp,
4630 struct bnx2x_queue_state_params *params)
4632 struct bnx2x_queue_sp_obj *o = params->q_obj;
4633 struct tx_queue_init_ramrod_data *rdata =
4634 (struct tx_queue_init_ramrod_data *)o->rdata;
4635 dma_addr_t data_mapping = o->rdata_mapping;
4636 int ramrod = RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP;
4637 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
4638 ¶ms->params.tx_only;
4639 u8 cid_index = tx_only_params->cid_index;
4641 if (cid_index >= o->max_cos) {
4642 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4643 o->cl_id, cid_index);
4647 DP(BNX2X_MSG_SP, "parameters received: cos: %d sp-id: %d\n",
4648 tx_only_params->gen_params.cos,
4649 tx_only_params->gen_params.spcl_id);
4651 /* Clear the ramrod data */
4652 memset(rdata, 0, sizeof(*rdata));
4654 /* Fill the ramrod data */
4655 bnx2x_q_fill_setup_tx_only(bp, params, rdata);
4657 DP(BNX2X_MSG_SP, "sending tx-only ramrod: cid %d, client-id %d, sp-client id %d, cos %d\n",
4658 o->cids[cid_index], rdata->general.client_id,
4659 rdata->general.sp_client_id, rdata->general.cos);
4661 /* No need for an explicit memory barrier here as long as we
4662 * ensure the ordering of writing to the SPQ element
4663 * and updating of the SPQ producer which involves a memory
4664 * read. If the memory read is removed we will have to put a
4665 * full memory barrier there (inside bnx2x_sp_post()).
4667 return bnx2x_sp_post(bp, ramrod, o->cids[cid_index],
4668 U64_HI(data_mapping),
4669 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4672 static void bnx2x_q_fill_update_data(struct bnx2x *bp,
4673 struct bnx2x_queue_sp_obj *obj,
4674 struct bnx2x_queue_update_params *params,
4675 struct client_update_ramrod_data *data)
4677 /* Client ID of the client to update */
4678 data->client_id = obj->cl_id;
4680 /* Function ID of the client to update */
4681 data->func_id = obj->func_id;
4683 /* Default VLAN value */
4684 data->default_vlan = cpu_to_le16(params->def_vlan);
4686 /* Inner VLAN stripping */
4687 data->inner_vlan_removal_enable_flg =
4688 test_bit(BNX2X_Q_UPDATE_IN_VLAN_REM, ¶ms->update_flags);
4689 data->inner_vlan_removal_change_flg =
4690 test_bit(BNX2X_Q_UPDATE_IN_VLAN_REM_CHNG,
4691 ¶ms->update_flags);
4693 /* Outer VLAN stripping */
4694 data->outer_vlan_removal_enable_flg =
4695 test_bit(BNX2X_Q_UPDATE_OUT_VLAN_REM, ¶ms->update_flags);
4696 data->outer_vlan_removal_change_flg =
4697 test_bit(BNX2X_Q_UPDATE_OUT_VLAN_REM_CHNG,
4698 ¶ms->update_flags);
4700 /* Drop packets that have source MAC that doesn't belong to this
4703 data->anti_spoofing_enable_flg =
4704 test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF, ¶ms->update_flags);
4705 data->anti_spoofing_change_flg =
4706 test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF_CHNG, ¶ms->update_flags);
4708 /* Activate/Deactivate */
4709 data->activate_flg =
4710 test_bit(BNX2X_Q_UPDATE_ACTIVATE, ¶ms->update_flags);
4711 data->activate_change_flg =
4712 test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, ¶ms->update_flags);
4714 /* Enable default VLAN */
4715 data->default_vlan_enable_flg =
4716 test_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN, ¶ms->update_flags);
4717 data->default_vlan_change_flg =
4718 test_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN_CHNG,
4719 ¶ms->update_flags);
4721 /* silent vlan removal */
4722 data->silent_vlan_change_flg =
4723 test_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
4724 ¶ms->update_flags);
4725 data->silent_vlan_removal_flg =
4726 test_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM, ¶ms->update_flags);
4727 data->silent_vlan_value = cpu_to_le16(params->silent_removal_value);
4728 data->silent_vlan_mask = cpu_to_le16(params->silent_removal_mask);
4731 data->tx_switching_flg =
4732 test_bit(BNX2X_Q_UPDATE_TX_SWITCHING, ¶ms->update_flags);
4733 data->tx_switching_change_flg =
4734 test_bit(BNX2X_Q_UPDATE_TX_SWITCHING_CHNG,
4735 ¶ms->update_flags);
4738 data->handle_ptp_pkts_flg =
4739 test_bit(BNX2X_Q_UPDATE_PTP_PKTS, ¶ms->update_flags);
4740 data->handle_ptp_pkts_change_flg =
4741 test_bit(BNX2X_Q_UPDATE_PTP_PKTS_CHNG, ¶ms->update_flags);
4744 static inline int bnx2x_q_send_update(struct bnx2x *bp,
4745 struct bnx2x_queue_state_params *params)
4747 struct bnx2x_queue_sp_obj *o = params->q_obj;
4748 struct client_update_ramrod_data *rdata =
4749 (struct client_update_ramrod_data *)o->rdata;
4750 dma_addr_t data_mapping = o->rdata_mapping;
4751 struct bnx2x_queue_update_params *update_params =
4752 ¶ms->params.update;
4753 u8 cid_index = update_params->cid_index;
4755 if (cid_index >= o->max_cos) {
4756 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4757 o->cl_id, cid_index);
4761 /* Clear the ramrod data */
4762 memset(rdata, 0, sizeof(*rdata));
4764 /* Fill the ramrod data */
4765 bnx2x_q_fill_update_data(bp, o, update_params, rdata);
4767 /* No need for an explicit memory barrier here as long as we
4768 * ensure the ordering of writing to the SPQ element
4769 * and updating of the SPQ producer which involves a memory
4770 * read. If the memory read is removed we will have to put a
4771 * full memory barrier there (inside bnx2x_sp_post()).
4773 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_UPDATE,
4774 o->cids[cid_index], U64_HI(data_mapping),
4775 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4779 * bnx2x_q_send_deactivate - send DEACTIVATE command
4781 * @bp: device handle
4784 * implemented using the UPDATE command.
4786 static inline int bnx2x_q_send_deactivate(struct bnx2x *bp,
4787 struct bnx2x_queue_state_params *params)
4789 struct bnx2x_queue_update_params *update = ¶ms->params.update;
4791 memset(update, 0, sizeof(*update));
4793 __set_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &update->update_flags);
4795 return bnx2x_q_send_update(bp, params);
4799 * bnx2x_q_send_activate - send ACTIVATE command
4801 * @bp: device handle
4804 * implemented using the UPDATE command.
4806 static inline int bnx2x_q_send_activate(struct bnx2x *bp,
4807 struct bnx2x_queue_state_params *params)
4809 struct bnx2x_queue_update_params *update = ¶ms->params.update;
4811 memset(update, 0, sizeof(*update));
4813 __set_bit(BNX2X_Q_UPDATE_ACTIVATE, &update->update_flags);
4814 __set_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &update->update_flags);
4816 return bnx2x_q_send_update(bp, params);
4819 static void bnx2x_q_fill_update_tpa_data(struct bnx2x *bp,
4820 struct bnx2x_queue_sp_obj *obj,
4821 struct bnx2x_queue_update_tpa_params *params,
4822 struct tpa_update_ramrod_data *data)
4824 data->client_id = obj->cl_id;
4825 data->complete_on_both_clients = params->complete_on_both_clients;
4826 data->dont_verify_rings_pause_thr_flg =
4827 params->dont_verify_thr;
4828 data->max_agg_size = cpu_to_le16(params->max_agg_sz);
4829 data->max_sges_for_packet = params->max_sges_pkt;
4830 data->max_tpa_queues = params->max_tpa_queues;
4831 data->sge_buff_size = cpu_to_le16(params->sge_buff_sz);
4832 data->sge_page_base_hi = cpu_to_le32(U64_HI(params->sge_map));
4833 data->sge_page_base_lo = cpu_to_le32(U64_LO(params->sge_map));
4834 data->sge_pause_thr_high = cpu_to_le16(params->sge_pause_thr_high);
4835 data->sge_pause_thr_low = cpu_to_le16(params->sge_pause_thr_low);
4836 data->tpa_mode = params->tpa_mode;
4837 data->update_ipv4 = params->update_ipv4;
4838 data->update_ipv6 = params->update_ipv6;
4841 static inline int bnx2x_q_send_update_tpa(struct bnx2x *bp,
4842 struct bnx2x_queue_state_params *params)
4844 struct bnx2x_queue_sp_obj *o = params->q_obj;
4845 struct tpa_update_ramrod_data *rdata =
4846 (struct tpa_update_ramrod_data *)o->rdata;
4847 dma_addr_t data_mapping = o->rdata_mapping;
4848 struct bnx2x_queue_update_tpa_params *update_tpa_params =
4849 ¶ms->params.update_tpa;
4852 /* Clear the ramrod data */
4853 memset(rdata, 0, sizeof(*rdata));
4855 /* Fill the ramrod data */
4856 bnx2x_q_fill_update_tpa_data(bp, o, update_tpa_params, rdata);
4858 /* Add the function id inside the type, so that sp post function
4859 * doesn't automatically add the PF func-id, this is required
4860 * for operations done by PFs on behalf of their VFs
4862 type = ETH_CONNECTION_TYPE |
4863 ((o->func_id) << SPE_HDR_FUNCTION_ID_SHIFT);
4865 /* No need for an explicit memory barrier here as long as we
4866 * ensure the ordering of writing to the SPQ element
4867 * and updating of the SPQ producer which involves a memory
4868 * read. If the memory read is removed we will have to put a
4869 * full memory barrier there (inside bnx2x_sp_post()).
4871 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_TPA_UPDATE,
4872 o->cids[BNX2X_PRIMARY_CID_INDEX],
4873 U64_HI(data_mapping),
4874 U64_LO(data_mapping), type);
4877 static inline int bnx2x_q_send_halt(struct bnx2x *bp,
4878 struct bnx2x_queue_state_params *params)
4880 struct bnx2x_queue_sp_obj *o = params->q_obj;
4882 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT,
4883 o->cids[BNX2X_PRIMARY_CID_INDEX], 0, o->cl_id,
4884 ETH_CONNECTION_TYPE);
4887 static inline int bnx2x_q_send_cfc_del(struct bnx2x *bp,
4888 struct bnx2x_queue_state_params *params)
4890 struct bnx2x_queue_sp_obj *o = params->q_obj;
4891 u8 cid_idx = params->params.cfc_del.cid_index;
4893 if (cid_idx >= o->max_cos) {
4894 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4899 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_CFC_DEL,
4900 o->cids[cid_idx], 0, 0, NONE_CONNECTION_TYPE);
4903 static inline int bnx2x_q_send_terminate(struct bnx2x *bp,
4904 struct bnx2x_queue_state_params *params)
4906 struct bnx2x_queue_sp_obj *o = params->q_obj;
4907 u8 cid_index = params->params.terminate.cid_index;
4909 if (cid_index >= o->max_cos) {
4910 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4911 o->cl_id, cid_index);
4915 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_TERMINATE,
4916 o->cids[cid_index], 0, 0, ETH_CONNECTION_TYPE);
4919 static inline int bnx2x_q_send_empty(struct bnx2x *bp,
4920 struct bnx2x_queue_state_params *params)
4922 struct bnx2x_queue_sp_obj *o = params->q_obj;
4924 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_EMPTY,
4925 o->cids[BNX2X_PRIMARY_CID_INDEX], 0, 0,
4926 ETH_CONNECTION_TYPE);
4929 static inline int bnx2x_queue_send_cmd_cmn(struct bnx2x *bp,
4930 struct bnx2x_queue_state_params *params)
4932 switch (params->cmd) {
4933 case BNX2X_Q_CMD_INIT:
4934 return bnx2x_q_init(bp, params);
4935 case BNX2X_Q_CMD_SETUP_TX_ONLY:
4936 return bnx2x_q_send_setup_tx_only(bp, params);
4937 case BNX2X_Q_CMD_DEACTIVATE:
4938 return bnx2x_q_send_deactivate(bp, params);
4939 case BNX2X_Q_CMD_ACTIVATE:
4940 return bnx2x_q_send_activate(bp, params);
4941 case BNX2X_Q_CMD_UPDATE:
4942 return bnx2x_q_send_update(bp, params);
4943 case BNX2X_Q_CMD_UPDATE_TPA:
4944 return bnx2x_q_send_update_tpa(bp, params);
4945 case BNX2X_Q_CMD_HALT:
4946 return bnx2x_q_send_halt(bp, params);
4947 case BNX2X_Q_CMD_CFC_DEL:
4948 return bnx2x_q_send_cfc_del(bp, params);
4949 case BNX2X_Q_CMD_TERMINATE:
4950 return bnx2x_q_send_terminate(bp, params);
4951 case BNX2X_Q_CMD_EMPTY:
4952 return bnx2x_q_send_empty(bp, params);
4954 BNX2X_ERR("Unknown command: %d\n", params->cmd);
4959 static int bnx2x_queue_send_cmd_e1x(struct bnx2x *bp,
4960 struct bnx2x_queue_state_params *params)
4962 switch (params->cmd) {
4963 case BNX2X_Q_CMD_SETUP:
4964 return bnx2x_q_send_setup_e1x(bp, params);
4965 case BNX2X_Q_CMD_INIT:
4966 case BNX2X_Q_CMD_SETUP_TX_ONLY:
4967 case BNX2X_Q_CMD_DEACTIVATE:
4968 case BNX2X_Q_CMD_ACTIVATE:
4969 case BNX2X_Q_CMD_UPDATE:
4970 case BNX2X_Q_CMD_UPDATE_TPA:
4971 case BNX2X_Q_CMD_HALT:
4972 case BNX2X_Q_CMD_CFC_DEL:
4973 case BNX2X_Q_CMD_TERMINATE:
4974 case BNX2X_Q_CMD_EMPTY:
4975 return bnx2x_queue_send_cmd_cmn(bp, params);
4977 BNX2X_ERR("Unknown command: %d\n", params->cmd);
4982 static int bnx2x_queue_send_cmd_e2(struct bnx2x *bp,
4983 struct bnx2x_queue_state_params *params)
4985 switch (params->cmd) {
4986 case BNX2X_Q_CMD_SETUP:
4987 return bnx2x_q_send_setup_e2(bp, params);
4988 case BNX2X_Q_CMD_INIT:
4989 case BNX2X_Q_CMD_SETUP_TX_ONLY:
4990 case BNX2X_Q_CMD_DEACTIVATE:
4991 case BNX2X_Q_CMD_ACTIVATE:
4992 case BNX2X_Q_CMD_UPDATE:
4993 case BNX2X_Q_CMD_UPDATE_TPA:
4994 case BNX2X_Q_CMD_HALT:
4995 case BNX2X_Q_CMD_CFC_DEL:
4996 case BNX2X_Q_CMD_TERMINATE:
4997 case BNX2X_Q_CMD_EMPTY:
4998 return bnx2x_queue_send_cmd_cmn(bp, params);
5000 BNX2X_ERR("Unknown command: %d\n", params->cmd);
5006 * bnx2x_queue_chk_transition - check state machine of a regular Queue
5008 * @bp: device handle
5013 * It both checks if the requested command is legal in a current
5014 * state and, if it's legal, sets a `next_state' in the object
5015 * that will be used in the completion flow to set the `state'
5018 * returns 0 if a requested command is a legal transition,
5019 * -EINVAL otherwise.
5021 static int bnx2x_queue_chk_transition(struct bnx2x *bp,
5022 struct bnx2x_queue_sp_obj *o,
5023 struct bnx2x_queue_state_params *params)
5025 enum bnx2x_q_state state = o->state, next_state = BNX2X_Q_STATE_MAX;
5026 enum bnx2x_queue_cmd cmd = params->cmd;
5027 struct bnx2x_queue_update_params *update_params =
5028 ¶ms->params.update;
5029 u8 next_tx_only = o->num_tx_only;
5031 /* Forget all pending for completion commands if a driver only state
5032 * transition has been requested.
5034 if (test_bit(RAMROD_DRV_CLR_ONLY, ¶ms->ramrod_flags)) {
5036 o->next_state = BNX2X_Q_STATE_MAX;
5039 /* Don't allow a next state transition if we are in the middle of
5043 BNX2X_ERR("Blocking transition since pending was %lx\n",
5049 case BNX2X_Q_STATE_RESET:
5050 if (cmd == BNX2X_Q_CMD_INIT)
5051 next_state = BNX2X_Q_STATE_INITIALIZED;
5054 case BNX2X_Q_STATE_INITIALIZED:
5055 if (cmd == BNX2X_Q_CMD_SETUP) {
5056 if (test_bit(BNX2X_Q_FLG_ACTIVE,
5057 ¶ms->params.setup.flags))
5058 next_state = BNX2X_Q_STATE_ACTIVE;
5060 next_state = BNX2X_Q_STATE_INACTIVE;
5064 case BNX2X_Q_STATE_ACTIVE:
5065 if (cmd == BNX2X_Q_CMD_DEACTIVATE)
5066 next_state = BNX2X_Q_STATE_INACTIVE;
5068 else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
5069 (cmd == BNX2X_Q_CMD_UPDATE_TPA))
5070 next_state = BNX2X_Q_STATE_ACTIVE;
5072 else if (cmd == BNX2X_Q_CMD_SETUP_TX_ONLY) {
5073 next_state = BNX2X_Q_STATE_MULTI_COS;
5077 else if (cmd == BNX2X_Q_CMD_HALT)
5078 next_state = BNX2X_Q_STATE_STOPPED;
5080 else if (cmd == BNX2X_Q_CMD_UPDATE) {
5081 /* If "active" state change is requested, update the
5082 * state accordingly.
5084 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
5085 &update_params->update_flags) &&
5086 !test_bit(BNX2X_Q_UPDATE_ACTIVATE,
5087 &update_params->update_flags))
5088 next_state = BNX2X_Q_STATE_INACTIVE;
5090 next_state = BNX2X_Q_STATE_ACTIVE;
5094 case BNX2X_Q_STATE_MULTI_COS:
5095 if (cmd == BNX2X_Q_CMD_TERMINATE)
5096 next_state = BNX2X_Q_STATE_MCOS_TERMINATED;
5098 else if (cmd == BNX2X_Q_CMD_SETUP_TX_ONLY) {
5099 next_state = BNX2X_Q_STATE_MULTI_COS;
5100 next_tx_only = o->num_tx_only + 1;
5103 else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
5104 (cmd == BNX2X_Q_CMD_UPDATE_TPA))
5105 next_state = BNX2X_Q_STATE_MULTI_COS;
5107 else if (cmd == BNX2X_Q_CMD_UPDATE) {
5108 /* If "active" state change is requested, update the
5109 * state accordingly.
5111 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
5112 &update_params->update_flags) &&
5113 !test_bit(BNX2X_Q_UPDATE_ACTIVATE,
5114 &update_params->update_flags))
5115 next_state = BNX2X_Q_STATE_INACTIVE;
5117 next_state = BNX2X_Q_STATE_MULTI_COS;
5121 case BNX2X_Q_STATE_MCOS_TERMINATED:
5122 if (cmd == BNX2X_Q_CMD_CFC_DEL) {
5123 next_tx_only = o->num_tx_only - 1;
5124 if (next_tx_only == 0)
5125 next_state = BNX2X_Q_STATE_ACTIVE;
5127 next_state = BNX2X_Q_STATE_MULTI_COS;
5131 case BNX2X_Q_STATE_INACTIVE:
5132 if (cmd == BNX2X_Q_CMD_ACTIVATE)
5133 next_state = BNX2X_Q_STATE_ACTIVE;
5135 else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
5136 (cmd == BNX2X_Q_CMD_UPDATE_TPA))
5137 next_state = BNX2X_Q_STATE_INACTIVE;
5139 else if (cmd == BNX2X_Q_CMD_HALT)
5140 next_state = BNX2X_Q_STATE_STOPPED;
5142 else if (cmd == BNX2X_Q_CMD_UPDATE) {
5143 /* If "active" state change is requested, update the
5144 * state accordingly.
5146 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
5147 &update_params->update_flags) &&
5148 test_bit(BNX2X_Q_UPDATE_ACTIVATE,
5149 &update_params->update_flags)){
5150 if (o->num_tx_only == 0)
5151 next_state = BNX2X_Q_STATE_ACTIVE;
5152 else /* tx only queues exist for this queue */
5153 next_state = BNX2X_Q_STATE_MULTI_COS;
5155 next_state = BNX2X_Q_STATE_INACTIVE;
5159 case BNX2X_Q_STATE_STOPPED:
5160 if (cmd == BNX2X_Q_CMD_TERMINATE)
5161 next_state = BNX2X_Q_STATE_TERMINATED;
5164 case BNX2X_Q_STATE_TERMINATED:
5165 if (cmd == BNX2X_Q_CMD_CFC_DEL)
5166 next_state = BNX2X_Q_STATE_RESET;
5170 BNX2X_ERR("Illegal state: %d\n", state);
5173 /* Transition is assured */
5174 if (next_state != BNX2X_Q_STATE_MAX) {
5175 DP(BNX2X_MSG_SP, "Good state transition: %d(%d)->%d\n",
5176 state, cmd, next_state);
5177 o->next_state = next_state;
5178 o->next_tx_only = next_tx_only;
5182 DP(BNX2X_MSG_SP, "Bad state transition request: %d %d\n", state, cmd);
5187 void bnx2x_init_queue_obj(struct bnx2x *bp,
5188 struct bnx2x_queue_sp_obj *obj,
5189 u8 cl_id, u32 *cids, u8 cid_cnt, u8 func_id,
5191 dma_addr_t rdata_mapping, unsigned long type)
5193 memset(obj, 0, sizeof(*obj));
5195 /* We support only BNX2X_MULTI_TX_COS Tx CoS at the moment */
5196 BUG_ON(BNX2X_MULTI_TX_COS < cid_cnt);
5198 memcpy(obj->cids, cids, sizeof(obj->cids[0]) * cid_cnt);
5199 obj->max_cos = cid_cnt;
5201 obj->func_id = func_id;
5203 obj->rdata_mapping = rdata_mapping;
5205 obj->next_state = BNX2X_Q_STATE_MAX;
5207 if (CHIP_IS_E1x(bp))
5208 obj->send_cmd = bnx2x_queue_send_cmd_e1x;
5210 obj->send_cmd = bnx2x_queue_send_cmd_e2;
5212 obj->check_transition = bnx2x_queue_chk_transition;
5214 obj->complete_cmd = bnx2x_queue_comp_cmd;
5215 obj->wait_comp = bnx2x_queue_wait_comp;
5216 obj->set_pending = bnx2x_queue_set_pending;
5219 /* return a queue object's logical state*/
5220 int bnx2x_get_q_logical_state(struct bnx2x *bp,
5221 struct bnx2x_queue_sp_obj *obj)
5223 switch (obj->state) {
5224 case BNX2X_Q_STATE_ACTIVE:
5225 case BNX2X_Q_STATE_MULTI_COS:
5226 return BNX2X_Q_LOGICAL_STATE_ACTIVE;
5227 case BNX2X_Q_STATE_RESET:
5228 case BNX2X_Q_STATE_INITIALIZED:
5229 case BNX2X_Q_STATE_MCOS_TERMINATED:
5230 case BNX2X_Q_STATE_INACTIVE:
5231 case BNX2X_Q_STATE_STOPPED:
5232 case BNX2X_Q_STATE_TERMINATED:
5233 case BNX2X_Q_STATE_FLRED:
5234 return BNX2X_Q_LOGICAL_STATE_STOPPED;
5240 /********************** Function state object *********************************/
5241 enum bnx2x_func_state bnx2x_func_get_state(struct bnx2x *bp,
5242 struct bnx2x_func_sp_obj *o)
5244 /* in the middle of transaction - return INVALID state */
5246 return BNX2X_F_STATE_MAX;
5248 /* unsure the order of reading of o->pending and o->state
5249 * o->pending should be read first
5256 static int bnx2x_func_wait_comp(struct bnx2x *bp,
5257 struct bnx2x_func_sp_obj *o,
5258 enum bnx2x_func_cmd cmd)
5260 return bnx2x_state_wait(bp, cmd, &o->pending);
5264 * bnx2x_func_state_change_comp - complete the state machine transition
5266 * @bp: device handle
5270 * Called on state change transition. Completes the state
5271 * machine transition only - no HW interaction.
5273 static inline int bnx2x_func_state_change_comp(struct bnx2x *bp,
5274 struct bnx2x_func_sp_obj *o,
5275 enum bnx2x_func_cmd cmd)
5277 unsigned long cur_pending = o->pending;
5279 if (!test_and_clear_bit(cmd, &cur_pending)) {
5280 BNX2X_ERR("Bad MC reply %d for func %d in state %d pending 0x%lx, next_state %d\n",
5281 cmd, BP_FUNC(bp), o->state,
5282 cur_pending, o->next_state);
5287 "Completing command %d for func %d, setting state to %d\n",
5288 cmd, BP_FUNC(bp), o->next_state);
5290 o->state = o->next_state;
5291 o->next_state = BNX2X_F_STATE_MAX;
5293 /* It's important that o->state and o->next_state are
5294 * updated before o->pending.
5298 clear_bit(cmd, &o->pending);
5299 smp_mb__after_atomic();
5305 * bnx2x_func_comp_cmd - complete the state change command
5307 * @bp: device handle
5311 * Checks that the arrived completion is expected.
5313 static int bnx2x_func_comp_cmd(struct bnx2x *bp,
5314 struct bnx2x_func_sp_obj *o,
5315 enum bnx2x_func_cmd cmd)
5317 /* Complete the state machine part first, check if it's a
5320 int rc = bnx2x_func_state_change_comp(bp, o, cmd);
5325 * bnx2x_func_chk_transition - perform function state machine transition
5327 * @bp: device handle
5331 * It both checks if the requested command is legal in a current
5332 * state and, if it's legal, sets a `next_state' in the object
5333 * that will be used in the completion flow to set the `state'
5336 * returns 0 if a requested command is a legal transition,
5337 * -EINVAL otherwise.
5339 static int bnx2x_func_chk_transition(struct bnx2x *bp,
5340 struct bnx2x_func_sp_obj *o,
5341 struct bnx2x_func_state_params *params)
5343 enum bnx2x_func_state state = o->state, next_state = BNX2X_F_STATE_MAX;
5344 enum bnx2x_func_cmd cmd = params->cmd;
5346 /* Forget all pending for completion commands if a driver only state
5347 * transition has been requested.
5349 if (test_bit(RAMROD_DRV_CLR_ONLY, ¶ms->ramrod_flags)) {
5351 o->next_state = BNX2X_F_STATE_MAX;
5354 /* Don't allow a next state transition if we are in the middle of
5361 case BNX2X_F_STATE_RESET:
5362 if (cmd == BNX2X_F_CMD_HW_INIT)
5363 next_state = BNX2X_F_STATE_INITIALIZED;
5366 case BNX2X_F_STATE_INITIALIZED:
5367 if (cmd == BNX2X_F_CMD_START)
5368 next_state = BNX2X_F_STATE_STARTED;
5370 else if (cmd == BNX2X_F_CMD_HW_RESET)
5371 next_state = BNX2X_F_STATE_RESET;
5374 case BNX2X_F_STATE_STARTED:
5375 if (cmd == BNX2X_F_CMD_STOP)
5376 next_state = BNX2X_F_STATE_INITIALIZED;
5377 /* afex ramrods can be sent only in started mode, and only
5378 * if not pending for function_stop ramrod completion
5379 * for these events - next state remained STARTED.
5381 else if ((cmd == BNX2X_F_CMD_AFEX_UPDATE) &&
5382 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5383 next_state = BNX2X_F_STATE_STARTED;
5385 else if ((cmd == BNX2X_F_CMD_AFEX_VIFLISTS) &&
5386 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5387 next_state = BNX2X_F_STATE_STARTED;
5389 /* Switch_update ramrod can be sent in either started or
5390 * tx_stopped state, and it doesn't change the state.
5392 else if ((cmd == BNX2X_F_CMD_SWITCH_UPDATE) &&
5393 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5394 next_state = BNX2X_F_STATE_STARTED;
5396 else if ((cmd == BNX2X_F_CMD_SET_TIMESYNC) &&
5397 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5398 next_state = BNX2X_F_STATE_STARTED;
5400 else if (cmd == BNX2X_F_CMD_TX_STOP)
5401 next_state = BNX2X_F_STATE_TX_STOPPED;
5404 case BNX2X_F_STATE_TX_STOPPED:
5405 if ((cmd == BNX2X_F_CMD_SWITCH_UPDATE) &&
5406 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5407 next_state = BNX2X_F_STATE_TX_STOPPED;
5409 else if ((cmd == BNX2X_F_CMD_SET_TIMESYNC) &&
5410 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5411 next_state = BNX2X_F_STATE_TX_STOPPED;
5413 else if (cmd == BNX2X_F_CMD_TX_START)
5414 next_state = BNX2X_F_STATE_STARTED;
5418 BNX2X_ERR("Unknown state: %d\n", state);
5421 /* Transition is assured */
5422 if (next_state != BNX2X_F_STATE_MAX) {
5423 DP(BNX2X_MSG_SP, "Good function state transition: %d(%d)->%d\n",
5424 state, cmd, next_state);
5425 o->next_state = next_state;
5429 DP(BNX2X_MSG_SP, "Bad function state transition request: %d %d\n",
5436 * bnx2x_func_init_func - performs HW init at function stage
5438 * @bp: device handle
5441 * Init HW when the current phase is
5442 * FW_MSG_CODE_DRV_LOAD_FUNCTION: initialize only FUNCTION-only
5445 static inline int bnx2x_func_init_func(struct bnx2x *bp,
5446 const struct bnx2x_func_sp_drv_ops *drv)
5448 return drv->init_hw_func(bp);
5452 * bnx2x_func_init_port - performs HW init at port stage
5454 * @bp: device handle
5457 * Init HW when the current phase is
5458 * FW_MSG_CODE_DRV_LOAD_PORT: initialize PORT-only and
5459 * FUNCTION-only HW blocks.
5462 static inline int bnx2x_func_init_port(struct bnx2x *bp,
5463 const struct bnx2x_func_sp_drv_ops *drv)
5465 int rc = drv->init_hw_port(bp);
5469 return bnx2x_func_init_func(bp, drv);
5473 * bnx2x_func_init_cmn_chip - performs HW init at chip-common stage
5475 * @bp: device handle
5478 * Init HW when the current phase is
5479 * FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: initialize COMMON_CHIP,
5480 * PORT-only and FUNCTION-only HW blocks.
5482 static inline int bnx2x_func_init_cmn_chip(struct bnx2x *bp,
5483 const struct bnx2x_func_sp_drv_ops *drv)
5485 int rc = drv->init_hw_cmn_chip(bp);
5489 return bnx2x_func_init_port(bp, drv);
5493 * bnx2x_func_init_cmn - performs HW init at common stage
5495 * @bp: device handle
5498 * Init HW when the current phase is
5499 * FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: initialize COMMON,
5500 * PORT-only and FUNCTION-only HW blocks.
5502 static inline int bnx2x_func_init_cmn(struct bnx2x *bp,
5503 const struct bnx2x_func_sp_drv_ops *drv)
5505 int rc = drv->init_hw_cmn(bp);
5509 return bnx2x_func_init_port(bp, drv);
5512 static int bnx2x_func_hw_init(struct bnx2x *bp,
5513 struct bnx2x_func_state_params *params)
5515 u32 load_code = params->params.hw_init.load_phase;
5516 struct bnx2x_func_sp_obj *o = params->f_obj;
5517 const struct bnx2x_func_sp_drv_ops *drv = o->drv;
5520 DP(BNX2X_MSG_SP, "function %d load_code %x\n",
5521 BP_ABS_FUNC(bp), load_code);
5523 /* Prepare buffers for unzipping the FW */
5524 rc = drv->gunzip_init(bp);
5529 rc = drv->init_fw(bp);
5531 BNX2X_ERR("Error loading firmware\n");
5535 /* Handle the beginning of COMMON_XXX pases separately... */
5536 switch (load_code) {
5537 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
5538 rc = bnx2x_func_init_cmn_chip(bp, drv);
5543 case FW_MSG_CODE_DRV_LOAD_COMMON:
5544 rc = bnx2x_func_init_cmn(bp, drv);
5549 case FW_MSG_CODE_DRV_LOAD_PORT:
5550 rc = bnx2x_func_init_port(bp, drv);
5555 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
5556 rc = bnx2x_func_init_func(bp, drv);
5562 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5567 drv->gunzip_end(bp);
5569 /* In case of success, complete the command immediately: no ramrods
5573 o->complete_cmd(bp, o, BNX2X_F_CMD_HW_INIT);
5579 * bnx2x_func_reset_func - reset HW at function stage
5581 * @bp: device handle
5584 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_FUNCTION stage: reset only
5585 * FUNCTION-only HW blocks.
5587 static inline void bnx2x_func_reset_func(struct bnx2x *bp,
5588 const struct bnx2x_func_sp_drv_ops *drv)
5590 drv->reset_hw_func(bp);
5594 * bnx2x_func_reset_port - reset HW at port stage
5596 * @bp: device handle
5599 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_PORT stage: reset
5600 * FUNCTION-only and PORT-only HW blocks.
5604 * It's important to call reset_port before reset_func() as the last thing
5605 * reset_func does is pf_disable() thus disabling PGLUE_B, which
5606 * makes impossible any DMAE transactions.
5608 static inline void bnx2x_func_reset_port(struct bnx2x *bp,
5609 const struct bnx2x_func_sp_drv_ops *drv)
5611 drv->reset_hw_port(bp);
5612 bnx2x_func_reset_func(bp, drv);
5616 * bnx2x_func_reset_cmn - reset HW at common stage
5618 * @bp: device handle
5621 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_COMMON and
5622 * FW_MSG_CODE_DRV_UNLOAD_COMMON_CHIP stages: reset COMMON,
5623 * COMMON_CHIP, FUNCTION-only and PORT-only HW blocks.
5625 static inline void bnx2x_func_reset_cmn(struct bnx2x *bp,
5626 const struct bnx2x_func_sp_drv_ops *drv)
5628 bnx2x_func_reset_port(bp, drv);
5629 drv->reset_hw_cmn(bp);
5632 static inline int bnx2x_func_hw_reset(struct bnx2x *bp,
5633 struct bnx2x_func_state_params *params)
5635 u32 reset_phase = params->params.hw_reset.reset_phase;
5636 struct bnx2x_func_sp_obj *o = params->f_obj;
5637 const struct bnx2x_func_sp_drv_ops *drv = o->drv;
5639 DP(BNX2X_MSG_SP, "function %d reset_phase %x\n", BP_ABS_FUNC(bp),
5642 switch (reset_phase) {
5643 case FW_MSG_CODE_DRV_UNLOAD_COMMON:
5644 bnx2x_func_reset_cmn(bp, drv);
5646 case FW_MSG_CODE_DRV_UNLOAD_PORT:
5647 bnx2x_func_reset_port(bp, drv);
5649 case FW_MSG_CODE_DRV_UNLOAD_FUNCTION:
5650 bnx2x_func_reset_func(bp, drv);
5653 BNX2X_ERR("Unknown reset_phase (0x%x) from MCP\n",
5658 /* Complete the command immediately: no ramrods have been sent. */
5659 o->complete_cmd(bp, o, BNX2X_F_CMD_HW_RESET);
5664 static inline int bnx2x_func_send_start(struct bnx2x *bp,
5665 struct bnx2x_func_state_params *params)
5667 struct bnx2x_func_sp_obj *o = params->f_obj;
5668 struct function_start_data *rdata =
5669 (struct function_start_data *)o->rdata;
5670 dma_addr_t data_mapping = o->rdata_mapping;
5671 struct bnx2x_func_start_params *start_params = ¶ms->params.start;
5673 memset(rdata, 0, sizeof(*rdata));
5675 /* Fill the ramrod data with provided parameters */
5676 rdata->function_mode = (u8)start_params->mf_mode;
5677 rdata->sd_vlan_tag = cpu_to_le16(start_params->sd_vlan_tag);
5678 rdata->path_id = BP_PATH(bp);
5679 rdata->network_cos_mode = start_params->network_cos_mode;
5681 rdata->vxlan_dst_port = cpu_to_le16(start_params->vxlan_dst_port);
5682 rdata->geneve_dst_port = cpu_to_le16(start_params->geneve_dst_port);
5683 rdata->inner_clss_l2gre = start_params->inner_clss_l2gre;
5684 rdata->inner_clss_l2geneve = start_params->inner_clss_l2geneve;
5685 rdata->inner_clss_vxlan = start_params->inner_clss_vxlan;
5686 rdata->inner_rss = start_params->inner_rss;
5688 rdata->sd_accept_mf_clss_fail = start_params->class_fail;
5689 if (start_params->class_fail_ethtype) {
5690 rdata->sd_accept_mf_clss_fail_match_ethtype = 1;
5691 rdata->sd_accept_mf_clss_fail_ethtype =
5692 cpu_to_le16(start_params->class_fail_ethtype);
5695 rdata->sd_vlan_force_pri_flg = start_params->sd_vlan_force_pri;
5696 rdata->sd_vlan_force_pri_val = start_params->sd_vlan_force_pri_val;
5697 if (start_params->sd_vlan_eth_type)
5698 rdata->sd_vlan_eth_type =
5699 cpu_to_le16(start_params->sd_vlan_eth_type);
5701 rdata->sd_vlan_eth_type =
5702 cpu_to_le16(0x8100);
5704 rdata->no_added_tags = start_params->no_added_tags;
5706 rdata->c2s_pri_tt_valid = start_params->c2s_pri_valid;
5707 if (rdata->c2s_pri_tt_valid) {
5708 memcpy(rdata->c2s_pri_trans_table.val,
5709 start_params->c2s_pri,
5710 MAX_VLAN_PRIORITIES);
5711 rdata->c2s_pri_default = start_params->c2s_pri_default;
5713 /* No need for an explicit memory barrier here as long we would
5714 * need to ensure the ordering of writing to the SPQ element
5715 * and updating of the SPQ producer which involves a memory
5716 * read and we will have to put a full memory barrier there
5717 * (inside bnx2x_sp_post()).
5720 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_START, 0,
5721 U64_HI(data_mapping),
5722 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5725 static inline int bnx2x_func_send_switch_update(struct bnx2x *bp,
5726 struct bnx2x_func_state_params *params)
5728 struct bnx2x_func_sp_obj *o = params->f_obj;
5729 struct function_update_data *rdata =
5730 (struct function_update_data *)o->rdata;
5731 dma_addr_t data_mapping = o->rdata_mapping;
5732 struct bnx2x_func_switch_update_params *switch_update_params =
5733 ¶ms->params.switch_update;
5735 memset(rdata, 0, sizeof(*rdata));
5737 /* Fill the ramrod data with provided parameters */
5738 if (test_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND_CHNG,
5739 &switch_update_params->changes)) {
5740 rdata->tx_switch_suspend_change_flg = 1;
5741 rdata->tx_switch_suspend =
5742 test_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND,
5743 &switch_update_params->changes);
5746 if (test_bit(BNX2X_F_UPDATE_SD_VLAN_TAG_CHNG,
5747 &switch_update_params->changes)) {
5748 rdata->sd_vlan_tag_change_flg = 1;
5749 rdata->sd_vlan_tag =
5750 cpu_to_le16(switch_update_params->vlan);
5753 if (test_bit(BNX2X_F_UPDATE_SD_VLAN_ETH_TYPE_CHNG,
5754 &switch_update_params->changes)) {
5755 rdata->sd_vlan_eth_type_change_flg = 1;
5756 rdata->sd_vlan_eth_type =
5757 cpu_to_le16(switch_update_params->vlan_eth_type);
5760 if (test_bit(BNX2X_F_UPDATE_VLAN_FORCE_PRIO_CHNG,
5761 &switch_update_params->changes)) {
5762 rdata->sd_vlan_force_pri_change_flg = 1;
5763 if (test_bit(BNX2X_F_UPDATE_VLAN_FORCE_PRIO_FLAG,
5764 &switch_update_params->changes))
5765 rdata->sd_vlan_force_pri_flg = 1;
5766 rdata->sd_vlan_force_pri_flg =
5767 switch_update_params->vlan_force_prio;
5770 if (test_bit(BNX2X_F_UPDATE_TUNNEL_CFG_CHNG,
5771 &switch_update_params->changes)) {
5772 rdata->update_tunn_cfg_flg = 1;
5773 if (test_bit(BNX2X_F_UPDATE_TUNNEL_INNER_CLSS_L2GRE,
5774 &switch_update_params->changes))
5775 rdata->inner_clss_l2gre = 1;
5776 if (test_bit(BNX2X_F_UPDATE_TUNNEL_INNER_CLSS_VXLAN,
5777 &switch_update_params->changes))
5778 rdata->inner_clss_vxlan = 1;
5779 if (test_bit(BNX2X_F_UPDATE_TUNNEL_INNER_CLSS_L2GENEVE,
5780 &switch_update_params->changes))
5781 rdata->inner_clss_l2geneve = 1;
5782 if (test_bit(BNX2X_F_UPDATE_TUNNEL_INNER_RSS,
5783 &switch_update_params->changes))
5784 rdata->inner_rss = 1;
5785 rdata->vxlan_dst_port =
5786 cpu_to_le16(switch_update_params->vxlan_dst_port);
5787 rdata->geneve_dst_port =
5788 cpu_to_le16(switch_update_params->geneve_dst_port);
5791 rdata->echo = SWITCH_UPDATE;
5793 /* No need for an explicit memory barrier here as long as we
5794 * ensure the ordering of writing to the SPQ element
5795 * and updating of the SPQ producer which involves a memory
5796 * read. If the memory read is removed we will have to put a
5797 * full memory barrier there (inside bnx2x_sp_post()).
5799 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_UPDATE, 0,
5800 U64_HI(data_mapping),
5801 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5804 static inline int bnx2x_func_send_afex_update(struct bnx2x *bp,
5805 struct bnx2x_func_state_params *params)
5807 struct bnx2x_func_sp_obj *o = params->f_obj;
5808 struct function_update_data *rdata =
5809 (struct function_update_data *)o->afex_rdata;
5810 dma_addr_t data_mapping = o->afex_rdata_mapping;
5811 struct bnx2x_func_afex_update_params *afex_update_params =
5812 ¶ms->params.afex_update;
5814 memset(rdata, 0, sizeof(*rdata));
5816 /* Fill the ramrod data with provided parameters */
5817 rdata->vif_id_change_flg = 1;
5818 rdata->vif_id = cpu_to_le16(afex_update_params->vif_id);
5819 rdata->afex_default_vlan_change_flg = 1;
5820 rdata->afex_default_vlan =
5821 cpu_to_le16(afex_update_params->afex_default_vlan);
5822 rdata->allowed_priorities_change_flg = 1;
5823 rdata->allowed_priorities = afex_update_params->allowed_priorities;
5824 rdata->echo = AFEX_UPDATE;
5826 /* No need for an explicit memory barrier here as long as we
5827 * ensure the ordering of writing to the SPQ element
5828 * and updating of the SPQ producer which involves a memory
5829 * read. If the memory read is removed we will have to put a
5830 * full memory barrier there (inside bnx2x_sp_post()).
5833 "afex: sending func_update vif_id 0x%x dvlan 0x%x prio 0x%x\n",
5835 rdata->afex_default_vlan, rdata->allowed_priorities);
5837 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_UPDATE, 0,
5838 U64_HI(data_mapping),
5839 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5843 inline int bnx2x_func_send_afex_viflists(struct bnx2x *bp,
5844 struct bnx2x_func_state_params *params)
5846 struct bnx2x_func_sp_obj *o = params->f_obj;
5847 struct afex_vif_list_ramrod_data *rdata =
5848 (struct afex_vif_list_ramrod_data *)o->afex_rdata;
5849 struct bnx2x_func_afex_viflists_params *afex_vif_params =
5850 ¶ms->params.afex_viflists;
5851 u64 *p_rdata = (u64 *)rdata;
5853 memset(rdata, 0, sizeof(*rdata));
5855 /* Fill the ramrod data with provided parameters */
5856 rdata->vif_list_index = cpu_to_le16(afex_vif_params->vif_list_index);
5857 rdata->func_bit_map = afex_vif_params->func_bit_map;
5858 rdata->afex_vif_list_command = afex_vif_params->afex_vif_list_command;
5859 rdata->func_to_clear = afex_vif_params->func_to_clear;
5861 /* send in echo type of sub command */
5862 rdata->echo = afex_vif_params->afex_vif_list_command;
5864 /* No need for an explicit memory barrier here as long we would
5865 * need to ensure the ordering of writing to the SPQ element
5866 * and updating of the SPQ producer which involves a memory
5867 * read and we will have to put a full memory barrier there
5868 * (inside bnx2x_sp_post()).
5871 DP(BNX2X_MSG_SP, "afex: ramrod lists, cmd 0x%x index 0x%x func_bit_map 0x%x func_to_clr 0x%x\n",
5872 rdata->afex_vif_list_command, rdata->vif_list_index,
5873 rdata->func_bit_map, rdata->func_to_clear);
5875 /* this ramrod sends data directly and not through DMA mapping */
5876 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_AFEX_VIF_LISTS, 0,
5877 U64_HI(*p_rdata), U64_LO(*p_rdata),
5878 NONE_CONNECTION_TYPE);
5881 static inline int bnx2x_func_send_stop(struct bnx2x *bp,
5882 struct bnx2x_func_state_params *params)
5884 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_STOP, 0, 0, 0,
5885 NONE_CONNECTION_TYPE);
5888 static inline int bnx2x_func_send_tx_stop(struct bnx2x *bp,
5889 struct bnx2x_func_state_params *params)
5891 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_STOP_TRAFFIC, 0, 0, 0,
5892 NONE_CONNECTION_TYPE);
5894 static inline int bnx2x_func_send_tx_start(struct bnx2x *bp,
5895 struct bnx2x_func_state_params *params)
5897 struct bnx2x_func_sp_obj *o = params->f_obj;
5898 struct flow_control_configuration *rdata =
5899 (struct flow_control_configuration *)o->rdata;
5900 dma_addr_t data_mapping = o->rdata_mapping;
5901 struct bnx2x_func_tx_start_params *tx_start_params =
5902 ¶ms->params.tx_start;
5905 memset(rdata, 0, sizeof(*rdata));
5907 rdata->dcb_enabled = tx_start_params->dcb_enabled;
5908 rdata->dcb_version = tx_start_params->dcb_version;
5909 rdata->dont_add_pri_0_en = tx_start_params->dont_add_pri_0_en;
5911 for (i = 0; i < ARRAY_SIZE(rdata->traffic_type_to_priority_cos); i++)
5912 rdata->traffic_type_to_priority_cos[i] =
5913 tx_start_params->traffic_type_to_priority_cos[i];
5915 for (i = 0; i < MAX_TRAFFIC_TYPES; i++)
5916 rdata->dcb_outer_pri[i] = tx_start_params->dcb_outer_pri[i];
5917 /* No need for an explicit memory barrier here as long as we
5918 * ensure the ordering of writing to the SPQ element
5919 * and updating of the SPQ producer which involves a memory
5920 * read. If the memory read is removed we will have to put a
5921 * full memory barrier there (inside bnx2x_sp_post()).
5923 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_START_TRAFFIC, 0,
5924 U64_HI(data_mapping),
5925 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5929 int bnx2x_func_send_set_timesync(struct bnx2x *bp,
5930 struct bnx2x_func_state_params *params)
5932 struct bnx2x_func_sp_obj *o = params->f_obj;
5933 struct set_timesync_ramrod_data *rdata =
5934 (struct set_timesync_ramrod_data *)o->rdata;
5935 dma_addr_t data_mapping = o->rdata_mapping;
5936 struct bnx2x_func_set_timesync_params *set_timesync_params =
5937 ¶ms->params.set_timesync;
5939 memset(rdata, 0, sizeof(*rdata));
5941 /* Fill the ramrod data with provided parameters */
5942 rdata->drift_adjust_cmd = set_timesync_params->drift_adjust_cmd;
5943 rdata->offset_cmd = set_timesync_params->offset_cmd;
5944 rdata->add_sub_drift_adjust_value =
5945 set_timesync_params->add_sub_drift_adjust_value;
5946 rdata->drift_adjust_value = set_timesync_params->drift_adjust_value;
5947 rdata->drift_adjust_period = set_timesync_params->drift_adjust_period;
5948 rdata->offset_delta.lo =
5949 cpu_to_le32(U64_LO(set_timesync_params->offset_delta));
5950 rdata->offset_delta.hi =
5951 cpu_to_le32(U64_HI(set_timesync_params->offset_delta));
5953 DP(BNX2X_MSG_SP, "Set timesync command params: drift_cmd = %d, offset_cmd = %d, add_sub_drift = %d, drift_val = %d, drift_period = %d, offset_lo = %d, offset_hi = %d\n",
5954 rdata->drift_adjust_cmd, rdata->offset_cmd,
5955 rdata->add_sub_drift_adjust_value, rdata->drift_adjust_value,
5956 rdata->drift_adjust_period, rdata->offset_delta.lo,
5957 rdata->offset_delta.hi);
5959 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_SET_TIMESYNC, 0,
5960 U64_HI(data_mapping),
5961 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5964 static int bnx2x_func_send_cmd(struct bnx2x *bp,
5965 struct bnx2x_func_state_params *params)
5967 switch (params->cmd) {
5968 case BNX2X_F_CMD_HW_INIT:
5969 return bnx2x_func_hw_init(bp, params);
5970 case BNX2X_F_CMD_START:
5971 return bnx2x_func_send_start(bp, params);
5972 case BNX2X_F_CMD_STOP:
5973 return bnx2x_func_send_stop(bp, params);
5974 case BNX2X_F_CMD_HW_RESET:
5975 return bnx2x_func_hw_reset(bp, params);
5976 case BNX2X_F_CMD_AFEX_UPDATE:
5977 return bnx2x_func_send_afex_update(bp, params);
5978 case BNX2X_F_CMD_AFEX_VIFLISTS:
5979 return bnx2x_func_send_afex_viflists(bp, params);
5980 case BNX2X_F_CMD_TX_STOP:
5981 return bnx2x_func_send_tx_stop(bp, params);
5982 case BNX2X_F_CMD_TX_START:
5983 return bnx2x_func_send_tx_start(bp, params);
5984 case BNX2X_F_CMD_SWITCH_UPDATE:
5985 return bnx2x_func_send_switch_update(bp, params);
5986 case BNX2X_F_CMD_SET_TIMESYNC:
5987 return bnx2x_func_send_set_timesync(bp, params);
5989 BNX2X_ERR("Unknown command: %d\n", params->cmd);
5994 void bnx2x_init_func_obj(struct bnx2x *bp,
5995 struct bnx2x_func_sp_obj *obj,
5996 void *rdata, dma_addr_t rdata_mapping,
5997 void *afex_rdata, dma_addr_t afex_rdata_mapping,
5998 struct bnx2x_func_sp_drv_ops *drv_iface)
6000 memset(obj, 0, sizeof(*obj));
6002 mutex_init(&obj->one_pending_mutex);
6005 obj->rdata_mapping = rdata_mapping;
6006 obj->afex_rdata = afex_rdata;
6007 obj->afex_rdata_mapping = afex_rdata_mapping;
6008 obj->send_cmd = bnx2x_func_send_cmd;
6009 obj->check_transition = bnx2x_func_chk_transition;
6010 obj->complete_cmd = bnx2x_func_comp_cmd;
6011 obj->wait_comp = bnx2x_func_wait_comp;
6013 obj->drv = drv_iface;
6017 * bnx2x_func_state_change - perform Function state change transition
6019 * @bp: device handle
6020 * @params: parameters to perform the transaction
6022 * returns 0 in case of successfully completed transition,
6023 * negative error code in case of failure, positive
6024 * (EBUSY) value if there is a completion to that is
6025 * still pending (possible only if RAMROD_COMP_WAIT is
6026 * not set in params->ramrod_flags for asynchronous
6029 int bnx2x_func_state_change(struct bnx2x *bp,
6030 struct bnx2x_func_state_params *params)
6032 struct bnx2x_func_sp_obj *o = params->f_obj;
6034 enum bnx2x_func_cmd cmd = params->cmd;
6035 unsigned long *pending = &o->pending;
6037 mutex_lock(&o->one_pending_mutex);
6039 /* Check that the requested transition is legal */
6040 rc = o->check_transition(bp, o, params);
6041 if ((rc == -EBUSY) &&
6042 (test_bit(RAMROD_RETRY, ¶ms->ramrod_flags))) {
6043 while ((rc == -EBUSY) && (--cnt > 0)) {
6044 mutex_unlock(&o->one_pending_mutex);
6046 mutex_lock(&o->one_pending_mutex);
6047 rc = o->check_transition(bp, o, params);
6050 mutex_unlock(&o->one_pending_mutex);
6051 BNX2X_ERR("timeout waiting for previous ramrod completion\n");
6055 mutex_unlock(&o->one_pending_mutex);
6059 /* Set "pending" bit */
6060 set_bit(cmd, pending);
6062 /* Don't send a command if only driver cleanup was requested */
6063 if (test_bit(RAMROD_DRV_CLR_ONLY, ¶ms->ramrod_flags)) {
6064 bnx2x_func_state_change_comp(bp, o, cmd);
6065 mutex_unlock(&o->one_pending_mutex);
6068 rc = o->send_cmd(bp, params);
6070 mutex_unlock(&o->one_pending_mutex);
6073 o->next_state = BNX2X_F_STATE_MAX;
6074 clear_bit(cmd, pending);
6075 smp_mb__after_atomic();
6079 if (test_bit(RAMROD_COMP_WAIT, ¶ms->ramrod_flags)) {
6080 rc = o->wait_comp(bp, o, cmd);
6088 return !!test_bit(cmd, pending);