Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *  Copyright (C) 2008, cozybit Inc.
0004  *  Copyright (C) 2007, Red Hat, Inc.
0005  *  Copyright (C) 2003-2006, Marvell International Ltd.
0006  */
0007 #include <linux/spinlock.h>
0008 #include <linux/device.h>
0009 #include <linux/kthread.h>
0010 #include <net/mac80211.h>
0011 
0012 #include "deb_defs.h"
0013 
0014 #ifndef DRV_NAME
0015 #define DRV_NAME "libertas_tf"
0016 #endif
0017 
0018 #define MRVL_DEFAULT_RETRIES            9
0019 #define MRVL_PER_PACKET_RATE            0x10
0020 #define MRVL_MAX_BCN_SIZE           440
0021 #define CMD_OPTION_WAITFORRSP           0x0002
0022 
0023 /* Return command are almost always the same as the host command, but with
0024  * bit 15 set high.  There are a few exceptions, though...
0025  */
0026 #define CMD_RET(cmd)            (0x8000 | cmd)
0027 
0028 /* Command codes */
0029 #define CMD_GET_HW_SPEC             0x0003
0030 #define CMD_802_11_RESET            0x0005
0031 #define CMD_MAC_MULTICAST_ADR           0x0010
0032 #define CMD_802_11_RADIO_CONTROL        0x001c
0033 #define CMD_802_11_RF_CHANNEL           0x001d
0034 #define CMD_802_11_RF_TX_POWER          0x001e
0035 #define CMD_MAC_CONTROL             0x0028
0036 #define CMD_802_11_MAC_ADDRESS          0x004d
0037 #define CMD_SET_BOOT2_VER           0x00a5
0038 #define CMD_802_11_BEACON_CTRL          0x00b0
0039 #define CMD_802_11_BEACON_SET           0x00cb
0040 #define CMD_802_11_SET_MODE         0x00cc
0041 #define CMD_802_11_SET_BSSID            0x00cd
0042 
0043 #define CMD_ACT_GET         0x0000
0044 #define CMD_ACT_SET         0x0001
0045 
0046 /* Define action or option for CMD_802_11_RESET */
0047 #define CMD_ACT_HALT            0x0003
0048 
0049 /* Define action or option for CMD_MAC_CONTROL */
0050 #define CMD_ACT_MAC_RX_ON           0x0001
0051 #define CMD_ACT_MAC_TX_ON           0x0002
0052 #define CMD_ACT_MAC_MULTICAST_ENABLE        0x0020
0053 #define CMD_ACT_MAC_BROADCAST_ENABLE        0x0040
0054 #define CMD_ACT_MAC_PROMISCUOUS_ENABLE      0x0080
0055 #define CMD_ACT_MAC_ALL_MULTICAST_ENABLE    0x0100
0056 
0057 /* Define action or option for CMD_802_11_RADIO_CONTROL */
0058 #define CMD_TYPE_AUTO_PREAMBLE      0x0001
0059 #define CMD_TYPE_SHORT_PREAMBLE     0x0002
0060 #define CMD_TYPE_LONG_PREAMBLE      0x0003
0061 
0062 #define TURN_ON_RF          0x01
0063 #define RADIO_ON            0x01
0064 #define RADIO_OFF           0x00
0065 
0066 #define SET_AUTO_PREAMBLE       0x05
0067 #define SET_SHORT_PREAMBLE      0x03
0068 #define SET_LONG_PREAMBLE       0x01
0069 
0070 /* Define action or option for CMD_802_11_RF_CHANNEL */
0071 #define CMD_OPT_802_11_RF_CHANNEL_GET   0x00
0072 #define CMD_OPT_802_11_RF_CHANNEL_SET   0x01
0073 
0074 /* Codes for CMD_802_11_SET_MODE */
0075 enum lbtf_mode {
0076     LBTF_PASSIVE_MODE,
0077     LBTF_STA_MODE,
0078     LBTF_AP_MODE,
0079 };
0080 
0081 /** Card Event definition */
0082 #define MACREG_INT_CODE_FIRMWARE_READY      48
0083 /** Buffer Constants */
0084 
0085 /*  The size of SQ memory PPA, DPA are 8 DWORDs, that keep the physical
0086 *   addresses of TxPD buffers. Station has only 8 TxPD available, Whereas
0087 *   driver has more local TxPDs. Each TxPD on the host memory is associated
0088 *   with a Tx control node. The driver maintains 8 RxPD descriptors for
0089 *   station firmware to store Rx packet information.
0090 *
0091 *   Current version of MAC has a 32x6 multicast address buffer.
0092 *
0093 *   802.11b can have up to  14 channels, the driver keeps the
0094 *   BSSID(MAC address) of each APs or Ad hoc stations it has sensed.
0095 */
0096 
0097 #define MRVDRV_MAX_MULTICAST_LIST_SIZE  32
0098 #define LBS_NUM_CMD_BUFFERS             10
0099 #define LBS_CMD_BUFFER_SIZE             (2 * 1024)
0100 #define MRVDRV_MAX_CHANNEL_SIZE     14
0101 #define MRVDRV_SNAP_HEADER_LEN          8
0102 
0103 #define LBS_UPLD_SIZE           2312
0104 #define DEV_NAME_LEN            32
0105 
0106 /** Misc constants */
0107 /* This section defines 802.11 specific contants */
0108 
0109 #define MRVDRV_MAX_REGION_CODE          6
0110 /**
0111  * the table to keep region code
0112  */
0113 #define LBTF_REGDOMAIN_US   0x10
0114 #define LBTF_REGDOMAIN_CA   0x20
0115 #define LBTF_REGDOMAIN_EU   0x30
0116 #define LBTF_REGDOMAIN_SP   0x31
0117 #define LBTF_REGDOMAIN_FR   0x32
0118 #define LBTF_REGDOMAIN_JP   0x40
0119 
0120 #define SBI_EVENT_CAUSE_SHIFT       3
0121 
0122 /** RxPD status */
0123 
0124 #define MRVDRV_RXPD_STATUS_OK                0x0001
0125 
0126 
0127 /* This is for firmware specific length */
0128 #define EXTRA_LEN   36
0129 
0130 #define MRVDRV_ETH_TX_PACKET_BUFFER_SIZE \
0131     (ETH_FRAME_LEN + sizeof(struct txpd) + EXTRA_LEN)
0132 
0133 #define MRVDRV_ETH_RX_PACKET_BUFFER_SIZE \
0134     (ETH_FRAME_LEN + sizeof(struct rxpd) \
0135      + MRVDRV_SNAP_HEADER_LEN + EXTRA_LEN)
0136 
0137 #define CMD_F_HOSTCMD       (1 << 0)
0138 #define FW_CAPINFO_WPA      (1 << 0)
0139 
0140 #define RF_ANTENNA_1        0x1
0141 #define RF_ANTENNA_2        0x2
0142 #define RF_ANTENNA_AUTO     0xFFFF
0143 
0144 #define LBTF_EVENT_BCN_SENT 55
0145 
0146 /** Global Variable Declaration */
0147 /** mv_ms_type */
0148 enum mv_ms_type {
0149     MVMS_DAT = 0,
0150     MVMS_CMD = 1,
0151     MVMS_TXDONE = 2,
0152     MVMS_EVENT
0153 };
0154 
0155 extern struct workqueue_struct *lbtf_wq;
0156 
0157 struct lbtf_private;
0158 
0159 struct lbtf_offset_value {
0160     u32 offset;
0161     u32 value;
0162 };
0163 
0164 struct channel_range {
0165     u8 regdomain;
0166     u8 start;
0167     u8 end; /* exclusive (channel must be less than end) */
0168 };
0169 
0170 struct if_usb_card;
0171 
0172 struct lbtf_ops {
0173     /** Hardware access */
0174     int (*hw_host_to_card)(struct lbtf_private *priv, u8 type,
0175                    u8 *payload, u16 nb);
0176     int (*hw_prog_firmware)(struct lbtf_private *priv);
0177     int (*hw_reset_device)(struct lbtf_private *priv);
0178 };
0179 
0180 /** Private structure for the MV device */
0181 struct lbtf_private {
0182     void *card;
0183     struct ieee80211_hw *hw;
0184     const struct lbtf_ops *ops;
0185 
0186     /* Command response buffer */
0187     u8 cmd_resp_buff[LBS_UPLD_SIZE];
0188     /* Download sent:
0189        bit0 1/0=data_sent/data_tx_done,
0190        bit1 1/0=cmd_sent/cmd_tx_done,
0191        all other bits reserved 0 */
0192     struct ieee80211_vif *vif;
0193 
0194     struct work_struct cmd_work;
0195     struct work_struct tx_work;
0196 
0197     /** Wlan adapter data structure*/
0198     /** STATUS variables */
0199     u32 fwrelease;
0200     u32 fwcapinfo;
0201     /* protected with big lock */
0202 
0203     struct mutex lock;
0204 
0205     /** command-related variables */
0206     u16 seqnum;
0207     /* protected by big lock */
0208 
0209     struct cmd_ctrl_node *cmd_array;
0210     /** Current command */
0211     struct cmd_ctrl_node *cur_cmd;
0212     /** command Queues */
0213     /** Free command buffers */
0214     struct list_head cmdfreeq;
0215     /** Pending command buffers */
0216     struct list_head cmdpendingq;
0217 
0218     /** spin locks */
0219     spinlock_t driver_lock;
0220 
0221     /** Timers */
0222     struct timer_list command_timer;
0223     int nr_retries;
0224     int cmd_timed_out;
0225 
0226     u8 cmd_response_rxed;
0227 
0228     /** capability Info used in Association, start, join */
0229     u16 capability;
0230 
0231     /** MAC address information */
0232     u8 current_addr[ETH_ALEN];
0233     u8 multicastlist[MRVDRV_MAX_MULTICAST_LIST_SIZE][ETH_ALEN];
0234     u32 nr_of_multicastmacaddr;
0235     int cur_freq;
0236 
0237     struct sk_buff *skb_to_tx;
0238     struct sk_buff *tx_skb;
0239 
0240     /** NIC Operation characteristics */
0241     u16 mac_control;
0242     u16 regioncode;
0243     struct channel_range range;
0244 
0245     u8 radioon;
0246     u32 preamble;
0247 
0248     struct ieee80211_channel channels[14];
0249     struct ieee80211_rate rates[12];
0250     struct ieee80211_supported_band band;
0251     struct lbtf_offset_value offsetvalue;
0252 
0253     u8 surpriseremoved;
0254     struct sk_buff_head bc_ps_buf;
0255 
0256     /* Most recently reported noise in dBm */
0257     s8 noise;
0258 };
0259 
0260 /* 802.11-related definitions */
0261 
0262 /* TxPD descriptor */
0263 struct txpd {
0264     /* Current Tx packet status */
0265     __le32 tx_status;
0266     /* Tx control */
0267     __le32 tx_control;
0268     __le32 tx_packet_location;
0269     /* Tx packet length */
0270     __le16 tx_packet_length;
0271     struct_group_attr(tx_dest_addr, __packed,
0272         /* First 2 byte of destination MAC address */
0273         u8 tx_dest_addr_high[2];
0274         /* Last 4 byte of destination MAC address */
0275         u8 tx_dest_addr_low[4];
0276     );
0277     /* Pkt Priority */
0278     u8 priority;
0279     /* Pkt Trasnit Power control */
0280     u8 powermgmt;
0281     /* Time the packet has been queued in the driver (units = 2ms) */
0282     u8 pktdelay_2ms;
0283     /* reserved */
0284     u8 reserved1;
0285 } __packed;
0286 
0287 /* RxPD Descriptor */
0288 struct rxpd {
0289     /* Current Rx packet status */
0290     __le16 status;
0291 
0292     /* SNR */
0293     u8 snr;
0294 
0295     /* Tx control */
0296     u8 rx_control;
0297 
0298     /* Pkt length */
0299     __le16 pkt_len;
0300 
0301     /* Noise Floor */
0302     u8 nf;
0303 
0304     /* Rx Packet Rate */
0305     u8 rx_rate;
0306 
0307     /* Pkt addr */
0308     __le32 pkt_ptr;
0309 
0310     /* Next Rx RxPD addr */
0311     __le32 next_rxpd_ptr;
0312 
0313     /* Pkt Priority */
0314     u8 priority;
0315     u8 reserved[3];
0316 } __packed;
0317 
0318 struct cmd_header {
0319     __le16 command;
0320     __le16 size;
0321     __le16 seqnum;
0322     __le16 result;
0323 } __packed;
0324 
0325 struct cmd_ctrl_node {
0326     struct list_head list;
0327     int result;
0328     /* command response */
0329     int (*callback)(struct lbtf_private *,
0330             unsigned long, struct cmd_header *);
0331     unsigned long callback_arg;
0332     /* command data */
0333     struct cmd_header *cmdbuf;
0334     /* wait queue */
0335     u16 cmdwaitqwoken;
0336     wait_queue_head_t cmdwait_q;
0337 };
0338 
0339 /*
0340  * Define data structure for CMD_GET_HW_SPEC
0341  * This structure defines the response for the GET_HW_SPEC command
0342  */
0343 struct cmd_ds_get_hw_spec {
0344     struct cmd_header hdr;
0345 
0346     /* HW Interface version number */
0347     __le16 hwifversion;
0348     /* HW version number */
0349     __le16 version;
0350     /* Max number of TxPD FW can handle */
0351     __le16 nr_txpd;
0352     /* Max no of Multicast address */
0353     __le16 nr_mcast_adr;
0354     /* MAC address */
0355     u8 permanentaddr[6];
0356 
0357     /* region Code */
0358     __le16 regioncode;
0359 
0360     /* Number of antenna used */
0361     __le16 nr_antenna;
0362 
0363     /* FW release number, example 0x01030304 = 2.3.4p1 */
0364     __le32 fwrelease;
0365 
0366     /* Base Address of TxPD queue */
0367     __le32 wcb_base;
0368     /* Read Pointer of RxPd queue */
0369     __le32 rxpd_rdptr;
0370 
0371     /* Write Pointer of RxPd queue */
0372     __le32 rxpd_wrptr;
0373 
0374     /*FW/HW capability */
0375     __le32 fwcapinfo;
0376 } __packed;
0377 
0378 struct cmd_ds_mac_control {
0379     struct cmd_header hdr;
0380     __le16 action;
0381     u16 reserved;
0382 } __packed;
0383 
0384 struct cmd_ds_802_11_mac_address {
0385     struct cmd_header hdr;
0386 
0387     __le16 action;
0388     uint8_t macadd[ETH_ALEN];
0389 } __packed;
0390 
0391 struct cmd_ds_mac_multicast_addr {
0392     struct cmd_header hdr;
0393 
0394     __le16 action;
0395     __le16 nr_of_adrs;
0396     u8 maclist[ETH_ALEN * MRVDRV_MAX_MULTICAST_LIST_SIZE];
0397 } __packed;
0398 
0399 struct cmd_ds_set_mode {
0400     struct cmd_header hdr;
0401 
0402     __le16 mode;
0403 } __packed;
0404 
0405 struct cmd_ds_set_bssid {
0406     struct cmd_header hdr;
0407 
0408     u8 bssid[6];
0409     u8 activate;
0410 } __packed;
0411 
0412 struct cmd_ds_802_11_radio_control {
0413     struct cmd_header hdr;
0414 
0415     __le16 action;
0416     __le16 control;
0417 } __packed;
0418 
0419 
0420 struct cmd_ds_802_11_rf_channel {
0421     struct cmd_header hdr;
0422 
0423     __le16 action;
0424     __le16 channel;
0425     __le16 rftype;      /* unused */
0426     __le16 reserved;    /* unused */
0427     u8 channellist[32]; /* unused */
0428 } __packed;
0429 
0430 struct cmd_ds_set_boot2_ver {
0431     struct cmd_header hdr;
0432 
0433     __le16 action;
0434     __le16 version;
0435 } __packed;
0436 
0437 struct cmd_ds_802_11_reset {
0438     struct cmd_header hdr;
0439 
0440     __le16 action;
0441 } __packed;
0442 
0443 struct cmd_ds_802_11_beacon_control {
0444     struct cmd_header hdr;
0445 
0446     __le16 action;
0447     __le16 beacon_enable;
0448     __le16 beacon_period;
0449 } __packed;
0450 
0451 struct cmd_ds_802_11_beacon_set {
0452     struct cmd_header hdr;
0453 
0454     __le16 len;
0455     u8 beacon[MRVL_MAX_BCN_SIZE];
0456 } __packed;
0457 
0458 struct cmd_ctrl_node;
0459 
0460 /** Function Prototype Declaration */
0461 void lbtf_set_mac_control(struct lbtf_private *priv);
0462 
0463 int lbtf_free_cmd_buffer(struct lbtf_private *priv);
0464 
0465 int lbtf_allocate_cmd_buffer(struct lbtf_private *priv);
0466 int lbtf_execute_next_command(struct lbtf_private *priv);
0467 int lbtf_set_radio_control(struct lbtf_private *priv);
0468 int lbtf_update_hw_spec(struct lbtf_private *priv);
0469 int lbtf_cmd_set_mac_multicast_addr(struct lbtf_private *priv);
0470 void lbtf_set_mode(struct lbtf_private *priv, enum lbtf_mode mode);
0471 void lbtf_set_bssid(struct lbtf_private *priv, bool activate, const u8 *bssid);
0472 int lbtf_set_mac_address(struct lbtf_private *priv, uint8_t *mac_addr);
0473 
0474 int lbtf_set_channel(struct lbtf_private *priv, u8 channel);
0475 
0476 int lbtf_beacon_set(struct lbtf_private *priv, struct sk_buff *beacon);
0477 int lbtf_beacon_ctrl(struct lbtf_private *priv, bool beacon_enable,
0478              int beacon_int);
0479 
0480 
0481 int lbtf_process_rx_command(struct lbtf_private *priv);
0482 void lbtf_complete_command(struct lbtf_private *priv, struct cmd_ctrl_node *cmd,
0483               int result);
0484 void lbtf_cmd_response_rx(struct lbtf_private *priv);
0485 
0486 /* main.c */
0487 struct chan_freq_power *lbtf_get_region_cfp_table(u8 region,
0488     int *cfp_no);
0489 struct lbtf_private *lbtf_add_card(void *card, struct device *dmdev,
0490                    const struct lbtf_ops *ops);
0491 int lbtf_remove_card(struct lbtf_private *priv);
0492 int lbtf_start_card(struct lbtf_private *priv);
0493 int lbtf_rx(struct lbtf_private *priv, struct sk_buff *skb);
0494 void lbtf_send_tx_feedback(struct lbtf_private *priv, u8 retrycnt, u8 fail);
0495 void lbtf_bcn_sent(struct lbtf_private *priv);
0496 
0497 /* support functions for cmd.c */
0498 /* lbtf_cmd() infers the size of the buffer to copy data back into, from
0499    the size of the target of the pointer. Since the command to be sent
0500    may often be smaller, that size is set in cmd->size by the caller.*/
0501 #define lbtf_cmd(priv, cmdnr, cmd, cb, cb_arg)  ({      \
0502     uint16_t __sz = le16_to_cpu((cmd)->hdr.size);       \
0503     (cmd)->hdr.size = cpu_to_le16(sizeof(*(cmd)));      \
0504     __lbtf_cmd(priv, cmdnr, &(cmd)->hdr, __sz, cb, cb_arg); \
0505 })
0506 
0507 #define lbtf_cmd_with_response(priv, cmdnr, cmd)    \
0508     lbtf_cmd(priv, cmdnr, cmd, lbtf_cmd_copyback, (unsigned long) (cmd))
0509 
0510 void lbtf_cmd_async(struct lbtf_private *priv, uint16_t command,
0511     struct cmd_header *in_cmd, int in_cmd_size);
0512 
0513 int __lbtf_cmd(struct lbtf_private *priv, uint16_t command,
0514           struct cmd_header *in_cmd, int in_cmd_size,
0515           int (*callback)(struct lbtf_private *, unsigned long,
0516                   struct cmd_header *),
0517           unsigned long callback_arg);
0518 
0519 int lbtf_cmd_copyback(struct lbtf_private *priv, unsigned long extra,
0520              struct cmd_header *resp);