if (!restore) { /* Try to cancel this element queue */
rc = o->optimize(bp, o->owner, elem); if (rc) goto free_and_exit;
/* Check if this request is ok */
rc = o->validate(bp, o->owner, elem); if (rc) {
DP(BNX2X_MSG_SP, "Preamble failed: %d\n", rc); goto free_and_exit;
}
}
/* If so, add it to the execution queue */
list_add_tail(&elem->link, &o->exe_queue);
/* Next step should not be performed until the current is finished, *unlessaDRV_CLEAR_ONLYbitisset.Inthiscasewejustwantto *properlyclearobjectinternalswithoutsendinganycommandtotheFW *whichalsoimpliestherewon'tbeanycompletiontoclearthe *'pending'list.
*/ if (!list_empty(&o->pending_comp)) { if (test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags)) {
DP(BNX2X_MSG_SP, "RAMROD_DRV_CLR_ONLY requested: resetting a pending_comp list\n");
__bnx2x_exe_queue_reset_pending(bp, o);
} else { return1;
}
}
/* Run through the pending commands list and create a next *executionchunk.
*/ while (!list_empty(&o->exe_queue)) {
elem = list_first_entry(&o->exe_queue, struct bnx2x_exeq_elem,
link);
WARN_ON(!elem->cmd_len);
if (cur_len + elem->cmd_len <= o->exe_chunk_len) {
cur_len += elem->cmd_len; /* Prevent from both lists being empty when moving an *element.Thiswillallowthecallof *bnx2x_exe_queue_empty()withoutlocking.
*/
list_add_tail(&spacer.link, &o->pending_comp);
mb();
list_move_tail(&elem->link, &o->pending_comp);
list_del(&spacer.link);
} else break;
}
/* Sanity check */ if (!cur_len) return0;
rc = o->execute(bp, o->owner, &o->pending_comp, ramrod_flags); if (rc < 0) /* In case of an error return the commands back to the queue *andresetthepending_comp.
*/
list_splice_init(&o->pending_comp, &o->exe_queue); elseif (!rc) /* If zero is returned, means there are no outstanding pending *completionsandwemaydismissthependinglist.
*/
__bnx2x_exe_queue_reset_pending(bp, o);
/** *bnx2x_state_wait-waituntilthegivenbit(state)iscleared * *@bp:devicehandle *@state:statewhichistobecleared *@pstate:statebuffer *
*/ staticinlineint bnx2x_state_wait(struct bnx2x *bp, int state, unsignedlong *pstate)
{ /* can take a while if any port is running */ int cnt = 5000;
if (CHIP_REV_IS_EMUL(bp))
cnt *= 20;
DP(BNX2X_MSG_SP, "waiting for state to become %d\n", state);
might_sleep(); while (cnt--) { if (!test_bit(state, pstate)) { #ifdef BNX2X_STOP_ON_ERROR
DP(BNX2X_MSG_SP, "exit (cnt %d)\n", 5000 - cnt); #endif return0;
}
usleep_range(1000, 2000);
if (bp->panic) return -EIO;
}
/* timeout! */
BNX2X_ERR("timeout waiting for state %d\n", state); #ifdef BNX2X_STOP_ON_ERROR
bnx2x_panic(); #endif
/** *__bnx2x_vlan_mac_h_read_unlock-unlockthevlanmacheadlistreaderlock * *@bp:devicehandle *@o:vlan_macobject * *Context:Shouldbecalledunderexecutionqueuelock.Noticeifapending *executionexists,itwouldbeperformedifthiswasthelast *reader.possiblyreleasingandreclaimingtheexecutionqueuelock.
*/ staticvoid __bnx2x_vlan_mac_h_read_unlock(struct bnx2x *bp, struct bnx2x_vlan_mac_obj *o)
{ if (!o->head_reader) {
BNX2X_ERR("Need to release vlan mac reader lock, but lock isn't taken\n"); #ifdef BNX2X_STOP_ON_ERROR
bnx2x_panic(); #endif
} else {
o->head_reader--;
DP(BNX2X_MSG_SP, "vlan_mac_lock - decreased readers to %d\n",
o->head_reader);
}
/* It's possible a new pending execution was added, and that this reader *waslast-ifsoweneedtoexecutethecommand.
*/ if (!o->head_reader && o->head_exe_request) {
DP(BNX2X_MSG_SP, "vlan_mac_lock - reader release encountered a pending request\n");
/* Writer release will do the trick */
__bnx2x_vlan_mac_h_write_unlock(bp, o);
}
}
staticint bnx2x_get_n_elements(struct bnx2x *bp, struct bnx2x_vlan_mac_obj *o, int n, u8 *base, u8 stride, u8 size)
{ struct bnx2x_vlan_mac_registry_elem *pos;
u8 *next = base; int counter = 0; int read_lock;
DP(BNX2X_MSG_SP, "get_n_elements - taking vlan_mac_lock (reader)\n");
read_lock = bnx2x_vlan_mac_h_read_lock(bp, o); if (read_lock != 0)
BNX2X_ERR("get_n_elements failed to get vlan mac reader lock; Access without lock\n");
/* traverse list */
list_for_each_entry(pos, &o->head, link) { if (counter < n) {
memcpy(next, &pos->u, size);
counter++;
DP(BNX2X_MSG_SP, "copied element number %d to address %p element was:\n",
counter, next);
next += stride + size;
}
}
/* Set LLH CAM entry: currently only iSCSI and ETH macs are *relevant.Inaddition,currentimplementationistunedfora *singleETHMAC. * *WhenmultipleunicastETHMACsPFconfigurationinswitch *independentmodeisrequired(NetQ,multiplenetdevMACs, *etc.),considerbetterutilisationof8perfunctionMAC *entriesintheLLHregister.Thereisalso *NIG_REG_P[01]_LLH_FUNC_MEM2registersthatcompletethe *totalnumberofCAMentriesto16. * *Currentlywewon'tconfigureNIGforMACsotherthanaprimaryETH *MACandiSCSIL2MAC. * *IfthisMACismovingfromoneQueuetoanother,noneedtochange *NIGconfiguration.
*/ if (cmd != BNX2X_VLAN_MAC_MOVE) { if (test_bit(BNX2X_ISCSI_ETH_MAC, vlan_mac_flags))
bnx2x_set_mac_in_nig(bp, add, mac,
BNX2X_LLH_CAM_ISCSI_ETH_LINE); elseif (test_bit(BNX2X_ETH_MAC, vlan_mac_flags))
bnx2x_set_mac_in_nig(bp, add, mac,
BNX2X_LLH_CAM_ETH_LINE);
}
/* Reset the ramrod data buffer for the first rule */ if (rule_idx == 0)
memset(data, 0, sizeof(*data));
/* Setup a command header */
bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_MAC,
&rule_entry->mac.header);
DP(BNX2X_MSG_SP, "About to %s MAC %pM for Queue %d\n",
(add ? "add" : "delete"), mac, raw->cl_id);
/* Set a MAC itself */
bnx2x_set_fw_mac_addr(&rule_entry->mac.mac_msb,
&rule_entry->mac.mac_mid,
&rule_entry->mac.mac_lsb, mac);
rule_entry->mac.inner_mac =
cpu_to_le16(elem->cmd_data.vlan_mac.u.mac.is_inner_mac);
/* MOVE: Add a rule that will add this MAC to the target Queue */ if (cmd == BNX2X_VLAN_MAC_MOVE) {
rule_entry++;
rule_cnt++;
/* Setup ramrod data */
bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
elem->cmd_data.vlan_mac.target_obj, true, CLASSIFY_RULE_OPCODE_MAC,
&rule_entry->mac.header);
/* Set a MAC itself */
bnx2x_set_fw_mac_addr(&rule_entry->mac.mac_msb,
&rule_entry->mac.mac_mid,
&rule_entry->mac.mac_lsb, mac);
rule_entry->mac.inner_mac =
cpu_to_le16(elem->cmd_data.vlan_mac.
u.mac.is_inner_mac);
}
/* Set the ramrod data header */ /* TODO: take this to the higher level in order to prevent multiple
writing */
bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
rule_cnt);
}
if (add) {
SET_FLAG(cfg_entry->flags, MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
T_ETH_MAC_COMMAND_SET);
SET_FLAG(cfg_entry->flags,
MAC_CONFIGURATION_ENTRY_VLAN_FILTERING_MODE, opcode);
/* Set a MAC in a ramrod data */
bnx2x_set_fw_mac_addr(&cfg_entry->msb_mac_addr,
&cfg_entry->middle_mac_addr,
&cfg_entry->lsb_mac_addr, mac);
} else
SET_FLAG(cfg_entry->flags, MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
T_ETH_MAC_COMMAND_INVALIDATE);
}
/* Set a VLAN itself */
rule_entry->vlan.vlan = cpu_to_le16(vlan);
/* MOVE: Add a rule that will add this MAC to the target Queue */ if (cmd == BNX2X_VLAN_MAC_MOVE) {
rule_entry++;
rule_cnt++;
/* Setup ramrod data */
bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
elem->cmd_data.vlan_mac.target_obj, true, CLASSIFY_RULE_OPCODE_VLAN,
&rule_entry->vlan.header);
/* Set a VLAN itself */
rule_entry->vlan.vlan = cpu_to_le16(vlan);
}
/* Set the ramrod data header */ /* TODO: take this to the higher level in order to prevent multiple
writing */
bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
rule_cnt);
}
/* Reset the ramrod data buffer for the first rule */ if (rule_idx == 0)
memset(data, 0, sizeof(*data));
/* Set a rule header */
bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_PAIR,
&rule_entry->pair.header);
/* Set VLAN and MAC themselves */
rule_entry->pair.vlan = cpu_to_le16(vlan);
bnx2x_set_fw_mac_addr(&rule_entry->pair.mac_msb,
&rule_entry->pair.mac_mid,
&rule_entry->pair.mac_lsb, mac);
inner_mac = elem->cmd_data.vlan_mac.u.vlan_mac.is_inner_mac;
rule_entry->pair.inner_mac = cpu_to_le16(inner_mac); /* MOVE: Add a rule that will add this MAC/VLAN to the target Queue */ if (cmd == BNX2X_VLAN_MAC_MOVE) { struct bnx2x_vlan_mac_obj *target_obj;
/* Check the registry */
rc = o->check_add(bp, o, &elem->cmd_data.vlan_mac.u); if (rc) {
DP(BNX2X_MSG_SP, "ADD command is not allowed considering current registry state.\n"); return rc;
}
/* Check if there is a pending ADD command for this *MAC/VLAN/VLAN-MAC.Returnanerrorifthereis.
*/ if (exeq->get(exeq, elem)) {
DP(BNX2X_MSG_SP, "There is a pending ADD command already\n"); return -EEXIST;
}
/* TODO: Check the pending MOVE from other objects where this *objectisadestinationobject.
*/
/* Consume the credit if not requested not to */ if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
&elem->cmd_data.vlan_mac.vlan_mac_flags) ||
o->get_credit(o))) return -EINVAL;
/* If this classification can not be deleted (doesn't exist) *-returnaBNX2X_EXIST.
*/
pos = o->check_del(bp, o, &elem->cmd_data.vlan_mac.u); if (!pos) {
DP(BNX2X_MSG_SP, "DEL command is not allowed considering current registry state\n"); return -EEXIST;
}
/* Check if there are pending DEL or MOVE commands for this *MAC/VLAN/VLAN-MAC.Returnanerrorifso.
*/
memcpy(&query_elem, elem, sizeof(query_elem));
/* Check for MOVE commands */
query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_MOVE; if (exeq->get(exeq, &query_elem)) {
BNX2X_ERR("There is a pending MOVE command already\n"); return -EINVAL;
}
/* Check for DEL commands */ if (exeq->get(exeq, elem)) {
DP(BNX2X_MSG_SP, "There is a pending DEL command already\n"); return -EEXIST;
}
/* Return the credit to the credit pool if not requested not to */ if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
&elem->cmd_data.vlan_mac.vlan_mac_flags) ||
o->put_credit(o))) {
BNX2X_ERR("Failed to return a credit\n"); return -EINVAL;
}
/* Check if we can perform this operation based on the current registry *state.
*/ if (!src_o->check_move(bp, src_o, dest_o,
&elem->cmd_data.vlan_mac.u)) {
DP(BNX2X_MSG_SP, "MOVE command is not allowed considering current registry state\n"); return -EINVAL;
}
/* Check if there is an already pending DEL or MOVE command for the *sourceobjectorADDcommandforadestinationobject.Returnan *errorifso.
*/
memcpy(&query_elem, elem, sizeof(query_elem));
/* Check DEL on source */
query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_DEL; if (src_exeq->get(src_exeq, &query_elem)) {
BNX2X_ERR("There is a pending DEL command on the source queue already\n"); return -EINVAL;
}
/* Check MOVE on source */ if (src_exeq->get(src_exeq, elem)) {
DP(BNX2X_MSG_SP, "There is a pending MOVE command already\n"); return -EEXIST;
}
/* Check ADD on destination */
query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_ADD; if (dest_exeq->get(dest_exeq, &query_elem)) {
BNX2X_ERR("There is a pending ADD command on the destination queue already\n"); return -EINVAL;
}
/* Consume the credit if not requested not to */ if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT_DEST,
&elem->cmd_data.vlan_mac.vlan_mac_flags) ||
dest_o->get_credit(dest_o))) return -EINVAL;
if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
&elem->cmd_data.vlan_mac.vlan_mac_flags) ||
src_o->put_credit(src_o))) { /* return the credit taken from dest... */
dest_o->put_credit(dest_o); return -EINVAL;
}
return0;
}
staticint bnx2x_validate_vlan_mac(struct bnx2x *bp, union bnx2x_qable_obj *qo, struct bnx2x_exeq_elem *elem)
{ switch (elem->cmd_data.vlan_mac.cmd) { case BNX2X_VLAN_MAC_ADD: return bnx2x_validate_vlan_mac_add(bp, qo, elem); case BNX2X_VLAN_MAC_DEL: return bnx2x_validate_vlan_mac_del(bp, qo, elem); case BNX2X_VLAN_MAC_MOVE: return bnx2x_validate_vlan_mac_move(bp, qo, elem); default: return -EINVAL;
}
}
staticint bnx2x_remove_vlan_mac(struct bnx2x *bp, union bnx2x_qable_obj *qo, struct bnx2x_exeq_elem *elem)
{ int rc = 0;
/* If consumption wasn't required, nothing to do */ if (test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
&elem->cmd_data.vlan_mac.vlan_mac_flags)) return0;
switch (elem->cmd_data.vlan_mac.cmd) { case BNX2X_VLAN_MAC_ADD: case BNX2X_VLAN_MAC_MOVE:
rc = qo->vlan_mac.put_credit(&qo->vlan_mac); break; case BNX2X_VLAN_MAC_DEL:
rc = qo->vlan_mac.get_credit(&qo->vlan_mac); break; default: return -EINVAL;
}
DP(BNX2X_MSG_SP, "vlan_mac_execute_step - trying to take writer lock\n");
rc = __bnx2x_vlan_mac_h_write_trylock(bp, o);
if (rc != 0) {
__bnx2x_vlan_mac_h_pend(bp, o, *ramrod_flags);
/* Calling function should not differentiate between this case *andthecaseinwhichthereisalreadyapendingramrod
*/
rc = 1;
} else {
rc = bnx2x_exe_queue_step(bp, &o->exe_queue, ramrod_flags);
}
spin_unlock_bh(&o->exe_queue.lock);
/* Clearing the pending list & raw state should be made *atomically(asexecutionflowassumestheyrepresentthesame).
*/
spin_lock_bh(&o->exe_queue.lock);
/* Reset pending list */
__bnx2x_exe_queue_reset_pending(bp, &o->exe_queue);
/* Clear pending */
r->clear_pending(r);
spin_unlock_bh(&o->exe_queue.lock);
/* If ramrod failed this is most likely a SW bug */ if (cqe->message.error) return -EINVAL;
/* Run the next bulk of pending commands if requested */ if (test_bit(RAMROD_CONT, ramrod_flags)) {
rc = __bnx2x_vlan_mac_execute_step(bp, o, ramrod_flags);
if (rc < 0) return rc;
}
/* If there is more work to do return PENDING */ if (!bnx2x_exe_queue_empty(&o->exe_queue)) return1;
switch (elem->cmd_data.vlan_mac.cmd) { case BNX2X_VLAN_MAC_ADD:
query.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_DEL; break; case BNX2X_VLAN_MAC_DEL:
query.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_ADD; break; default: /* Don't handle anything other than ADD or DEL */ return0;
}
/* If we found the appropriate element - delete it */
pos = exeq->get(exeq, &query); if (pos) {
/* Return the credit of the optimized command */ if (!test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
&pos->cmd_data.vlan_mac.vlan_mac_flags)) { if ((query.cmd_data.vlan_mac.cmd ==
BNX2X_VLAN_MAC_ADD) && !o->put_credit(o)) {
BNX2X_ERR("Failed to return the credit for the optimized ADD command\n"); return -EINVAL;
} elseif (!o->get_credit(o)) { /* VLAN_MAC_DEL */
BNX2X_ERR("Failed to recover the credit from the optimized DEL command\n"); return -EINVAL;
}
}
/* Allocate a new registry element if needed. */ if (!restore &&
((cmd == BNX2X_VLAN_MAC_ADD) || (cmd == BNX2X_VLAN_MAC_MOVE))) {
reg_elem = kzalloc(sizeof(*reg_elem), GFP_ATOMIC); if (!reg_elem) return -ENOMEM;
/* Get a new CAM offset */ if (!o->get_cam_offset(o, ®_elem->cam_offset)) { /* This shall never happen, because we have checked the *CAMavailabilityinthe'validate'.
*/
WARN_ON(1);
kfree(reg_elem); return -EINVAL;
}
/* Set a VLAN-MAC data */
memcpy(®_elem->u, &elem->cmd_data.vlan_mac.u, sizeof(reg_elem->u));
/* Copy the flags (needed for DEL and RESTORE flows) */
reg_elem->vlan_mac_flags =
elem->cmd_data.vlan_mac.vlan_mac_flags;
} else/* DEL, RESTORE */
reg_elem = o->check_del(bp, o, &elem->cmd_data.vlan_mac.u);
/* If DRIVER_ONLY execution is requested, cleanup a registry *andexit.OtherwisesendaramrodtoFW.
*/ if (!drv_only) {
WARN_ON(r->check_pending(r));
/* Set pending */
r->set_pending(r);
/* Fill the ramrod data */
list_for_each_entry(elem, exe_chunk, link) {
cmd = elem->cmd_data.vlan_mac.cmd; /* We will add to the target object in MOVE command, so *changetheobjectforaCAMsearch.
*/ if (cmd == BNX2X_VLAN_MAC_MOVE)
cam_obj = elem->cmd_data.vlan_mac.target_obj; else
cam_obj = o;
/* Push a new entry into the registry */ if (!restore &&
((cmd == BNX2X_VLAN_MAC_ADD) ||
(cmd == BNX2X_VLAN_MAC_MOVE)))
list_add(®_elem->link, &cam_obj->head);
/* Configure a single command in a ramrod data buffer */
o->set_one_rule(bp, o, elem, idx,
reg_elem->cam_offset);
/* MOVE command consumes 2 entries in the ramrod data */ if (cmd == BNX2X_VLAN_MAC_MOVE)
idx += 2; else
idx++;
}
/* No need for an explicit memory barrier here as long we would *needtoensuretheorderingofwritingtotheSPQelement *andupdatingoftheSPQproducerwhichinvolvesamemory *readandwewillhavetoputafullmemorybarrierthere *(insidebnx2x_sp_post()).
*/
/* Now, when we are done with the ramrod - clean up the registry */
list_for_each_entry(elem, exe_chunk, link) {
cmd = elem->cmd_data.vlan_mac.cmd; if ((cmd == BNX2X_VLAN_MAC_DEL) ||
(cmd == BNX2X_VLAN_MAC_MOVE)) {
reg_elem = o->check_del(bp, o,
&elem->cmd_data.vlan_mac.u);
/* *Addnewelementstotheexecutionlistforcommandsthatrequireit.
*/ if (!cont) {
rc = bnx2x_vlan_mac_push_new_cmd(bp, p); if (rc) return rc;
}
/* If nothing will be executed further in this iteration we want to *returnPENDINGiftherearependingcommands
*/ if (!bnx2x_exe_queue_empty(&o->exe_queue))
rc = 1;
if (test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags)) {
DP(BNX2X_MSG_SP, "RAMROD_DRV_CLR_ONLY requested: clearing a pending bit.\n");
raw->clear_pending(raw);
}
/* Execute commands if required */ if (cont || test_bit(RAMROD_EXEC, ramrod_flags) ||
test_bit(RAMROD_COMP_WAIT, ramrod_flags)) {
rc = __bnx2x_vlan_mac_execute_step(bp, p->vlan_mac_obj,
&p->ramrod_flags); if (rc < 0) return rc;
}
/* RAMROD_COMP_WAIT is a superset of RAMROD_EXEC. If it was set *thenuserwanttowaituntilthelastcommandisdone.
*/ if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags)) { /* Wait maximum for the current exe_queue length iterations plus *one(forthecurrentpendingcommand).
*/ int max_iterations = bnx2x_exe_queue_length(&o->exe_queue) + 1;
while (!bnx2x_exe_queue_empty(&o->exe_queue) &&
max_iterations--) {
/* Wait for the current command to complete */
rc = raw->wait_comp(bp, raw); if (rc) return rc;
/* Make a next step */
rc = __bnx2x_vlan_mac_execute_step(bp,
p->vlan_mac_obj,
&p->ramrod_flags); if (rc < 0) return rc;
}
/* Add all but the last VLAN-MAC to the execution queue without actually *executionanything.
*/
__clear_bit(RAMROD_COMP_WAIT, &p.ramrod_flags);
__clear_bit(RAMROD_EXEC, &p.ramrod_flags);
__clear_bit(RAMROD_CONT, &p.ramrod_flags);
/* CAM pool handling */
vlan_mac_obj->get_credit = bnx2x_get_credit_vlan_mac;
vlan_mac_obj->put_credit = bnx2x_put_credit_vlan_mac; /* CAM offset is relevant for 57710 and 57711 chips only which have a *singleCAMforbothMACsandVLAN-MACpairs.Sotheoffset *willbetakenfromMACs'poolobjectonly.
*/
vlan_mac_obj->get_cam_offset = bnx2x_get_cam_offset_mac;
vlan_mac_obj->put_cam_offset = bnx2x_put_cam_offset_mac;
if (CHIP_IS_E1(bp)) {
BNX2X_ERR("Do not support chips others than E2\n");
BUG();
} elseif (CHIP_IS_E1H(bp)) {
vlan_mac_obj->set_one_rule = bnx2x_set_one_vlan_mac_e1h;
vlan_mac_obj->check_del = bnx2x_check_vlan_mac_del;
vlan_mac_obj->check_add = bnx2x_check_vlan_mac_add;
vlan_mac_obj->check_move = bnx2x_check_move_always_err;
vlan_mac_obj->ramrod_cmd = RAMROD_CMD_ID_ETH_SET_MAC;
/* In e1x there we only take into account rx accept flag since tx switching
* isn't enabled. */ if (test_bit(BNX2X_ACCEPT_UNICAST, &p->rx_accept_flags)) /* accept matched ucast */
drop_all_ucast = 0;
/* start with 'drop-all' */
state = ETH_FILTER_RULES_CMD_UCAST_DROP_ALL |
ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
if (test_bit(BNX2X_ACCEPT_UNICAST, accept_flags))
state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
if (test_bit(BNX2X_ACCEPT_MULTICAST, accept_flags))
state &= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
if (test_bit(BNX2X_ACCEPT_ALL_UNICAST, accept_flags)) {
state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
state |= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL;
}
if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST, accept_flags)) {
state |= ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL;
state &= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
}
if (test_bit(BNX2X_ACCEPT_BROADCAST, accept_flags))
state |= ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL;
if (test_bit(BNX2X_ACCEPT_UNMATCHED, accept_flags)) {
state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
state |= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED;
}
if (test_bit(BNX2X_ACCEPT_ANY_VLAN, accept_flags))
state |= ETH_FILTER_RULES_CMD_ACCEPT_ANY_VLAN;
/* Clear ACCEPT_ALL_XXX flags for FCoE L2 Queue */
if (clear_accept_all) {
state &= ~ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL;
state &= ~ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL;
state &= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL;
state &= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED;
}
cmd->state = cpu_to_le16(state);
}
static int bnx2x_set_rx_mode_e2(struct bnx2x *bp,
struct bnx2x_rx_mode_ramrod_params *p)
{
struct eth_filter_rules_ramrod_data *data = p->rdata;
int rc;
u8 rule_idx = 0;
/* Reset the ramrod data buffer */
memset(data, 0, sizeof(*data));
/* If FCoE Queue configuration has been requested configure the Rx and
* internal switching modes for this queue in separate rules.
*
* FCoE queue shell never be set to ACCEPT_ALL packets of any sort:
* MCAST_ALL, UCAST_ALL, BCAST_ALL and UNMATCHED.
*/
if (test_bit(BNX2X_RX_MODE_FCOE_ETH, &p->rx_mode_flags)) {
/* Tx (internal switching) */
if (test_bit(RAMROD_TX, &p->ramrod_flags)) {
data->rules[rule_idx].client_id = bnx2x_fcoe(bp, cl_id);
data->rules[rule_idx].func_id = p->func_id;
/* No need for an explicit memory barrier here as long as we
* ensure the ordering of writing to the SPQ element
* and updating of the SPQ producer which involves a memory
* read. If the memory read is removed we will have to put a
* full memory barrier there (inside bnx2x_sp_post()).
*/
/* Send a ramrod */
rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_FILTER_RULES, p->cid,
U64_HI(p->rdata_mapping),
U64_LO(p->rdata_mapping),
ETH_CONNECTION_TYPE);
if (rc)
return rc;
static int bnx2x_empty_rx_mode_wait(struct bnx2x *bp,
struct bnx2x_rx_mode_ramrod_params *p)
{
/* Do nothing */
return 0;
}
int bnx2x_config_rx_mode(struct bnx2x *bp,
struct bnx2x_rx_mode_ramrod_params *p)
{
int rc;
/* Configure the new classification in the chip */
rc = p->rx_mode_obj->config_rx_mode(bp, p);
if (rc < 0)
return rc;
/* Wait for a ramrod completion if was requested */
if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags)) {
rc = p->rx_mode_obj->wait_comp(bp, p);
if (rc)
return rc;
}
struct bnx2x_pending_mcast_cmd {
struct list_head link;
struct list_head group_head;
int type; /* BNX2X_MCAST_CMD_X */
union {
struct list_head macs_head;
u32 macs_num; /* Needed for DEL command */
int next_bin; /* Needed for RESTORE flow with aprox match */
} data;
bool set_convert; /* in case type == BNX2X_MCAST_CMD_SET, this is set
* when macs_head had been converted to a list of
* bnx2x_mcast_bin_elem.
*/
bool done; /* set to true, when the command has been handled,
* practically used in 57712 handling only, where one pending
* command may be handled in a few operations. As long as for
* other chips every operation handling is completed in a
* single ramrod, there is no need to utilize this field.
*/
};
static int bnx2x_mcast_wait(struct bnx2x *bp,
struct bnx2x_mcast_obj *o)
{
if (bnx2x_state_wait(bp, o->sched_state, o->raw.pstate) ||
o->raw.wait_comp(bp, &o->raw))
return -EBUSY;
/* When adding MACs we'll need to store their values */
if (cmd == BNX2X_MCAST_CMD_ADD || cmd == BNX2X_MCAST_CMD_SET)
macs_list_len = p->mcast_list_len;
/* If the command is empty ("handle pending commands only"), break */
if (!p->mcast_list_len)
return 0;
/* Add mcast is called under spin_lock, thus calling with GFP_ATOMIC */
new_cmd = kzalloc(sizeof(*new_cmd), GFP_ATOMIC);
if (!new_cmd)
return -ENOMEM;
DP(BNX2X_MSG_SP, "About to enqueue a new %d command. macs_list_len=%d\n",
cmd, macs_list_len);
switch (cmd) {
case BNX2X_MCAST_CMD_ADD:
case BNX2X_MCAST_CMD_SET:
/* For a set command, we need to allocate sufficient memory for
* all the bins, since we can't analyze at this point how much
* memory would be required.
*/
total_elems = macs_list_len;
if (cmd == BNX2X_MCAST_CMD_SET) {
if (total_elems < BNX2X_MCAST_BINS_NUM)
total_elems = BNX2X_MCAST_BINS_NUM;
}
while (total_elems > 0) {
elem_group = (struct bnx2x_mcast_elem_group *)
__get_free_page(GFP_ATOMIC | __GFP_ZERO);
if (!elem_group) {
bnx2x_free_groups(&new_cmd->group_head);
kfree(new_cmd);
return -ENOMEM;
}
total_elems -= MCAST_MAC_ELEMS_PER_PG;
list_add_tail(&elem_group->mcast_group_link,
&new_cmd->group_head);
}
elem_group = list_first_entry(&new_cmd->group_head,
struct bnx2x_mcast_elem_group,
mcast_group_link);
list_for_each_entry(pos, &p->mcast_list, link) {
mac_elem = &elem_group->mcast_elems[offset].mac_elem;
memcpy(mac_elem->mac, pos->mac, ETH_ALEN);
/* Push the MACs of the current command into the pending
* command MACs list: FIFO
*/
list_add_tail(&mac_elem->link,
&new_cmd->data.macs_head);
offset++;
if (offset == MCAST_MAC_ELEMS_PER_PG) {
offset = 0;
elem_group = list_next_entry(elem_group,
mcast_group_link);
}
}
break;
case BNX2X_MCAST_CMD_DEL:
new_cmd->data.macs_num = p->mcast_list_len;
break;
case BNX2X_MCAST_CMD_RESTORE:
new_cmd->data.next_bin = 0;
break;
/* Push the new pending command to the tail of the pending list: FIFO */
list_add_tail(&new_cmd->link, &o->pending_cmds_head);
o->set_sched(o);
return 1;
}
/**
* bnx2x_mcast_get_next_bin - get the next set bin (index)
*
* @o: multicast object info
* @last: index to start looking from (including)
*
* returns the next found (set) bin or a negative value if none is found.
*/
static inline int bnx2x_mcast_get_next_bin(struct bnx2x_mcast_obj *o, int last)
{
int i, j, inner_start = last % BIT_VEC64_ELEM_SZ;
for (i = last / BIT_VEC64_ELEM_SZ; i < BNX2X_MCAST_VEC_SZ; i++) {
if (o->registry.aprox_match.vec[i])
for (j = inner_start; j < BIT_VEC64_ELEM_SZ; j++) {
int cur_bit = j + BIT_VEC64_ELEM_SZ * i;
if (BIT_VEC64_TEST_BIT(o->registry.aprox_match.
vec, cur_bit)) {
return cur_bit;
}
}
inner_start = 0;
}
/* None found */
return -1;
}
/**
* bnx2x_mcast_clear_first_bin - find the first set bin and clear it
*
* @o:
*
* returns the index of the found bin or -1 if none is found
*/
static inline int bnx2x_mcast_clear_first_bin(struct bnx2x_mcast_obj *o)
{
int cur_bit = bnx2x_mcast_get_next_bin(o, 0);
if (cur_bit >= 0)
BIT_VEC64_CLEAR_BIT(o->registry.aprox_match.vec, cur_bit);
/* Get a bin and update a bins' vector */
switch (cmd) {
case BNX2X_MCAST_CMD_ADD:
bin = bnx2x_mcast_bin_from_mac(cfg_data->mac);
BIT_VEC64_SET_BIT(o->registry.aprox_match.vec, bin);
break;
case BNX2X_MCAST_CMD_DEL:
/* If there were no more bins to clear
* (bnx2x_mcast_clear_first_bin() returns -1) then we would
* clear any (0xff) bin.
* See bnx2x_mcast_validate_e2() for explanation when it may
* happen.
*/
bin = bnx2x_mcast_clear_first_bin(o);
break;
case BNX2X_MCAST_CMD_RESTORE:
bin = cfg_data->bin;
break;
case BNX2X_MCAST_CMD_SET_ADD:
bin = cfg_data->bin;
BIT_VEC64_SET_BIT(o->registry.aprox_match.vec, bin);
break;
case BNX2X_MCAST_CMD_SET_DEL:
bin = cfg_data->bin;
BIT_VEC64_CLEAR_BIT(o->registry.aprox_match.vec, bin);
break;
/**
* bnx2x_mcast_handle_restore_cmd_e2 - restore configuration from the registry
*
* @bp: device handle
* @o: multicast object info
* @start_bin: index in the registry to start from (including)
* @rdata_idx: index in the ramrod data to start from
*
* returns last handled bin index or -1 if all bins have been handled
*/
static inline int bnx2x_mcast_handle_restore_cmd_e2(
struct bnx2x *bp, struct bnx2x_mcast_obj *o , int start_bin,
int *rdata_idx)
{
int cur_bin, cnt = *rdata_idx;
union bnx2x_mcast_config_data cfg_data = {NULL};
/* go through the registry and configure the bins from it */
for (cur_bin = bnx2x_mcast_get_next_bin(o, start_bin); cur_bin >= 0;
cur_bin = bnx2x_mcast_get_next_bin(o, cur_bin + 1)) {
cfg_data.bin = (u8)cur_bin;
o->set_one_rule(bp, o, cnt, &cfg_data,
BNX2X_MCAST_CMD_RESTORE);
cnt++;
DP(BNX2X_MSG_SP, "About to configure a bin %d\n", cur_bin);
/* Break if we reached the maximum number
* of rules.
*/
if (cnt >= o->max_cmd_len)
break;
}
*rdata_idx = cnt;
return cur_bin;
}
static inline void bnx2x_mcast_hdl_pending_add_e2(struct bnx2x *bp,
struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
int *line_idx)
{
struct bnx2x_mcast_mac_elem *pmac_pos, *pmac_pos_n;
int cnt = *line_idx;
union bnx2x_mcast_config_data cfg_data = {NULL};
if (cmd_pos->data.next_bin < 0)
/* If o->set_restore returned -1 we are done */
cmd_pos->done = true;
else
/* Start from the next bin next time */
cmd_pos->data.next_bin++;
}
/* Fill `current' with the required set of bins to configure */
list_for_each_entry_safe(pmac_pos, pmac_pos_n, &cmd_pos->data.macs_head,
link) {
int bin = bnx2x_mcast_bin_from_mac(pmac_pos->mac);
/* We no longer have use for the MACs; Need to re-use memory for
* a list that will be used to configure bins.
*/
cmd_pos->set_convert = true;
INIT_LIST_HEAD(&cmd_pos->data.macs_head);
elem_group = list_first_entry(&cmd_pos->group_head,
struct bnx2x_mcast_elem_group,
mcast_group_link);
for (i = 0; i < BNX2X_MCAST_BINS_NUM; i++) {
bool b_current = !!BIT_VEC64_TEST_BIT(cur, i);
bool b_required = !!BIT_VEC64_TEST_BIT(req, i);
/* We now definitely know how many commands are hiding here.
* Also need to correct the disruption we've added to guarantee this
* would be enqueued.
*/
o->total_pending_num -= (o->max_cmd_len + mac_cnt);
o->total_pending_num += cnt;
/* This is actually a 2-part scheme - it starts by converting the MACs
* into a list of bins to be added/removed, and correcting the numbers
* on the object. this is now allowed, as we're now sure that all
* previous configured requests have already applied.
* The second part is actually adding rules for the newly introduced
* entries [like all the rest of the hdl_pending functions].
*/
if (!cmd_pos->set_convert)
bnx2x_mcast_hdl_pending_set_e2_convert(bp, o, cmd_pos);
/* If the command has been completed - remove it from the list
* and free the memory
*/
if (cmd_pos->done) {
list_del(&cmd_pos->link);
bnx2x_free_groups(&cmd_pos->group_head);
kfree(cmd_pos);
}
/* Break if we reached the maximum number of rules */
if (cnt >= o->max_cmd_len)
break;
}
return cnt;
}
static inline void bnx2x_mcast_hdl_add(struct bnx2x *bp,
struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
int *line_idx)
{
struct bnx2x_mcast_list_elem *mlist_pos;
union bnx2x_mcast_config_data cfg_data = {NULL};
int cnt = *line_idx;
/**
* bnx2x_mcast_handle_current_cmd - send command if room
*
* @bp: device handle
* @p: ramrod mcast info
* @cmd: command
* @start_cnt: first line in the ramrod data that may be used
*
* This function is called iff there is enough place for the current command in
* the ramrod data.
* Returns number of lines filled in the ramrod data in total.
*/
static inline int bnx2x_mcast_handle_current_cmd(struct bnx2x *bp,
struct bnx2x_mcast_ramrod_params *p,
enum bnx2x_mcast_cmd cmd,
int start_cnt)
{
struct bnx2x_mcast_obj *o = p->mcast_obj;
int cnt = start_cnt;
switch (cmd) {
/* DEL command deletes all currently configured MACs */
case BNX2X_MCAST_CMD_DEL:
o->set_registry_size(o, 0);
fallthrough;
/* RESTORE command will restore the entire multicast configuration */
case BNX2X_MCAST_CMD_RESTORE:
/* Here we set the approximate amount of work to do, which in
* fact may be only less as some MACs in postponed ADD
* command(s) scheduled before this command may fall into
* the same bin and the actual number of bins set in the
* registry would be less than we estimated here. See
* bnx2x_mcast_set_one_rule_e2() for further details.
*/
p->mcast_list_len = reg_sz;
break;
case BNX2X_MCAST_CMD_ADD:
case BNX2X_MCAST_CMD_CONT:
/* Here we assume that all new MACs will fall into new bins.
* However we will correct the real registry size after we
* handle all pending commands.
*/
o->set_registry_size(o, reg_sz + p->mcast_list_len);
break;
case BNX2X_MCAST_CMD_SET:
/* We can only learn how many commands would actually be used
* when this is being configured. So for now, simply guarantee
* the command will be enqueued [to refrain from adding logic
* that handles this and THEN learns it needs several ramrods].
* Just like for ADD/Cont, the mcast_list_len might be an over
* estimation; or even more so, since we don't take into
* account the possibility of removal of existing bins.
*/
o->set_registry_size(o, reg_sz + p->mcast_list_len);
o->total_pending_num += o->max_cmd_len;
break;
/**
* bnx2x_mcast_refresh_registry_e2 - recalculate the actual number of set bins
*
* @bp: device handle
* @o:
*
* Recalculate the actual number of set bins in the registry using Brian
* Kernighan's algorithm: it's execution complexity is as a number of set bins.
*
* returns 0 for the compliance with bnx2x_mcast_refresh_registry_e1().
*/
static inline int bnx2x_mcast_refresh_registry_e2(struct bnx2x *bp,
struct bnx2x_mcast_obj *o)
{
int i, cnt = 0;
u64 elem;
for (i = 0; i < BNX2X_MCAST_VEC_SZ; i++) {
elem = o->registry.aprox_match.vec[i];
for (; elem; cnt++)
elem &= elem - 1;
}
/* Reset the ramrod data buffer */
memset(data, 0, sizeof(*data));
cnt = bnx2x_mcast_handle_pending_cmds_e2(bp, p);
/* If there are no more pending commands - clear SCHEDULED state */
if (list_empty(&o->pending_cmds_head))
o->clear_sched(o);
/* The below may be true iff there was enough room in ramrod
* data for all pending commands and for the current
* command. Otherwise the current command would have been added
* to the pending commands and p->mcast_list_len would have been
* zeroed.
*/
if (p->mcast_list_len > 0)
cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, cnt);
/* We've pulled out some MACs - update the total number of
* outstanding.
*/
o->total_pending_num -= cnt;
/* Update a registry size if there are no more pending operations.
*
* We don't want to change the value of the registry size if there are
* pending operations because we want it to always be equal to the
* exact or the approximate number (see bnx2x_mcast_validate_e2()) of
* set bins after the last requested operation in order to properly
* evaluate the size of the next DEL/RESTORE operation.
*
* Note that we update the registry itself during command(s) handling
* - see bnx2x_mcast_set_one_rule_e2(). That's because for 57712 we
* aggregate multiple commands (ADD/DEL/RESTORE) into one ramrod but
* with a limited amount of update commands (per MAC/bin) and we don't
* know in this scope what the actual state of bins configuration is
* going to be after this ramrod.
*/
if (!o->total_pending_num)
bnx2x_mcast_refresh_registry_e2(bp, o);
/* If CLEAR_ONLY was requested - don't send a ramrod and clear
* RAMROD_PENDING status immediately. due to the SET option, it's also
* possible that after evaluating the differences there's no need for
* a ramrod. In that case, we can skip it as well.
*/
if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags) || !cnt) {
raw->clear_pending(raw);
return 0;
} else {
/* No need for an explicit memory barrier here as long as we
* ensure the ordering of writing to the SPQ element
* and updating of the SPQ producer which involves a memory
* read. If the memory read is removed we will have to put a
* full memory barrier there (inside bnx2x_sp_post()).
*/
/* Send a ramrod */
rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_MULTICAST_RULES,
raw->cid, U64_HI(raw->rdata_mapping),
U64_LO(raw->rdata_mapping),
ETH_CONNECTION_TYPE);
if (rc)
return rc;
/* Ramrod completion is pending */
return 1;
}
}
static int bnx2x_mcast_validate_e1h(struct bnx2x *bp,
struct bnx2x_mcast_ramrod_params *p,
enum bnx2x_mcast_cmd cmd)
{
if (cmd == BNX2X_MCAST_CMD_SET) {
BNX2X_ERR("Can't use `set' command on e1h!\n");
return -EINVAL;
}
/* Mark, that there is a work to do */
if ((cmd == BNX2X_MCAST_CMD_DEL) || (cmd == BNX2X_MCAST_CMD_RESTORE))
p->mcast_list_len = 1;
return 0;
}
static void bnx2x_mcast_revert_e1h(struct bnx2x *bp,
struct bnx2x_mcast_ramrod_params *p,
int old_num_bins,
enum bnx2x_mcast_cmd cmd)
{
/* Do nothing */
}
#define BNX2X_57711_SET_MC_FILTER(filter, bit) \
do { \
(filter)[(bit) >> 5] |= (1 << ((bit) & 0x1f)); \
} while (0)
for (bit = bnx2x_mcast_get_next_bin(o, 0);
bit >= 0;
bit = bnx2x_mcast_get_next_bin(o, bit + 1)) {
BNX2X_57711_SET_MC_FILTER(mc_filter, bit);
DP(BNX2X_MSG_SP, "About to set bin %d\n", bit);
}
}
/* On 57711 we write the multicast MACs' approximate match
* table by directly into the TSTORM's internal RAM. So we don't
* really need to handle any tricks to make it work.
*/
static int bnx2x_mcast_setup_e1h(struct bnx2x *bp,
struct bnx2x_mcast_ramrod_params *p,
enum bnx2x_mcast_cmd cmd)
{
int i;
struct bnx2x_mcast_obj *o = p->mcast_obj;
struct bnx2x_raw_obj *r = &o->raw;
/* If CLEAR_ONLY has been requested - clear the registry
* and clear a pending bit.
*/
if (!test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
u32 mc_filter[MC_HASH_SIZE] = {0};
/* Set the multicast filter bits before writing it into
* the internal memory.
*/
switch (cmd) {
case BNX2X_MCAST_CMD_ADD:
bnx2x_mcast_hdl_add_e1h(bp, o, p, mc_filter);
break;
case BNX2X_MCAST_CMD_DEL:
DP(BNX2X_MSG_SP,
"Invalidating multicast MACs configuration\n");
/* clear the registry */
memset(o->registry.aprox_match.vec, 0,
sizeof(o->registry.aprox_match.vec));
break;
case BNX2X_MCAST_CMD_RESTORE:
bnx2x_mcast_hdl_restore_e1h(bp, o, p, mc_filter);
break;
/* Set the mcast filter in the internal memory */
for (i = 0; i < MC_HASH_SIZE; i++)
REG_WR(bp, MC_HASH_OFFSET(bp, i), mc_filter[i]);
} else
/* clear the registry */
memset(o->registry.aprox_match.vec, 0,
sizeof(o->registry.aprox_match.vec));
if (cmd == BNX2X_MCAST_CMD_SET) {
BNX2X_ERR("Can't use `set' command on e1!\n");
return -EINVAL;
}
switch (cmd) {
/* DEL command deletes all currently configured MACs */
case BNX2X_MCAST_CMD_DEL:
o->set_registry_size(o, 0);
fallthrough;
/* RESTORE command will restore the entire multicast configuration */
case BNX2X_MCAST_CMD_RESTORE:
p->mcast_list_len = reg_sz;
DP(BNX2X_MSG_SP, "Command %d, p->mcast_list_len=%d\n",
cmd, p->mcast_list_len);
break;
case BNX2X_MCAST_CMD_ADD:
case BNX2X_MCAST_CMD_CONT:
/* Multicast MACs on 57710 are configured as unicast MACs and
* there is only a limited number of CAM entries for that
* matter.
*/
if (p->mcast_list_len > o->max_cmd_len) {
BNX2X_ERR("Can't configure more than %d multicast MACs on 57710\n",
o->max_cmd_len);
return -EINVAL;
}
/* Every configured MAC should be cleared if DEL command is
* called. Only the last ADD command is relevant as long as
* every ADD commands overrides the previous configuration.
*/
DP(BNX2X_MSG_SP, "p->mcast_list_len=%d\n", p->mcast_list_len);
if (p->mcast_list_len > 0)
o->set_registry_size(o, p->mcast_list_len);
/* We want to ensure that commands are executed one by one for 57710.
* Therefore each none-empty command will consume o->max_cmd_len.
*/
if (p->mcast_list_len)
o->total_pending_num += o->max_cmd_len;
/* If current command hasn't been handled yet and we are
* here means that it's meant to be dropped and we have to
* update the number of outstanding MACs accordingly.
*/
if (p->mcast_list_len)
o->total_pending_num -= o->max_cmd_len;
}
/**
* bnx2x_mcast_handle_restore_cmd_e1 - restore command for 57710
*
* @bp: device handle
* @o: multicast info
* @start_idx: index in the registry to start from
* @rdata_idx: index in the ramrod data to start from
*
* restore command for 57710 is like all other commands - always a stand alone
* command - start_idx and rdata_idx will always be 0. This function will always
* succeed.
* returns -1 to comply with 57712 variant.
*/
static inline int bnx2x_mcast_handle_restore_cmd_e1(
struct bnx2x *bp, struct bnx2x_mcast_obj *o , int start_idx,
int *rdata_idx)
{
struct bnx2x_mcast_mac_elem *elem;
int i = 0;
union bnx2x_mcast_config_data cfg_data = {NULL};
/* go through the registry and configure the MACs from it. */
list_for_each_entry(elem, &o->registry.exact_match.macs, link) {
cfg_data.mac = &elem->mac[0];
o->set_one_rule(bp, o, i, &cfg_data, BNX2X_MCAST_CMD_RESTORE);
i++;
DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
cfg_data.mac);
}
/**
* bnx2x_mcast_refresh_registry_e1 -
*
* @bp: device handle
* @o: multicast info
*
* Check the ramrod data first entry flag to see if it's a DELETE or ADD command
* and update the registry correspondingly: if ADD - allocate a memory and add
* the entries to the registry (list), if DELETE - clear the registry and free
* the memory.
*/
static inline int bnx2x_mcast_refresh_registry_e1(struct bnx2x *bp,
struct bnx2x_mcast_obj *o)
{
struct bnx2x_raw_obj *raw = &o->raw;
struct bnx2x_mcast_mac_elem *elem;
struct mac_configuration_cmd *data =
(struct mac_configuration_cmd *)(raw->rdata);
/* If first entry contains a SET bit - the command was ADD,
* otherwise - DEL_ALL
*/
if (GET_FLAG(data->config_table[0].flags,
MAC_CONFIGURATION_ENTRY_ACTION_TYPE)) {
int i, len = data->hdr.length;
/* Break if it was a RESTORE command */
if (!list_empty(&o->registry.exact_match.macs))
return 0;
elem = kcalloc(len, sizeof(*elem), GFP_ATOMIC);
if (!elem) {
BNX2X_ERR("Failed to allocate registry memory\n");
return -ENOMEM;
}
for (i = 0; i < len; i++, elem++) {
bnx2x_get_fw_mac_addr(
&data->config_table[i].msb_mac_addr,
&data->config_table[i].middle_mac_addr,
&data->config_table[i].lsb_mac_addr,
elem->mac);
DP(BNX2X_MSG_SP, "Adding registry entry for [%pM]\n",
elem->mac);
list_add_tail(&elem->link,
&o->registry.exact_match.macs);
}
} else {
elem = list_first_entry(&o->registry.exact_match.macs,
struct bnx2x_mcast_mac_elem, link);
DP(BNX2X_MSG_SP, "Deleting a registry\n");
kfree(elem);
INIT_LIST_HEAD(&o->registry.exact_match.macs);
}
/* Reset the ramrod data buffer */
memset(data, 0, sizeof(*data));
/* First set all entries as invalid */
for (i = 0; i < o->max_cmd_len ; i++)
SET_FLAG(data->config_table[i].flags,
MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
T_ETH_MAC_COMMAND_INVALIDATE);
/* Handle pending commands first */
cnt = bnx2x_mcast_handle_pending_cmds_e1(bp, p);
/* If there are no more pending commands - clear SCHEDULED state */
if (list_empty(&o->pending_cmds_head))
o->clear_sched(o);
/* The below may be true iff there were no pending commands */
if (!cnt)
cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, 0);
/* For 57710 every command has o->max_cmd_len length to ensure that
* commands are done one at a time.
*/
o->total_pending_num -= o->max_cmd_len;
/* send a ramrod */
WARN_ON(cnt > o->max_cmd_len);
/* Set ramrod header (in particular, a number of entries to update) */
bnx2x_mcast_set_rdata_hdr_e1(bp, p, (u8)cnt);
/* update a registry: we need the registry contents to be always up
* to date in order to be able to execute a RESTORE opcode. Here
* we use the fact that for 57710 we sent one command at a time
* hence we may take the registry update out of the command handling
* and do it in a simpler way here.
*/
rc = bnx2x_mcast_refresh_registry_e1(bp, o);
if (rc)
return rc;
/* If CLEAR_ONLY was requested - don't send a ramrod and clear
* RAMROD_PENDING status immediately.
*/
if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
raw->clear_pending(raw);
return 0;
} else {
/* No need for an explicit memory barrier here as long as we
* ensure the ordering of writing to the SPQ element
* and updating of the SPQ producer which involves a memory
* read. If the memory read is removed we will have to put a
* full memory barrier there (inside bnx2x_sp_post()).
*/
/* Send a ramrod */
rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, raw->cid,
U64_HI(raw->rdata_mapping),
U64_LO(raw->rdata_mapping),
ETH_CONNECTION_TYPE);
if (rc)
return rc;
/* Ramrod completion is pending */
return 1;
}
}
static int bnx2x_mcast_get_registry_size_exact(struct bnx2x_mcast_obj *o)
{
return o->registry.exact_match.num_macs_set;
}
static int bnx2x_mcast_get_registry_size_aprox(struct bnx2x_mcast_obj *o)
{
return o->registry.aprox_match.num_bins_set;
}
/* Enqueue the current command to the pending list if we can't complete
* it in the current iteration
*/
if (r->check_pending(r) ||
((o->max_cmd_len > 0) && (o->total_pending_num > o->max_cmd_len))) {
rc = o->enqueue_cmd(bp, p->mcast_obj, p, cmd);
if (rc < 0)
goto error_exit1;
/* As long as the current command is in a command list we
* don't need to handle it separately.
*/
p->mcast_list_len = 0;
}
if (!r->check_pending(r)) {
/* Set 'pending' state */
r->set_pending(r);
/* Configure the new classification in the chip */
rc = o->config_mcast(bp, p, cmd);
if (rc < 0)
goto error_exit2;
/* Wait for a ramrod completion if was requested */
if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags))
rc = o->wait_comp(bp, o);
}
/**
* __atomic_add_ifless - add if the result is less than a given value.
*
* @v: pointer of type atomic_t
* @a: the amount to add to v...
* @u: ...if (v + a) is less than u.
*
* returns true if (v + a) was less than u, and false otherwise.
*
*/
static inline bool __atomic_add_ifless(atomic_t *v, int a, int u)
{
int c, old;
c = atomic_read(v);
for (;;) {
if (unlikely(c + a >= u))
return false;
old = atomic_cmpxchg((v), c, c + a);
if (likely(old == c))
break;
c = old;
}
return true;
}
/**
* __atomic_dec_ifmoe - dec if the result is more or equal than a given value.
*
* @v: pointer of type atomic_t
* @a: the amount to dec from v...
* @u: ...if (v - a) is more or equal than u.
*
* returns true if (v - a) was more or equal than u, and false
* otherwise.
*/
static inline bool __atomic_dec_ifmoe(atomic_t *v, int a, int u)
{
int c, old;
c = atomic_read(v);
for (;;) {
if (unlikely(c - a < u))
return false;
old = atomic_cmpxchg((v), c, c - a);
if (likely(old == c))
break;
c = old;
}
return true;
}
static bool bnx2x_credit_pool_get(struct bnx2x_credit_pool_obj *o, int cnt)
{
bool rc;
static bool bnx2x_credit_pool_get_entry_always_true(
struct bnx2x_credit_pool_obj *o,
int *offset)
{
*offset = -1;
return true;
}
/**
* bnx2x_init_credit_pool - initialize credit pool internals.
*
* @p: credit pool
* @base: Base entry in the CAM to use.
* @credit: pool size.
*
* If base is negative no CAM entries handling will be performed.
* If credit is negative pool operations will always succeed (unlimited pool).
*
*/
void bnx2x_init_credit_pool(struct bnx2x_credit_pool_obj *p,
int base, int credit)
{
/* Zero the object first */
memset(p, 0, sizeof(*p));
/* Set the table to all 1s */
memset(&p->pool_mirror, 0xff, sizeof(p->pool_mirror));
/* Init a pool as full */
atomic_set(&p->credit, credit);
/* The total poll size */
p->pool_sz = credit;
p->base_pool_offset = base;
/* Commit the change */
smp_mb();
p->check = bnx2x_credit_pool_check;
/* if pool credit is negative - disable the checks */
if (credit >= 0) {
p->put = bnx2x_credit_pool_put;
p->get = bnx2x_credit_pool_get;
p->put_entry = bnx2x_credit_pool_put_entry;
p->get_entry = bnx2x_credit_pool_get_entry;
} else {
p->put = bnx2x_credit_pool_always_true;
p->get = bnx2x_credit_pool_always_true;
p->put_entry = bnx2x_credit_pool_put_entry_always_true;
p->get_entry = bnx2x_credit_pool_get_entry_always_true;
}
/* If base is negative - disable entries handling */
if (base < 0) {
p->put_entry = bnx2x_credit_pool_put_entry_always_true;
p->get_entry = bnx2x_credit_pool_get_entry_always_true;
}
}
void bnx2x_init_mac_credit_pool(struct bnx2x *bp,
struct bnx2x_credit_pool_obj *p, u8 func_id,
u8 func_num)
{
/* TODO: this will be defined in consts as well... */
#define BNX2X_CAM_SIZE_EMUL 5
int cam_sz;
if (CHIP_IS_E1(bp)) {
/* In E1, Multicast is saved in cam... */
if (!CHIP_REV_IS_SLOW(bp))
cam_sz = (MAX_MAC_CREDIT_E1 / 2) - BNX2X_MAX_MULTICAST;
else
cam_sz = BNX2X_CAM_SIZE_EMUL - BNX2X_MAX_EMUL_MULTI;
} else if (CHIP_IS_E1H(bp)) {
/* CAM credit is equaly divided between all active functions
* on the PORT!.
*/
if ((func_num > 0)) {
if (!CHIP_REV_IS_SLOW(bp))
cam_sz = (MAX_MAC_CREDIT_E1H / (2*func_num));
else
cam_sz = BNX2X_CAM_SIZE_EMUL;
bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
} else {
/* this should never happen! Block MAC operations. */
bnx2x_init_credit_pool(p, 0, 0);
}
} else {
/* CAM credit is equaly divided between all active functions
* on the PATH.
*/
if (func_num > 0) {
if (!CHIP_REV_IS_SLOW(bp))
cam_sz = PF_MAC_CREDIT_E2(bp, func_num);
else
cam_sz = BNX2X_CAM_SIZE_EMUL;
/* No need for CAM entries handling for 57712 and
* newer.
*/
bnx2x_init_credit_pool(p, -1, cam_sz);
} else {
/* this should never happen! Block MAC operations. */
bnx2x_init_credit_pool(p, 0, 0);
}
}
}
void bnx2x_init_vlan_credit_pool(struct bnx2x *bp,
struct bnx2x_credit_pool_obj *p,
u8 func_id,
u8 func_num)
{
if (CHIP_IS_E1x(bp)) {
/* There is no VLAN credit in HW on 57710 and 57711 only
* MAC / MAC-VLAN can be set
*/
bnx2x_init_credit_pool(p, 0, -1);
} else {
/* CAM credit is equally divided between all active functions
* on the PATH.
*/
if (func_num > 0) {
int credit = PF_VLAN_CREDIT_E2(bp, func_num);
bnx2x_init_credit_pool(p, -1/*unused for E2*/, credit);
} else
/* this should never happen! Block VLAN operations. */
bnx2x_init_credit_pool(p, 0, 0);
}
}
/****************** RSS Configuration ******************/
/**
* bnx2x_debug_print_ind_table - prints the indirection table configuration.
*
* @bp: driver handle
* @p: pointer to rss configuration
*
* Prints it when NETIF_MSG_IFUP debug level is configured.
*/
static inline void bnx2x_debug_print_ind_table(struct bnx2x *bp,
struct bnx2x_config_rss_params *p)
{
int i;
DP(BNX2X_MSG_SP, "Setting indirection table to:\n");
DP(BNX2X_MSG_SP, "0x0000: ");
for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++) {
DP_CONT(BNX2X_MSG_SP, "0x%02x ", p->ind_table[i]);
/* Print 4 bytes in a line */
if ((i + 1 < T_ETH_INDIRECTION_TABLE_SIZE) &&
(((i + 1) & 0x3) == 0)) {
DP_CONT(BNX2X_MSG_SP, "\n");
DP(BNX2X_MSG_SP, "0x%04x: ", i + 1);
}
}
/* Apparently, bnx2x reads this array in reverse order
* We need to byte swap rss_key to comply with Toeplitz specs.
*/
for (i = 0; i < sizeof(data->rss_key); i++)
*--dst = *src++;
/* Remember the last configuration */
memcpy(o->ind_table, p->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
/* Print the indirection table */
if (netif_msg_ifup(bp))
bnx2x_debug_print_ind_table(bp, p);
/* No need for an explicit memory barrier here as long as we
* ensure the ordering of writing to the SPQ element
* and updating of the SPQ producer which involves a memory
* read. If the memory read is removed we will have to put a
* full memory barrier there (inside bnx2x_sp_post()).
*/
int bnx2x_config_rss(struct bnx2x *bp,
struct bnx2x_config_rss_params *p)
{
int rc;
struct bnx2x_rss_config_obj *o = p->rss_obj;
struct bnx2x_raw_obj *r = &o->raw;
/* Do nothing if only driver cleanup was requested */
if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
DP(BNX2X_MSG_SP, "Not configuring RSS ramrod_flags=%lx\n",
p->ramrod_flags);
return 0;
}
/********************** Queue state object ***********************************/
/**
* bnx2x_queue_state_change - perform Queue state change transition
*
* @bp: device handle
* @params: parameters to perform the transition
*
* returns 0 in case of successfully completed transition, negative error
* code in case of failure, positive (EBUSY) value if there is a completion
* to that is still pending (possible only if RAMROD_COMP_WAIT is
* not set in params->ramrod_flags for asynchronous commands).
*
*/
int bnx2x_queue_state_change(struct bnx2x *bp,
struct bnx2x_queue_state_params *params)
{
struct bnx2x_queue_sp_obj *o = params->q_obj;
int rc, pending_bit;
unsigned long *pending = &o->pending;
/* Check that the requested transition is legal */
rc = o->check_transition(bp, o, params);
if (rc) {
BNX2X_ERR("check transition returned an error. rc %d\n", rc);
return -EINVAL;
}
/* Set "pending" bit */
DP(BNX2X_MSG_SP, "pending bit was=%lx\n", o->pending);
pending_bit = o->set_pending(o, params);
DP(BNX2X_MSG_SP, "pending bit now=%lx\n", o->pending);
/* Don't send a command if only driver cleanup was requested */
if (test_bit(RAMROD_DRV_CLR_ONLY, ¶ms->ramrod_flags))
o->complete_cmd(bp, o, pending_bit);
else {
/* Send a ramrod */
rc = o->send_cmd(bp, params);
if (rc) {
o->next_state = BNX2X_Q_STATE_MAX;
clear_bit(pending_bit, pending);
smp_mb__after_atomic();
return rc;
}
if (test_bit(RAMROD_COMP_WAIT, ¶ms->ramrod_flags)) {
rc = o->wait_comp(bp, o, pending_bit);
if (rc)
return rc;
/* ACTIVATE and DEACTIVATE commands are implemented on top of
* UPDATE command.
*/
if ((cmd == BNX2X_Q_CMD_ACTIVATE) ||
(cmd == BNX2X_Q_CMD_DEACTIVATE))
bit = BNX2X_Q_CMD_UPDATE;
else
bit = cmd;
/**
* bnx2x_queue_comp_cmd - complete the state change command.
*
* @bp: device handle
* @o: queue info
* @cmd: command to exec
*
* Checks that the arrived completion is expected.
*/
static int bnx2x_queue_comp_cmd(struct bnx2x *bp,
struct bnx2x_queue_sp_obj *o,
enum bnx2x_queue_cmd cmd)
{
unsigned long cur_pending = o->pending;
if (!test_and_clear_bit(cmd, &cur_pending)) {
BNX2X_ERR("Bad MC reply %d for queue %d in state %d pending 0x%lx, next_state %d\n",
cmd, o->cids[BNX2X_PRIMARY_CID_INDEX],
o->state, cur_pending, o->next_state);
return -EINVAL;
}
if (o->next_tx_only >= o->max_cos)
/* >= because tx only must always be smaller than cos since the
* primary connection supports COS 0
*/
BNX2X_ERR("illegal value for next tx_only: %d. max cos was %d",
o->next_tx_only, o->max_cos);
DP(BNX2X_MSG_SP,
"Completing command %d for queue %d, setting state to %d\n",
cmd, o->cids[BNX2X_PRIMARY_CID_INDEX], o->next_state);
if (o->next_tx_only) /* print num tx-only if any exist */
DP(BNX2X_MSG_SP, "primary cid %d: num tx-only cons %d\n",
o->cids[BNX2X_PRIMARY_CID_INDEX], o->next_tx_only);
/* initialize the general, tx and rx parts of a queue object */
static void bnx2x_q_fill_setup_data_cmn(struct bnx2x *bp,
struct bnx2x_queue_state_params *cmd_params,
struct client_init_ramrod_data *data)
{
bnx2x_q_fill_init_general_data(bp, cmd_params->q_obj,
&cmd_params->params.setup.gen_params,
&data->general,
&cmd_params->params.setup.flags);
/* initialize the general and tx parts of a tx-only queue object */
static void bnx2x_q_fill_setup_tx_only(struct bnx2x *bp,
struct bnx2x_queue_state_params *cmd_params,
struct tx_queue_init_ramrod_data *data)
{
bnx2x_q_fill_init_general_data(bp, cmd_params->q_obj,
&cmd_params->params.tx_only.gen_params,
&data->general,
&cmd_params->params.tx_only.flags);
/* Clear the ramrod data */
memset(rdata, 0, sizeof(*rdata));
/* Fill the ramrod data */
bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
/* No need for an explicit memory barrier here as long as we
* ensure the ordering of writing to the SPQ element
* and updating of the SPQ producer which involves a memory
* read. If the memory read is removed we will have to put a
* full memory barrier there (inside bnx2x_sp_post()).
*/
return bnx2x_sp_post(bp, ramrod, o->cids[BNX2X_PRIMARY_CID_INDEX],
U64_HI(data_mapping),
U64_LO(data_mapping), ETH_CONNECTION_TYPE);
}
/* Clear the ramrod data */
memset(rdata, 0, sizeof(*rdata));
/* Fill the ramrod data */
bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
bnx2x_q_fill_setup_data_e2(bp, params, rdata);
/* No need for an explicit memory barrier here as long as we
* ensure the ordering of writing to the SPQ element
* and updating of the SPQ producer which involves a memory
* read. If the memory read is removed we will have to put a
* full memory barrier there (inside bnx2x_sp_post()).
*/
return bnx2x_sp_post(bp, ramrod, o->cids[BNX2X_PRIMARY_CID_INDEX],
U64_HI(data_mapping),
U64_LO(data_mapping), ETH_CONNECTION_TYPE);
}
/* Clear the ramrod data */
memset(rdata, 0, sizeof(*rdata));
/* Fill the ramrod data */
bnx2x_q_fill_setup_tx_only(bp, params, rdata);
DP(BNX2X_MSG_SP, "sending tx-only ramrod: cid %d, client-id %d, sp-client id %d, cos %d\n",
o->cids[cid_index], rdata->general.client_id,
rdata->general.sp_client_id, rdata->general.cos);
/* No need for an explicit memory barrier here as long as we
* ensure the ordering of writing to the SPQ element
* and updating of the SPQ producer which involves a memory
* read. If the memory read is removed we will have to put a
* full memory barrier there (inside bnx2x_sp_post()).
*/
return bnx2x_sp_post(bp, ramrod, o->cids[cid_index],
U64_HI(data_mapping),
U64_LO(data_mapping), ETH_CONNECTION_TYPE);
}
static void bnx2x_q_fill_update_data(struct bnx2x *bp,
struct bnx2x_queue_sp_obj *obj,
struct bnx2x_queue_update_params *params,
struct client_update_ramrod_data *data)
{
/* Client ID of the client to update */
data->client_id = obj->cl_id;
/* Function ID of the client to update */
data->func_id = obj->func_id;
/* Default VLAN value */
data->default_vlan = cpu_to_le16(params->def_vlan);
/* Drop packets that have source MAC that doesn't belong to this
* Queue.
*/
data->anti_spoofing_enable_flg =
test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF, ¶ms->update_flags);
data->anti_spoofing_change_flg =
test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF_CHNG, ¶ms->update_flags);
if (cid_index >= o->max_cos) {
BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
o->cl_id, cid_index);
return -EINVAL;
}
/* Clear the ramrod data */
memset(rdata, 0, sizeof(*rdata));
/* Fill the ramrod data */
bnx2x_q_fill_update_data(bp, o, update_params, rdata);
/* No need for an explicit memory barrier here as long as we
* ensure the ordering of writing to the SPQ element
* and updating of the SPQ producer which involves a memory
* read. If the memory read is removed we will have to put a
* full memory barrier there (inside bnx2x_sp_post()).
*/
return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_UPDATE,
o->cids[cid_index], U64_HI(data_mapping),
U64_LO(data_mapping), ETH_CONNECTION_TYPE);
}
/* Clear the ramrod data */
memset(rdata, 0, sizeof(*rdata));
/* Fill the ramrod data */
bnx2x_q_fill_update_tpa_data(bp, o, update_tpa_params, rdata);
/* Add the function id inside the type, so that sp post function
* doesn't automatically add the PF func-id, this is required
* for operations done by PFs on behalf of their VFs
*/
type = ETH_CONNECTION_TYPE |
((o->func_id) << SPE_HDR_FUNCTION_ID_SHIFT);
/* No need for an explicit memory barrier here as long as we
* ensure the ordering of writing to the SPQ element
* and updating of the SPQ producer which involves a memory
* read. If the memory read is removed we will have to put a
* full memory barrier there (inside bnx2x_sp_post()).
*/
return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_TPA_UPDATE,
o->cids[BNX2X_PRIMARY_CID_INDEX],
U64_HI(data_mapping),
U64_LO(data_mapping), type);
}
static inline int bnx2x_queue_send_cmd_cmn(struct bnx2x *bp,
struct bnx2x_queue_state_params *params)
{
switch (params->cmd) {
case BNX2X_Q_CMD_INIT:
return bnx2x_q_init(bp, params);
case BNX2X_Q_CMD_SETUP_TX_ONLY:
return bnx2x_q_send_setup_tx_only(bp, params);
case BNX2X_Q_CMD_DEACTIVATE:
return bnx2x_q_send_deactivate(bp, params);
case BNX2X_Q_CMD_ACTIVATE:
return bnx2x_q_send_activate(bp, params);
case BNX2X_Q_CMD_UPDATE:
return bnx2x_q_send_update(bp, params);
case BNX2X_Q_CMD_UPDATE_TPA:
return bnx2x_q_send_update_tpa(bp, params);
case BNX2X_Q_CMD_HALT:
return bnx2x_q_send_halt(bp, params);
case BNX2X_Q_CMD_CFC_DEL:
return bnx2x_q_send_cfc_del(bp, params);
case BNX2X_Q_CMD_TERMINATE:
return bnx2x_q_send_terminate(bp, params);
case BNX2X_Q_CMD_EMPTY:
return bnx2x_q_send_empty(bp, params);
default:
BNX2X_ERR("Unknown command: %d\n", params->cmd);
return -EINVAL;
}
}
static int bnx2x_queue_send_cmd_e1x(struct bnx2x *bp,
struct bnx2x_queue_state_params *params)
{
switch (params->cmd) {
case BNX2X_Q_CMD_SETUP:
return bnx2x_q_send_setup_e1x(bp, params);
case BNX2X_Q_CMD_INIT:
case BNX2X_Q_CMD_SETUP_TX_ONLY:
case BNX2X_Q_CMD_DEACTIVATE:
case BNX2X_Q_CMD_ACTIVATE:
case BNX2X_Q_CMD_UPDATE:
case BNX2X_Q_CMD_UPDATE_TPA:
case BNX2X_Q_CMD_HALT:
case BNX2X_Q_CMD_CFC_DEL:
case BNX2X_Q_CMD_TERMINATE:
case BNX2X_Q_CMD_EMPTY:
return bnx2x_queue_send_cmd_cmn(bp, params);
default:
BNX2X_ERR("Unknown command: %d\n", params->cmd);
return -EINVAL;
}
}
static int bnx2x_queue_send_cmd_e2(struct bnx2x *bp,
struct bnx2x_queue_state_params *params)
{
switch (params->cmd) {
case BNX2X_Q_CMD_SETUP:
return bnx2x_q_send_setup_e2(bp, params);
case BNX2X_Q_CMD_INIT:
case BNX2X_Q_CMD_SETUP_TX_ONLY:
case BNX2X_Q_CMD_DEACTIVATE:
case BNX2X_Q_CMD_ACTIVATE:
case BNX2X_Q_CMD_UPDATE:
case BNX2X_Q_CMD_UPDATE_TPA:
case BNX2X_Q_CMD_HALT:
case BNX2X_Q_CMD_CFC_DEL:
case BNX2X_Q_CMD_TERMINATE:
case BNX2X_Q_CMD_EMPTY:
return bnx2x_queue_send_cmd_cmn(bp, params);
default:
BNX2X_ERR("Unknown command: %d\n", params->cmd);
return -EINVAL;
}
}
/**
* bnx2x_queue_chk_transition - check state machine of a regular Queue
*
* @bp: device handle
* @o: queue info
* @params: queue state
*
* (not Forwarding)
* It both checks if the requested command is legal in a current
* state and, if it's legal, sets a `next_state' in the object
* that will be used in the completion flow to set the `state'
* of the object.
*
* returns 0 if a requested command is a legal transition,
* -EINVAL otherwise.
*/
static int bnx2x_queue_chk_transition(struct bnx2x *bp,
struct bnx2x_queue_sp_obj *o,
struct bnx2x_queue_state_params *params)
{
enum bnx2x_q_state state = o->state, next_state = BNX2X_Q_STATE_MAX;
enum bnx2x_queue_cmd cmd = params->cmd;
struct bnx2x_queue_update_params *update_params =
¶ms->params.update;
u8 next_tx_only = o->num_tx_only;
/* Forget all pending for completion commands if a driver only state
* transition has been requested.
*/
if (test_bit(RAMROD_DRV_CLR_ONLY, ¶ms->ramrod_flags)) {
o->pending = 0;
o->next_state = BNX2X_Q_STATE_MAX;
}
/* Don't allow a next state transition if we are in the middle of
* the previous one.
*/
if (o->pending) {
BNX2X_ERR("Blocking transition since pending was %lx\n",
o->pending);
return -EBUSY;
}
switch (state) {
case BNX2X_Q_STATE_RESET:
if (cmd == BNX2X_Q_CMD_INIT)
next_state = BNX2X_Q_STATE_INITIALIZED;
break;
case BNX2X_Q_STATE_INITIALIZED:
if (cmd == BNX2X_Q_CMD_SETUP) {
if (test_bit(BNX2X_Q_FLG_ACTIVE,
¶ms->params.setup.flags))
next_state = BNX2X_Q_STATE_ACTIVE;
else
next_state = BNX2X_Q_STATE_INACTIVE;
}
break;
case BNX2X_Q_STATE_ACTIVE:
if (cmd == BNX2X_Q_CMD_DEACTIVATE)
next_state = BNX2X_Q_STATE_INACTIVE;
else if (cmd == BNX2X_Q_CMD_HALT)
next_state = BNX2X_Q_STATE_STOPPED;
else if (cmd == BNX2X_Q_CMD_UPDATE) {
/* If "active" state change is requested, update the
* state accordingly.
*/
if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
&update_params->update_flags) &&
!test_bit(BNX2X_Q_UPDATE_ACTIVATE,
&update_params->update_flags))
next_state = BNX2X_Q_STATE_INACTIVE;
else
next_state = BNX2X_Q_STATE_ACTIVE;
}
break;
case BNX2X_Q_STATE_MULTI_COS:
if (cmd == BNX2X_Q_CMD_TERMINATE)
next_state = BNX2X_Q_STATE_MCOS_TERMINATED;
else if (cmd == BNX2X_Q_CMD_UPDATE) {
/* If "active" state change is requested, update the
* state accordingly.
*/
if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
&update_params->update_flags) &&
!test_bit(BNX2X_Q_UPDATE_ACTIVATE,
&update_params->update_flags))
next_state = BNX2X_Q_STATE_INACTIVE;
else
next_state = BNX2X_Q_STATE_MULTI_COS;
}
break;
case BNX2X_Q_STATE_MCOS_TERMINATED:
if (cmd == BNX2X_Q_CMD_CFC_DEL) {
next_tx_only = o->num_tx_only - 1;
if (next_tx_only == 0)
next_state = BNX2X_Q_STATE_ACTIVE;
else
next_state = BNX2X_Q_STATE_MULTI_COS;
}
break;
case BNX2X_Q_STATE_INACTIVE:
if (cmd == BNX2X_Q_CMD_ACTIVATE)
next_state = BNX2X_Q_STATE_ACTIVE;
else if (cmd == BNX2X_Q_CMD_HALT)
next_state = BNX2X_Q_STATE_STOPPED;
else if (cmd == BNX2X_Q_CMD_UPDATE) {
/* If "active" state change is requested, update the
* state accordingly.
*/
if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
&update_params->update_flags) &&
test_bit(BNX2X_Q_UPDATE_ACTIVATE,
&update_params->update_flags)){
if (o->num_tx_only == 0)
next_state = BNX2X_Q_STATE_ACTIVE;
else /* tx only queues exist for this queue */
next_state = BNX2X_Q_STATE_MULTI_COS;
} else
next_state = BNX2X_Q_STATE_INACTIVE;
}
break;
case BNX2X_Q_STATE_STOPPED:
if (cmd == BNX2X_Q_CMD_TERMINATE)
next_state = BNX2X_Q_STATE_TERMINATED;
break;
case BNX2X_Q_STATE_TERMINATED:
if (cmd == BNX2X_Q_CMD_CFC_DEL)
next_state = BNX2X_Q_STATE_RESET;
/* return a queue object's logical state*/
int bnx2x_get_q_logical_state(struct bnx2x *bp,
struct bnx2x_queue_sp_obj *obj)
{
switch (obj->state) {
case BNX2X_Q_STATE_ACTIVE:
case BNX2X_Q_STATE_MULTI_COS:
return BNX2X_Q_LOGICAL_STATE_ACTIVE;
case BNX2X_Q_STATE_RESET:
case BNX2X_Q_STATE_INITIALIZED:
case BNX2X_Q_STATE_MCOS_TERMINATED:
case BNX2X_Q_STATE_INACTIVE:
case BNX2X_Q_STATE_STOPPED:
case BNX2X_Q_STATE_TERMINATED:
case BNX2X_Q_STATE_FLRED:
return BNX2X_Q_LOGICAL_STATE_STOPPED;
default:
return -EINVAL;
}
}
/********************** Function state object *********************************/
enum bnx2x_func_state bnx2x_func_get_state(struct bnx2x *bp,
struct bnx2x_func_sp_obj *o)
{
/* in the middle of transaction - return INVALID state */
if (o->pending)
return BNX2X_F_STATE_MAX;
/* unsure the order of reading of o->pending and o->state
* o->pending should be read first
*/
rmb();
/**
* bnx2x_func_state_change_comp - complete the state machine transition
*
* @bp: device handle
* @o: function info
* @cmd: more info
*
* Called on state change transition. Completes the state
* machine transition only - no HW interaction.
*/
static inline int bnx2x_func_state_change_comp(struct bnx2x *bp,
struct bnx2x_func_sp_obj *o,
enum bnx2x_func_cmd cmd)
{
unsigned long cur_pending = o->pending;
if (!test_and_clear_bit(cmd, &cur_pending)) {
BNX2X_ERR("Bad MC reply %d for func %d in state %d pending 0x%lx, next_state %d\n",
cmd, BP_FUNC(bp), o->state,
cur_pending, o->next_state);
return -EINVAL;
}
DP(BNX2X_MSG_SP,
"Completing command %d for func %d, setting state to %d\n",
cmd, BP_FUNC(bp), o->next_state);
/**
* bnx2x_func_comp_cmd - complete the state change command
*
* @bp: device handle
* @o: function info
* @cmd: more info
*
* Checks that the arrived completion is expected.
*/
static int bnx2x_func_comp_cmd(struct bnx2x *bp,
struct bnx2x_func_sp_obj *o,
enum bnx2x_func_cmd cmd)
{
/* Complete the state machine part first, check if it's a
* legal completion.
*/
int rc = bnx2x_func_state_change_comp(bp, o, cmd);
return rc;
}
/**
* bnx2x_func_chk_transition - perform function state machine transition
*
* @bp: device handle
* @o: function info
* @params: state parameters
*
* It both checks if the requested command is legal in a current
* state and, if it's legal, sets a `next_state' in the object
* that will be used in the completion flow to set the `state'
* of the object.
*
* returns 0 if a requested command is a legal transition,
* -EINVAL otherwise.
*/
static int bnx2x_func_chk_transition(struct bnx2x *bp,
struct bnx2x_func_sp_obj *o,
struct bnx2x_func_state_params *params)
{
enum bnx2x_func_state state = o->state, next_state = BNX2X_F_STATE_MAX;
enum bnx2x_func_cmd cmd = params->cmd;
/* Forget all pending for completion commands if a driver only state
* transition has been requested.
*/
if (test_bit(RAMROD_DRV_CLR_ONLY, ¶ms->ramrod_flags)) {
o->pending = 0;
o->next_state = BNX2X_F_STATE_MAX;
}
/* Don't allow a next state transition if we are in the middle of
* the previous one.
*/
if (o->pending)
return -EBUSY;
switch (state) {
case BNX2X_F_STATE_RESET:
if (cmd == BNX2X_F_CMD_HW_INIT)
next_state = BNX2X_F_STATE_INITIALIZED;
break;
case BNX2X_F_STATE_INITIALIZED:
if (cmd == BNX2X_F_CMD_START)
next_state = BNX2X_F_STATE_STARTED;
else if (cmd == BNX2X_F_CMD_HW_RESET)
next_state = BNX2X_F_STATE_RESET;
break;
case BNX2X_F_STATE_STARTED:
if (cmd == BNX2X_F_CMD_STOP)
next_state = BNX2X_F_STATE_INITIALIZED;
/* afex ramrods can be sent only in started mode, and only
* if not pending for function_stop ramrod completion
* for these events - next state remained STARTED.
*/
else if ((cmd == BNX2X_F_CMD_AFEX_UPDATE) &&
(!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
next_state = BNX2X_F_STATE_STARTED;
/* Switch_update ramrod can be sent in either started or
* tx_stopped state, and it doesn't change the state.
*/
else if ((cmd == BNX2X_F_CMD_SWITCH_UPDATE) &&
(!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
next_state = BNX2X_F_STATE_STARTED;
rdata->c2s_pri_tt_valid = start_params->c2s_pri_valid;
if (rdata->c2s_pri_tt_valid) {
memcpy(rdata->c2s_pri_trans_table.val,
start_params->c2s_pri,
MAX_VLAN_PRIORITIES);
rdata->c2s_pri_default = start_params->c2s_pri_default;
}
/* No need for an explicit memory barrier here as long we would
* need to ensure the ordering of writing to the SPQ element
* and updating of the SPQ producer which involves a memory
* read and we will have to put a full memory barrier there
* (inside bnx2x_sp_post()).
*/
/* Fill the ramrod data with provided parameters */
if (test_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND_CHNG,
&switch_update_params->changes)) {
rdata->tx_switch_suspend_change_flg = 1;
rdata->tx_switch_suspend =
test_bit(BNX2X_F_UPDATE_TX_SWITCH_SUSPEND,
&switch_update_params->changes);
}
if (test_bit(BNX2X_F_UPDATE_VLAN_FORCE_PRIO_CHNG,
&switch_update_params->changes)) {
rdata->sd_vlan_force_pri_change_flg = 1;
if (test_bit(BNX2X_F_UPDATE_VLAN_FORCE_PRIO_FLAG,
&switch_update_params->changes))
rdata->sd_vlan_force_pri_flg = 1;
rdata->sd_vlan_force_pri_flg =
switch_update_params->vlan_force_prio;
}
if (test_bit(BNX2X_F_UPDATE_TUNNEL_CFG_CHNG,
&switch_update_params->changes)) {
rdata->update_tunn_cfg_flg = 1;
if (test_bit(BNX2X_F_UPDATE_TUNNEL_INNER_CLSS_L2GRE,
&switch_update_params->changes))
rdata->inner_clss_l2gre = 1;
if (test_bit(BNX2X_F_UPDATE_TUNNEL_INNER_CLSS_VXLAN,
&switch_update_params->changes))
rdata->inner_clss_vxlan = 1;
if (test_bit(BNX2X_F_UPDATE_TUNNEL_INNER_CLSS_L2GENEVE,
&switch_update_params->changes))
rdata->inner_clss_l2geneve = 1;
if (test_bit(BNX2X_F_UPDATE_TUNNEL_INNER_RSS,
&switch_update_params->changes))
rdata->inner_rss = 1;
rdata->vxlan_dst_port =
cpu_to_le16(switch_update_params->vxlan_dst_port);
rdata->geneve_dst_port =
cpu_to_le16(switch_update_params->geneve_dst_port);
}
rdata->echo = SWITCH_UPDATE;
/* No need for an explicit memory barrier here as long as we
* ensure the ordering of writing to the SPQ element
* and updating of the SPQ producer which involves a memory
* read. If the memory read is removed we will have to put a
* full memory barrier there (inside bnx2x_sp_post()).
*/
return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_UPDATE, 0,
U64_HI(data_mapping),
U64_LO(data_mapping), NONE_CONNECTION_TYPE);
}
/* Fill the ramrod data with provided parameters */
rdata->vif_id_change_flg = 1;
rdata->vif_id = cpu_to_le16(afex_update_params->vif_id);
rdata->afex_default_vlan_change_flg = 1;
rdata->afex_default_vlan =
cpu_to_le16(afex_update_params->afex_default_vlan);
rdata->allowed_priorities_change_flg = 1;
rdata->allowed_priorities = afex_update_params->allowed_priorities;
rdata->echo = AFEX_UPDATE;
/* No need for an explicit memory barrier here as long as we
* ensure the ordering of writing to the SPQ element
* and updating of the SPQ producer which involves a memory
* read. If the memory read is removed we will have to put a
* full memory barrier there (inside bnx2x_sp_post()).
*/
DP(BNX2X_MSG_SP,
"afex: sending func_update vif_id 0x%x dvlan 0x%x prio 0x%x\n",
rdata->vif_id,
rdata->afex_default_vlan, rdata->allowed_priorities);
/* Fill the ramrod data with provided parameters */
rdata->vif_list_index = cpu_to_le16(afex_vif_params->vif_list_index);
rdata->func_bit_map = afex_vif_params->func_bit_map;
rdata->afex_vif_list_command = afex_vif_params->afex_vif_list_command;
rdata->func_to_clear = afex_vif_params->func_to_clear;
/* send in echo type of sub command */
rdata->echo = afex_vif_params->afex_vif_list_command;
/* No need for an explicit memory barrier here as long we would
* need to ensure the ordering of writing to the SPQ element
* and updating of the SPQ producer which involves a memory
* read and we will have to put a full memory barrier there
* (inside bnx2x_sp_post()).
*/
/* this ramrod sends data directly and not through DMA mapping */
return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_AFEX_VIF_LISTS, 0,
U64_HI(*p_rdata), U64_LO(*p_rdata),
NONE_CONNECTION_TYPE);
}
for (i = 0; i < ARRAY_SIZE(rdata->traffic_type_to_priority_cos); i++)
rdata->traffic_type_to_priority_cos[i] =
tx_start_params->traffic_type_to_priority_cos[i];
for (i = 0; i < MAX_TRAFFIC_TYPES; i++)
rdata->dcb_outer_pri[i] = tx_start_params->dcb_outer_pri[i];
/* No need for an explicit memory barrier here as long as we
* ensure the ordering of writing to the SPQ element
* and updating of the SPQ producer which involves a memory
* read. If the memory read is removed we will have to put a
* full memory barrier there (inside bnx2x_sp_post()).
*/
return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_START_TRAFFIC, 0,
U64_HI(data_mapping),
U64_LO(data_mapping), NONE_CONNECTION_TYPE);
}
/**
* bnx2x_func_state_change - perform Function state change transition
*
* @bp: device handle
* @params: parameters to perform the transaction
*
* returns 0 in case of successfully completed transition,
* negative error code in case of failure, positive
* (EBUSY) value if there is a completion to that is
* still pending (possible only if RAMROD_COMP_WAIT is
* not set in params->ramrod_flags for asynchronous
* commands).
*/
int bnx2x_func_state_change(struct bnx2x *bp,
struct bnx2x_func_state_params *params)
{
struct bnx2x_func_sp_obj *o = params->f_obj;
int rc, cnt = 300;
enum bnx2x_func_cmd cmd = params->cmd;
unsigned long *pending = &o->pending;
mutex_lock(&o->one_pending_mutex);
/* Check that the requested transition is legal */
rc = o->check_transition(bp, o, params);
if ((rc == -EBUSY) &&
(test_bit(RAMROD_RETRY, ¶ms->ramrod_flags))) {
while ((rc == -EBUSY) && (--cnt > 0)) {
mutex_unlock(&o->one_pending_mutex);
msleep(10);
mutex_lock(&o->one_pending_mutex);
rc = o->check_transition(bp, o, params);
}
if (rc == -EBUSY) {
mutex_unlock(&o->one_pending_mutex);
BNX2X_ERR("timeout waiting for previous ramrod completion\n");
return rc;
}
} else if (rc) {
mutex_unlock(&o->one_pending_mutex);
return rc;
}
/* Set "pending" bit */
set_bit(cmd, pending);
/* Don't send a command if only driver cleanup was requested */
if (test_bit(RAMROD_DRV_CLR_ONLY, ¶ms->ramrod_flags)) {
bnx2x_func_state_change_comp(bp, o, cmd);
mutex_unlock(&o->one_pending_mutex);
} else {
/* Send a ramrod */
rc = o->send_cmd(bp, params);
if (test_bit(RAMROD_COMP_WAIT, ¶ms->ramrod_flags)) {
rc = o->wait_comp(bp, o, cmd);
if (rc)
return rc;
return 0;
}
}
return !!test_bit(cmd, pending);
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.197Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.