net/mac802154/tx.c

Source file repositories/reference/linux-study-clean/net/mac802154/tx.c

File Facts

System
Linux kernel
Corpus path
net/mac802154/tx.c
Extension
.c
Size
5830 bytes
Lines
241
Domain
Networking Core
Bucket
Sockets, Protocols, Packet Path, And Network Policy
Inferred role
Networking Core: implementation source
Status
source implementation candidate

Why This File Exists

Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.

Dependency Surface

Detected Declarations

Annotated Snippet

if (unlikely(skb_tailroom(skb) < IEEE802154_FCS_LEN)) {
			nskb = skb_copy_expand(skb, 0, IEEE802154_FCS_LEN,
					       GFP_ATOMIC);
			if (likely(nskb)) {
				consume_skb(skb);
				skb = nskb;
			} else {
				goto err_free_skb;
			}
		}

		crc = crc_ccitt(0, skb->data, skb->len);
		put_unaligned_le16(crc, skb_put(skb, 2));
	}

	/* Stop the netif queue on each sub_if_data object. */
	ieee802154_hold_queue(local);
	atomic_inc(&local->phy->ongoing_txs);

	/* Drivers should preferably implement the async callback. In some rare
	 * cases they only provide a sync callback which we will use as a
	 * fallback.
	 */
	if (local->ops->xmit_async) {
		unsigned int len = skb->len;

		ret = drv_xmit_async(local, skb);
		if (ret)
			goto err_wake_netif_queue;

		DEV_STATS_INC(dev, tx_packets);
		DEV_STATS_ADD(dev, tx_bytes, len);
	} else {
		local->tx_skb = skb;
		queue_work(local->workqueue, &local->sync_tx_work);
	}

	return NETDEV_TX_OK;

err_wake_netif_queue:
	ieee802154_release_queue(local);
	if (atomic_dec_and_test(&local->phy->ongoing_txs))
		wake_up(&local->phy->sync_txq);
err_free_skb:
	kfree_skb(skb);
	return NETDEV_TX_OK;
}

static int ieee802154_sync_queue(struct ieee802154_local *local)
{
	int ret;

	ieee802154_hold_queue(local);
	ieee802154_disable_queue(local);
	wait_event(local->phy->sync_txq, !atomic_read(&local->phy->ongoing_txs));
	ret = local->tx_result;
	ieee802154_release_queue(local);

	return ret;
}

int ieee802154_sync_and_hold_queue(struct ieee802154_local *local)
{
	int ret;

	ieee802154_hold_queue(local);
	ret = ieee802154_sync_queue(local);
	set_bit(WPAN_PHY_FLAG_STATE_QUEUE_STOPPED, &local->phy->flags);

	return ret;
}

int ieee802154_mlme_op_pre(struct ieee802154_local *local)
{
	return ieee802154_sync_and_hold_queue(local);
}

int ieee802154_mlme_tx_locked(struct ieee802154_local *local,
			      struct ieee802154_sub_if_data *sdata,
			      struct sk_buff *skb)
{
	/* Avoid possible calls to ->ndo_stop() when we asynchronously perform
	 * MLME transmissions.
	 */
	ASSERT_RTNL();

	/* Ensure the device was not stopped, otherwise error out */
	if (!local->open_count)
		return -ENETDOWN;

Annotation

Implementation Notes