Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2007-2011 Atheros Communications Inc.
0003  * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
0004  *
0005  * Permission to use, copy, modify, and/or distribute this software for any
0006  * purpose with or without fee is hereby granted, provided that the above
0007  * copyright notice and this permission notice appear in all copies.
0008  *
0009  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
0010  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
0011  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
0012  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
0013  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
0014  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
0015  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0016  */
0017 
0018 #include <linux/module.h>
0019 #include <linux/usb.h>
0020 
0021 #include "debug.h"
0022 #include "core.h"
0023 
0024 /* constants */
0025 #define TX_URB_COUNT            32
0026 #define RX_URB_COUNT            32
0027 #define ATH6KL_USB_RX_BUFFER_SIZE  4096
0028 
0029 /* tx/rx pipes for usb */
0030 enum ATH6KL_USB_PIPE_ID {
0031     ATH6KL_USB_PIPE_TX_CTRL = 0,
0032     ATH6KL_USB_PIPE_TX_DATA_LP,
0033     ATH6KL_USB_PIPE_TX_DATA_MP,
0034     ATH6KL_USB_PIPE_TX_DATA_HP,
0035     ATH6KL_USB_PIPE_RX_CTRL,
0036     ATH6KL_USB_PIPE_RX_DATA,
0037     ATH6KL_USB_PIPE_RX_DATA2,
0038     ATH6KL_USB_PIPE_RX_INT,
0039     ATH6KL_USB_PIPE_MAX
0040 };
0041 
0042 #define ATH6KL_USB_PIPE_INVALID ATH6KL_USB_PIPE_MAX
0043 
0044 struct ath6kl_usb_pipe {
0045     struct list_head urb_list_head;
0046     struct usb_anchor urb_submitted;
0047     u32 urb_alloc;
0048     u32 urb_cnt;
0049     u32 urb_cnt_thresh;
0050     unsigned int usb_pipe_handle;
0051     u32 flags;
0052     u8 ep_address;
0053     u8 logical_pipe_num;
0054     struct ath6kl_usb *ar_usb;
0055     u16 max_packet_size;
0056     struct work_struct io_complete_work;
0057     struct sk_buff_head io_comp_queue;
0058     struct usb_endpoint_descriptor *ep_desc;
0059 };
0060 
0061 #define ATH6KL_USB_PIPE_FLAG_TX    (1 << 0)
0062 
0063 /* usb device object */
0064 struct ath6kl_usb {
0065     /* protects pipe->urb_list_head and  pipe->urb_cnt */
0066     spinlock_t cs_lock;
0067 
0068     struct usb_device *udev;
0069     struct usb_interface *interface;
0070     struct ath6kl_usb_pipe pipes[ATH6KL_USB_PIPE_MAX];
0071     u8 *diag_cmd_buffer;
0072     u8 *diag_resp_buffer;
0073     struct ath6kl *ar;
0074     struct workqueue_struct *wq;
0075 };
0076 
0077 /* usb urb object */
0078 struct ath6kl_urb_context {
0079     struct list_head link;
0080     struct ath6kl_usb_pipe *pipe;
0081     struct sk_buff *skb;
0082     struct ath6kl *ar;
0083 };
0084 
0085 /* USB endpoint definitions */
0086 #define ATH6KL_USB_EP_ADDR_APP_CTRL_IN          0x81
0087 #define ATH6KL_USB_EP_ADDR_APP_DATA_IN          0x82
0088 #define ATH6KL_USB_EP_ADDR_APP_DATA2_IN         0x83
0089 #define ATH6KL_USB_EP_ADDR_APP_INT_IN           0x84
0090 
0091 #define ATH6KL_USB_EP_ADDR_APP_CTRL_OUT         0x01
0092 #define ATH6KL_USB_EP_ADDR_APP_DATA_LP_OUT      0x02
0093 #define ATH6KL_USB_EP_ADDR_APP_DATA_MP_OUT      0x03
0094 #define ATH6KL_USB_EP_ADDR_APP_DATA_HP_OUT      0x04
0095 
0096 /* diagnostic command defnitions */
0097 #define ATH6KL_USB_CONTROL_REQ_SEND_BMI_CMD        1
0098 #define ATH6KL_USB_CONTROL_REQ_RECV_BMI_RESP       2
0099 #define ATH6KL_USB_CONTROL_REQ_DIAG_CMD            3
0100 #define ATH6KL_USB_CONTROL_REQ_DIAG_RESP           4
0101 
0102 #define ATH6KL_USB_CTRL_DIAG_CC_READ               0
0103 #define ATH6KL_USB_CTRL_DIAG_CC_WRITE              1
0104 
0105 struct ath6kl_usb_ctrl_diag_cmd_write {
0106     __le32 cmd;
0107     __le32 address;
0108     __le32 value;
0109     __le32 _pad[1];
0110 } __packed;
0111 
0112 struct ath6kl_usb_ctrl_diag_cmd_read {
0113     __le32 cmd;
0114     __le32 address;
0115 } __packed;
0116 
0117 struct ath6kl_usb_ctrl_diag_resp_read {
0118     __le32 value;
0119 } __packed;
0120 
0121 /* function declarations */
0122 static void ath6kl_usb_recv_complete(struct urb *urb);
0123 
0124 #define ATH6KL_USB_IS_BULK_EP(attr) (((attr) & 3) == 0x02)
0125 #define ATH6KL_USB_IS_INT_EP(attr)  (((attr) & 3) == 0x03)
0126 #define ATH6KL_USB_IS_ISOC_EP(attr)  (((attr) & 3) == 0x01)
0127 #define ATH6KL_USB_IS_DIR_IN(addr)  ((addr) & 0x80)
0128 
0129 /* pipe/urb operations */
0130 static struct ath6kl_urb_context *
0131 ath6kl_usb_alloc_urb_from_pipe(struct ath6kl_usb_pipe *pipe)
0132 {
0133     struct ath6kl_urb_context *urb_context = NULL;
0134     unsigned long flags;
0135 
0136     /* bail if this pipe is not initialized */
0137     if (!pipe->ar_usb)
0138         return NULL;
0139 
0140     spin_lock_irqsave(&pipe->ar_usb->cs_lock, flags);
0141     if (!list_empty(&pipe->urb_list_head)) {
0142         urb_context =
0143             list_first_entry(&pipe->urb_list_head,
0144                      struct ath6kl_urb_context, link);
0145         list_del(&urb_context->link);
0146         pipe->urb_cnt--;
0147     }
0148     spin_unlock_irqrestore(&pipe->ar_usb->cs_lock, flags);
0149 
0150     return urb_context;
0151 }
0152 
0153 static void ath6kl_usb_free_urb_to_pipe(struct ath6kl_usb_pipe *pipe,
0154                     struct ath6kl_urb_context *urb_context)
0155 {
0156     unsigned long flags;
0157 
0158     /* bail if this pipe is not initialized */
0159     if (!pipe->ar_usb)
0160         return;
0161 
0162     spin_lock_irqsave(&pipe->ar_usb->cs_lock, flags);
0163     pipe->urb_cnt++;
0164 
0165     list_add(&urb_context->link, &pipe->urb_list_head);
0166     spin_unlock_irqrestore(&pipe->ar_usb->cs_lock, flags);
0167 }
0168 
0169 static void ath6kl_usb_cleanup_recv_urb(struct ath6kl_urb_context *urb_context)
0170 {
0171     dev_kfree_skb(urb_context->skb);
0172     urb_context->skb = NULL;
0173 
0174     ath6kl_usb_free_urb_to_pipe(urb_context->pipe, urb_context);
0175 }
0176 
0177 static inline struct ath6kl_usb *ath6kl_usb_priv(struct ath6kl *ar)
0178 {
0179     return ar->hif_priv;
0180 }
0181 
0182 /* pipe resource allocation/cleanup */
0183 static int ath6kl_usb_alloc_pipe_resources(struct ath6kl_usb_pipe *pipe,
0184                        int urb_cnt)
0185 {
0186     struct ath6kl_urb_context *urb_context;
0187     int status = 0, i;
0188 
0189     INIT_LIST_HEAD(&pipe->urb_list_head);
0190     init_usb_anchor(&pipe->urb_submitted);
0191 
0192     for (i = 0; i < urb_cnt; i++) {
0193         urb_context = kzalloc(sizeof(struct ath6kl_urb_context),
0194                       GFP_KERNEL);
0195         if (urb_context == NULL) {
0196             status = -ENOMEM;
0197             goto fail_alloc_pipe_resources;
0198         }
0199 
0200         urb_context->pipe = pipe;
0201 
0202         /*
0203          * we are only allocate the urb contexts here, the actual URB
0204          * is allocated from the kernel as needed to do a transaction
0205          */
0206         pipe->urb_alloc++;
0207         ath6kl_usb_free_urb_to_pipe(pipe, urb_context);
0208     }
0209 
0210     ath6kl_dbg(ATH6KL_DBG_USB,
0211            "ath6kl usb: alloc resources lpipe:%d hpipe:0x%X urbs:%d\n",
0212            pipe->logical_pipe_num, pipe->usb_pipe_handle,
0213            pipe->urb_alloc);
0214 
0215 fail_alloc_pipe_resources:
0216     return status;
0217 }
0218 
0219 static void ath6kl_usb_free_pipe_resources(struct ath6kl_usb_pipe *pipe)
0220 {
0221     struct ath6kl_urb_context *urb_context;
0222 
0223     if (pipe->ar_usb == NULL) {
0224         /* nothing allocated for this pipe */
0225         return;
0226     }
0227 
0228     ath6kl_dbg(ATH6KL_DBG_USB,
0229            "ath6kl usb: free resources lpipe:%d"
0230            "hpipe:0x%X urbs:%d avail:%d\n",
0231            pipe->logical_pipe_num, pipe->usb_pipe_handle,
0232            pipe->urb_alloc, pipe->urb_cnt);
0233 
0234     if (pipe->urb_alloc != pipe->urb_cnt) {
0235         ath6kl_dbg(ATH6KL_DBG_USB,
0236                "ath6kl usb: urb leak! lpipe:%d"
0237                "hpipe:0x%X urbs:%d avail:%d\n",
0238                pipe->logical_pipe_num, pipe->usb_pipe_handle,
0239                pipe->urb_alloc, pipe->urb_cnt);
0240     }
0241 
0242     while (true) {
0243         urb_context = ath6kl_usb_alloc_urb_from_pipe(pipe);
0244         if (urb_context == NULL)
0245             break;
0246         kfree(urb_context);
0247     }
0248 }
0249 
0250 static void ath6kl_usb_cleanup_pipe_resources(struct ath6kl_usb *ar_usb)
0251 {
0252     int i;
0253 
0254     for (i = 0; i < ATH6KL_USB_PIPE_MAX; i++)
0255         ath6kl_usb_free_pipe_resources(&ar_usb->pipes[i]);
0256 }
0257 
0258 static u8 ath6kl_usb_get_logical_pipe_num(struct ath6kl_usb *ar_usb,
0259                       u8 ep_address, int *urb_count)
0260 {
0261     u8 pipe_num = ATH6KL_USB_PIPE_INVALID;
0262 
0263     switch (ep_address) {
0264     case ATH6KL_USB_EP_ADDR_APP_CTRL_IN:
0265         pipe_num = ATH6KL_USB_PIPE_RX_CTRL;
0266         *urb_count = RX_URB_COUNT;
0267         break;
0268     case ATH6KL_USB_EP_ADDR_APP_DATA_IN:
0269         pipe_num = ATH6KL_USB_PIPE_RX_DATA;
0270         *urb_count = RX_URB_COUNT;
0271         break;
0272     case ATH6KL_USB_EP_ADDR_APP_INT_IN:
0273         pipe_num = ATH6KL_USB_PIPE_RX_INT;
0274         *urb_count = RX_URB_COUNT;
0275         break;
0276     case ATH6KL_USB_EP_ADDR_APP_DATA2_IN:
0277         pipe_num = ATH6KL_USB_PIPE_RX_DATA2;
0278         *urb_count = RX_URB_COUNT;
0279         break;
0280     case ATH6KL_USB_EP_ADDR_APP_CTRL_OUT:
0281         pipe_num = ATH6KL_USB_PIPE_TX_CTRL;
0282         *urb_count = TX_URB_COUNT;
0283         break;
0284     case ATH6KL_USB_EP_ADDR_APP_DATA_LP_OUT:
0285         pipe_num = ATH6KL_USB_PIPE_TX_DATA_LP;
0286         *urb_count = TX_URB_COUNT;
0287         break;
0288     case ATH6KL_USB_EP_ADDR_APP_DATA_MP_OUT:
0289         pipe_num = ATH6KL_USB_PIPE_TX_DATA_MP;
0290         *urb_count = TX_URB_COUNT;
0291         break;
0292     case ATH6KL_USB_EP_ADDR_APP_DATA_HP_OUT:
0293         pipe_num = ATH6KL_USB_PIPE_TX_DATA_HP;
0294         *urb_count = TX_URB_COUNT;
0295         break;
0296     default:
0297         /* note: there may be endpoints not currently used */
0298         break;
0299     }
0300 
0301     return pipe_num;
0302 }
0303 
0304 static int ath6kl_usb_setup_pipe_resources(struct ath6kl_usb *ar_usb)
0305 {
0306     struct usb_interface *interface = ar_usb->interface;
0307     struct usb_host_interface *iface_desc = interface->cur_altsetting;
0308     struct usb_endpoint_descriptor *endpoint;
0309     struct ath6kl_usb_pipe *pipe;
0310     int i, urbcount, status = 0;
0311     u8 pipe_num;
0312 
0313     ath6kl_dbg(ATH6KL_DBG_USB, "setting up USB Pipes using interface\n");
0314 
0315     /* walk descriptors and setup pipes */
0316     for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
0317         endpoint = &iface_desc->endpoint[i].desc;
0318 
0319         if (ATH6KL_USB_IS_BULK_EP(endpoint->bmAttributes)) {
0320             ath6kl_dbg(ATH6KL_DBG_USB,
0321                    "%s Bulk Ep:0x%2.2X maxpktsz:%d\n",
0322                    ATH6KL_USB_IS_DIR_IN
0323                    (endpoint->bEndpointAddress) ?
0324                    "RX" : "TX", endpoint->bEndpointAddress,
0325                    le16_to_cpu(endpoint->wMaxPacketSize));
0326         } else if (ATH6KL_USB_IS_INT_EP(endpoint->bmAttributes)) {
0327             ath6kl_dbg(ATH6KL_DBG_USB,
0328                    "%s Int Ep:0x%2.2X maxpktsz:%d interval:%d\n",
0329                    ATH6KL_USB_IS_DIR_IN
0330                    (endpoint->bEndpointAddress) ?
0331                    "RX" : "TX", endpoint->bEndpointAddress,
0332                    le16_to_cpu(endpoint->wMaxPacketSize),
0333                    endpoint->bInterval);
0334         } else if (ATH6KL_USB_IS_ISOC_EP(endpoint->bmAttributes)) {
0335             /* TODO for ISO */
0336             ath6kl_dbg(ATH6KL_DBG_USB,
0337                    "%s ISOC Ep:0x%2.2X maxpktsz:%d interval:%d\n",
0338                    ATH6KL_USB_IS_DIR_IN
0339                    (endpoint->bEndpointAddress) ?
0340                    "RX" : "TX", endpoint->bEndpointAddress,
0341                    le16_to_cpu(endpoint->wMaxPacketSize),
0342                    endpoint->bInterval);
0343         }
0344 
0345         /* Ignore broken descriptors. */
0346         if (usb_endpoint_maxp(endpoint) == 0)
0347             continue;
0348 
0349         urbcount = 0;
0350 
0351         pipe_num =
0352             ath6kl_usb_get_logical_pipe_num(ar_usb,
0353                             endpoint->bEndpointAddress,
0354                             &urbcount);
0355         if (pipe_num == ATH6KL_USB_PIPE_INVALID)
0356             continue;
0357 
0358         pipe = &ar_usb->pipes[pipe_num];
0359         if (pipe->ar_usb != NULL) {
0360             /* hmmm..pipe was already setup */
0361             continue;
0362         }
0363 
0364         pipe->ar_usb = ar_usb;
0365         pipe->logical_pipe_num = pipe_num;
0366         pipe->ep_address = endpoint->bEndpointAddress;
0367         pipe->max_packet_size = le16_to_cpu(endpoint->wMaxPacketSize);
0368 
0369         if (ATH6KL_USB_IS_BULK_EP(endpoint->bmAttributes)) {
0370             if (ATH6KL_USB_IS_DIR_IN(pipe->ep_address)) {
0371                 pipe->usb_pipe_handle =
0372                     usb_rcvbulkpipe(ar_usb->udev,
0373                             pipe->ep_address);
0374             } else {
0375                 pipe->usb_pipe_handle =
0376                     usb_sndbulkpipe(ar_usb->udev,
0377                             pipe->ep_address);
0378             }
0379         } else if (ATH6KL_USB_IS_INT_EP(endpoint->bmAttributes)) {
0380             if (ATH6KL_USB_IS_DIR_IN(pipe->ep_address)) {
0381                 pipe->usb_pipe_handle =
0382                     usb_rcvintpipe(ar_usb->udev,
0383                            pipe->ep_address);
0384             } else {
0385                 pipe->usb_pipe_handle =
0386                     usb_sndintpipe(ar_usb->udev,
0387                            pipe->ep_address);
0388             }
0389         } else if (ATH6KL_USB_IS_ISOC_EP(endpoint->bmAttributes)) {
0390             /* TODO for ISO */
0391             if (ATH6KL_USB_IS_DIR_IN(pipe->ep_address)) {
0392                 pipe->usb_pipe_handle =
0393                     usb_rcvisocpipe(ar_usb->udev,
0394                             pipe->ep_address);
0395             } else {
0396                 pipe->usb_pipe_handle =
0397                     usb_sndisocpipe(ar_usb->udev,
0398                             pipe->ep_address);
0399             }
0400         }
0401 
0402         pipe->ep_desc = endpoint;
0403 
0404         if (!ATH6KL_USB_IS_DIR_IN(pipe->ep_address))
0405             pipe->flags |= ATH6KL_USB_PIPE_FLAG_TX;
0406 
0407         status = ath6kl_usb_alloc_pipe_resources(pipe, urbcount);
0408         if (status != 0)
0409             break;
0410     }
0411 
0412     return status;
0413 }
0414 
0415 /* pipe operations */
0416 static void ath6kl_usb_post_recv_transfers(struct ath6kl_usb_pipe *recv_pipe,
0417                        int buffer_length)
0418 {
0419     struct ath6kl_urb_context *urb_context;
0420     struct urb *urb;
0421     int usb_status;
0422 
0423     while (true) {
0424         urb_context = ath6kl_usb_alloc_urb_from_pipe(recv_pipe);
0425         if (urb_context == NULL)
0426             break;
0427 
0428         urb_context->skb = dev_alloc_skb(buffer_length);
0429         if (urb_context->skb == NULL)
0430             goto err_cleanup_urb;
0431 
0432         urb = usb_alloc_urb(0, GFP_ATOMIC);
0433         if (urb == NULL)
0434             goto err_cleanup_urb;
0435 
0436         usb_fill_bulk_urb(urb,
0437                   recv_pipe->ar_usb->udev,
0438                   recv_pipe->usb_pipe_handle,
0439                   urb_context->skb->data,
0440                   buffer_length,
0441                   ath6kl_usb_recv_complete, urb_context);
0442 
0443         ath6kl_dbg(ATH6KL_DBG_USB_BULK,
0444                "ath6kl usb: bulk recv submit:%d, 0x%X (ep:0x%2.2X), %d bytes buf:0x%p\n",
0445                recv_pipe->logical_pipe_num,
0446                recv_pipe->usb_pipe_handle, recv_pipe->ep_address,
0447                buffer_length, urb_context->skb);
0448 
0449         usb_anchor_urb(urb, &recv_pipe->urb_submitted);
0450         usb_status = usb_submit_urb(urb, GFP_ATOMIC);
0451 
0452         if (usb_status) {
0453             ath6kl_dbg(ATH6KL_DBG_USB_BULK,
0454                    "ath6kl usb : usb bulk recv failed %d\n",
0455                    usb_status);
0456             usb_unanchor_urb(urb);
0457             usb_free_urb(urb);
0458             goto err_cleanup_urb;
0459         }
0460         usb_free_urb(urb);
0461     }
0462     return;
0463 
0464 err_cleanup_urb:
0465     ath6kl_usb_cleanup_recv_urb(urb_context);
0466     return;
0467 }
0468 
0469 static void ath6kl_usb_flush_all(struct ath6kl_usb *ar_usb)
0470 {
0471     int i;
0472 
0473     for (i = 0; i < ATH6KL_USB_PIPE_MAX; i++) {
0474         if (ar_usb->pipes[i].ar_usb != NULL)
0475             usb_kill_anchored_urbs(&ar_usb->pipes[i].urb_submitted);
0476     }
0477 
0478     /*
0479      * Flushing any pending I/O may schedule work this call will block
0480      * until all scheduled work runs to completion.
0481      */
0482     flush_workqueue(ar_usb->wq);
0483 }
0484 
0485 static void ath6kl_usb_start_recv_pipes(struct ath6kl_usb *ar_usb)
0486 {
0487     /*
0488      * note: control pipe is no longer used
0489      * ar_usb->pipes[ATH6KL_USB_PIPE_RX_CTRL].urb_cnt_thresh =
0490      *      ar_usb->pipes[ATH6KL_USB_PIPE_RX_CTRL].urb_alloc/2;
0491      * ath6kl_usb_post_recv_transfers(&ar_usb->
0492      *      pipes[ATH6KL_USB_PIPE_RX_CTRL],
0493      *      ATH6KL_USB_RX_BUFFER_SIZE);
0494      */
0495 
0496     ar_usb->pipes[ATH6KL_USB_PIPE_RX_DATA].urb_cnt_thresh = 1;
0497 
0498     ath6kl_usb_post_recv_transfers(&ar_usb->pipes[ATH6KL_USB_PIPE_RX_DATA],
0499                        ATH6KL_USB_RX_BUFFER_SIZE);
0500 }
0501 
0502 /* hif usb rx/tx completion functions */
0503 static void ath6kl_usb_recv_complete(struct urb *urb)
0504 {
0505     struct ath6kl_urb_context *urb_context = urb->context;
0506     struct ath6kl_usb_pipe *pipe = urb_context->pipe;
0507     struct sk_buff *skb = NULL;
0508     int status = 0;
0509 
0510     ath6kl_dbg(ATH6KL_DBG_USB_BULK,
0511            "%s: recv pipe: %d, stat:%d, len:%d urb:0x%p\n", __func__,
0512            pipe->logical_pipe_num, urb->status, urb->actual_length,
0513            urb);
0514 
0515     if (urb->status != 0) {
0516         status = -EIO;
0517         switch (urb->status) {
0518         case -ECONNRESET:
0519         case -ENOENT:
0520         case -ESHUTDOWN:
0521             /*
0522              * no need to spew these errors when device
0523              * removed or urb killed due to driver shutdown
0524              */
0525             status = -ECANCELED;
0526             break;
0527         default:
0528             ath6kl_dbg(ATH6KL_DBG_USB_BULK,
0529                    "%s recv pipe: %d (ep:0x%2.2X), failed:%d\n",
0530                    __func__, pipe->logical_pipe_num,
0531                    pipe->ep_address, urb->status);
0532             break;
0533         }
0534         goto cleanup_recv_urb;
0535     }
0536 
0537     if (urb->actual_length == 0)
0538         goto cleanup_recv_urb;
0539 
0540     skb = urb_context->skb;
0541 
0542     /* we are going to pass it up */
0543     urb_context->skb = NULL;
0544     skb_put(skb, urb->actual_length);
0545 
0546     /* note: queue implements a lock */
0547     skb_queue_tail(&pipe->io_comp_queue, skb);
0548     queue_work(pipe->ar_usb->wq, &pipe->io_complete_work);
0549 
0550 cleanup_recv_urb:
0551     ath6kl_usb_cleanup_recv_urb(urb_context);
0552 
0553     if (status == 0 &&
0554         pipe->urb_cnt >= pipe->urb_cnt_thresh) {
0555         /* our free urbs are piling up, post more transfers */
0556         ath6kl_usb_post_recv_transfers(pipe, ATH6KL_USB_RX_BUFFER_SIZE);
0557     }
0558 }
0559 
0560 static void ath6kl_usb_usb_transmit_complete(struct urb *urb)
0561 {
0562     struct ath6kl_urb_context *urb_context = urb->context;
0563     struct ath6kl_usb_pipe *pipe = urb_context->pipe;
0564     struct sk_buff *skb;
0565 
0566     ath6kl_dbg(ATH6KL_DBG_USB_BULK,
0567            "%s: pipe: %d, stat:%d, len:%d\n",
0568            __func__, pipe->logical_pipe_num, urb->status,
0569            urb->actual_length);
0570 
0571     if (urb->status != 0) {
0572         ath6kl_dbg(ATH6KL_DBG_USB_BULK,
0573                "%s:  pipe: %d, failed:%d\n",
0574                __func__, pipe->logical_pipe_num, urb->status);
0575     }
0576 
0577     skb = urb_context->skb;
0578     urb_context->skb = NULL;
0579     ath6kl_usb_free_urb_to_pipe(urb_context->pipe, urb_context);
0580 
0581     /* note: queue implements a lock */
0582     skb_queue_tail(&pipe->io_comp_queue, skb);
0583     queue_work(pipe->ar_usb->wq, &pipe->io_complete_work);
0584 }
0585 
0586 static void ath6kl_usb_io_comp_work(struct work_struct *work)
0587 {
0588     struct ath6kl_usb_pipe *pipe = container_of(work,
0589                             struct ath6kl_usb_pipe,
0590                             io_complete_work);
0591     struct ath6kl_usb *ar_usb;
0592     struct sk_buff *skb;
0593 
0594     ar_usb = pipe->ar_usb;
0595 
0596     while ((skb = skb_dequeue(&pipe->io_comp_queue))) {
0597         if (pipe->flags & ATH6KL_USB_PIPE_FLAG_TX) {
0598             ath6kl_dbg(ATH6KL_DBG_USB_BULK,
0599                    "ath6kl usb xmit callback buf:0x%p\n", skb);
0600             ath6kl_core_tx_complete(ar_usb->ar, skb);
0601         } else {
0602             ath6kl_dbg(ATH6KL_DBG_USB_BULK,
0603                    "ath6kl usb recv callback buf:0x%p\n", skb);
0604             ath6kl_core_rx_complete(ar_usb->ar, skb,
0605                         pipe->logical_pipe_num);
0606         }
0607     }
0608 }
0609 
0610 #define ATH6KL_USB_MAX_DIAG_CMD (sizeof(struct ath6kl_usb_ctrl_diag_cmd_write))
0611 #define ATH6KL_USB_MAX_DIAG_RESP (sizeof(struct ath6kl_usb_ctrl_diag_resp_read))
0612 
0613 static void ath6kl_usb_destroy(struct ath6kl_usb *ar_usb)
0614 {
0615     ath6kl_usb_flush_all(ar_usb);
0616 
0617     ath6kl_usb_cleanup_pipe_resources(ar_usb);
0618 
0619     usb_set_intfdata(ar_usb->interface, NULL);
0620 
0621     kfree(ar_usb->diag_cmd_buffer);
0622     kfree(ar_usb->diag_resp_buffer);
0623     destroy_workqueue(ar_usb->wq);
0624 
0625     kfree(ar_usb);
0626 }
0627 
0628 static struct ath6kl_usb *ath6kl_usb_create(struct usb_interface *interface)
0629 {
0630     struct usb_device *dev = interface_to_usbdev(interface);
0631     struct ath6kl_usb *ar_usb;
0632     struct ath6kl_usb_pipe *pipe;
0633     int status = 0;
0634     int i;
0635 
0636     /* ath6kl_usb_destroy() needs ar_usb != NULL && ar_usb->wq != NULL. */
0637     ar_usb = kzalloc(sizeof(struct ath6kl_usb), GFP_KERNEL);
0638     if (ar_usb == NULL)
0639         return NULL;
0640     ar_usb->wq = alloc_workqueue("ath6kl_wq", 0, 0);
0641     if (!ar_usb->wq) {
0642         kfree(ar_usb);
0643         return NULL;
0644     }
0645 
0646     usb_set_intfdata(interface, ar_usb);
0647     spin_lock_init(&(ar_usb->cs_lock));
0648     ar_usb->udev = dev;
0649     ar_usb->interface = interface;
0650 
0651     for (i = 0; i < ATH6KL_USB_PIPE_MAX; i++) {
0652         pipe = &ar_usb->pipes[i];
0653         INIT_WORK(&pipe->io_complete_work,
0654               ath6kl_usb_io_comp_work);
0655         skb_queue_head_init(&pipe->io_comp_queue);
0656     }
0657 
0658     ar_usb->diag_cmd_buffer = kzalloc(ATH6KL_USB_MAX_DIAG_CMD, GFP_KERNEL);
0659     if (ar_usb->diag_cmd_buffer == NULL) {
0660         status = -ENOMEM;
0661         goto fail_ath6kl_usb_create;
0662     }
0663 
0664     ar_usb->diag_resp_buffer = kzalloc(ATH6KL_USB_MAX_DIAG_RESP,
0665                        GFP_KERNEL);
0666     if (ar_usb->diag_resp_buffer == NULL) {
0667         status = -ENOMEM;
0668         goto fail_ath6kl_usb_create;
0669     }
0670 
0671     status = ath6kl_usb_setup_pipe_resources(ar_usb);
0672 
0673 fail_ath6kl_usb_create:
0674     if (status != 0) {
0675         ath6kl_usb_destroy(ar_usb);
0676         ar_usb = NULL;
0677     }
0678     return ar_usb;
0679 }
0680 
0681 static void ath6kl_usb_device_detached(struct usb_interface *interface)
0682 {
0683     struct ath6kl_usb *ar_usb;
0684 
0685     ar_usb = usb_get_intfdata(interface);
0686     if (ar_usb == NULL)
0687         return;
0688 
0689     ath6kl_stop_txrx(ar_usb->ar);
0690 
0691     /* Delay to wait for the target to reboot */
0692     mdelay(20);
0693     ath6kl_core_cleanup(ar_usb->ar);
0694     ath6kl_usb_destroy(ar_usb);
0695 }
0696 
0697 /* exported hif usb APIs for htc pipe */
0698 static void hif_start(struct ath6kl *ar)
0699 {
0700     struct ath6kl_usb *device = ath6kl_usb_priv(ar);
0701     int i;
0702 
0703     ath6kl_usb_start_recv_pipes(device);
0704 
0705     /* set the TX resource avail threshold for each TX pipe */
0706     for (i = ATH6KL_USB_PIPE_TX_CTRL;
0707          i <= ATH6KL_USB_PIPE_TX_DATA_HP; i++) {
0708         device->pipes[i].urb_cnt_thresh =
0709             device->pipes[i].urb_alloc / 2;
0710     }
0711 }
0712 
0713 static int ath6kl_usb_send(struct ath6kl *ar, u8 PipeID,
0714                struct sk_buff *hdr_skb, struct sk_buff *skb)
0715 {
0716     struct ath6kl_usb *device = ath6kl_usb_priv(ar);
0717     struct ath6kl_usb_pipe *pipe = &device->pipes[PipeID];
0718     struct ath6kl_urb_context *urb_context;
0719     int usb_status, status = 0;
0720     struct urb *urb;
0721     u8 *data;
0722     u32 len;
0723 
0724     ath6kl_dbg(ATH6KL_DBG_USB_BULK, "+%s pipe : %d, buf:0x%p\n",
0725            __func__, PipeID, skb);
0726 
0727     urb_context = ath6kl_usb_alloc_urb_from_pipe(pipe);
0728 
0729     if (urb_context == NULL) {
0730         /*
0731          * TODO: it is possible to run out of urbs if
0732          * 2 endpoints map to the same pipe ID
0733          */
0734         ath6kl_dbg(ATH6KL_DBG_USB_BULK,
0735                "%s pipe:%d no urbs left. URB Cnt : %d\n",
0736                __func__, PipeID, pipe->urb_cnt);
0737         status = -ENOMEM;
0738         goto fail_hif_send;
0739     }
0740 
0741     urb_context->skb = skb;
0742 
0743     data = skb->data;
0744     len = skb->len;
0745 
0746     urb = usb_alloc_urb(0, GFP_ATOMIC);
0747     if (urb == NULL) {
0748         status = -ENOMEM;
0749         ath6kl_usb_free_urb_to_pipe(urb_context->pipe,
0750                         urb_context);
0751         goto fail_hif_send;
0752     }
0753 
0754     usb_fill_bulk_urb(urb,
0755               device->udev,
0756               pipe->usb_pipe_handle,
0757               data,
0758               len,
0759               ath6kl_usb_usb_transmit_complete, urb_context);
0760 
0761     if ((len % pipe->max_packet_size) == 0) {
0762         /* hit a max packet boundary on this pipe */
0763         urb->transfer_flags |= URB_ZERO_PACKET;
0764     }
0765 
0766     ath6kl_dbg(ATH6KL_DBG_USB_BULK,
0767            "athusb bulk send submit:%d, 0x%X (ep:0x%2.2X), %d bytes\n",
0768            pipe->logical_pipe_num, pipe->usb_pipe_handle,
0769            pipe->ep_address, len);
0770 
0771     usb_anchor_urb(urb, &pipe->urb_submitted);
0772     usb_status = usb_submit_urb(urb, GFP_ATOMIC);
0773 
0774     if (usb_status) {
0775         ath6kl_dbg(ATH6KL_DBG_USB_BULK,
0776                "ath6kl usb : usb bulk transmit failed %d\n",
0777                usb_status);
0778         usb_unanchor_urb(urb);
0779         ath6kl_usb_free_urb_to_pipe(urb_context->pipe,
0780                         urb_context);
0781         status = -EINVAL;
0782     }
0783     usb_free_urb(urb);
0784 
0785 fail_hif_send:
0786     return status;
0787 }
0788 
0789 static void hif_stop(struct ath6kl *ar)
0790 {
0791     struct ath6kl_usb *device = ath6kl_usb_priv(ar);
0792 
0793     ath6kl_usb_flush_all(device);
0794 }
0795 
0796 static void ath6kl_usb_get_default_pipe(struct ath6kl *ar,
0797                     u8 *ul_pipe, u8 *dl_pipe)
0798 {
0799     *ul_pipe = ATH6KL_USB_PIPE_TX_CTRL;
0800     *dl_pipe = ATH6KL_USB_PIPE_RX_CTRL;
0801 }
0802 
0803 static int ath6kl_usb_map_service_pipe(struct ath6kl *ar, u16 svc_id,
0804                        u8 *ul_pipe, u8 *dl_pipe)
0805 {
0806     int status = 0;
0807 
0808     switch (svc_id) {
0809     case HTC_CTRL_RSVD_SVC:
0810     case WMI_CONTROL_SVC:
0811         *ul_pipe = ATH6KL_USB_PIPE_TX_CTRL;
0812         /* due to large control packets, shift to data pipe */
0813         *dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
0814         break;
0815     case WMI_DATA_BE_SVC:
0816     case WMI_DATA_BK_SVC:
0817         *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_LP;
0818         /*
0819         * Disable rxdata2 directly, it will be enabled
0820         * if FW enable rxdata2
0821         */
0822         *dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
0823         break;
0824     case WMI_DATA_VI_SVC:
0825 
0826         if (test_bit(ATH6KL_FW_CAPABILITY_MAP_LP_ENDPOINT,
0827                  ar->fw_capabilities))
0828             *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_LP;
0829         else
0830             *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_MP;
0831         /*
0832         * Disable rxdata2 directly, it will be enabled
0833         * if FW enable rxdata2
0834         */
0835         *dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
0836         break;
0837     case WMI_DATA_VO_SVC:
0838 
0839         if (test_bit(ATH6KL_FW_CAPABILITY_MAP_LP_ENDPOINT,
0840                  ar->fw_capabilities))
0841             *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_LP;
0842         else
0843             *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_MP;
0844         /*
0845         * Disable rxdata2 directly, it will be enabled
0846         * if FW enable rxdata2
0847         */
0848         *dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
0849         break;
0850     default:
0851         status = -EPERM;
0852         break;
0853     }
0854 
0855     return status;
0856 }
0857 
0858 static u16 ath6kl_usb_get_free_queue_number(struct ath6kl *ar, u8 pipe_id)
0859 {
0860     struct ath6kl_usb *device = ath6kl_usb_priv(ar);
0861 
0862     return device->pipes[pipe_id].urb_cnt;
0863 }
0864 
0865 static void hif_detach_htc(struct ath6kl *ar)
0866 {
0867     struct ath6kl_usb *device = ath6kl_usb_priv(ar);
0868 
0869     ath6kl_usb_flush_all(device);
0870 }
0871 
0872 static int ath6kl_usb_submit_ctrl_out(struct ath6kl_usb *ar_usb,
0873                    u8 req, u16 value, u16 index, void *data,
0874                    u32 size)
0875 {
0876     u8 *buf = NULL;
0877     int ret;
0878 
0879     if (size > 0) {
0880         buf = kmemdup(data, size, GFP_KERNEL);
0881         if (buf == NULL)
0882             return -ENOMEM;
0883     }
0884 
0885     /* note: if successful returns number of bytes transfered */
0886     ret = usb_control_msg(ar_usb->udev,
0887                   usb_sndctrlpipe(ar_usb->udev, 0),
0888                   req,
0889                   USB_DIR_OUT | USB_TYPE_VENDOR |
0890                   USB_RECIP_DEVICE, value, index, buf,
0891                   size, 1000);
0892 
0893     if (ret < 0) {
0894         ath6kl_warn("Failed to submit usb control message: %d\n", ret);
0895         kfree(buf);
0896         return ret;
0897     }
0898 
0899     kfree(buf);
0900 
0901     return 0;
0902 }
0903 
0904 static int ath6kl_usb_submit_ctrl_in(struct ath6kl_usb *ar_usb,
0905                   u8 req, u16 value, u16 index, void *data,
0906                   u32 size)
0907 {
0908     u8 *buf = NULL;
0909     int ret;
0910 
0911     if (size > 0) {
0912         buf = kmalloc(size, GFP_KERNEL);
0913         if (buf == NULL)
0914             return -ENOMEM;
0915     }
0916 
0917     /* note: if successful returns number of bytes transfered */
0918     ret = usb_control_msg(ar_usb->udev,
0919                  usb_rcvctrlpipe(ar_usb->udev, 0),
0920                  req,
0921                  USB_DIR_IN | USB_TYPE_VENDOR |
0922                  USB_RECIP_DEVICE, value, index, buf,
0923                  size, 2000);
0924 
0925     if (ret < 0) {
0926         ath6kl_warn("Failed to read usb control message: %d\n", ret);
0927         kfree(buf);
0928         return ret;
0929     }
0930 
0931     memcpy((u8 *) data, buf, size);
0932 
0933     kfree(buf);
0934 
0935     return 0;
0936 }
0937 
0938 static int ath6kl_usb_ctrl_msg_exchange(struct ath6kl_usb *ar_usb,
0939                      u8 req_val, u8 *req_buf, u32 req_len,
0940                      u8 resp_val, u8 *resp_buf, u32 *resp_len)
0941 {
0942     int ret;
0943 
0944     /* send command */
0945     ret = ath6kl_usb_submit_ctrl_out(ar_usb, req_val, 0, 0,
0946                      req_buf, req_len);
0947 
0948     if (ret != 0)
0949         return ret;
0950 
0951     if (resp_buf == NULL) {
0952         /* no expected response */
0953         return ret;
0954     }
0955 
0956     /* get response */
0957     ret = ath6kl_usb_submit_ctrl_in(ar_usb, resp_val, 0, 0,
0958                     resp_buf, *resp_len);
0959 
0960     return ret;
0961 }
0962 
0963 static int ath6kl_usb_diag_read32(struct ath6kl *ar, u32 address, u32 *data)
0964 {
0965     struct ath6kl_usb *ar_usb = ar->hif_priv;
0966     struct ath6kl_usb_ctrl_diag_resp_read *resp;
0967     struct ath6kl_usb_ctrl_diag_cmd_read *cmd;
0968     u32 resp_len;
0969     int ret;
0970 
0971     cmd = (struct ath6kl_usb_ctrl_diag_cmd_read *) ar_usb->diag_cmd_buffer;
0972 
0973     memset(cmd, 0, sizeof(*cmd));
0974     cmd->cmd = ATH6KL_USB_CTRL_DIAG_CC_READ;
0975     cmd->address = cpu_to_le32(address);
0976     resp_len = sizeof(*resp);
0977 
0978     ret = ath6kl_usb_ctrl_msg_exchange(ar_usb,
0979                 ATH6KL_USB_CONTROL_REQ_DIAG_CMD,
0980                 (u8 *) cmd,
0981                 sizeof(struct ath6kl_usb_ctrl_diag_cmd_write),
0982                 ATH6KL_USB_CONTROL_REQ_DIAG_RESP,
0983                 ar_usb->diag_resp_buffer, &resp_len);
0984 
0985     if (ret) {
0986         ath6kl_warn("diag read32 failed: %d\n", ret);
0987         return ret;
0988     }
0989 
0990     resp = (struct ath6kl_usb_ctrl_diag_resp_read *)
0991         ar_usb->diag_resp_buffer;
0992 
0993     *data = le32_to_cpu(resp->value);
0994 
0995     return ret;
0996 }
0997 
0998 static int ath6kl_usb_diag_write32(struct ath6kl *ar, u32 address, __le32 data)
0999 {
1000     struct ath6kl_usb *ar_usb = ar->hif_priv;
1001     struct ath6kl_usb_ctrl_diag_cmd_write *cmd;
1002     int ret;
1003 
1004     cmd = (struct ath6kl_usb_ctrl_diag_cmd_write *) ar_usb->diag_cmd_buffer;
1005 
1006     memset(cmd, 0, sizeof(struct ath6kl_usb_ctrl_diag_cmd_write));
1007     cmd->cmd = cpu_to_le32(ATH6KL_USB_CTRL_DIAG_CC_WRITE);
1008     cmd->address = cpu_to_le32(address);
1009     cmd->value = data;
1010 
1011     ret = ath6kl_usb_ctrl_msg_exchange(ar_usb,
1012                        ATH6KL_USB_CONTROL_REQ_DIAG_CMD,
1013                        (u8 *) cmd,
1014                        sizeof(*cmd),
1015                        0, NULL, NULL);
1016     if (ret) {
1017         ath6kl_warn("diag_write32 failed: %d\n", ret);
1018         return ret;
1019     }
1020 
1021     return 0;
1022 }
1023 
1024 static int ath6kl_usb_bmi_read(struct ath6kl *ar, u8 *buf, u32 len)
1025 {
1026     struct ath6kl_usb *ar_usb = ar->hif_priv;
1027     int ret;
1028 
1029     /* get response */
1030     ret = ath6kl_usb_submit_ctrl_in(ar_usb,
1031                     ATH6KL_USB_CONTROL_REQ_RECV_BMI_RESP,
1032                     0, 0, buf, len);
1033     if (ret) {
1034         ath6kl_err("Unable to read the bmi data from the device: %d\n",
1035                ret);
1036         return ret;
1037     }
1038 
1039     return 0;
1040 }
1041 
1042 static int ath6kl_usb_bmi_write(struct ath6kl *ar, u8 *buf, u32 len)
1043 {
1044     struct ath6kl_usb *ar_usb = ar->hif_priv;
1045     int ret;
1046 
1047     /* send command */
1048     ret = ath6kl_usb_submit_ctrl_out(ar_usb,
1049                      ATH6KL_USB_CONTROL_REQ_SEND_BMI_CMD,
1050                      0, 0, buf, len);
1051     if (ret) {
1052         ath6kl_err("unable to send the bmi data to the device: %d\n",
1053                ret);
1054         return ret;
1055     }
1056 
1057     return 0;
1058 }
1059 
1060 static int ath6kl_usb_power_on(struct ath6kl *ar)
1061 {
1062     hif_start(ar);
1063     return 0;
1064 }
1065 
1066 static int ath6kl_usb_power_off(struct ath6kl *ar)
1067 {
1068     hif_detach_htc(ar);
1069     return 0;
1070 }
1071 
1072 static void ath6kl_usb_stop(struct ath6kl *ar)
1073 {
1074     hif_stop(ar);
1075 }
1076 
1077 static void ath6kl_usb_cleanup_scatter(struct ath6kl *ar)
1078 {
1079     /*
1080      * USB doesn't support it. Just return.
1081      */
1082     return;
1083 }
1084 
1085 static int ath6kl_usb_suspend(struct ath6kl *ar, struct cfg80211_wowlan *wow)
1086 {
1087     /*
1088      * cfg80211 suspend/WOW currently not supported for USB.
1089      */
1090     return 0;
1091 }
1092 
1093 static int ath6kl_usb_resume(struct ath6kl *ar)
1094 {
1095     /*
1096      * cfg80211 resume currently not supported for USB.
1097      */
1098     return 0;
1099 }
1100 
1101 static const struct ath6kl_hif_ops ath6kl_usb_ops = {
1102     .diag_read32 = ath6kl_usb_diag_read32,
1103     .diag_write32 = ath6kl_usb_diag_write32,
1104     .bmi_read = ath6kl_usb_bmi_read,
1105     .bmi_write = ath6kl_usb_bmi_write,
1106     .power_on = ath6kl_usb_power_on,
1107     .power_off = ath6kl_usb_power_off,
1108     .stop = ath6kl_usb_stop,
1109     .pipe_send = ath6kl_usb_send,
1110     .pipe_get_default = ath6kl_usb_get_default_pipe,
1111     .pipe_map_service = ath6kl_usb_map_service_pipe,
1112     .pipe_get_free_queue_number = ath6kl_usb_get_free_queue_number,
1113     .cleanup_scatter = ath6kl_usb_cleanup_scatter,
1114     .suspend = ath6kl_usb_suspend,
1115     .resume = ath6kl_usb_resume,
1116 };
1117 
1118 /* ath6kl usb driver registered functions */
1119 static int ath6kl_usb_probe(struct usb_interface *interface,
1120                 const struct usb_device_id *id)
1121 {
1122     struct usb_device *dev = interface_to_usbdev(interface);
1123     struct ath6kl *ar;
1124     struct ath6kl_usb *ar_usb = NULL;
1125     int vendor_id, product_id;
1126     int ret = 0;
1127 
1128     usb_get_dev(dev);
1129 
1130     vendor_id = le16_to_cpu(dev->descriptor.idVendor);
1131     product_id = le16_to_cpu(dev->descriptor.idProduct);
1132 
1133     ath6kl_dbg(ATH6KL_DBG_USB, "vendor_id = %04x\n", vendor_id);
1134     ath6kl_dbg(ATH6KL_DBG_USB, "product_id = %04x\n", product_id);
1135 
1136     if (interface->cur_altsetting)
1137         ath6kl_dbg(ATH6KL_DBG_USB, "USB Interface %d\n",
1138                interface->cur_altsetting->desc.bInterfaceNumber);
1139 
1140 
1141     if (dev->speed == USB_SPEED_HIGH)
1142         ath6kl_dbg(ATH6KL_DBG_USB, "USB 2.0 Host\n");
1143     else
1144         ath6kl_dbg(ATH6KL_DBG_USB, "USB 1.1 Host\n");
1145 
1146     ar_usb = ath6kl_usb_create(interface);
1147 
1148     if (ar_usb == NULL) {
1149         ret = -ENOMEM;
1150         goto err_usb_put;
1151     }
1152 
1153     ar = ath6kl_core_create(&ar_usb->udev->dev);
1154     if (ar == NULL) {
1155         ath6kl_err("Failed to alloc ath6kl core\n");
1156         ret = -ENOMEM;
1157         goto err_usb_destroy;
1158     }
1159 
1160     ar->hif_priv = ar_usb;
1161     ar->hif_type = ATH6KL_HIF_TYPE_USB;
1162     ar->hif_ops = &ath6kl_usb_ops;
1163     ar->mbox_info.block_size = 16;
1164     ar->bmi.max_data_size = 252;
1165 
1166     ar_usb->ar = ar;
1167 
1168     ret = ath6kl_core_init(ar, ATH6KL_HTC_TYPE_PIPE);
1169     if (ret) {
1170         ath6kl_err("Failed to init ath6kl core: %d\n", ret);
1171         goto err_core_free;
1172     }
1173 
1174     return ret;
1175 
1176 err_core_free:
1177     ath6kl_core_destroy(ar);
1178 err_usb_destroy:
1179     ath6kl_usb_destroy(ar_usb);
1180 err_usb_put:
1181     usb_put_dev(dev);
1182 
1183     return ret;
1184 }
1185 
1186 static void ath6kl_usb_remove(struct usb_interface *interface)
1187 {
1188     usb_put_dev(interface_to_usbdev(interface));
1189     ath6kl_usb_device_detached(interface);
1190 }
1191 
1192 #ifdef CONFIG_PM
1193 
1194 static int ath6kl_usb_pm_suspend(struct usb_interface *interface,
1195                   pm_message_t message)
1196 {
1197     struct ath6kl_usb *device;
1198     device = usb_get_intfdata(interface);
1199 
1200     ath6kl_usb_flush_all(device);
1201     return 0;
1202 }
1203 
1204 static int ath6kl_usb_pm_resume(struct usb_interface *interface)
1205 {
1206     struct ath6kl_usb *device;
1207     device = usb_get_intfdata(interface);
1208 
1209     ath6kl_usb_post_recv_transfers(&device->pipes[ATH6KL_USB_PIPE_RX_DATA],
1210                        ATH6KL_USB_RX_BUFFER_SIZE);
1211     ath6kl_usb_post_recv_transfers(&device->pipes[ATH6KL_USB_PIPE_RX_DATA2],
1212                        ATH6KL_USB_RX_BUFFER_SIZE);
1213 
1214     return 0;
1215 }
1216 
1217 #else
1218 
1219 #define ath6kl_usb_pm_suspend NULL
1220 #define ath6kl_usb_pm_resume NULL
1221 
1222 #endif
1223 
1224 /* table of devices that work with this driver */
1225 static const struct usb_device_id ath6kl_usb_ids[] = {
1226     {USB_DEVICE(0x0cf3, 0x9375)},
1227     {USB_DEVICE(0x0cf3, 0x9374)},
1228     {USB_DEVICE(0x04da, 0x390d)},
1229     { /* Terminating entry */ },
1230 };
1231 
1232 MODULE_DEVICE_TABLE(usb, ath6kl_usb_ids);
1233 
1234 static struct usb_driver ath6kl_usb_driver = {
1235     .name = "ath6kl_usb",
1236     .probe = ath6kl_usb_probe,
1237     .suspend = ath6kl_usb_pm_suspend,
1238     .resume = ath6kl_usb_pm_resume,
1239     .disconnect = ath6kl_usb_remove,
1240     .id_table = ath6kl_usb_ids,
1241     .supports_autosuspend = true,
1242     .disable_hub_initiated_lpm = 1,
1243 };
1244 
1245 module_usb_driver(ath6kl_usb_driver);
1246 
1247 MODULE_AUTHOR("Atheros Communications, Inc.");
1248 MODULE_DESCRIPTION("Driver support for Atheros AR600x USB devices");
1249 MODULE_LICENSE("Dual BSD/GPL");
1250 MODULE_FIRMWARE(AR6004_HW_1_0_FIRMWARE_FILE);
1251 MODULE_FIRMWARE(AR6004_HW_1_0_BOARD_DATA_FILE);
1252 MODULE_FIRMWARE(AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE);
1253 MODULE_FIRMWARE(AR6004_HW_1_1_FIRMWARE_FILE);
1254 MODULE_FIRMWARE(AR6004_HW_1_1_BOARD_DATA_FILE);
1255 MODULE_FIRMWARE(AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE);
1256 MODULE_FIRMWARE(AR6004_HW_1_2_FIRMWARE_FILE);
1257 MODULE_FIRMWARE(AR6004_HW_1_2_BOARD_DATA_FILE);
1258 MODULE_FIRMWARE(AR6004_HW_1_2_DEFAULT_BOARD_DATA_FILE);
1259 MODULE_FIRMWARE(AR6004_HW_1_3_FW_DIR "/" AR6004_HW_1_3_FIRMWARE_FILE);
1260 MODULE_FIRMWARE(AR6004_HW_1_3_BOARD_DATA_FILE);
1261 MODULE_FIRMWARE(AR6004_HW_1_3_DEFAULT_BOARD_DATA_FILE);