Skip to contentSkip to conversation

be2net: Implementation of request_firmware interface.

PATCH In review Sarveshwar Bandi 4 participants 7 messages Jul 2, 2009 – Aug 11, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 be2net: Implementation of request_firmware interface.

Please review and apply patch to net-next tree. Patch implements the request_firmware interface.

- Sarvesh

---
 drivers/net/benet/be.h      |    1 
 drivers/net/benet/be_cmds.c |   28 ++++
 drivers/net/benet/be_cmds.h |   18 +++
 drivers/net/benet/be_hw.h   |   89 ++++++++++++++
 drivers/net/benet/be_main.c |  271 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 407 insertions(+), 0 deletions(-)
drivers/net/benet/be.h +1 -0
index f703758..4f9ae46 100644
@@ -29,6 +29,7 @@ #include <linux/if_vlan.h>
 #include <linux/workqueue.h>
 #include <linux/interrupt.h>
 #include <linux/inet_lro.h>
+#include <linux/firmware.h>
 
 #include "be_hw.h"
 
drivers/net/benet/be_cmds.c +28 -0
index 583517e..acb3115 100644
@@ -1061,3 +1061,31 @@ int be_cmd_query_fw_cfg(struct be_ctrl_i
 	spin_unlock(&ctrl->mbox_lock);
 	return status;
 }
+
+int be_cmd_write_flashrom(struct be_ctrl_info *ctrl, struct be_dma_mem *cmd,
+			u32 flash_type, u32 flash_opcode, u32 buf_size)
+{
+	struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
+	struct be_cmd_write_flashrom *req = cmd->va;
+	struct be_sge *sge = nonembedded_sgl(wrb);
+	int status;
+
+	spin_lock(&ctrl->mbox_lock);
+	memset(wrb, 0, sizeof(*wrb));
+	be_wrb_hdr_prepare(wrb, cmd->size, false, 1);
+
+	be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
+		OPCODE_COMMON_WRITE_FLASHROM, cmd->size);
+	sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
+	sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
+	sge->len = cpu_to_le32(cmd->size);
+
+	req->params.op_type = cpu_to_le32(flash_type);
+	req->params.op_code = cpu_to_le32(flash_opcode);
+	req->params.data_buf_size = cpu_to_le32(buf_size);
+
+	status = be_mbox_db_ring(ctrl);
+
+	spin_unlock(&ctrl->mbox_lock);
+	return status;
+}
drivers/net/benet/be_cmds.h +18 -0
index 747626d..e2b8479 100644
@@ -117,6 +117,7 @@ #define OPCODE_COMMON_NTWK_MAC_SET			2
 #define OPCODE_COMMON_NTWK_MULTICAST_SET		3
 #define OPCODE_COMMON_NTWK_VLAN_CONFIG  		4
 #define OPCODE_COMMON_NTWK_LINK_STATUS_QUERY		5
+#define OPCODE_COMMON_WRITE_FLASHROM			7
 #define OPCODE_COMMON_CQ_CREATE				12
 #define OPCODE_COMMON_EQ_CREATE				13
 #define OPCODE_COMMON_MCC_CREATE        		21
@@ -697,6 +698,20 @@ struct be_cmd_resp_query_fw_cfg {
 	u32 rsvd[26];
 };
 
