// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
* All rights reserved.
*
* File: main_usb.c
*
* Purpose: driver entry for initial, open, close, tx and rx.
*
* Author: Lyndon Chen
*
* Date: Dec 8, 2005
*
* Functions:
*
* vt6656_probe - module initial (insmod) driver entry
* vnt_free_tx_bufs - free tx buffer function
* vnt_init_registers- initial MAC & BBP & RF internal registers.
*
* Revision History:
*/
#undef __NO_VERSION__
#include <linux/bits.h>
#include <linux/etherdevice.h>
#include <linux/file.h>
#include <linux/kernel.h>
#include "device.h"
#include "card.h"
#include "baseband.h"
#include "mac.h"
#include "power.h"
#include "wcmd.h"
#include "rxtx.h"
#include "rf.h"
#include "usbpipe.h"
#include "channel.h"
/*
* define module options
*/
/* version information */
#define DRIVER_AUTHOR \
"VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>"
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM);
#define RX_DESC_DEF0 64
static int vnt_rx_buffers = RX_DESC_DEF0;
module_param_named(rx_buffers, vnt_rx_buffers, int, 0644);
MODULE_PARM_DESC(rx_buffers, "Number of receive usb rx buffers");
#define TX_DESC_DEF0 64
static int vnt_tx_buffers = TX_DESC_DEF0;
module_param_named(tx_buffers, vnt_tx_buffers, int, 0644);
MODULE_PARM_DESC(tx_buffers, "Number of receive usb tx buffers");
#define RTS_THRESH_DEF 2347
#define FRAG_THRESH_DEF 2346
/* BasebandType[] baseband type selected
* 0: indicate 802.11a type
* 1: indicate 802.11b type
* 2: indicate 802.11g type
*/
#define BBP_TYPE_DEF 2
/*
* Static vars definitions
*/
static const struct usb_device_id vt6656_table[] = {
{USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)},
{}
};
static void vnt_set_options(struct vnt_private *priv)
{
/* Set number of TX buffers */
if (vnt_tx_buffers < CB_MIN_TX_DESC || vnt_tx_buffers > CB_MAX_TX_DESC)
priv->num_tx_context = TX_DESC_DEF0;
else
priv->num_tx_context = vnt_tx_buffers;
/* Set number of RX buffers */
if (vnt_rx_buffers < CB_MIN_RX_DESC || vnt_rx_buffers > CB_MAX_RX_DESC)
priv->num_rcb = RX_DESC_DEF0;
else
priv->num_rcb = vnt_rx_buffers;
priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
priv->bb_type = BBP_TYPE_DEF;
priv->packet_type = priv->bb_type;
priv->preamble_type = PREAMBLE_LONG;
priv->exist_sw_net_addr = false;
}
static int vnt_download_firmware(struct vnt_private *priv)
{
struct device *dev = &priv->usb->dev;
const struct firmware *fw;
u16 length;
int ii;
int ret = 0;
dev_dbg(dev, "---->Download firmware\n");
ret = request_firmware(&fw, FIRMWARE_NAME, dev);
if (ret) {
dev_err(dev, "firmware file %s request failed (%d)\n",
FIRMWARE_NAME, ret);
goto end;
}
for (ii = 0; ii < fw->size; ii += FIRMWARE_CHUNK_SIZE) {
length = min_t(int, fw->size - ii, FIRMWARE_CHUNK_SIZE);
ret = vnt_control_out(priv, 0, 0x1200 + ii, 0x0000, length,
fw->data + ii);
if (ret)
goto free_fw;
dev_dbg(dev, "Download firmware...%d %zu\n", ii, fw->size);
}
free_fw:
release_firmware(fw);
end:
return ret;
}
static int vnt_firmware_branch_to_sram(struct vnt_private *priv)
{
dev_dbg(&priv->usb->dev, "---->Branch to Sram\n");
return vnt_control_out(priv, 1, 0x1200, 0x0000, 0, NULL);
}
static int vnt_check_firmware_version(struct vnt_private *priv)
{
int ret = 0;
ret = vnt_control_in(priv