44
/* table of firmware file names */
45
static const struct lbs_fw_table fw_table[] = {
46
{ MODEL_8388, "libertas/usb8388_olpc.bin", NULL },
47
{ MODEL_8388, "libertas/usb8388_v9.bin", NULL },
48
{ MODEL_8388, "libertas/usb8388_v5.bin", NULL },
49
{ MODEL_8388, "libertas/usb8388.bin", NULL },
50
{ MODEL_8388, "usb8388.bin", NULL },
51
{ MODEL_8682, "libertas/usb8682.bin", NULL }
47
54
static struct usb_device_id if_usb_table[] = {
48
55
/* Enter the device signature inside */
49
56
{ USB_DEVICE(0x1286, 0x2001), .driver_info = MODEL_8388 },
56
63
static void if_usb_receive(struct urb *urb);
57
64
static void if_usb_receive_fwload(struct urb *urb);
58
static int __if_usb_prog_firmware(struct if_usb_card *cardp,
59
const char *fwname, int cmd);
60
static int if_usb_prog_firmware(struct if_usb_card *cardp,
61
const char *fwname, int cmd);
65
static void if_usb_prog_firmware(struct lbs_private *priv, int ret,
66
const struct firmware *fw,
67
const struct firmware *unused);
62
68
static int if_usb_host_to_card(struct lbs_private *priv, uint8_t type,
63
69
uint8_t *payload, uint16_t nb);
64
70
static int usb_tx_block(struct if_usb_card *cardp, uint8_t *payload,
67
73
static int if_usb_submit_rx_urb(struct if_usb_card *cardp);
68
74
static int if_usb_reset_device(struct if_usb_card *cardp);
73
* Set function to write firmware to device's persistent memory
75
static ssize_t if_usb_firmware_set(struct device *dev,
76
struct device_attribute *attr, const char *buf, size_t count)
78
struct lbs_private *priv = to_net_dev(dev)->ml_priv;
79
struct if_usb_card *cardp = priv->card;
84
ret = if_usb_prog_firmware(cardp, buf, BOOT_CMD_UPDATE_FW);
92
* lbs_flash_fw attribute to be exported per ethX interface through sysfs
93
* (/sys/class/net/ethX/lbs_flash_fw). Use this like so to write firmware to
94
* the device's persistent memory:
95
* echo usb8388-5.126.0.p5.bin > /sys/class/net/ethX/lbs_flash_fw
97
static DEVICE_ATTR(lbs_flash_fw, 0200, NULL, if_usb_firmware_set);
100
* if_usb_boot2_set - write firmware to device's persistent memory
102
* @dev: target device
103
* @attr: device attributes
104
* @buf: firmware buffer to write
105
* @count: number of bytes to write
107
* returns: number of bytes written or negative error code
109
static ssize_t if_usb_boot2_set(struct device *dev,
110
struct device_attribute *attr, const char *buf, size_t count)
112
struct lbs_private *priv = to_net_dev(dev)->ml_priv;
113
struct if_usb_card *cardp = priv->card;
118
ret = if_usb_prog_firmware(cardp, buf, BOOT_CMD_UPDATE_BOOT2);
126
* lbs_flash_boot2 attribute to be exported per ethX interface through sysfs
127
* (/sys/class/net/ethX/lbs_flash_boot2). Use this like so to write firmware
128
* to the device's persistent memory:
129
* echo usb8388-5.126.0.p5.bin > /sys/class/net/ethX/lbs_flash_boot2
131
static DEVICE_ATTR(lbs_flash_boot2, 0200, NULL, if_usb_boot2_set);
134
77
* if_usb_write_bulk_callback - callback function to handle the status
340
274
cardp->boot2_version = udev->descriptor.bcdDevice;
342
if_usb_submit_rx_urb(cardp);
344
if (lbs_start_card(priv))
347
if_usb_setup_firmware(priv);
349
276
usb_get_dev(udev);
350
277
usb_set_intfdata(intf, cardp);
352
if (device_create_file(&priv->dev->dev, &dev_attr_lbs_flash_fw))
353
netdev_err(priv->dev,
354
"cannot register lbs_flash_fw attribute\n");
356
if (device_create_file(&priv->dev->dev, &dev_attr_lbs_flash_boot2))
357
netdev_err(priv->dev,
358
"cannot register lbs_flash_boot2 attribute\n");
361
* EHS_REMOVE_WAKEUP is not supported on all versions of the firmware.
363
priv->wol_criteria = EHS_REMOVE_WAKEUP;
364
if (lbs_host_sleep_cfg(priv, priv->wol_criteria, NULL))
365
priv->ehs_remove_supported = false;
279
r = lbs_get_firmware_async(priv, &udev->dev, cardp->model,
280
fw_table, if_usb_prog_firmware);
370
287
lbs_remove_card(priv);
372
289
if_usb_reset_device(cardp);
374
291
if_usb_free(cardp);
917
* if_usb_prog_firmware - programs the firmware subject to cmd
919
* @cardp: the if_usb_card descriptor
920
* @fwname: firmware or boot2 image file name
921
* @cmd: either BOOT_CMD_FW_BY_USB, BOOT_CMD_UPDATE_FW,
922
* or BOOT_CMD_UPDATE_BOOT2.
923
* returns: 0 or error code
925
static int if_usb_prog_firmware(struct if_usb_card *cardp,
926
const char *fwname, int cmd)
928
struct lbs_private *priv = cardp->priv;
929
unsigned long flags, caps;
932
caps = priv->fwcapinfo;
933
if (((cmd == BOOT_CMD_UPDATE_FW) && !(caps & FW_CAPINFO_FIRMWARE_UPGRADE)) ||
934
((cmd == BOOT_CMD_UPDATE_BOOT2) && !(caps & FW_CAPINFO_BOOT2_UPGRADE)))
937
/* Ensure main thread is idle. */
938
spin_lock_irqsave(&priv->driver_lock, flags);
939
while (priv->cur_cmd != NULL || priv->dnld_sent != DNLD_RES_RECEIVED) {
940
spin_unlock_irqrestore(&priv->driver_lock, flags);
941
if (wait_event_interruptible(priv->waitq,
942
(priv->cur_cmd == NULL &&
943
priv->dnld_sent == DNLD_RES_RECEIVED))) {
946
spin_lock_irqsave(&priv->driver_lock, flags);
948
priv->dnld_sent = DNLD_BOOTCMD_SENT;
949
spin_unlock_irqrestore(&priv->driver_lock, flags);
951
ret = __if_usb_prog_firmware(cardp, fwname, cmd);
953
spin_lock_irqsave(&priv->driver_lock, flags);
954
priv->dnld_sent = DNLD_RES_RECEIVED;
955
spin_unlock_irqrestore(&priv->driver_lock, flags);
957
wake_up(&priv->waitq);
962
/* table of firmware file names */
963
static const struct {
967
{ MODEL_8388, "libertas/usb8388_v9.bin" },
968
{ MODEL_8388, "libertas/usb8388_v5.bin" },
969
{ MODEL_8388, "libertas/usb8388.bin" },
970
{ MODEL_8388, "usb8388.bin" },
971
{ MODEL_8682, "libertas/usb8682.bin" }
976
static int try_olpc_fw(struct if_usb_card *cardp)
978
int retval = -ENOENT;
980
/* try the OLPC firmware first; fall back to fw_table list */
981
if (machine_is_olpc() && cardp->model == MODEL_8388)
982
retval = request_firmware(&cardp->fw,
983
"libertas/usb8388_olpc.bin", &cardp->udev->dev);
988
static int try_olpc_fw(struct if_usb_card *cardp) { return -ENOENT; }
989
#endif /* !CONFIG_OLPC */
991
static int get_fw(struct if_usb_card *cardp, const char *fwname)
995
/* Try user-specified firmware first */
997
return request_firmware(&cardp->fw, fwname, &cardp->udev->dev);
999
/* Handle OLPC firmware */
1000
if (try_olpc_fw(cardp) == 0)
1003
/* Otherwise search for firmware to use */
1004
for (i = 0; i < ARRAY_SIZE(fw_table); i++) {
1005
if (fw_table[i].model != cardp->model)
1007
if (request_firmware(&cardp->fw, fw_table[i].fwname,
1008
&cardp->udev->dev) == 0)
1015
static int __if_usb_prog_firmware(struct if_usb_card *cardp,
1016
const char *fwname, int cmd)
829
static void if_usb_prog_firmware(struct lbs_private *priv, int ret,
830
const struct firmware *fw,
831
const struct firmware *unused)
833
struct if_usb_card *cardp = priv->card;
1019
835
static int reset_count = 10;
1022
837
lbs_deb_enter(LBS_DEB_USB);
1024
ret = get_fw(cardp, fwname);
1026
840
pr_err("failed to find firmware (%d)\n", ret);
1030
845
if (check_fwfile_format(cardp->fw->data, cardp->fw->size)) {
1032
847
goto release_fw;
1109
924
goto release_fw;
927
cardp->priv->fw_ready = 1;
928
if_usb_submit_rx_urb(cardp);
930
if (lbs_start_card(priv))
933
if_usb_setup_firmware(priv);
936
* EHS_REMOVE_WAKEUP is not supported on all versions of the firmware.
938
priv->wol_criteria = EHS_REMOVE_WAKEUP;
939
if (lbs_host_sleep_cfg(priv, priv->wol_criteria, NULL))
940
priv->ehs_remove_supported = false;
1113
943
release_firmware(cardp->fw);
1114
944
cardp->fw = NULL;
1117
lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
947
lbs_deb_leave(LBS_DEB_USB);