2 * Copyright (c) 2014 Redpine Signals Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <linux/firmware.h>
22 * rsi_copy_to_card() - This function includes the actual funtionality of
23 * copying the TA firmware to the card.Basically this
24 * function includes opening the TA file,reading the TA
25 * file and writing their values in blocks of data.
26 * @common: Pointer to the driver private structure.
27 * @fw: Pointer to the firmware value to be written.
28 * @len: length of firmware file.
29 * @num_blocks: Number of blocks to be written to the card.
31 * Return: 0 on success and -1 on failure.
33 static int rsi_copy_to_card(struct rsi_common
*common
,
38 struct rsi_hw
*adapter
= common
->priv
;
39 struct rsi_91x_usbdev
*dev
= (struct rsi_91x_usbdev
*)adapter
->rsi_dev
;
41 u32 block_size
= dev
->tx_blk_size
;
45 base_address
= TA_LOAD_ADDRESS
;
47 for (indx
= 0, ii
= 0; ii
< num_blocks
; ii
++, indx
+= block_size
) {
48 lsb_address
= base_address
;
49 if (rsi_usb_write_register_multiple(adapter
,
54 "%s: Unable to load %s blk\n", __func__
,
58 rsi_dbg(INIT_ZONE
, "%s: loading block: %d\n", __func__
, ii
);
59 base_address
+= block_size
;
62 if (len
% block_size
) {
63 lsb_address
= base_address
;
64 if (rsi_usb_write_register_multiple(adapter
,
69 "%s: Unable to load %s blk\n", __func__
,
75 "%s: Succesfully loaded %s instructions\n", __func__
,
78 rsi_dbg(INIT_ZONE
, "%s: loaded firmware\n", __func__
);
83 * rsi_usb_rx_thread() - This is a kernel thread to receive the packets from
85 * @common: Pointer to the driver private structure.
89 void rsi_usb_rx_thread(struct rsi_common
*common
)
91 struct rsi_hw
*adapter
= common
->priv
;
92 struct rsi_91x_usbdev
*dev
= (struct rsi_91x_usbdev
*)adapter
->rsi_dev
;
96 rsi_wait_event(&dev
->rx_thread
.event
, EVENT_WAIT_FOREVER
);
98 if (atomic_read(&dev
->rx_thread
.thread_done
))
101 mutex_lock(&common
->tx_rxlock
);
102 status
= rsi_read_pkt(common
, 0);
104 rsi_dbg(ERR_ZONE
, "%s: Failed To read data", __func__
);
105 mutex_unlock(&common
->tx_rxlock
);
108 mutex_unlock(&common
->tx_rxlock
);
109 rsi_reset_event(&dev
->rx_thread
.event
);
110 if (adapter
->rx_urb_submit(adapter
)) {
112 "%s: Failed in urb submission", __func__
);
118 rsi_dbg(INFO_ZONE
, "%s: Terminated thread\n", __func__
);
119 complete_and_exit(&dev
->rx_thread
.completion
, 0);
124 * rsi_load_ta_instructions() - This function includes the actual funtionality
125 * of loading the TA firmware.This function also
126 * includes opening the TA file,reading the TA
127 * file and writing their value in blocks of data.
128 * @common: Pointer to the driver private structure.
130 * Return: status: 0 on success, -1 on failure.
132 static int rsi_load_ta_instructions(struct rsi_common
*common
)
134 struct rsi_hw
*adapter
= common
->priv
;
135 struct rsi_91x_usbdev
*dev
= (struct rsi_91x_usbdev
*)adapter
->rsi_dev
;
136 const struct firmware
*fw_entry
= NULL
;
137 u32 block_size
= dev
->tx_blk_size
;
142 status
= request_firmware(&fw_entry
, FIRMWARE_RSI9113
, adapter
->device
);
144 rsi_dbg(ERR_ZONE
, "%s Firmware file %s not found\n",
145 __func__
, FIRMWARE_RSI9113
);
149 fw
= kmemdup(fw_entry
->data
, fw_entry
->size
, GFP_KERNEL
);
150 len
= fw_entry
->size
;
153 len
+= (4 - (len
% 4));
155 num_blocks
= (len
/ block_size
);
157 rsi_dbg(INIT_ZONE
, "%s: Instruction size:%d\n", __func__
, len
);
158 rsi_dbg(INIT_ZONE
, "%s: num blocks: %d\n", __func__
, num_blocks
);
160 status
= rsi_copy_to_card(common
, fw
, len
, num_blocks
);
161 release_firmware(fw_entry
);
166 * rsi_device_init() - This Function Initializes The HAL.
167 * @common: Pointer to the driver private structure.
169 * Return: 0 on success, -1 on failure.
171 int rsi_usb_device_init(struct rsi_common
*common
)
173 if (rsi_load_ta_instructions(common
))