Re: [PATCH] [v11] wireless: Initial driver submission for pureLiFi STA devices

From: Kalle Valo
Date: Sat Dec 19 2020 - 08:15:41 EST


Srinivasan Raju <srini.raju@xxxxxxxxxxxx> writes:

> This introduces the pureLiFi LiFi driver for LiFi-X, LiFi-XC
> and LiFi-XL USB devices.
>
> This driver implementation has been based on the zd1211rw driver.
>
> Driver is based on 802.11 softMAC Architecture and uses
> native 802.11 for configuration and management.
>
> The driver is compiled and tested in ARM, x86 architectures and
> compiled in powerpc architecture.
>
> Signed-off-by: Srinivasan Raju <srini.raju@xxxxxxxxxxxx>

[...]

> +int download_fpga(struct usb_interface *intf)
> +{
> + int r, actual_length;
> + int fw_data_i, blk_tran_len = 16384;
> + const char *fw_name;
> + unsigned char fpga_setting[2];
> + unsigned char *fpga_dmabuff;
> + unsigned char *fw_data;
> + unsigned char fpga_state[9];
> + struct firmware *fw = NULL;
> + struct usb_device *udev = interface_to_usbdev(intf);
> +
> + if ((le16_to_cpu(udev->descriptor.idVendor) ==
> + PURELIFI_X_VENDOR_ID_0) &&
> + (le16_to_cpu(udev->descriptor.idProduct) ==
> + PURELIFI_X_PRODUCT_ID_0)) {
> + fw_name = "purelifi/li_fi_x/LiFi-X.bin";
> + dev_info(&intf->dev, "bin file for X selected\n");
> +
> + } else if ((le16_to_cpu(udev->descriptor.idVendor)) ==
> + PURELIFI_XC_VENDOR_ID_0 &&
> + (le16_to_cpu(udev->descriptor.idProduct) ==
> + PURELIFI_XC_PRODUCT_ID_0)) {
> + fw_name = "purelifi/li_fi_x/LiFi-XC.bin";
> + dev_info(&intf->dev, "bin file for XC selected\n");
> +
> + } else {
> + r = -EINVAL;
> + goto error;
> + }
> +
> + r = request_firmware((const struct firmware **)&fw, fw_name,
> + &intf->dev);
> + if (r) {
> + dev_err(&intf->dev, "request_firmware failed (%d)\n", r);
> + goto error;
> + }
> + fpga_dmabuff = NULL;
> + fpga_dmabuff = kmalloc(2, GFP_KERNEL);
> +
> + if (!fpga_dmabuff) {
> + r = -ENOMEM;
> + goto error_free_fw;
> + }
> + send_vendor_request(udev, 0x33, fpga_dmabuff, sizeof(fpga_setting));
> + memcpy(fpga_setting, fpga_dmabuff, 2);
> + kfree(fpga_dmabuff);
> +
> + send_vendor_command(udev, 0x34, NULL, 0);

I see lots of magic numbers in the driver like 2, 0x33 and 0x34 here.
Please convert the magic numbers to proper defines explaining the
meaning. And for vendor commands you could even use enum to group them
better in .h file somewhere.

--
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches