BNX2X: loads and checks firmware
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 19 Feb 2015 16:44:01 +0000 (11:44 -0500)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 2 Mar 2015 16:59:10 +0000 (11:59 -0500)
From KFS.

kern/drivers/net/bnx2x/akaros_compat.h
kern/drivers/net/bnx2x/bnx2x_main.c
kern/kfs/lib/firmware/bnx2x/bnx2x-e1-7.10.51.0.fw [new file with mode: 0644]

index 762d91b..f01a4a4 100644 (file)
@@ -39,6 +39,7 @@
 #define likely(x) (x)
 #define UINT_MAX UINT64_MAX
 #define L1_CACHE_SHIFT (LOG2_UP(ARCH_CL_SIZE))
+#define __stringify(x...) STRINGIFY(x)
 
 /* Wanted to keep the _t variants in the code, in case that's useful in the
  * future */
@@ -589,4 +590,49 @@ static inline void *pci_resource_end(struct pci_device *dev, int bir)
        memset(bp->dev->ea, 0, Eaddrlen);
 */
 
+struct firmware {
+       const uint8_t *data;
+       size_t size;
+};
+
+/* the ignored param is a &pcidev->dev in linux, which is a struct dev.  our
+ * pcidev->dev is the "slot" */
+static inline int request_firmware(const struct firmware **fwp,
+                                   const char *file_name, uint8_t *ignored)
+{
+       struct firmware *ret_fw;
+       struct file *fw_file;
+       void *fw_data;
+       char dirname[] = "/lib/firmware/";
+       /* could dynamically allocate the min of this and some MAX */
+       char fullpath[sizeof(dirname) + strlen(file_name) + 1];
+
+       snprintf(fullpath, sizeof(fullpath), "%s%s", dirname, file_name);
+       fw_file = do_file_open(fullpath, 0, 0);
+       if (!fw_file) {
+               printk("Unable to find firmware file %s!\n", fullpath);
+               return -1;
+       }
+       fw_data = kread_whole_file(fw_file);
+       if (!fw_data) {
+               printk("Unable to load firmware file %s!\n", fullpath);
+               kref_put(&fw_file->f_kref);
+               return -1;
+       }
+       ret_fw = kmalloc(sizeof(struct firmware), KMALLOC_WAIT);
+       ret_fw->data = fw_data;
+       ret_fw->size = fw_file->f_dentry->d_inode->i_size;
+       *fwp = ret_fw;
+       kref_put(&fw_file->f_kref);
+       return 0;
+}
+
+static inline void release_firmware(const struct firmware *fw)
+{
+       if (fw) {
+               kfree((void*)fw->data);
+               kfree((void*)fw);
+       }
+}
+
 #endif /* ROS_KERN_AKAROS_COMPAT_H */
index 9527bc2..ab8c78c 100644 (file)
@@ -12918,8 +12918,6 @@ err_out:
 
 static int bnx2x_check_firmware(struct bnx2x *bp)
 {
-panic("Not implemented");
-#if 0 // AKAROS_PORT
        const struct firmware *firmware = bp->firmware;
        struct bnx2x_fw_file_hdr *fw_hdr;
        struct bnx2x_fw_file_section *sections;
@@ -12976,7 +12974,6 @@ panic("Not implemented");
        }
 
        return 0;
-#endif
 }
 
 static void be32_to_cpu_n(const uint8_t *_source, uint8_t *_target,
@@ -13056,8 +13053,6 @@ do {                                                                    \
 
 static int bnx2x_init_firmware(struct bnx2x *bp)
 {
-panic("Not implemented");
-#if 0 // AKAROS_PORT
        const char *fw_file_name;
        struct bnx2x_fw_file_hdr *fw_hdr;
        int rc;
@@ -13136,19 +13131,15 @@ request_firmware_exit:
        bp->firmware = NULL;
 
        return rc;
-#endif
 }
 
 static void bnx2x_release_firmware(struct bnx2x *bp)
 {
-panic("Not implemented");
-#if 0 // AKAROS_PORT
        kfree(bp->init_ops_offsets);
        kfree(bp->init_ops);
        kfree(bp->init_data);
        release_firmware(bp->firmware);
        bp->firmware = NULL;
-#endif
 }
 
 static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
diff --git a/kern/kfs/lib/firmware/bnx2x/bnx2x-e1-7.10.51.0.fw b/kern/kfs/lib/firmware/bnx2x/bnx2x-e1-7.10.51.0.fw
new file mode 100644 (file)
index 0000000..5b1c894
Binary files /dev/null and b/kern/kfs/lib/firmware/bnx2x/bnx2x-e1-7.10.51.0.fw differ