blob: 3a10940db9b7da54cd8730ce62da06c7c24631b8 [file] [log] [blame]
Larry Finger2865d422010-08-20 10:15:30 -05001/******************************************************************************
2 * rtl871x_io.c
3 *
4 * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
5 * Linux device driver for RTL8192SU
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 *
20 * Modifications for inclusion into the Linux staging tree are
21 * Copyright(c) 2010 Larry Finger. All rights reserved.
22 *
23 * Contact information:
24 * WLAN FAE <wlanfae@realtek.com>
25 * Larry Finger <Larry.Finger@lwfinger.net>
26 *
27 ******************************************************************************/
28/*
29 *
30 * The purpose of rtl871x_io.c
31 *
32 * a. provides the API
33 * b. provides the protocol engine
34 * c. provides the software interface between caller and the hardware interface
35 *
36 * For r8712u, both sync/async operations are provided.
37 *
38 * Only sync read/write_mem operations are provided.
39 *
40 */
41
42#define _RTL871X_IO_C_
43
44#include "osdep_service.h"
45#include "drv_types.h"
46#include "rtl871x_io.h"
47#include "osdep_intf.h"
48#include "usb_ops.h"
49
50static uint _init_intf_hdl(struct _adapter *padapter,
51 struct intf_hdl *pintf_hdl)
52{
53 struct intf_priv *pintf_priv;
54 void (*set_intf_option)(u32 *poption) = NULL;
55 void (*set_intf_funs)(struct intf_hdl *pintf_hdl);
56 void (*set_intf_ops)(struct _io_ops *pops);
57 uint (*init_intf_priv)(struct intf_priv *pintfpriv);
58
59 set_intf_option = &(r8712_usb_set_intf_option);
60 set_intf_funs = &(r8712_usb_set_intf_funs);
61 set_intf_ops = &r8712_usb_set_intf_ops;
62 init_intf_priv = &r8712_usb_init_intf_priv;
Vitaly Osipov91d435f2014-05-24 18:19:27 +100063 pintf_priv = pintf_hdl->pintfpriv = kmalloc(sizeof(struct intf_priv),
64 GFP_ATOMIC);
Larry Finger2865d422010-08-20 10:15:30 -050065 if (pintf_priv == NULL)
66 goto _init_intf_hdl_fail;
67 pintf_hdl->adapter = (u8 *)padapter;
68 set_intf_option(&pintf_hdl->intf_option);
69 set_intf_funs(pintf_hdl);
70 set_intf_ops(&pintf_hdl->io_ops);
71 pintf_priv->intf_dev = (u8 *)&(padapter->dvobjpriv);
72 if (init_intf_priv(pintf_priv) == _FAIL)
73 goto _init_intf_hdl_fail;
74 return _SUCCESS;
75_init_intf_hdl_fail:
Alexander Beregalov40083862011-03-26 20:18:14 +030076 kfree(pintf_priv);
Larry Finger2865d422010-08-20 10:15:30 -050077 return _FAIL;
78}
79
80static void _unload_intf_hdl(struct intf_priv *pintfpriv)
81{
82 void (*unload_intf_priv)(struct intf_priv *pintfpriv);
83
84 unload_intf_priv = &r8712_usb_unload_intf_priv;
85 unload_intf_priv(pintfpriv);
Alexander Beregalov40083862011-03-26 20:18:14 +030086 kfree(pintfpriv);
Larry Finger2865d422010-08-20 10:15:30 -050087}
88
89static uint register_intf_hdl(u8 *dev, struct intf_hdl *pintfhdl)
90{
91 struct _adapter *adapter = (struct _adapter *)dev;
92
93 pintfhdl->intf_option = 0;
94 pintfhdl->adapter = dev;
95 pintfhdl->intf_dev = (u8 *)&(adapter->dvobjpriv);
Tapasweni Pathak366ba422014-10-06 14:23:18 +053096 if (!_init_intf_hdl(adapter, pintfhdl))
Larry Finger2865d422010-08-20 10:15:30 -050097 goto register_intf_hdl_fail;
98 return _SUCCESS;
99register_intf_hdl_fail:
100 return false;
101}
102
103static void unregister_intf_hdl(struct intf_hdl *pintfhdl)
104{
105 _unload_intf_hdl(pintfhdl->pintfpriv);
106 memset((u8 *)pintfhdl, 0, sizeof(struct intf_hdl));
107}
108
109uint r8712_alloc_io_queue(struct _adapter *adapter)
110{
111 u32 i;
112 struct io_queue *pio_queue;
113 struct io_req *pio_req;
114
Vitaly Osipovbd9dc622014-06-14 21:47:21 +1000115 pio_queue = kmalloc(sizeof(*pio_queue), GFP_ATOMIC);
Bhumika Goyal9155c922016-02-24 16:09:31 +0530116 if (!pio_queue)
Larry Finger2865d422010-08-20 10:15:30 -0500117 goto alloc_io_queue_fail;
James A Shackleford534c4ac2014-06-24 22:52:34 -0400118 INIT_LIST_HEAD(&pio_queue->free_ioreqs);
119 INIT_LIST_HEAD(&pio_queue->processing);
120 INIT_LIST_HEAD(&pio_queue->pending);
Larry Finger2865d422010-08-20 10:15:30 -0500121 spin_lock_init(&pio_queue->lock);
Vitaly Osipov91d435f2014-05-24 18:19:27 +1000122 pio_queue->pallocated_free_ioreqs_buf = kmalloc(NUM_IOREQ *
Tapasweni Pathak57b66862014-09-21 06:42:21 +0530123 (sizeof(struct io_req)) + 4,
124 GFP_ATOMIC);
Larry Finger2865d422010-08-20 10:15:30 -0500125 if ((pio_queue->pallocated_free_ioreqs_buf) == NULL)
126 goto alloc_io_queue_fail;
127 memset(pio_queue->pallocated_free_ioreqs_buf, 0,
128 (NUM_IOREQ * (sizeof(struct io_req)) + 4));
129 pio_queue->free_ioreqs_buf = pio_queue->pallocated_free_ioreqs_buf + 4
130 - ((addr_t)(pio_queue->pallocated_free_ioreqs_buf)
131 & 3);
132 pio_req = (struct io_req *)(pio_queue->free_ioreqs_buf);
133 for (i = 0; i < NUM_IOREQ; i++) {
James A Shackleford534c4ac2014-06-24 22:52:34 -0400134 INIT_LIST_HEAD(&pio_req->list);
James A Shacklefordfdfbf782014-06-24 22:52:36 -0400135 list_add_tail(&pio_req->list, &pio_queue->free_ioreqs);
Larry Finger2865d422010-08-20 10:15:30 -0500136 pio_req++;
137 }
138 if ((register_intf_hdl((u8 *)adapter, &(pio_queue->intf))) == _FAIL)
139 goto alloc_io_queue_fail;
140 adapter->pio_queue = pio_queue;
141 return _SUCCESS;
142alloc_io_queue_fail:
143 if (pio_queue) {
144 kfree(pio_queue->pallocated_free_ioreqs_buf);
Tapasweni Pathak646da832014-10-08 20:41:26 +0530145 kfree(pio_queue);
Larry Finger2865d422010-08-20 10:15:30 -0500146 }
147 adapter->pio_queue = NULL;
148 return _FAIL;
149}
150
151void r8712_free_io_queue(struct _adapter *adapter)
152{
Shivani Bhardwaj0b2ea2c2015-10-14 19:14:59 +0530153 struct io_queue *pio_queue = adapter->pio_queue;
Larry Finger2865d422010-08-20 10:15:30 -0500154
155 if (pio_queue) {
156 kfree(pio_queue->pallocated_free_ioreqs_buf);
157 adapter->pio_queue = NULL;
158 unregister_intf_hdl(&pio_queue->intf);
Tapasweni Pathak646da832014-10-08 20:41:26 +0530159 kfree(pio_queue);
Larry Finger2865d422010-08-20 10:15:30 -0500160 }
161}