drivers/net/ethernet/chelsio/cxgb4/cxgb4_mps.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/chelsio/cxgb4/cxgb4_mps.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/chelsio/cxgb4/cxgb4_mps.c- Extension
.c- Size
- 3439 bytes
- Lines
- 144
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
cxgb4.h
Detected Declarations
function cxgb4_mps_ref_dec_by_macfunction cxgb4_mps_ref_incfunction cxgb4_free_mac_filtfunction cxgb4_alloc_mac_filtfunction cxgb4_update_mac_filtfunction cxgb4_init_mps_ref_entriesfunction cxgb4_free_mps_ref_entries
Annotated Snippet
ether_addr_equal(mps_entry->mask, mask ? mask : bitmask)) {
if (!refcount_dec_and_test(&mps_entry->refcnt)) {
spin_unlock_bh(&adap->mps_ref_lock);
return -EBUSY;
}
list_del(&mps_entry->list);
kfree(mps_entry);
ret = 0;
break;
}
}
spin_unlock_bh(&adap->mps_ref_lock);
return ret;
}
static int cxgb4_mps_ref_inc(struct adapter *adap, const u8 *mac_addr,
u16 idx, const u8 *mask)
{
u8 bitmask[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
struct mps_entries_ref *mps_entry;
int ret = 0;
spin_lock_bh(&adap->mps_ref_lock);
list_for_each_entry(mps_entry, &adap->mps_ref, list) {
if (mps_entry->idx == idx) {
refcount_inc(&mps_entry->refcnt);
goto unlock;
}
}
mps_entry = kzalloc_obj(*mps_entry, GFP_ATOMIC);
if (!mps_entry) {
ret = -ENOMEM;
goto unlock;
}
ether_addr_copy(mps_entry->mask, mask ? mask : bitmask);
ether_addr_copy(mps_entry->addr, mac_addr);
mps_entry->idx = idx;
refcount_set(&mps_entry->refcnt, 1);
list_add_tail(&mps_entry->list, &adap->mps_ref);
unlock:
spin_unlock_bh(&adap->mps_ref_lock);
return ret;
}
int cxgb4_free_mac_filt(struct adapter *adap, unsigned int viid,
unsigned int naddr, const u8 **addr, bool sleep_ok)
{
int ret, i;
for (i = 0; i < naddr; i++) {
if (!cxgb4_mps_ref_dec_by_mac(adap, addr[i], NULL)) {
ret = t4_free_mac_filt(adap, adap->mbox, viid,
1, &addr[i], sleep_ok);
if (ret < 0)
return ret;
}
}
/* return number of filters freed */
return naddr;
}
int cxgb4_alloc_mac_filt(struct adapter *adap, unsigned int viid,
bool free, unsigned int naddr, const u8 **addr,
u16 *idx, u64 *hash, bool sleep_ok)
{
int ret, i;
ret = t4_alloc_mac_filt(adap, adap->mbox, viid, free,
naddr, addr, idx, hash, sleep_ok);
if (ret < 0)
return ret;
for (i = 0; i < naddr; i++) {
if (idx[i] != 0xffff) {
if (cxgb4_mps_ref_inc(adap, addr[i], idx[i], NULL)) {
ret = -ENOMEM;
goto error;
}
}
}
goto out;
error:
cxgb4_free_mac_filt(adap, viid, naddr, addr, sleep_ok);
out:
/* Returns a negative error number or the number of filters allocated */
return ret;
}
Annotation
- Immediate include surface: `cxgb4.h`.
- Detected declarations: `function cxgb4_mps_ref_dec_by_mac`, `function cxgb4_mps_ref_inc`, `function cxgb4_free_mac_filt`, `function cxgb4_alloc_mac_filt`, `function cxgb4_update_mac_filt`, `function cxgb4_init_mps_ref_entries`, `function cxgb4_free_mps_ref_entries`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.