forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/net/wireless/marvell/libertas_tf/if_usb.c
....@@ -1,11 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2008, cozybit Inc.
34 * Copyright (C) 2003-2006, Marvell International Ltd.
4
- *
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 (at
8
- * your option) any later version.
95 */
106 #define DRV_NAME "lbtf_usb"
117
....@@ -42,19 +38,19 @@
4238
4339 static void if_usb_receive(struct urb *urb);
4440 static void if_usb_receive_fwload(struct urb *urb);
45
-static int if_usb_prog_firmware(struct if_usb_card *cardp);
41
+static int if_usb_prog_firmware(struct lbtf_private *priv);
4642 static int if_usb_host_to_card(struct lbtf_private *priv, uint8_t type,
4743 uint8_t *payload, uint16_t nb);
4844 static int usb_tx_block(struct if_usb_card *cardp, uint8_t *payload,
4945 uint16_t nb, u8 data);
5046 static void if_usb_free(struct if_usb_card *cardp);
5147 static int if_usb_submit_rx_urb(struct if_usb_card *cardp);
52
-static int if_usb_reset_device(struct if_usb_card *cardp);
48
+static int if_usb_reset_device(struct lbtf_private *priv);
5349
5450 /**
5551 * if_usb_wrike_bulk_callback - call back to handle URB status
5652 *
57
- * @param urb pointer to urb structure
53
+ * @urb: pointer to urb structure
5854 */
5955 static void if_usb_write_bulk_callback(struct urb *urb)
6056 {
....@@ -71,7 +67,7 @@
7167 /**
7268 * if_usb_free - free tx/rx urb, skb and rx buffer
7369 *
74
- * @param cardp pointer if_usb_card
70
+ * @cardp: pointer if_usb_card
7571 */
7672 static void if_usb_free(struct if_usb_card *cardp)
7773 {
....@@ -131,11 +127,17 @@
131127 lbtf_deb_leave(LBTF_DEB_USB);
132128 }
133129
130
+static const struct lbtf_ops if_usb_ops = {
131
+ .hw_host_to_card = if_usb_host_to_card,
132
+ .hw_prog_firmware = if_usb_prog_firmware,
133
+ .hw_reset_device = if_usb_reset_device,
134
+};
135
+
134136 /**
135137 * if_usb_probe - sets the configuration values
136138 *
137
- * @ifnum interface number
138
- * @id pointer to usb_device_id
139
+ * @intf: USB interface structure
140
+ * @id: pointer to usb_device_id
139141 *
140142 * Returns: 0 on success, error code on failure
141143 */
....@@ -216,16 +218,10 @@
216218 goto dealloc;
217219 }
218220
219
- priv = lbtf_add_card(cardp, &udev->dev);
221
+ cardp->boot2_version = udev->descriptor.bcdDevice;
222
+ priv = lbtf_add_card(cardp, &udev->dev, &if_usb_ops);
220223 if (!priv)
221224 goto dealloc;
222
-
223
- cardp->priv = priv;
224
-
225
- priv->hw_host_to_card = if_usb_host_to_card;
226
- priv->hw_prog_firmware = if_usb_prog_firmware;
227
- priv->hw_reset_device = if_usb_reset_device;
228
- cardp->boot2_version = udev->descriptor.bcdDevice;
229225
230226 usb_get_dev(udev);
231227 usb_set_intfdata(intf, cardp);
....@@ -243,7 +239,7 @@
243239 /**
244240 * if_usb_disconnect - free resource and cleanup
245241 *
246
- * @intf USB interface structure
242
+ * @intf: USB interface structure
247243 */
248244 static void if_usb_disconnect(struct usb_interface *intf)
249245 {
....@@ -252,10 +248,10 @@
252248
253249 lbtf_deb_enter(LBTF_DEB_MAIN);
254250
255
- if_usb_reset_device(cardp);
256
-
257
- if (priv)
251
+ if (priv) {
252
+ if_usb_reset_device(priv);
258253 lbtf_remove_card(priv);
254
+ }
259255
260256 /* Unlink and free urb */
261257 if_usb_free(cardp);
....@@ -270,7 +266,7 @@
270266 /**
271267 * if_usb_send_fw_pkt - This function downloads the FW
272268 *
273
- * @priv pointer to struct lbtf_private
269
+ * @cardp: pointer if_usb_card
274270 *
275271 * Returns: 0
276272 */
....@@ -321,7 +317,7 @@
321317 } else if (fwdata->hdr.dnldcmd == cpu_to_le32(FW_HAS_LAST_BLOCK)) {
322318 lbtf_deb_usb2(&cardp->udev->dev,
323319 "Host has finished FW downloading\n");
324
- lbtf_deb_usb2(&cardp->udev->dev, "Donwloading FW JUMP BLOCK\n");
320
+ lbtf_deb_usb2(&cardp->udev->dev, "Downloading FW JUMP BLOCK\n");
325321
326322 /* Host has finished FW downloading
327323 * Donwloading FW JUMP BLOCK
....@@ -336,8 +332,9 @@
336332 return 0;
337333 }
338334
339
-static int if_usb_reset_device(struct if_usb_card *cardp)
335
+static int if_usb_reset_device(struct lbtf_private *priv)
340336 {
337
+ struct if_usb_card *cardp = priv->card;
341338 struct cmd_ds_802_11_reset *cmd = cardp->ep_out_buf + 4;
342339 int ret;
343340
....@@ -365,10 +362,10 @@
365362 /**
366363 * usb_tx_block - transfer data to the device
367364 *
368
- * @priv pointer to struct lbtf_private
369
- * @payload pointer to payload data
370
- * @nb data length
371
- * @data non-zero for data, zero for commands
365
+ * @cardp: pointer if_usb_card
366
+ * @payload: pointer to payload data
367
+ * @nb: data length
368
+ * @data: non-zero for data, zero for commands
372369 *
373370 * Returns: 0 on success, nonzero otherwise.
374371 */
....@@ -616,7 +613,7 @@
616613 spin_lock_irqsave(&priv->driver_lock, flags);
617614 memcpy(priv->cmd_resp_buff, recvbuff + MESSAGE_HEADER_LEN,
618615 recvlength - MESSAGE_HEADER_LEN);
619
- kfree_skb(skb);
616
+ dev_kfree_skb_irq(skb);
620617 lbtf_cmd_response_rx(priv);
621618 spin_unlock_irqrestore(&priv->driver_lock, flags);
622619 }
....@@ -624,7 +621,7 @@
624621 /**
625622 * if_usb_receive - read data received from the device.
626623 *
627
- * @urb pointer to struct urb
624
+ * @urb: pointer to struct urb
628625 */
629626 static void if_usb_receive(struct urb *urb)
630627 {
....@@ -707,10 +704,10 @@
707704 /**
708705 * if_usb_host_to_card - Download data to the device
709706 *
710
- * @priv pointer to struct lbtf_private structure
711
- * @type type of data
712
- * @buf pointer to data buffer
713
- * @len number of bytes
707
+ * @priv: pointer to struct lbtf_private structure
708
+ * @type: type of data
709
+ * @payload: pointer to payload buffer
710
+ * @nb: number of bytes
714711 *
715712 * Returns: 0 on success, nonzero otherwise
716713 */
....@@ -739,7 +736,8 @@
739736 /**
740737 * if_usb_issue_boot_command - Issue boot command to Boot2.
741738 *
742
- * @ivalue 1 boots from FW by USB-Download, 2 boots from FW in EEPROM.
739
+ * @cardp: pointer if_usb_card
740
+ * @ivalue: 1 boots from FW by USB-Download, 2 boots from FW in EEPROM.
743741 *
744742 * Returns: 0
745743 */
....@@ -762,8 +760,8 @@
762760 /**
763761 * check_fwfile_format - Check the validity of Boot2/FW image.
764762 *
765
- * @data pointer to image
766
- * @totlen image length
763
+ * @data: pointer to image
764
+ * @totlen: image length
767765 *
768766 * Returns: 0 if the image is valid, nonzero otherwise.
769767 */
....@@ -808,13 +806,16 @@
808806 }
809807
810808
811
-static int if_usb_prog_firmware(struct if_usb_card *cardp)
809
+static int if_usb_prog_firmware(struct lbtf_private *priv)
812810 {
811
+ struct if_usb_card *cardp = priv->card;
813812 int i = 0;
814813 static int reset_count = 10;
815814 int ret = 0;
816815
817816 lbtf_deb_enter(LBTF_DEB_USB);
817
+
818
+ cardp->priv = priv;
818819
819820 kernel_param_lock(THIS_MODULE);
820821 ret = request_firmware(&cardp->fw, lbtf_fw_name, &cardp->udev->dev);
....@@ -851,7 +852,7 @@
851852
852853 if (cardp->bootcmdresp <= 0) {
853854 if (--reset_count >= 0) {
854
- if_usb_reset_device(cardp);
855
+ if_usb_reset_device(priv);
855856 goto restart;
856857 }
857858 return -1;
....@@ -880,7 +881,7 @@
880881 if (!cardp->fwdnldover) {
881882 pr_info("failed to load fw, resetting device!\n");
882883 if (--reset_count >= 0) {
883
- if_usb_reset_device(cardp);
884
+ if_usb_reset_device(priv);
884885 goto restart;
885886 }
886887
....@@ -888,8 +889,6 @@
888889 ret = -1;
889890 goto release_fw;
890891 }
891
-
892
- cardp->priv->fw_ready = 1;
893892
894893 release_fw:
895894 release_firmware(cardp->fw);