hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/net/wireless/ath/ath9k/hif_usb.c
....@@ -244,11 +244,11 @@
244244 ath9k_htc_txcompletion_cb(hif_dev->htc_handle,
245245 skb, txok);
246246 if (txok) {
247
- TX_STAT_INC(skb_success);
248
- TX_STAT_ADD(skb_success_bytes, ln);
247
+ TX_STAT_INC(hif_dev, skb_success);
248
+ TX_STAT_ADD(hif_dev, skb_success_bytes, ln);
249249 }
250250 else
251
- TX_STAT_INC(skb_failed);
251
+ TX_STAT_INC(hif_dev, skb_failed);
252252 }
253253 }
254254
....@@ -302,7 +302,7 @@
302302 hif_dev->tx.tx_buf_cnt++;
303303 if (!(hif_dev->tx.flags & HIF_USB_TX_STOP))
304304 __hif_usb_tx(hif_dev); /* Check for pending SKBs */
305
- TX_STAT_INC(buf_completed);
305
+ TX_STAT_INC(hif_dev, buf_completed);
306306 spin_unlock(&hif_dev->tx.tx_lock);
307307 }
308308
....@@ -353,7 +353,7 @@
353353 tx_buf->len += tx_buf->offset;
354354
355355 __skb_queue_tail(&tx_buf->skb_queue, nskb);
356
- TX_STAT_INC(skb_queued);
356
+ TX_STAT_INC(hif_dev, skb_queued);
357357 }
358358
359359 usb_fill_bulk_urb(tx_buf->urb, hif_dev->udev,
....@@ -368,10 +368,9 @@
368368 __skb_queue_head_init(&tx_buf->skb_queue);
369369 list_move_tail(&tx_buf->list, &hif_dev->tx.tx_buf);
370370 hif_dev->tx.tx_buf_cnt++;
371
+ } else {
372
+ TX_STAT_INC(hif_dev, buf_queued);
371373 }
372
-
373
- if (!ret)
374
- TX_STAT_INC(buf_queued);
375374
376375 return ret;
377376 }
....@@ -515,7 +514,7 @@
515514 ath9k_htc_txcompletion_cb(hif_dev->htc_handle,
516515 skb, false);
517516 hif_dev->tx.tx_skb_cnt--;
518
- TX_STAT_INC(skb_failed);
517
+ TX_STAT_INC(hif_dev, skb_failed);
519518 }
520519 }
521520
....@@ -534,6 +533,24 @@
534533 .sta_drain = hif_usb_sta_drain,
535534 .send = hif_usb_send,
536535 };
536
+
537
+/* Need to free remain_skb allocated in ath9k_hif_usb_rx_stream
538
+ * in case ath9k_hif_usb_rx_stream wasn't called next time to
539
+ * process the buffer and subsequently free it.
540
+ */
541
+static void ath9k_hif_usb_free_rx_remain_skb(struct hif_device_usb *hif_dev)
542
+{
543
+ unsigned long flags;
544
+
545
+ spin_lock_irqsave(&hif_dev->rx_lock, flags);
546
+ if (hif_dev->remain_skb) {
547
+ dev_kfree_skb_any(hif_dev->remain_skb);
548
+ hif_dev->remain_skb = NULL;
549
+ hif_dev->rx_remain_len = 0;
550
+ RX_STAT_INC(hif_dev, skb_dropped);
551
+ }
552
+ spin_unlock_irqrestore(&hif_dev->rx_lock, flags);
553
+}
537554
538555 static void ath9k_hif_usb_rx_stream(struct hif_device_usb *hif_dev,
539556 struct sk_buff *skb)
....@@ -562,11 +579,11 @@
562579 memcpy(ptr, skb->data, rx_remain_len);
563580
564581 rx_pkt_len += rx_remain_len;
565
- hif_dev->rx_remain_len = 0;
566582 skb_put(remain_skb, rx_pkt_len);
567583
568584 skb_pool[pool_index++] = remain_skb;
569
-
585
+ hif_dev->remain_skb = NULL;
586
+ hif_dev->rx_remain_len = 0;
570587 } else {
571588 index = rx_remain_len;
572589 }
....@@ -585,16 +602,21 @@
585602 pkt_len = get_unaligned_le16(ptr + index);
586603 pkt_tag = get_unaligned_le16(ptr + index + 2);
587604
605
+ /* It is supposed that if we have an invalid pkt_tag or
606
+ * pkt_len then the whole input SKB is considered invalid
607
+ * and dropped; the associated packets already in skb_pool
608
+ * are dropped, too.
609
+ */
588610 if (pkt_tag != ATH_USB_RX_STREAM_MODE_TAG) {
589
- RX_STAT_INC(skb_dropped);
590
- return;
611
+ RX_STAT_INC(hif_dev, skb_dropped);
612
+ goto invalid_pkt;
591613 }
592614
593615 if (pkt_len > 2 * MAX_RX_BUF_SIZE) {
594616 dev_err(&hif_dev->udev->dev,
595617 "ath9k_htc: invalid pkt_len (%x)\n", pkt_len);
596
- RX_STAT_INC(skb_dropped);
597
- return;
618
+ RX_STAT_INC(hif_dev, skb_dropped);
619
+ goto invalid_pkt;
598620 }
599621
600622 pad_len = 4 - (pkt_len & 0x3);
....@@ -606,11 +628,6 @@
606628
607629 if (index > MAX_RX_BUF_SIZE) {
608630 spin_lock(&hif_dev->rx_lock);
609
- hif_dev->rx_remain_len = index - MAX_RX_BUF_SIZE;
610
- hif_dev->rx_transfer_len =
611
- MAX_RX_BUF_SIZE - chk_idx - 4;
612
- hif_dev->rx_pad_len = pad_len;
613
-
614631 nskb = __dev_alloc_skb(pkt_len + 32, GFP_ATOMIC);
615632 if (!nskb) {
616633 dev_err(&hif_dev->udev->dev,
....@@ -618,8 +635,14 @@
618635 spin_unlock(&hif_dev->rx_lock);
619636 goto err;
620637 }
638
+
639
+ hif_dev->rx_remain_len = index - MAX_RX_BUF_SIZE;
640
+ hif_dev->rx_transfer_len =
641
+ MAX_RX_BUF_SIZE - chk_idx - 4;
642
+ hif_dev->rx_pad_len = pad_len;
643
+
621644 skb_reserve(nskb, 32);
622
- RX_STAT_INC(skb_allocated);
645
+ RX_STAT_INC(hif_dev, skb_allocated);
623646
624647 memcpy(nskb->data, &(skb->data[chk_idx+4]),
625648 hif_dev->rx_transfer_len);
....@@ -640,7 +663,7 @@
640663 goto err;
641664 }
642665 skb_reserve(nskb, 32);
643
- RX_STAT_INC(skb_allocated);
666
+ RX_STAT_INC(hif_dev, skb_allocated);
644667
645668 memcpy(nskb->data, &(skb->data[chk_idx+4]), pkt_len);
646669 skb_put(nskb, pkt_len);
....@@ -650,11 +673,18 @@
650673
651674 err:
652675 for (i = 0; i < pool_index; i++) {
653
- RX_STAT_ADD(skb_completed_bytes, skb_pool[i]->len);
676
+ RX_STAT_ADD(hif_dev, skb_completed_bytes, skb_pool[i]->len);
654677 ath9k_htc_rx_msg(hif_dev->htc_handle, skb_pool[i],
655678 skb_pool[i]->len, USB_WLAN_RX_PIPE);
656
- RX_STAT_INC(skb_completed);
679
+ RX_STAT_INC(hif_dev, skb_completed);
657680 }
681
+ return;
682
+invalid_pkt:
683
+ for (i = 0; i < pool_index; i++) {
684
+ dev_kfree_skb_any(skb_pool[i]);
685
+ RX_STAT_INC(hif_dev, skb_dropped);
686
+ }
687
+ return;
658688 }
659689
660690 static void ath9k_hif_usb_rx_cb(struct urb *urb)
....@@ -709,14 +739,13 @@
709739 struct rx_buf *rx_buf = (struct rx_buf *)urb->context;
710740 struct hif_device_usb *hif_dev = rx_buf->hif_dev;
711741 struct sk_buff *skb = rx_buf->skb;
712
- struct sk_buff *nskb;
713742 int ret;
714743
715744 if (!skb)
716745 return;
717746
718747 if (!hif_dev)
719
- goto free;
748
+ goto free_skb;
720749
721750 switch (urb->status) {
722751 case 0:
....@@ -725,7 +754,7 @@
725754 case -ECONNRESET:
726755 case -ENODEV:
727756 case -ESHUTDOWN:
728
- goto free;
757
+ goto free_skb;
729758 default:
730759 skb_reset_tail_pointer(skb);
731760 skb_trim(skb, 0);
....@@ -736,25 +765,27 @@
736765 if (likely(urb->actual_length != 0)) {
737766 skb_put(skb, urb->actual_length);
738767
739
- /* Process the command first */
768
+ /*
769
+ * Process the command first.
770
+ * skb is either freed here or passed to be
771
+ * managed to another callback function.
772
+ */
740773 ath9k_htc_rx_msg(hif_dev->htc_handle, skb,
741774 skb->len, USB_REG_IN_PIPE);
742775
743
-
744
- nskb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC);
745
- if (!nskb) {
776
+ skb = alloc_skb(MAX_REG_IN_BUF_SIZE, GFP_ATOMIC);
777
+ if (!skb) {
746778 dev_err(&hif_dev->udev->dev,
747779 "ath9k_htc: REG_IN memory allocation failure\n");
748
- urb->context = NULL;
749
- return;
780
+ goto free_rx_buf;
750781 }
751782
752
- rx_buf->skb = nskb;
783
+ rx_buf->skb = skb;
753784
754785 usb_fill_int_urb(urb, hif_dev->udev,
755786 usb_rcvintpipe(hif_dev->udev,
756787 USB_REG_IN_PIPE),
757
- nskb->data, MAX_REG_IN_BUF_SIZE,
788
+ skb->data, MAX_REG_IN_BUF_SIZE,
758789 ath9k_hif_usb_reg_in_cb, rx_buf, 1);
759790 }
760791
....@@ -763,12 +794,13 @@
763794 ret = usb_submit_urb(urb, GFP_ATOMIC);
764795 if (ret) {
765796 usb_unanchor_urb(urb);
766
- goto free;
797
+ goto free_skb;
767798 }
768799
769800 return;
770
-free:
801
+free_skb:
771802 kfree_skb(skb);
803
+free_rx_buf:
772804 kfree(rx_buf);
773805 urb->context = NULL;
774806 }
....@@ -781,14 +813,10 @@
781813 spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
782814 list_for_each_entry_safe(tx_buf, tx_buf_tmp,
783815 &hif_dev->tx.tx_buf, list) {
784
- usb_get_urb(tx_buf->urb);
785
- spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
786
- usb_kill_urb(tx_buf->urb);
787816 list_del(&tx_buf->list);
788817 usb_free_urb(tx_buf->urb);
789818 kfree(tx_buf->buf);
790819 kfree(tx_buf);
791
- spin_lock_irqsave(&hif_dev->tx.tx_lock, flags);
792820 }
793821 spin_unlock_irqrestore(&hif_dev->tx.tx_lock, flags);
794822
....@@ -858,6 +886,7 @@
858886 static void ath9k_hif_usb_dealloc_rx_urbs(struct hif_device_usb *hif_dev)
859887 {
860888 usb_kill_anchored_urbs(&hif_dev->rx_submitted);
889
+ ath9k_hif_usb_free_rx_remain_skb(hif_dev);
861890 }
862891
863892 static int ath9k_hif_usb_alloc_rx_urbs(struct hif_device_usb *hif_dev)
....@@ -1330,9 +1359,23 @@
13301359 static int ath9k_hif_usb_probe(struct usb_interface *interface,
13311360 const struct usb_device_id *id)
13321361 {
1362
+ struct usb_endpoint_descriptor *bulk_in, *bulk_out, *int_in, *int_out;
13331363 struct usb_device *udev = interface_to_usbdev(interface);
1364
+ struct usb_host_interface *alt;
13341365 struct hif_device_usb *hif_dev;
13351366 int ret = 0;
1367
+
1368
+ /* Verify the expected endpoints are present */
1369
+ alt = interface->cur_altsetting;
1370
+ if (usb_find_common_endpoints(alt, &bulk_in, &bulk_out, &int_in, &int_out) < 0 ||
1371
+ usb_endpoint_num(bulk_in) != USB_WLAN_RX_PIPE ||
1372
+ usb_endpoint_num(bulk_out) != USB_WLAN_TX_PIPE ||
1373
+ usb_endpoint_num(int_in) != USB_REG_IN_PIPE ||
1374
+ usb_endpoint_num(int_out) != USB_REG_OUT_PIPE) {
1375
+ dev_err(&udev->dev,
1376
+ "ath9k_htc: Device endpoint numbers are not the expected ones\n");
1377
+ return -ENODEV;
1378
+ }
13361379
13371380 if (id->driver_info == STORAGE_DEVICE)
13381381 return send_eject_command(interface);
....@@ -1400,8 +1443,6 @@
14001443
14011444 if (hif_dev->flags & HIF_USB_READY) {
14021445 ath9k_htc_hw_deinit(hif_dev->htc_handle, unplugged);
1403
- ath9k_hif_usb_dev_deinit(hif_dev);
1404
- ath9k_destroy_wmi(hif_dev->htc_handle->drv_priv);
14051446 ath9k_htc_hw_free(hif_dev->htc_handle);
14061447 }
14071448