20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 #include <linux/module.h>
24 #include <linux/netdevice.h>
31 #define BNX2X_MAX_EMUL_MULTI 16
33 #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
48 static inline void bnx2x_exe_queue_init(
struct bnx2x *bp,
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,
91 spin_lock_bh(&o->
lock);
96 spin_unlock_bh(&o->lock);
118 spin_lock_bh(&o->lock);
122 rc = o->optimize(bp, o->owner, elem);
127 rc = o->validate(bp, o->owner, elem);
137 spin_unlock_bh(&o->lock);
142 bnx2x_exe_queue_free_elem(bp, elem);
144 spin_unlock_bh(&o->lock);
150 static inline void __bnx2x_exe_queue_reset_pending(
161 bnx2x_exe_queue_free_elem(bp, elem);
165 static inline void bnx2x_exe_queue_reset_pending(
struct bnx2x *bp,
169 spin_lock_bh(&o->
lock);
171 __bnx2x_exe_queue_reset_pending(bp, o);
173 spin_unlock_bh(&o->
lock);
186 static inline int bnx2x_exe_queue_step(
struct bnx2x *bp,
188 unsigned long *ramrod_flags)
193 memset(&spacer, 0,
sizeof(spacer));
195 spin_lock_bh(&o->
lock);
206 DP(
BNX2X_MSG_SP,
"RAMROD_DRV_CLR_ONLY requested: resetting a pending_comp list\n");
207 __bnx2x_exe_queue_reset_pending(bp, o);
209 spin_unlock_bh(&o->
lock);
240 spin_unlock_bh(&o->
lock);
256 __bnx2x_exe_queue_reset_pending(bp, o);
258 spin_unlock_bh(&o->
lock);
307 static inline int bnx2x_state_wait(
struct bnx2x *bp,
int state,
322 #ifdef BNX2X_STOP_ON_ERROR
335 BNX2X_ERR(
"timeout waiting for state %d\n", state);
336 #ifdef BNX2X_STOP_ON_ERROR
345 return bnx2x_state_wait(bp, raw->
state, raw->
pstate);
365 return mp->
get(mp, 1);
383 return vp->
get(vp, 1);
394 if (!vp->
get(vp, 1)) {
413 return mp->
put(mp, 1);
427 return vp->
put(vp, 1);
438 if (!vp->
put(vp, 1)) {
469 DP(
BNX2X_MSG_SP,
"copied element number %d to address %p element was %pM\n",
470 counter, next, pos->
u.
mac.mac);
477 static int bnx2x_check_mac_add(
struct bnx2x *bp,
485 if (!is_valid_ether_addr(data->
mac.mac))
502 DP(
BNX2X_MSG_SP,
"Checking VLAN %d for ADD command\n", data->vlan.vlan);
511 static
int bnx2x_check_vlan_mac_add(
struct bnx2x *bp,
518 data->vlan_mac.mac, data->vlan_mac.vlan);
521 if ((data->vlan_mac.
vlan == pos->
u.vlan_mac.
vlan) &&
522 (!
memcmp(data->vlan_mac.mac, pos->
u.vlan_mac.mac,
538 DP(
BNX2X_MSG_SP,
"Checking MAC %pM for DEL command\n", data->mac.mac);
554 DP(
BNX2X_MSG_SP,
"Checking VLAN %d for DEL command\n", data->vlan.vlan);
571 data->vlan_mac.mac, data->vlan_mac.vlan);
574 if ((data->vlan_mac.
vlan == pos->
u.vlan_mac.
vlan) &&
575 (!
memcmp(data->vlan_mac.mac, pos->
u.vlan_mac.mac,
594 pos = src_o->check_del(bp, src_o, data);
597 rc = dst_o->check_add(bp, dst_o, data);
608 static bool bnx2x_check_move_always_err(
636 bool add,
unsigned char *dev_addr,
int index)
649 (add ?
"ADD" :
"DELETE"), index);
653 reg_offset += 8*
index;
655 wb_data[0] = ((dev_addr[2] << 24) | (dev_addr[3] << 16) |
656 (dev_addr[4] << 8) | dev_addr[5]);
657 wb_data[1] = ((dev_addr[0] << 8) | dev_addr[1]);
676 static inline void bnx2x_vlan_mac_set_cmd_hdr_e2(
struct bnx2x *bp,
687 bnx2x_vlan_mac_get_rx_tx_flag(o);
707 static inline void bnx2x_vlan_mac_set_rdata_hdr_e2(
u32 cid,
int type,
716 static void bnx2x_set_one_mac_e2(
struct bnx2x *bp,
759 memset(data, 0,
sizeof(*data));
763 &rule_entry->
mac.header);
766 (add ?
"add" :
"delete"), mac, raw->
cl_id);
769 bnx2x_set_fw_mac_addr(&rule_entry->
mac.mac_msb,
770 &rule_entry->
mac.mac_mid,
771 &rule_entry->
mac.mac_lsb, mac);
779 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
782 &rule_entry->
mac.header);
785 bnx2x_set_fw_mac_addr(&rule_entry->
mac.mac_msb,
786 &rule_entry->
mac.mac_mid,
787 &rule_entry->
mac.mac_lsb, mac);
793 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->
cid, raw->
state, &data->
header,
808 static inline void bnx2x_vlan_mac_set_rdata_hdr_e1x(
struct bnx2x *bp,
820 static inline void bnx2x_vlan_mac_set_cfg_entry_e1x(
struct bnx2x *bp,
846 static inline void bnx2x_vlan_mac_set_rdata_e1x(
struct bnx2x *bp,
853 bnx2x_vlan_mac_set_rdata_hdr_e1x(bp, o, type, cam_offset,
855 bnx2x_vlan_mac_set_cfg_entry_e1x(bp, o, add, opcode, mac, vlan_id,
859 (add ?
"setting" :
"clearing"),
860 mac, raw->
cl_id, cam_offset);
872 static void bnx2x_set_one_mac_e1x(
struct bnx2x *bp,
888 memset(config, 0,
sizeof(*config));
890 bnx2x_vlan_mac_set_rdata_e1x(bp, o, raw->
state,
896 static void bnx2x_set_one_vlan_e2(
struct bnx2x *bp,
904 int rule_cnt = rule_idx + 1;
912 memset(data, 0,
sizeof(*data));
916 &rule_entry->
vlan.header);
918 DP(
BNX2X_MSG_SP,
"About to %s VLAN %d\n", (add ?
"add" :
"delete"),
930 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
933 &rule_entry->
vlan.header);
942 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->
cid, raw->
state, &data->
header,
946 static void bnx2x_set_one_vlan_mac_e2(
struct bnx2x *bp,
949 int rule_idx,
int cam_offset)
954 int rule_cnt = rule_idx + 1;
964 memset(data, 0,
sizeof(*data));
968 &rule_entry->
pair.header);
972 bnx2x_set_fw_mac_addr(&rule_entry->
pair.mac_msb,
973 &rule_entry->
pair.mac_mid,
974 &rule_entry->
pair.mac_lsb, mac);
982 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
985 &rule_entry->
pair.header);
989 bnx2x_set_fw_mac_addr(&rule_entry->
pair.mac_msb,
990 &rule_entry->
pair.mac_mid,
991 &rule_entry->
pair.mac_lsb, mac);
997 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->
cid, raw->
state, &data->
header,
1010 static void bnx2x_set_one_vlan_mac_e1h(
struct bnx2x *bp,
1013 int rule_idx,
int cam_offset)
1026 memset(config, 0,
sizeof(*config));
1035 #define list_next_entry(pos, member) \
1036 list_entry((pos)->member.next, typeof(*(pos)), member)
1057 static int bnx2x_vlan_mac_restore(
struct bnx2x *bp,
1065 if (list_empty(&o->
head)) {
1081 if (list_is_last(&pos->
link, &o->
head))
1113 if (!
memcmp(&pos->cmd_data.vlan_mac.
u.mac, data,
1115 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1130 if (!
memcmp(&pos->cmd_data.vlan_mac.
u.vlan, data,
1132 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1144 &elem->cmd_data.vlan_mac.u.vlan_mac;
1148 if (!
memcmp(&pos->cmd_data.vlan_mac.
u.vlan_mac, data,
1150 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1178 rc = o->
check_add(bp, o, &elem->cmd_data.vlan_mac.u);
1180 DP(
BNX2X_MSG_SP,
"ADD command is not allowed considering current registry state.\n");
1188 if (exeq->
get(exeq, elem)) {
1200 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1219 static inline int bnx2x_validate_vlan_mac_del(
struct bnx2x *bp,
1233 DP(
BNX2X_MSG_SP,
"DEL command is not allowed considering current registry state\n");
1241 memcpy(&query_elem, elem,
sizeof(query_elem));
1245 if (exeq->
get(exeq, &query_elem)) {
1246 BNX2X_ERR(
"There is a pending MOVE command already\n");
1251 if (exeq->
get(exeq, elem)) {
1260 BNX2X_ERR(
"Failed to return a credit\n");
1279 static inline int bnx2x_validate_vlan_mac_move(
struct bnx2x *bp,
1295 DP(
BNX2X_MSG_SP,
"MOVE command is not allowed considering current registry state\n");
1304 memcpy(&query_elem, elem,
sizeof(query_elem));
1308 if (src_exeq->
get(src_exeq, &query_elem)) {
1309 BNX2X_ERR(
"There is a pending DEL command on the source queue already\n");
1314 if (src_exeq->
get(src_exeq, elem)) {
1321 if (dest_exeq->
get(dest_exeq, &query_elem)) {
1322 BNX2X_ERR(
"There is a pending ADD command on the destination queue already\n");
1343 static int bnx2x_validate_vlan_mac(
struct bnx2x *bp,
1349 return bnx2x_validate_vlan_mac_add(bp, qo, elem);
1351 return bnx2x_validate_vlan_mac_del(bp, qo, elem);
1353 return bnx2x_validate_vlan_mac_move(bp, qo, elem);
1359 static int bnx2x_remove_vlan_mac(
struct bnx2x *bp,
1395 static int bnx2x_wait_vlan_mac(
struct bnx2x *bp,
1409 if (!bnx2x_exe_queue_empty(exeq))
1427 static int bnx2x_complete_vlan_mac(
struct bnx2x *bp,
1430 unsigned long *ramrod_flags)
1436 bnx2x_exe_queue_reset_pending(bp, &o->
exe_queue);
1447 rc = bnx2x_exe_queue_step(bp, &o->
exe_queue, ramrod_flags);
1453 if (!bnx2x_exe_queue_empty(&o->
exe_queue))
1466 static int bnx2x_optimize_vlan_mac(
struct bnx2x *bp,
1495 if ((
query.cmd_data.vlan_mac.cmd ==
1497 BNX2X_ERR(
"Failed to return the credit for the optimized ADD command\n");
1500 BNX2X_ERR(
"Failed to recover the credit from the optimized DEL command\n");
1510 bnx2x_exe_queue_free_elem(bp, pos);
1528 static inline int bnx2x_vlan_mac_get_registry_elem(
1541 reg_elem = kzalloc(
sizeof(*reg_elem),
GFP_ATOMIC);
1560 sizeof(reg_elem->
u));
1582 static int bnx2x_execute_vlan_mac(
struct bnx2x *bp,
1585 unsigned long *ramrod_flags)
1618 rc = bnx2x_vlan_mac_get_registry_elem(bp, cam_obj,
1630 list_add(®_elem->
link, &cam_obj->head);
1708 static inline int bnx2x_vlan_mac_push_new_cmd(
1717 elem = bnx2x_exe_queue_alloc_elem(bp);
1734 return bnx2x_exe_queue_add(bp, &o->
exe_queue, elem, restore);
1758 rc = bnx2x_vlan_mac_push_new_cmd(bp, p);
1767 if (!bnx2x_exe_queue_empty(&o->
exe_queue))
1771 DP(
BNX2X_MSG_SP,
"RAMROD_DRV_CLR_ONLY requested: clearing a pending bit.\n");
1778 rc = bnx2x_exe_queue_step(bp, &o->
exe_queue, ramrod_flags);
1792 int max_iterations = bnx2x_exe_queue_length(&o->
exe_queue) + 1;
1794 while (!bnx2x_exe_queue_empty(&o->
exe_queue) &&
1803 rc = bnx2x_exe_queue_step(bp, &o->
exe_queue,
1830 static int bnx2x_vlan_mac_del_all(
struct bnx2x *bp,
1832 unsigned long *vlan_mac_flags,
1833 unsigned long *ramrod_flags)
1843 spin_lock_bh(&exeq->
lock);
1850 BNX2X_ERR(
"Failed to remove command\n");
1851 spin_unlock_bh(&exeq->
lock);
1858 spin_unlock_bh(&exeq->
lock);
1861 memset(&p, 0,
sizeof(p));
1880 BNX2X_ERR(
"Failed to add a new DEL command\n");
1892 static inline void bnx2x_init_raw_obj(
struct bnx2x_raw_obj *raw,
u8 cl_id,
1916 INIT_LIST_HEAD(&o->
head);
1922 o->
restore = bnx2x_vlan_mac_restore;
1923 o->
complete = bnx2x_complete_vlan_mac;
1924 o->
wait = bnx2x_wait_vlan_mac;
1926 bnx2x_init_raw_obj(&o->
raw, cl_id, cid, func_id, rdata, rdata_mapping,
1927 state, pstate, type);
1940 bnx2x_init_vlan_mac_common(mac_obj, cl_id, cid, func_id, rdata,
1941 rdata_mapping, state, pstate, type,
1952 mac_obj->
check_del = bnx2x_check_mac_del;
1953 mac_obj->
check_add = bnx2x_check_mac_add;
1954 mac_obj->
check_move = bnx2x_check_move_always_err;
1958 bnx2x_exe_queue_init(bp,
1960 bnx2x_validate_vlan_mac,
1961 bnx2x_remove_vlan_mac,
1962 bnx2x_optimize_vlan_mac,
1963 bnx2x_execute_vlan_mac,
1964 bnx2x_exeq_get_mac);
1967 mac_obj->
check_del = bnx2x_check_mac_del;
1968 mac_obj->
check_add = bnx2x_check_mac_add;
1975 bnx2x_exe_queue_init(bp,
1977 qable_obj, bnx2x_validate_vlan_mac,
1978 bnx2x_remove_vlan_mac,
1979 bnx2x_optimize_vlan_mac,
1980 bnx2x_execute_vlan_mac,
1981 bnx2x_exeq_get_mac);
1994 bnx2x_init_vlan_mac_common(vlan_obj, cl_id, cid, func_id, rdata,
1995 rdata_mapping, state, pstate, type, NULL,
1998 vlan_obj->
get_credit = bnx2x_get_credit_vlan;
1999 vlan_obj->
put_credit = bnx2x_put_credit_vlan;
2004 BNX2X_ERR(
"Do not support chips others than E2 and newer\n");
2008 vlan_obj->
check_del = bnx2x_check_vlan_del;
2009 vlan_obj->
check_add = bnx2x_check_vlan_add;
2015 bnx2x_exe_queue_init(bp,
2017 qable_obj, bnx2x_validate_vlan_mac,
2018 bnx2x_remove_vlan_mac,
2019 bnx2x_optimize_vlan_mac,
2020 bnx2x_execute_vlan_mac,
2021 bnx2x_exeq_get_vlan);
2036 bnx2x_init_vlan_mac_common(vlan_mac_obj, cl_id, cid, func_id, rdata,
2037 rdata_mapping, state, pstate, type,
2038 macs_pool, vlans_pool);
2041 vlan_mac_obj->
get_credit = bnx2x_get_credit_vlan_mac;
2042 vlan_mac_obj->
put_credit = bnx2x_put_credit_vlan_mac;
2052 BNX2X_ERR(
"Do not support chips others than E2\n");
2055 vlan_mac_obj->
set_one_rule = bnx2x_set_one_vlan_mac_e1h;
2056 vlan_mac_obj->
check_del = bnx2x_check_vlan_mac_del;
2057 vlan_mac_obj->
check_add = bnx2x_check_vlan_mac_add;
2058 vlan_mac_obj->
check_move = bnx2x_check_move_always_err;
2062 bnx2x_exe_queue_init(bp,
2064 bnx2x_validate_vlan_mac,
2065 bnx2x_remove_vlan_mac,
2066 bnx2x_optimize_vlan_mac,
2067 bnx2x_execute_vlan_mac,
2068 bnx2x_exeq_get_vlan_mac);
2070 vlan_mac_obj->
set_one_rule = bnx2x_set_one_vlan_mac_e2;
2071 vlan_mac_obj->
check_del = bnx2x_check_vlan_mac_del;
2072 vlan_mac_obj->
check_add = bnx2x_check_vlan_mac_add;
2078 bnx2x_exe_queue_init(bp,
2081 qable_obj, bnx2x_validate_vlan_mac,
2082 bnx2x_remove_vlan_mac,
2083 bnx2x_optimize_vlan_mac,
2084 bnx2x_execute_vlan_mac,
2085 bnx2x_exeq_get_vlan_mac);
2091 static inline void __storm_memset_mac_filters(
struct bnx2x *bp,
2100 __storm_memset_struct(bp, addr, size, (
u32 *)mac_filters);
2103 static int bnx2x_set_rx_mode_e1x(
struct bnx2x *bp,
2113 u8 drop_all_ucast = 1, drop_all_mcast = 1;
2114 u8 accp_all_ucast = 0, accp_all_bcast = 0, accp_all_mcast = 0;
2168 DP(
BNX2X_MSG_SP,
"drop_ucast 0x%x\ndrop_mcast 0x%x\n accp_ucast 0x%x\n"
2169 "accp_mcast 0x%x\naccp_bcast 0x%x\n",
2175 __storm_memset_mac_filters(bp, mac_filters, p->
func_id);
2185 static inline void bnx2x_rx_mode_set_rdata_hdr_e2(
u32 cid,
2193 static inline void bnx2x_rx_mode_set_cmd_state_e2(
struct bnx2x *bp,
2194 unsigned long accept_flags,
2196 bool clear_accept_all)
2232 if (clear_accept_all) {
2243 static int bnx2x_set_rx_mode_e2(
struct bnx2x *bp,
2251 memset(data, 0,
sizeof(*data));
2260 data->
rules[rule_idx].cmd_general_data =
2264 &(data->
rules[rule_idx++]),
false);
2272 data->
rules[rule_idx].cmd_general_data =
2276 &(data->
rules[rule_idx++]),
false);
2293 data->
rules[rule_idx].cmd_general_data =
2297 &(data->
rules[rule_idx++]),
2306 data->
rules[rule_idx].cmd_general_data =
2310 &(data->
rules[rule_idx++]),
2319 bnx2x_rx_mode_set_rdata_hdr_e2(p->
cid, &data->
header, rule_idx);
2321 DP(
BNX2X_MSG_SP,
"About to configure %d rules, rx_accept_flags 0x%lx, tx_accept_flags 0x%lx\n",
2345 static int bnx2x_wait_rx_mode_comp_e2(
struct bnx2x *bp,
2351 static int bnx2x_empty_rx_mode_wait(
struct bnx2x *bp,
2382 o->
wait_comp = bnx2x_empty_rx_mode_wait;
2385 o->
wait_comp = bnx2x_wait_rx_mode_comp_e2;
2391 static inline u8 bnx2x_mcast_bin_from_mac(
u8 *mac)
2419 static int bnx2x_mcast_wait(
struct bnx2x *bp,
2423 o->
raw.wait_comp(bp, &o->
raw))
2429 static int bnx2x_mcast_enqueue_cmd(
struct bnx2x *bp,
2445 total_sz =
sizeof(*new_cmd) +
2454 DP(
BNX2X_MSG_SP,
"About to enqueue a new %d command. macs_list_len=%d\n",
2455 cmd, macs_list_len);
2457 INIT_LIST_HEAD(&new_cmd->data.macs_head);
2459 new_cmd->type =
cmd;
2460 new_cmd->done =
false;
2465 ((
u8 *)new_cmd +
sizeof(*new_cmd));
2483 new_cmd->data.next_bin = 0;
2488 BNX2X_ERR(
"Unknown command: %d\n", cmd);
2508 static inline int bnx2x_mcast_get_next_bin(
struct bnx2x_mcast_obj *o,
int last)
2515 int cur_bit = j + BIT_VEC64_ELEM_SZ *
i;
2535 static inline int bnx2x_mcast_clear_first_bin(
struct bnx2x_mcast_obj *o)
2537 int cur_bit = bnx2x_mcast_get_next_bin(o, 0);
2561 static void bnx2x_mcast_set_one_rule_e2(
struct bnx2x *bp,
2570 u8 rx_tx_add_flag = bnx2x_mcast_get_rx_tx_flag(o);
2576 data->
rules[
idx].cmd_general_data |= rx_tx_add_flag;
2581 bin = bnx2x_mcast_bin_from_mac(cfg_data->
mac);
2592 bin = bnx2x_mcast_clear_first_bin(o);
2596 bin = cfg_data->
bin;
2600 BNX2X_ERR(
"Unknown command: %d\n", cmd);
2606 "Setting" :
"Clearing"), bin);
2623 static inline int bnx2x_mcast_handle_restore_cmd_e2(
2627 int cur_bin, cnt = *rdata_idx;
2631 for (cur_bin = bnx2x_mcast_get_next_bin(o, start_bin); cur_bin >= 0;
2632 cur_bin = bnx2x_mcast_get_next_bin(o, cur_bin + 1)) {
2634 cfg_data.
bin = (
u8)cur_bin;
2654 static inline void bnx2x_mcast_hdl_pending_add_e2(
struct bnx2x *bp,
2659 int cnt = *line_idx;
2665 cfg_data.
mac = &pmac_pos->
mac[0];
2686 cmd_pos->
done =
true;
2689 static inline void bnx2x_mcast_hdl_pending_del_e2(
struct bnx2x *bp,
2693 int cnt = *line_idx;
2716 cmd_pos->
done =
true;
2719 static inline void bnx2x_mcast_hdl_pending_restore_e2(
struct bnx2x *bp,
2728 cmd_pos->
done =
true;
2734 static inline int bnx2x_mcast_handle_pending_cmds_e2(
struct bnx2x *bp,
2743 switch (cmd_pos->
type) {
2745 bnx2x_mcast_hdl_pending_add_e2(bp, o, cmd_pos, &cnt);
2749 bnx2x_mcast_hdl_pending_del_e2(bp, o, cmd_pos, &cnt);
2753 bnx2x_mcast_hdl_pending_restore_e2(bp, o, cmd_pos,
2765 if (cmd_pos->
done) {
2778 static inline void bnx2x_mcast_hdl_add(
struct bnx2x *bp,
2784 int cnt = *line_idx;
2787 cfg_data.
mac = mlist_pos->
mac;
2799 static inline void bnx2x_mcast_hdl_del(
struct bnx2x *bp,
2803 int cnt = *line_idx,
i;
2829 static inline int bnx2x_mcast_handle_current_cmd(
struct bnx2x *bp,
2834 int cnt = start_cnt;
2840 bnx2x_mcast_hdl_add(bp, o, p, &cnt);
2844 bnx2x_mcast_hdl_del(bp, o, p, &cnt);
2852 BNX2X_ERR(
"Unknown command: %d\n", cmd);
2862 static int bnx2x_mcast_validate_e2(
struct bnx2x *bp,
2897 BNX2X_ERR(
"Unknown command: %d\n", cmd);
2908 static void bnx2x_mcast_revert_e2(
struct bnx2x *bp,
2925 static inline void bnx2x_mcast_set_rdata_hdr_e2(
struct bnx2x *bp,
2935 data->
header.rule_cnt = len;
2949 static inline int bnx2x_mcast_refresh_registry_e2(
struct bnx2x *bp,
2966 static int bnx2x_mcast_setup_e2(
struct bnx2x *bp,
2977 memset(data, 0,
sizeof(*data));
2979 cnt = bnx2x_mcast_handle_pending_cmds_e2(bp, p);
2992 cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, cnt);
3003 bnx2x_mcast_set_rdata_hdr_e2(bp, p, (
u8)cnt);
3021 bnx2x_mcast_refresh_registry_e2(bp, o);
3052 static int bnx2x_mcast_validate_e1h(
struct bnx2x *bp,
3063 static void bnx2x_mcast_revert_e1h(
struct bnx2x *bp,
3070 #define BNX2X_57711_SET_MC_FILTER(filter, bit) \
3072 (filter)[(bit) >> 5] |= (1 << ((bit) & 0x1f)); \
3075 static inline void bnx2x_mcast_hdl_add_e1h(
struct bnx2x *bp,
3084 bit = bnx2x_mcast_bin_from_mac(mlist_pos->
mac);
3088 mlist_pos->
mac, bit);
3096 static inline void bnx2x_mcast_hdl_restore_e1h(
struct bnx2x *bp,
3102 for (bit = bnx2x_mcast_get_next_bin(o, 0);
3104 bit = bnx2x_mcast_get_next_bin(o, bit + 1)) {
3114 static int bnx2x_mcast_setup_e1h(
struct bnx2x *bp,
3133 bnx2x_mcast_hdl_add_e1h(bp, o, p, mc_filter);
3138 "Invalidating multicast MACs configuration\n");
3146 bnx2x_mcast_hdl_restore_e1h(bp, o, p, mc_filter);
3150 BNX2X_ERR(
"Unknown command: %d\n", cmd);
3168 static int bnx2x_mcast_validate_e1(
struct bnx2x *bp,
3195 BNX2X_ERR(
"Can't configure more than %d multicast MACs on 57710\n",
3210 BNX2X_ERR(
"Unknown command: %d\n", cmd);
3224 static void bnx2x_mcast_revert_e1(
struct bnx2x *bp,
3240 static void bnx2x_mcast_set_one_rule_e1(
struct bnx2x *bp,
3251 bnx2x_set_fw_mac_addr(&data->
config_table[idx].msb_mac_addr,
3274 static inline void bnx2x_mcast_set_rdata_hdr_e1(
struct bnx2x *bp,
3287 data->
hdr.client_id = 0xff;
3290 data->
hdr.length = len;
3306 static inline int bnx2x_mcast_handle_restore_cmd_e1(
3316 cfg_data.
mac = &elem->
mac[0];
3331 static inline int bnx2x_mcast_handle_pending_cmds_e1(
3349 switch (cmd_pos->
type) {
3352 cfg_data.
mac = &pmac_pos->
mac[0];
3390 static inline void bnx2x_get_fw_mac_addr(
__le16 *fw_hi,
__le16 *fw_mid,
3393 mac[1] = ((
u8 *)fw_hi)[0];
3394 mac[0] = ((
u8 *)fw_hi)[1];
3395 mac[3] = ((
u8 *)fw_mid)[0];
3396 mac[2] = ((
u8 *)fw_mid)[1];
3397 mac[5] = ((
u8 *)fw_lo)[0];
3398 mac[4] = ((
u8 *)fw_lo)[1];
3412 static inline int bnx2x_mcast_refresh_registry_e1(
struct bnx2x *bp,
3425 int i, len = data->
hdr.length;
3431 elem = kcalloc(len,
sizeof(*elem),
GFP_ATOMIC);
3433 BNX2X_ERR(
"Failed to allocate registry memory\n");
3437 for (i = 0; i < len; i++, elem++) {
3438 bnx2x_get_fw_mac_addr(
3459 static int bnx2x_mcast_setup_e1(
struct bnx2x *bp,
3470 memset(data, 0,
sizeof(*data));
3479 cnt = bnx2x_mcast_handle_pending_cmds_e1(bp, p);
3487 cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, 0);
3499 bnx2x_mcast_set_rdata_hdr_e1(bp, p, (
u8)cnt);
3507 rc = bnx2x_mcast_refresh_registry_e1(bp, o);
3541 static int bnx2x_mcast_get_registry_size_exact(
struct bnx2x_mcast_obj *o)
3546 static int bnx2x_mcast_get_registry_size_aprox(
struct bnx2x_mcast_obj *o)
3551 static void bnx2x_mcast_set_registry_size_exact(
struct bnx2x_mcast_obj *o,
3557 static void bnx2x_mcast_set_registry_size_aprox(
struct bnx2x_mcast_obj *o,
3569 int rc = 0, old_reg_size;
3585 DP(
BNX2X_MSG_SP,
"o->total_pending_num=%d p->mcast_list_len=%d o->max_cmd_len=%d\n",
3624 o->
revert(bp, p, old_reg_size);
3655 u8 mcast_cl_id,
u32 mcast_cid,
u8 func_id,
3659 memset(mcast_obj, 0,
sizeof(*mcast_obj));
3661 bnx2x_init_raw_obj(&mcast_obj->
raw, mcast_cl_id, mcast_cid, func_id,
3662 rdata, rdata_mapping, state, pstate, type);
3670 mcast_obj->
set_sched = bnx2x_mcast_set_sched;
3677 bnx2x_mcast_handle_restore_cmd_e1;
3685 mcast_obj->
wait_comp = bnx2x_mcast_wait;
3687 mcast_obj->
validate = bnx2x_mcast_validate_e1;
3688 mcast_obj->
revert = bnx2x_mcast_revert_e1;
3690 bnx2x_mcast_get_registry_size_exact;
3692 bnx2x_mcast_set_registry_size_exact;
3709 mcast_obj->
wait_comp = bnx2x_mcast_wait;
3711 mcast_obj->
validate = bnx2x_mcast_validate_e1h;
3712 mcast_obj->
revert = bnx2x_mcast_revert_e1h;
3714 bnx2x_mcast_get_registry_size_aprox;
3716 bnx2x_mcast_set_registry_size_aprox;
3721 bnx2x_mcast_handle_restore_cmd_e2;
3726 mcast_obj->
wait_comp = bnx2x_mcast_wait;
3728 mcast_obj->
validate = bnx2x_mcast_validate_e2;
3729 mcast_obj->
revert = bnx2x_mcast_revert_e2;
3731 bnx2x_mcast_get_registry_size_aprox;
3733 bnx2x_mcast_set_registry_size_aprox;
3749 static inline bool __atomic_add_ifless(
atomic_t *
v,
int a,
int u)
3777 static inline bool __atomic_dec_ifmoe(
atomic_t *v,
int a,
int u)
3800 rc = __atomic_dec_ifmoe(&o->
credit, cnt, 0);
3837 static bool bnx2x_credit_pool_get_entry(
3853 for (idx = vec * BIT_VEC64_ELEM_SZ, i = 0;
3867 static bool bnx2x_credit_pool_put_entry(
3885 static bool bnx2x_credit_pool_put_entry_always_true(
3892 static bool bnx2x_credit_pool_get_entry_always_true(
3911 int base,
int credit)
3914 memset(p, 0,
sizeof(*p));
3930 p->
check = bnx2x_credit_pool_check;
3934 p->
put = bnx2x_credit_pool_put;
3935 p->
get = bnx2x_credit_pool_get;
3936 p->
put_entry = bnx2x_credit_pool_put_entry;
3937 p->
get_entry = bnx2x_credit_pool_get_entry;
3939 p->
put = bnx2x_credit_pool_always_true;
3940 p->
get = bnx2x_credit_pool_always_true;
3941 p->
put_entry = bnx2x_credit_pool_put_entry_always_true;
3942 p->
get_entry = bnx2x_credit_pool_get_entry_always_true;
3947 p->
put_entry = bnx2x_credit_pool_put_entry_always_true;
3948 p->
get_entry = bnx2x_credit_pool_get_entry_always_true;
3957 #define BNX2X_CAM_SIZE_EMUL 5
3968 bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
3974 if ((func_num > 0)) {
3979 bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
3982 bnx2x_init_credit_pool(p, 0, 0);
3991 if ((func_num > 0)) {
4001 bnx2x_init_credit_pool(p, -1, cam_sz);
4004 bnx2x_init_credit_pool(p, 0, 0);
4020 bnx2x_init_credit_pool(p, 0, -1);
4028 bnx2x_init_credit_pool(p, func_id * credit, credit);
4031 bnx2x_init_credit_pool(p, 0, 0);
4044 static inline void bnx2x_debug_print_ind_table(
struct bnx2x *bp,
4055 if ((i + 1 < T_ETH_INDIRECTION_TABLE_SIZE) &&
4056 (((i + 1) & 0x3) == 0)) {
4073 static int bnx2x_setup_rss(
struct bnx2x *bp,
4083 memset(data, 0,
sizeof(*data));
4136 T_ETH_INDIRECTION_TABLE_SIZE);
4143 bnx2x_debug_print_ind_table(bp, p);
4208 int state,
unsigned long *pstate,
4211 bnx2x_init_raw_obj(&rss_obj->
raw, cl_id, cid, func_id, rdata,
4212 rdata_mapping, state, pstate, type);
4236 int rc, pending_bit;
4268 return !!
test_bit(pending_bit, pending);
4290 static int bnx2x_queue_wait_comp(
struct bnx2x *bp,
4294 return bnx2x_state_wait(bp, cmd, &o->
pending);
4306 static int bnx2x_queue_comp_cmd(
struct bnx2x *bp,
4310 unsigned long cur_pending = o->
pending;
4313 BNX2X_ERR(
"Bad MC reply %d for queue %d in state %d pending 0x%lx, next_state %d\n",
4323 BNX2X_ERR(
"illegal value for next tx_only: %d. max cos was %d",
4327 "Completing command %d for queue %d, setting state to %d\n",
4349 static void bnx2x_q_fill_setup_data_e2(
struct bnx2x *bp,
4362 static void bnx2x_q_fill_init_general_data(
struct bnx2x *bp,
4366 unsigned long *
flags)
4387 gen_data->
cos = params->
cos;
4400 unsigned long *flags)
4445 unsigned long *flags)
4511 static void bnx2x_q_fill_setup_data_cmn(
struct bnx2x *bp,
4515 bnx2x_q_fill_init_general_data(bp, cmd_params->
q_obj,
4520 bnx2x_q_fill_init_tx_data(cmd_params->
q_obj,
4525 bnx2x_q_fill_init_rx_data(cmd_params->
q_obj,
4530 bnx2x_q_fill_init_pause_data(cmd_params->
q_obj,
4536 static void bnx2x_q_fill_setup_tx_only(
struct bnx2x *bp,
4540 bnx2x_q_fill_init_general_data(bp, cmd_params->
q_obj,
4545 bnx2x_q_fill_init_tx_data(cmd_params->
q_obj,
4551 cmd_params->
q_obj->cids[0],
4552 data->
tx.tx_bd_page_base.lo,
4553 data->
tx.tx_bd_page_base.hi);
4567 static inline int bnx2x_q_init(
struct bnx2x *bp,
4578 hc_usec = init->
tx.hc_rate ? 1000000 / init->
tx.hc_rate : 0;
4581 init->
tx.sb_cq_index,
4589 hc_usec = init->
rx.hc_rate ? 1000000 / init->
rx.hc_rate : 0;
4592 init->
rx.sb_cq_index,
4598 for (cos = 0; cos < o->
max_cos; cos++) {
4614 static inline int bnx2x_q_send_setup_e1x(
struct bnx2x *bp,
4624 memset(rdata, 0,
sizeof(*rdata));
4627 bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
4642 static inline int bnx2x_q_send_setup_e2(
struct bnx2x *bp,
4652 memset(rdata, 0,
sizeof(*rdata));
4655 bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
4656 bnx2x_q_fill_setup_data_e2(bp, params, rdata);
4671 static inline int bnx2x_q_send_setup_tx_only(
struct bnx2x *bp,
4681 u8 cid_index = tx_only_params->cid_index;
4685 BNX2X_ERR(
"queue[%d]: cid_index (%d) is out of range\n",
4686 o->
cl_id, cid_index);
4691 tx_only_params->gen_params.cos,
4692 tx_only_params->gen_params.spcl_id);
4695 memset(rdata, 0,
sizeof(*rdata));
4698 bnx2x_q_fill_setup_tx_only(bp, params, rdata);
4700 DP(
BNX2X_MSG_SP,
"sending tx-only ramrod: cid %d, client-id %d, sp-client id %d, cos %d\n",
4717 static void bnx2x_q_fill_update_data(
struct bnx2x *bp,
4776 static inline int bnx2x_q_send_update(
struct bnx2x *bp,
4785 u8 cid_index = update_params->cid_index;
4788 BNX2X_ERR(
"queue[%d]: cid_index (%d) is out of range\n",
4789 o->
cl_id, cid_index);
4795 memset(rdata, 0,
sizeof(*rdata));
4798 bnx2x_q_fill_update_data(bp, o, update_params, rdata);
4821 static inline int bnx2x_q_send_deactivate(
struct bnx2x *bp,
4826 memset(update, 0,
sizeof(*update));
4830 return bnx2x_q_send_update(bp, params);
4841 static inline int bnx2x_q_send_activate(
struct bnx2x *bp,
4846 memset(update, 0,
sizeof(*update));
4851 return bnx2x_q_send_update(bp, params);
4854 static inline int bnx2x_q_send_update_tpa(
struct bnx2x *bp,
4861 static inline int bnx2x_q_send_halt(
struct bnx2x *bp,
4871 static inline int bnx2x_q_send_cfc_del(
struct bnx2x *bp,
4878 BNX2X_ERR(
"queue[%d]: cid_index (%d) is out of range\n",
4887 static inline int bnx2x_q_send_terminate(
struct bnx2x *bp,
4893 if (cid_index >= o->
max_cos) {
4894 BNX2X_ERR(
"queue[%d]: cid_index (%d) is out of range\n",
4895 o->
cl_id, cid_index);
4903 static inline int bnx2x_q_send_empty(
struct bnx2x *bp,
4913 static inline int bnx2x_queue_send_cmd_cmn(
struct bnx2x *bp,
4916 switch (params->
cmd) {
4918 return bnx2x_q_init(bp, params);
4920 return bnx2x_q_send_setup_tx_only(bp, params);
4922 return bnx2x_q_send_deactivate(bp, params);
4924 return bnx2x_q_send_activate(bp, params);
4926 return bnx2x_q_send_update(bp, params);
4928 return bnx2x_q_send_update_tpa(bp, params);
4930 return bnx2x_q_send_halt(bp, params);
4932 return bnx2x_q_send_cfc_del(bp, params);
4934 return bnx2x_q_send_terminate(bp, params);
4936 return bnx2x_q_send_empty(bp, params);
4943 static int bnx2x_queue_send_cmd_e1x(
struct bnx2x *bp,
4946 switch (params->
cmd) {
4948 return bnx2x_q_send_setup_e1x(bp, params);
4959 return bnx2x_queue_send_cmd_cmn(bp, params);
4966 static int bnx2x_queue_send_cmd_e2(
struct bnx2x *bp,
4969 switch (params->
cmd) {
4971 return bnx2x_q_send_setup_e2(bp, params);
4982 return bnx2x_queue_send_cmd_cmn(bp, params);
5005 static int bnx2x_queue_chk_transition(
struct bnx2x *bp,
5107 if (next_tx_only == 0)
5153 BNX2X_ERR(
"Illegal state: %d\n", state);
5165 DP(
BNX2X_MSG_SP,
"Bad state transition request: %d %d\n", state, cmd);
5172 u8 cl_id,
u32 *cids,
u8 cid_cnt,
u8 func_id,
5174 dma_addr_t rdata_mapping,
unsigned long type)
5176 memset(obj, 0,
sizeof(*obj));
5191 obj->
send_cmd = bnx2x_queue_send_cmd_e1x;
5193 obj->
send_cmd = bnx2x_queue_send_cmd_e2;
5219 static int bnx2x_func_wait_comp(
struct bnx2x *bp,
5223 return bnx2x_state_wait(bp, cmd, &o->
pending);
5236 static inline int bnx2x_func_state_change_comp(
struct bnx2x *bp,
5240 unsigned long cur_pending = o->
pending;
5243 BNX2X_ERR(
"Bad MC reply %d for func %d in state %d pending 0x%lx, next_state %d\n",
5250 "Completing command %d for func %d, setting state to %d\n",
5276 static int bnx2x_func_comp_cmd(
struct bnx2x *bp,
5283 int rc = bnx2x_func_state_change_comp(bp, o, cmd);
5302 static int bnx2x_func_chk_transition(
struct bnx2x *bp,
5363 BNX2X_ERR(
"Unknown state: %d\n", state);
5374 DP(
BNX2X_MSG_SP,
"Bad function state transition request: %d %d\n",
5390 static inline int bnx2x_func_init_func(
struct bnx2x *bp,
5407 static inline int bnx2x_func_init_port(
struct bnx2x *bp,
5414 return bnx2x_func_init_func(bp, drv);
5427 static inline int bnx2x_func_init_cmn_chip(
struct bnx2x *bp,
5434 return bnx2x_func_init_port(bp, drv);
5447 static inline int bnx2x_func_init_cmn(
struct bnx2x *bp,
5454 return bnx2x_func_init_port(bp, drv);
5457 static int bnx2x_func_hw_init(
struct bnx2x *bp,
5481 switch (load_code) {
5483 rc = bnx2x_func_init_cmn_chip(bp, drv);
5489 rc = bnx2x_func_init_cmn(bp, drv);
5495 rc = bnx2x_func_init_port(bp, drv);
5501 rc = bnx2x_func_init_func(bp, drv);
5507 BNX2X_ERR(
"Unknown load_code (0x%x) from MCP\n", load_code);
5532 static inline void bnx2x_func_reset_func(
struct bnx2x *bp,
5553 static inline void bnx2x_func_reset_port(
struct bnx2x *bp,
5557 bnx2x_func_reset_func(bp, drv);
5570 static inline void bnx2x_func_reset_cmn(
struct bnx2x *bp,
5573 bnx2x_func_reset_port(bp, drv);
5578 static inline int bnx2x_func_hw_reset(
struct bnx2x *bp,
5588 switch (reset_phase) {
5590 bnx2x_func_reset_cmn(bp, drv);
5593 bnx2x_func_reset_port(bp, drv);
5596 bnx2x_func_reset_func(bp, drv);
5599 BNX2X_ERR(
"Unknown reset_phase (0x%x) from MCP\n",
5610 static inline int bnx2x_func_send_start(
struct bnx2x *bp,
5619 memset(rdata, 0,
sizeof(*rdata));
5640 static inline int bnx2x_func_send_afex_update(
struct bnx2x *bp,
5650 memset(rdata, 0,
sizeof(*rdata));
5657 cpu_to_le16(afex_update_params->afex_default_vlan);
5668 "afex: sending func_update vif_id 0x%x dvlan 0x%x prio 0x%x\n",
5678 inline int bnx2x_func_send_afex_viflists(
struct bnx2x *bp,
5686 u64 *p_rdata = (
u64 *)rdata;
5688 memset(rdata, 0,
sizeof(*rdata));
5692 rdata->
func_bit_map = afex_viflist_params->func_bit_map;
5694 afex_viflist_params->afex_vif_list_command;
5698 rdata->
echo = afex_viflist_params->afex_vif_list_command;
5707 DP(
BNX2X_MSG_SP,
"afex: ramrod lists, cmd 0x%x index 0x%x func_bit_map 0x%x func_to_clr 0x%x\n",
5717 static inline int bnx2x_func_send_stop(
struct bnx2x *bp,
5724 static inline int bnx2x_func_send_tx_stop(
struct bnx2x *bp,
5730 static inline int bnx2x_func_send_tx_start(
struct bnx2x *bp,
5741 memset(rdata, 0,
sizeof(*rdata));
5743 rdata->
dcb_enabled = tx_start_params->dcb_enabled;
5744 rdata->
dcb_version = tx_start_params->dcb_version;
5749 tx_start_params->traffic_type_to_priority_cos[i];
5756 static int bnx2x_func_send_cmd(
struct bnx2x *bp,
5759 switch (params->
cmd) {
5761 return bnx2x_func_hw_init(bp, params);
5763 return bnx2x_func_send_start(bp, params);
5765 return bnx2x_func_send_stop(bp, params);
5767 return bnx2x_func_hw_reset(bp, params);
5769 return bnx2x_func_send_afex_update(bp, params);
5771 return bnx2x_func_send_afex_viflists(bp, params);
5773 return bnx2x_func_send_tx_stop(bp, params);
5775 return bnx2x_func_send_tx_start(bp, params);
5785 void *afex_rdata,
dma_addr_t afex_rdata_mapping,
5788 memset(obj, 0,
sizeof(*obj));
5796 obj->
send_cmd = bnx2x_func_send_cmd;
5801 obj->
drv = drv_iface;
5838 bnx2x_func_state_change_comp(bp, o, cmd);