2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
18 * Purpose: Handle USB control endpoint
25 * vnt_control_out - Write variable length bytes to MEM/BB/MAC/EEPROM
26 * vnt_control_in - Read variable length bytes from MEM/BB/MAC/EEPROM
27 * vnt_control_out_u8 - Write one byte to MEM/BB/MAC/EEPROM
28 * vnt_control_in_u8 - Read one byte from MEM/BB/MAC/EEPROM
31 * 04-05-2004 Jerry Chen: Initial release
32 * 11-24-2004 Warren Hsu: Add ControlvWriteByte,ControlvReadByte,
44 #define USB_CTL_WAIT 500 /* ms */
46 int vnt_control_out(struct vnt_private
*priv
, u8 request
, u16 value
,
47 u16 index
, u16 length
, u8
*buffer
)
52 if (test_bit(DEVICE_FLAGS_DISCONNECTED
, &priv
->flags
))
53 return STATUS_FAILURE
;
55 mutex_lock(&priv
->usb_lock
);
57 usb_buffer
= kmemdup(buffer
, length
, GFP_KERNEL
);
59 mutex_unlock(&priv
->usb_lock
);
63 status
= usb_control_msg(priv
->usb
,
64 usb_sndctrlpipe(priv
->usb
, 0),
66 index
, usb_buffer
, length
, USB_CTL_WAIT
);
70 mutex_unlock(&priv
->usb_lock
);
72 if (status
< (int)length
)
73 return STATUS_FAILURE
;
75 return STATUS_SUCCESS
;
78 void vnt_control_out_u8(struct vnt_private
*priv
, u8 reg
, u8 reg_off
, u8 data
)
80 vnt_control_out(priv
, MESSAGE_TYPE_WRITE
,
81 reg_off
, reg
, sizeof(u8
), &data
);
84 int vnt_control_in(struct vnt_private
*priv
, u8 request
, u16 value
,
85 u16 index
, u16 length
, u8
*buffer
)
90 if (test_bit(DEVICE_FLAGS_DISCONNECTED
, &priv
->flags
))
91 return STATUS_FAILURE
;
93 mutex_lock(&priv
->usb_lock
);
95 usb_buffer
= kmalloc(length
, GFP_KERNEL
);
97 mutex_unlock(&priv
->usb_lock
);
101 status
= usb_control_msg(priv
->usb
,
102 usb_rcvctrlpipe(priv
->usb
, 0),
103 request
, 0xc0, value
,
104 index
, usb_buffer
, length
, USB_CTL_WAIT
);
106 if (status
== length
)
107 memcpy(buffer
, usb_buffer
, length
);
111 mutex_unlock(&priv
->usb_lock
);
113 if (status
< (int)length
)
114 return STATUS_FAILURE
;
116 return STATUS_SUCCESS
;
119 void vnt_control_in_u8(struct vnt_private
*priv
, u8 reg
, u8 reg_off
, u8
*data
)
121 vnt_control_in(priv
, MESSAGE_TYPE_READ
,
122 reg_off
, reg
, sizeof(u8
), data
);
125 static void vnt_start_interrupt_urb_complete(struct urb
*urb
)
127 struct vnt_private
*priv
= urb
->context
;
128 int status
= urb
->status
;
137 priv
->int_buf
.in_use
= false;
144 priv
->int_buf
.in_use
= false;
146 dev_dbg(&priv
->usb
->dev
, "%s status = %d\n", __func__
, status
);
148 vnt_int_process_data(priv
);
151 status
= usb_submit_urb(priv
->interrupt_urb
, GFP_ATOMIC
);
153 dev_dbg(&priv
->usb
->dev
, "Submit int URB failed %d\n", status
);
155 priv
->int_buf
.in_use
= true;
158 int vnt_start_interrupt_urb(struct vnt_private
*priv
)
160 int status
= STATUS_FAILURE
;
162 if (priv
->int_buf
.in_use
)
163 return STATUS_FAILURE
;
165 priv
->int_buf
.in_use
= true;
167 usb_fill_int_urb(priv
->interrupt_urb
,
169 usb_rcvintpipe(priv
->usb
, 1),
170 priv
->int_buf
.data_buf
,
172 vnt_start_interrupt_urb_complete
,
176 status
= usb_submit_urb(priv
->interrupt_urb
, GFP_ATOMIC
);
178 dev_dbg(&priv
->usb
->dev
, "Submit int URB failed %d\n", status
);
179 priv
->int_buf
.in_use
= false;
185 static void vnt_submit_rx_urb_complete(struct urb
*urb
)
187 struct vnt_rcb
*rcb
= urb
->context
;
188 struct vnt_private
*priv
= rcb
->priv
;
190 switch (urb
->status
) {
199 dev_dbg(&priv
->usb
->dev
, "BULK In failed %d\n", urb
->status
);
203 if (urb
->actual_length
) {
204 if (vnt_rx_data(priv
, rcb
, urb
->actual_length
)) {
205 rcb
->skb
= dev_alloc_skb(priv
->rx_buf_sz
);
207 dev_dbg(&priv
->usb
->dev
,
208 "Failed to re-alloc rx skb\n");
214 skb_push(rcb
->skb
, skb_headroom(rcb
->skb
));
215 skb_trim(rcb
->skb
, 0);
218 urb
->transfer_buffer
= skb_put(rcb
->skb
,
219 skb_tailroom(rcb
->skb
));
222 if (usb_submit_urb(urb
, GFP_ATOMIC
)) {
223 dev_dbg(&priv
->usb
->dev
, "Failed to re submit rx skb\n");
229 int vnt_submit_rx_urb(struct vnt_private
*priv
, struct vnt_rcb
*rcb
)
232 struct urb
*urb
= rcb
->urb
;
235 dev_dbg(&priv
->usb
->dev
, "rcb->skb is null\n");
239 usb_fill_bulk_urb(urb
,
241 usb_rcvbulkpipe(priv
->usb
, 2),
242 skb_put(rcb
->skb
, skb_tailroom(rcb
->skb
)),
243 MAX_TOTAL_SIZE_WITH_ALL_HEADERS
,
244 vnt_submit_rx_urb_complete
,
247 status
= usb_submit_urb(urb
, GFP_ATOMIC
);
249 dev_dbg(&priv
->usb
->dev
, "Submit Rx URB failed %d\n", status
);
250 return STATUS_FAILURE
;
258 static void vnt_tx_context_complete(struct urb
*urb
)
260 struct vnt_usb_send_context
*context
= urb
->context
;
261 struct vnt_private
*priv
= context
->priv
;
263 switch (urb
->status
) {
265 dev_dbg(&priv
->usb
->dev
, "Write %d bytes\n", context
->buf_len
);
270 context
->in_use
= false;
274 dev_dbg(&priv
->usb
->dev
, "BULK Out failed %d\n", urb
->status
);
278 if (context
->type
== CONTEXT_DATA_PACKET
)
279 ieee80211_wake_queues(priv
->hw
);
281 if (urb
->status
|| context
->type
== CONTEXT_BEACON_PACKET
) {
283 ieee80211_free_txskb(priv
->hw
, context
->skb
);
285 context
->in_use
= false;
289 int vnt_tx_context(struct vnt_private
*priv
,
290 struct vnt_usb_send_context
*context
)
293 struct urb
*urb
= context
->urb
;
295 if (test_bit(DEVICE_FLAGS_DISCONNECTED
, &priv
->flags
)) {
296 context
->in_use
= false;
297 return STATUS_RESOURCES
;
300 usb_fill_bulk_urb(urb
,
302 usb_sndbulkpipe(priv
->usb
, 3),
305 vnt_tx_context_complete
,
308 status
= usb_submit_urb(urb
, GFP_ATOMIC
);
310 dev_dbg(&priv
->usb
->dev
, "Submit Tx URB failed %d\n", status
);
312 context
->in_use
= false;
313 return STATUS_FAILURE
;
316 return STATUS_PENDING
;