1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
4 *
5 * Contact Information: wlanfae <wlanfae@realtek.com>
6 */
7 #include "rtl_core.h"
8 #include "r8192E_hw.h"
9 #include "r8192E_cmdpkt.h"
10
rtl92e_send_cmd_pkt(struct net_device * dev,u32 type,const void * data,u32 len)11 bool rtl92e_send_cmd_pkt(struct net_device *dev, u32 type, const void *data,
12 u32 len)
13 {
14 struct r8192_priv *priv = rtllib_priv(dev);
15 u16 frag_length = 0, frag_offset = 0;
16 struct sk_buff *skb;
17 unsigned char *seg_ptr;
18 struct cb_desc *tcb_desc;
19 u8 last_ini_pkt;
20
21 struct tx_fwinfo_8190pci *pTxFwInfo = NULL;
22
23 do {
24 if ((len - frag_offset) > CMDPACKET_FRAG_SIZE) {
25 frag_length = CMDPACKET_FRAG_SIZE;
26 last_ini_pkt = 0;
27
28 } else {
29 frag_length = (u16)(len - frag_offset);
30 last_ini_pkt = 1;
31 }
32
33 if (type == DESC_PACKET_TYPE_NORMAL)
34 skb = dev_alloc_skb(frag_length +
35 priv->rtllib->tx_headroom + 4);
36 else
37 skb = dev_alloc_skb(frag_length + 4);
38
39 if (!skb)
40 return false;
41
42 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
43 tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
44 tcb_desc->queue_index = TXCMD_QUEUE;
45 tcb_desc->cmd_or_init = type;
46 tcb_desc->last_ini_pkt = last_ini_pkt;
47
48 if (type == DESC_PACKET_TYPE_NORMAL) {
49 tcb_desc->pkt_size = frag_length;
50
51 seg_ptr = skb_put(skb, priv->rtllib->tx_headroom);
52 pTxFwInfo = (struct tx_fwinfo_8190pci *)seg_ptr;
53 memset(pTxFwInfo, 0, sizeof(struct tx_fwinfo_8190pci));
54 memset(pTxFwInfo, 0x12, 8);
55 } else {
56 tcb_desc->txbuf_size = frag_length;
57 }
58
59 skb_put_data(skb, data, frag_length);
60
61 if (type == DESC_PACKET_TYPE_INIT &&
62 (!priv->rtllib->check_nic_enough_desc(dev, TXCMD_QUEUE) ||
63 (!skb_queue_empty(&priv->rtllib->skb_waitq[TXCMD_QUEUE])) ||
64 (priv->rtllib->queue_stop))) {
65 skb_queue_tail(&priv->rtllib->skb_waitq[TXCMD_QUEUE],
66 skb);
67 } else {
68 priv->rtllib->softmac_hard_start_xmit(skb, dev);
69 }
70
71 data += frag_length;
72 frag_offset += frag_length;
73
74 } while (frag_offset < len);
75
76 rtl92e_writeb(dev, TP_POLL, TP_POLL_CQ);
77
78 return true;
79 }
80