+/****************** Firmware Flash ******************/
+struct flashrom_params {
+	u32 op_code;
+	u32 op_type;
+	u32 data_buf_size;
+	u32 offset;
+	u8 data_buf[4];
+};
+
+struct be_cmd_write_flashrom {
+	struct be_cmd_req_hdr hdr;
+	struct flashrom_params params;
+};
+
 extern int be_pci_fnum_get(struct be_ctrl_info *ctrl);
 extern int be_cmd_POST(struct be_ctrl_info *ctrl);
 extern int be_cmd_mac_addr_query(struct be_ctrl_info *ctrl, u8 *mac_addr,
@@ -745,4 +760,7 @@ extern int be_cmd_set_flow_control(struc
 extern int be_cmd_get_flow_control(struct be_ctrl_info *ctrl,
 			u32 *tx_fc, u32 *rx_fc);
 extern int be_cmd_query_fw_cfg(struct be_ctrl_info *ctrl, u32 *port_num);
+extern int be_cmd_write_flashrom(struct be_ctrl_info *ctrl,
+			struct be_dma_mem *cmd, u32 flash_oper,
+			u32 flash_opcode, u32 buf_size);
 extern void be_process_mcc(struct be_ctrl_info *ctrl);
drivers/net/benet/be_hw.h +89 -0

98 lines not on this page · raw message

drivers/net/benet/be_main.c +271 -0

283 lines not on this page · raw message

Signature · 1 line
1.4.0
#1 lore raw
Quoted 2 lines · Sarveshwar Bandi

Please review and apply patch to net-next tree. Patch implements the request_firmware interface.

[...]

drivers/net/benet/be_main.c static int be_close(struct net_device *n · line 1847

Quoted 7 lines
drivers/net/benet/be_main.c +7 -0
+	/* fw ver on board matches */
+	if (!strncmp(fhdr->sign + strlen(FW_FILE_HDR_SIGN), fw_ver,
+			FW_VER_LEN))
+		goto fw_exit;
+
+	dev_info(&adapter->pdev->dev,
+		"Flashing firmware file %s\n", fw_file);

[...]

request_firmware() is really intended for loading non-persistent "firmware" that must be loaded into the device's RAM after power-on reset. It is not expected and should not be necessary that drivers automatically update firmware in flash memory. I also understand that some OEMs specifically forbid their suppliers to do this automatically in drivers.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#2 lore raw

I understand that most drivers use request_firmware() to load volatile firmware. I do see that there are other nic drivers that use this inferface to flash persistent firmware.

We have other tools for offline flashing; but there is requirement
to flash f/w through driver without having to use other proprietary tools. Since the firmware load happens only when there is a version mismatch with f/w in /lib/firmware, Users who want to avoid automatic flashing at boot time can choose not to copy the f/w file under /lib/firmware.

- Sarvesh

Quoted 26 lines · Ben Hutchings
Quoted 2 lines · Sarveshwar Bandi

Please review and apply patch to net-next tree. Patch implements the request_firmware interface.

[...]

drivers/net/benet/be_main.c static int be_close(struct net_device *n · line 1847

Quoted 7 lines
drivers/net/benet/be_main.c +7 -0
+	/* fw ver on board matches */
+	if (!strncmp(fhdr->sign + strlen(FW_FILE_HDR_SIGN), fw_ver,
+			FW_VER_LEN))
+		goto fw_exit;
+
+	dev_info(&adapter->pdev->dev,
+		"Flashing firmware file %s\n", fw_file);

[...]

request_firmware() is really intended for loading non-persistent "firmware" that must be loaded into the device's RAM after power-on reset. It is not expected and should not be necessary that drivers automatically update firmware in flash memory. I also understand that some OEMs specifically forbid their suppliers to do this automatically in drivers.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#3 lore raw
Quoted 6 lines · Sarveshwar Bandi

I understand that most drivers use request_firmware() to load volatile firmware. I do see that there are other nic drivers that use this inferface to flash persistent firmware.

We have other tools for offline flashing; but there is requirement
to flash f/w through driver without having to use other proprietary tools.

The firmware blob is proprietary and has to be distributed separately from the kernel. So does it really matter that you have to distribute a special tool as well?

(Based on requirements specified by major OEMs, I have implemented firmware update through the sfc driver (MDIO and MTD interfaces) but under the control of a separate tool.)

Quoted 3 lines

Since the firmware load happens only when there is a version mismatch with f/w in /lib/firmware, Users who want to avoid automatic flashing at boot time can choose not to copy the f/w file under /lib/firmware.

[...]

Is there a way of loading the firmware into the controller's RAM but not writing it to flash? That ought to be the default behaviour.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#4 lore raw
Quoted 16 lines · Ben Hutchings
Quoted 6 lines · Sarveshwar Bandi

I understand that most drivers use request_firmware() to load volatile firmware. I do see that there are other nic drivers that use this inferface to flash persistent firmware.

We have other tools for offline flashing; but there is requirement
to flash f/w through driver without having to use other proprietary tools.

The firmware blob is proprietary and has to be distributed separately from the kernel. So does it really matter that you have to distribute a special tool as well?

(Based on requirements specified by major OEMs, I have implemented firmware update through the sfc driver (MDIO and MTD interfaces) but under the control of a separate tool.)

Quoted 8 lines
Quoted 3 lines

Since the firmware load happens only when there is a version mismatch with f/w in /lib/firmware, Users who want to avoid automatic flashing at boot time can choose not to copy the f/w file under /lib/firmware.

[...]

Is there a way of loading the firmware into the controller's RAM but not writing it to flash? That ought to be the default behaviour.

Given that the volatile and non-volatile firmware reside in the same file, it is not possible for the driver to selectively load the intended firmware.

However, is this behavior a gating factor for this patch from being accepted?

RP

Quoted 2 lines

Ben.

Signature · 6 lines
Ram Pai
System X Device-Driver Enablement Lead
Linux Technology Center
Beaverton OR-97006
503-5783752 t/l 7753752
[email protected]
#5 lore raw
Quoted 22 lines · Ram Pai
Quoted 21 lines · Ben Hutchings
Quoted 6 lines · Sarveshwar Bandi

I understand that most drivers use request_firmware() to load volatile firmware. I do see that there are other nic drivers that use this inferface to flash persistent firmware.

We have other tools for offline flashing; but there is requirement
to flash f/w through driver without having to use other proprietary tools.

The firmware blob is proprietary and has to be distributed separately from the kernel. So does it really matter that you have to distribute a special tool as well?

(Based on requirements specified by major OEMs, I have implemented firmware update through the sfc driver (MDIO and MTD interfaces) but under the control of a separate tool.)

Quoted 3 lines

Since the firmware load happens only when there is a version mismatch with f/w in /lib/firmware, Users who want to avoid automatic flashing at boot time can choose not to copy the f/w file under /lib/firmware.

[...]

Quoted 7 lines
Quoted 3 lines

Is there a way of loading the firmware into the controller's RAM but not writing it to flash? That ought to be the default behaviour.

Given that the volatile and non-volatile firmware reside in the same file, it is not possible for the driver to selectively load the intended firmware.

Your design error is your problem.

Quoted 2 lines

However, is this behavior a gating factor for this patch from being accepted?

I'm not a gatekeeper; ask David Miller.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#6 lore raw
In reply to Ben Hutchings
Quoted 5 lines · Ben Hutchings
Quoted 4 lines · Sarveshwar Bandi

I understand that most drivers use request_firmware() to load volatile firmware. I do see that there are other nic drivers that use this inferface to flash persistent firmware.

Quoted 7 lines
Quoted 2 lines

We have other tools for offline flashing; but there is requirement
to flash f/w through driver without having to use other proprietary tools.

The firmware blob is proprietary and has to be distributed separately from the kernel. So does it really matter that you have to distribute a special tool as well?

I guess I don't share the same opinion that the binary firmware is required to be distributed separately since it is not that way today. If we get rid of all files in firmware/ that do not have source included, there will not be much left.

I applaud efforts by hardware vendors and others to submit patches that allow drivers to update their own firmware at load-time if the on-card version isn't compatible with the driver getting ready to load. If one does not want them updated, don't put the files in /lib/firmware.

Using a standard method (like using request_firmware) seems much more logical than requiring users to download and compile some vendor specific application to get new firmware. It also means that if a vendor is willing to drop a binary blob into firmware/ it's a pretty easy thing to do.

Quoted 3 lines

(Based on requirements specified by major OEMs, I have implemented firmware update through the sfc driver (MDIO and MTD interfaces) but under the control of a separate tool.)

And there are plenty of OEMs out there that complain loudly if it's not easy to move quickly from one on-card/in-memory firmware to another when changing driver versions. Trust me, I hear from them.