linux/drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.c
<<
>>
Prefs
   1/******************************************************************************
   2 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
   3 *
   4 * This program is distributed in the hope that it will be useful, but WITHOUT
   5 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   6 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   7 * more details.
   8 *
   9 * The full GNU General Public License is included in this distribution in the
  10 * file called LICENSE.
  11 *
  12 * Contact Information:
  13 * wlanfae <wlanfae@realtek.com>
  14 *****************************************************************************/
  15
  16#include "rtl_core.h"
  17#include "r8192E_hw.h"
  18#include "r8192E_cmdpkt.h"
  19
  20bool rtl92e_send_cmd_pkt(struct net_device *dev, u32 type, const void *data,
  21                         u32 len)
  22{
  23
  24        bool                            rt_status = true;
  25        struct r8192_priv *priv = rtllib_priv(dev);
  26        u16                             frag_length = 0, frag_offset = 0;
  27        struct sk_buff          *skb;
  28        unsigned char           *seg_ptr;
  29        struct cb_desc *tcb_desc;
  30        u8                              bLastIniPkt;
  31
  32        struct tx_fwinfo_8190pci *pTxFwInfo = NULL;
  33
  34        RT_TRACE(COMP_CMDPKT, "%s(),buffer_len is %d\n", __func__, len);
  35
  36        do {
  37                if ((len - frag_offset) > CMDPACKET_FRAG_SIZE) {
  38                        frag_length = CMDPACKET_FRAG_SIZE;
  39                        bLastIniPkt = 0;
  40
  41                } else {
  42                        frag_length = (u16)(len - frag_offset);
  43                        bLastIniPkt = 1;
  44                }
  45
  46                if (type == DESC_PACKET_TYPE_NORMAL)
  47                        skb = dev_alloc_skb(frag_length +
  48                                            priv->rtllib->tx_headroom + 4);
  49                else
  50                        skb = dev_alloc_skb(frag_length + 4);
  51
  52                if (!skb) {
  53                        rt_status = false;
  54                        goto Failed;
  55                }
  56
  57                memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
  58                tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
  59                tcb_desc->queue_index = TXCMD_QUEUE;
  60                tcb_desc->bCmdOrInit = type;
  61                tcb_desc->bLastIniPkt = bLastIniPkt;
  62
  63                if (type == DESC_PACKET_TYPE_NORMAL) {
  64                        tcb_desc->pkt_size = frag_length;
  65
  66                        seg_ptr = skb_put(skb, priv->rtllib->tx_headroom);
  67                        pTxFwInfo = (struct tx_fwinfo_8190pci *)seg_ptr;
  68                        memset(pTxFwInfo, 0, sizeof(struct tx_fwinfo_8190pci));
  69                        memset(pTxFwInfo, 0x12, 8);
  70                } else {
  71                        tcb_desc->txbuf_size = (u16)frag_length;
  72                }
  73
  74                seg_ptr = skb_put(skb, frag_length);
  75                memcpy(seg_ptr, data, (u32)frag_length);
  76
  77                if (type == DESC_PACKET_TYPE_INIT &&
  78                    (!priv->rtllib->check_nic_enough_desc(dev, TXCMD_QUEUE) ||
  79                     (!skb_queue_empty(&priv->rtllib->skb_waitQ[TXCMD_QUEUE])) ||
  80                     (priv->rtllib->queue_stop))) {
  81                        skb_queue_tail(&priv->rtllib->skb_waitQ[TXCMD_QUEUE],
  82                                       skb);
  83                } else {
  84                        priv->rtllib->softmac_hard_start_xmit(skb, dev);
  85                }
  86
  87                data += frag_length;
  88                frag_offset += frag_length;
  89
  90        } while (frag_offset < len);
  91
  92        rtl92e_writeb(dev, TPPoll, TPPoll_CQ);
  93Failed:
  94        return rt_status;
  95}
  96