src/dpdk/drivers/net/cxgbe/cxgbe_main.c
static int adap_init0_config(struct adapter *adapter, int reset)
{
	u32 finiver, finicsum, cfcsum, param, val;
	struct fw_caps_config_cmd caps_cmd;
	unsigned long mtype = 0, maddr = 0;
	u8 config_issued = 0;
	char config_name[20];
	int cfg_addr, ret;

	/*
	 * Reset device if necessary.
	 */
	if (reset) {
		ret = t4_fw_reset(adapter, adapter->mbox,
				  F_PIORSTMODE | F_PIORST);
		if (ret < 0) {
			dev_warn(adapter, "Firmware reset failed, error %d\n",
				 -ret);
			goto bye;
		}
	}

	cfg_addr = t4_flash_cfg_addr(adapter);
	if (cfg_addr < 0) {
		ret = cfg_addr;
		dev_warn(adapter, "Finding address for firmware config file in flash failed, error %d\n",
			 -ret);
		goto bye;
	}

	strcpy(config_name, "On Flash");
	mtype = FW_MEMTYPE_CF_FLASH;
	maddr = cfg_addr;

	/* Enable HASH filter region when support is available. */
	val = 1;
	param = CXGBE_FW_PARAM_DEV(HASHFILTER_WITH_OFLD);
	t4_set_params(adapter, adapter->mbox, adapter->pf, 0, 1,
		      &param, &val);

	/*
	 * Issue a Capability Configuration command to the firmware to get it
	 * to parse the Configuration File.  We don't use t4_fw_config_file()
	 * because we want the ability to modify various features after we've
	 * processed the configuration file ...
	 */
	memset(&caps_cmd, 0, sizeof(caps_cmd));
	caps_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
					   F_FW_CMD_REQUEST | F_FW_CMD_READ);
	caps_cmd.cfvalid_to_len16 =
		cpu_to_be32(F_FW_CAPS_CONFIG_CMD_CFVALID |
			    V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) |
			    V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(maddr >> 16) |
			    FW_LEN16(caps_cmd));
	ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
			 &caps_cmd);
	/*
	 * If the CAPS_CONFIG failed with an ENOENT (for a Firmware
	 * Configuration File in FLASH), our last gasp effort is to use the
	 * Firmware Configuration File which is embedded in the firmware.  A
	 * very few early versions of the firmware didn't have one embedded
	 * but we can ignore those.
	 */
	if (ret == -ENOENT) {
		dev_info(adapter, "%s: Going for embedded config in firmware..\n",
			 __func__);

		memset(&caps_cmd, 0, sizeof(caps_cmd));
		caps_cmd.op_to_write =
			cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
				    F_FW_CMD_REQUEST | F_FW_CMD_READ);
		caps_cmd.cfvalid_to_len16 = cpu_to_be32(FW_LEN16(caps_cmd));
		ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd,
				 sizeof(caps_cmd), &caps_cmd);
		strcpy(config_name, "Firmware Default");
	}

	config_issued = 1;
	if (ret < 0)
		goto bye;

	finiver = be32_to_cpu(caps_cmd.finiver);
	finicsum = be32_to_cpu(caps_cmd.finicsum);
	cfcsum = be32_to_cpu(caps_cmd.cfcsum);
	if (finicsum != cfcsum)
		dev_warn(adapter, "Configuration File checksum mismatch: [fini] csum=%#x, computed csum=%#x\n",
			 finicsum, cfcsum);

	/*
	 * If we're a pure NIC driver then disable all offloading facilities.
	 * This will allow the firmware to optimize aspects of the hardware
	 * configuration which will result in improved performance.
	 */
	caps_cmd.niccaps &= cpu_to_be16(~FW_CAPS_CONFIG_NIC_ETHOFLD);
	caps_cmd.toecaps = 0;
	caps_cmd.iscsicaps = 0;
	caps_cmd.rdmacaps = 0;
	caps_cmd.fcoecaps = 0;
	caps_cmd.cryptocaps = 0;

	/*
	 * And now tell the firmware to use the configuration we just loaded.
	 */
	caps_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
					   F_FW_CMD_REQUEST | F_FW_CMD_WRITE);
	caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
	ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
			 NULL);
	if (ret < 0) {
		dev_warn(adapter, "Unable to finalize Firmware Capabilities %d\n",
			 -ret);
		goto bye;
	}

	/*
	 * Tweak configuration based on system architecture, etc.
	 */
	ret = adap_init0_tweaks(adapter);
	if (ret < 0) {
		dev_warn(adapter, "Unable to do init0-tweaks %d\n", -ret);
		goto bye;
	}

	/*
	 * And finally tell the firmware to initialize itself using the
	 * parameters from the Configuration File.
	 */
	ret = t4_fw_initialize(adapter, adapter->mbox);
	if (ret < 0) {
		dev_warn(adapter, "Initializing Firmware failed, error %d\n",
			 -ret);
		goto bye;
	}

	/*
	 * Return successfully and note that we're operating with parameters
	 * not supplied by the driver, rather than from hard-wired
	 * initialization constants buried in the driver.
	 */
	dev_info(adapter,
		 "Successfully configured using Firmware Configuration File \"%s\", version %#x, computed checksum %#x\n",
		 config_name, finiver, cfcsum);

	return 0;

	/*
	 * Something bad happened.  Return the error ...  (If the "error"
	 * is that there's no Configuration File on the adapter we don't
	 * want to issue a warning since this is fairly common.)
	 */
bye:
	if (config_issued && ret != -ENOENT)
		dev_warn(adapter, "\"%s\" configuration file error %d\n",
			 config_name, -ret);

	dev_debug(adapter, "%s: returning ret = %d ..\n", __func__, ret);
	return ret;
}
/*
 * Attempt to initialize the adapter via a Firmware Configuration File.
 */
Attempt to initialize the adapter via a Firmware Configuration File.
Attempt to initialize the adapter via a Firmware Configuration File .
static int adap_init0_config(struct adapter *adapter, int reset)
{
	u32 finiver, finicsum, cfcsum, param, val;
	struct fw_caps_config_cmd caps_cmd;
	unsigned long mtype = 0, maddr = 0;
	u8 config_issued = 0;
	char config_name[20];
	int cfg_addr, ret;
	if (reset) {
		ret = t4_fw_reset(adapter, adapter->mbox,
				  F_PIORSTMODE | F_PIORST);
		if (ret < 0) {
			dev_warn(adapter, "Firmware reset failed, error %d\n",
				 -ret);
			goto bye;
		}
	}
	cfg_addr = t4_flash_cfg_addr(adapter);
	if (cfg_addr < 0) {
		ret = cfg_addr;
		dev_warn(adapter, "Finding address for firmware config file in flash failed, error %d\n",
			 -ret);
		goto bye;
	}
	strcpy(config_name, "On Flash");
	mtype = FW_MEMTYPE_CF_FLASH;
	maddr = cfg_addr;
	val = 1;
	param = CXGBE_FW_PARAM_DEV(HASHFILTER_WITH_OFLD);
	t4_set_params(adapter, adapter->mbox, adapter->pf, 0, 1,
		      &param, &val);
	memset(&caps_cmd, 0, sizeof(caps_cmd));
	caps_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
					   F_FW_CMD_REQUEST | F_FW_CMD_READ);
	caps_cmd.cfvalid_to_len16 =
		cpu_to_be32(F_FW_CAPS_CONFIG_CMD_CFVALID |
			    V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) |
			    V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(maddr >> 16) |
			    FW_LEN16(caps_cmd));
	ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
			 &caps_cmd);
	if (ret == -ENOENT) {
		dev_info(adapter, "%s: Going for embedded config in firmware..\n",
			 __func__);
		memset(&caps_cmd, 0, sizeof(caps_cmd));
		caps_cmd.op_to_write =
			cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
				    F_FW_CMD_REQUEST | F_FW_CMD_READ);
		caps_cmd.cfvalid_to_len16 = cpu_to_be32(FW_LEN16(caps_cmd));
		ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd,
				 sizeof(caps_cmd), &caps_cmd);
		strcpy(config_name, "Firmware Default");
	}
	config_issued = 1;
	if (ret < 0)
		goto bye;
	finiver = be32_to_cpu(caps_cmd.finiver);
	finicsum = be32_to_cpu(caps_cmd.finicsum);
	cfcsum = be32_to_cpu(caps_cmd.cfcsum);
	if (finicsum != cfcsum)
		dev_warn(adapter, "Configuration File checksum mismatch: [fini] csum=%#x, computed csum=%#x\n",
			 finicsum, cfcsum);
	caps_cmd.niccaps &= cpu_to_be16(~FW_CAPS_CONFIG_NIC_ETHOFLD);
	caps_cmd.toecaps = 0;
	caps_cmd.iscsicaps = 0;
	caps_cmd.rdmacaps = 0;
	caps_cmd.fcoecaps = 0;
	caps_cmd.cryptocaps = 0;
	caps_cmd.op_to_write = cpu_to_be32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
					   F_FW_CMD_REQUEST | F_FW_CMD_WRITE);
	caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
	ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
			 NULL);
	if (ret < 0) {
		dev_warn(adapter, "Unable to finalize Firmware Capabilities %d\n",
			 -ret);
		goto bye;
	}
	ret = adap_init0_tweaks(adapter);
	if (ret < 0) {
		dev_warn(adapter, "Unable to do init0-tweaks %d\n", -ret);
		goto bye;
	}
	ret = t4_fw_initialize(adapter, adapter->mbox);
	if (ret < 0) {
		dev_warn(adapter, "Initializing Firmware failed, error %d\n",
			 -ret);
		goto bye;
	}
	dev_info(adapter,
		 "Successfully configured using Firmware Configuration File \"%s\", version %#x, computed checksum %#x\n",
		 config_name, finiver, cfcsum);
	return 0;
bye:
	if (config_issued && ret != -ENOENT)
		dev_warn(adapter, "\"%s\" configuration file error %d\n",
			 config_name, -ret);
	dev_debug(adapter, "%s: returning ret = %d ..\n", __func__, ret);
	return ret;
}
static int adap_init0_config ( struct adapter * adapter , int reset ) { u32 finiver , finicsum , cfcsum , param , val ; struct fw_caps_config_cmd caps_cmd ; unsigned long mtype = 0 , maddr = 0 ; u8 config_issued = 0 ; char config_name [ 20 ] ; int cfg_addr , ret ; if ( reset ) { ret = t4_fw_reset ( adapter , adapter -> mbox , F_PIORSTMODE | F_PIORST ) ; if ( ret < 0 ) { dev_warn ( adapter , " \n " , - ret ) ; goto bye ; } } cfg_addr = t4_flash_cfg_addr ( adapter ) ; if ( cfg_addr < 0 ) { ret = cfg_addr ; dev_warn ( adapter , " \n " , - ret ) ; goto bye ; } strcpy ( config_name , " " ) ; mtype = FW_MEMTYPE_CF_FLASH ; maddr = cfg_addr ; val = 1 ; param = CXGBE_FW_PARAM_DEV ( HASHFILTER_WITH_OFLD ) ; t4_set_params ( adapter , adapter -> mbox , adapter -> pf , 0 , 1 , & param , & val ) ; memset ( & caps_cmd , 0 , sizeof ( caps_cmd ) ) ; caps_cmd . op_to_write = cpu_to_be32 ( V_FW_CMD_OP ( FW_CAPS_CONFIG_CMD ) | F_FW_CMD_REQUEST | F_FW_CMD_READ ) ; caps_cmd . cfvalid_to_len16 = cpu_to_be32 ( F_FW_CAPS_CONFIG_CMD_CFVALID | V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF ( mtype ) | V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF ( maddr >> 16 ) | FW_LEN16 ( caps_cmd ) ) ; ret = t4_wr_mbox ( adapter , adapter -> mbox , & caps_cmd , sizeof ( caps_cmd ) , & caps_cmd ) ; if ( ret == - ENOENT ) { dev_info ( adapter , " \n " , __func__ ) ; memset ( & caps_cmd , 0 , sizeof ( caps_cmd ) ) ; caps_cmd . op_to_write = cpu_to_be32 ( V_FW_CMD_OP ( FW_CAPS_CONFIG_CMD ) | F_FW_CMD_REQUEST | F_FW_CMD_READ ) ; caps_cmd . cfvalid_to_len16 = cpu_to_be32 ( FW_LEN16 ( caps_cmd ) ) ; ret = t4_wr_mbox ( adapter , adapter -> mbox , & caps_cmd , sizeof ( caps_cmd ) , & caps_cmd ) ; strcpy ( config_name , " " ) ; } config_issued = 1 ; if ( ret < 0 ) goto bye ; finiver = be32_to_cpu ( caps_cmd . finiver ) ; finicsum = be32_to_cpu ( caps_cmd . finicsum ) ; cfcsum = be32_to_cpu ( caps_cmd . cfcsum ) ; if ( finicsum != cfcsum ) dev_warn ( adapter , " \n " , finicsum , cfcsum ) ; caps_cmd . niccaps &= cpu_to_be16 ( ~ FW_CAPS_CONFIG_NIC_ETHOFLD ) ; caps_cmd . toecaps = 0 ; caps_cmd . iscsicaps = 0 ; caps_cmd . rdmacaps = 0 ; caps_cmd . fcoecaps = 0 ; caps_cmd . cryptocaps = 0 ; caps_cmd . op_to_write = cpu_to_be32 ( V_FW_CMD_OP ( FW_CAPS_CONFIG_CMD ) | F_FW_CMD_REQUEST | F_FW_CMD_WRITE ) ; caps_cmd . cfvalid_to_len16 = htonl ( FW_LEN16 ( caps_cmd ) ) ; ret = t4_wr_mbox ( adapter , adapter -> mbox , & caps_cmd , sizeof ( caps_cmd ) , NULL ) ; if ( ret < 0 ) { dev_warn ( adapter , " \n " , - ret ) ; goto bye ; } ret = adap_init0_tweaks ( adapter ) ; if ( ret < 0 ) { dev_warn ( adapter , " \n " , - ret ) ; goto bye ; } ret = t4_fw_initialize ( adapter , adapter -> mbox ) ; if ( ret < 0 ) { dev_warn ( adapter , " \n " , - ret ) ; goto bye ; } dev_info ( adapter , " \" \" \n " , config_name , finiver , cfcsum ) ; return 0 ; bye : if ( config_issued && ret != - ENOENT ) dev_warn ( adapter , " \" \" \n " , config_name , - ret ) ; dev_debug ( adapter , " \n " , __func__ , ret ) ; return ret ; }
Attempt to initialize the adapter via a Firmware Configuration File.
Attempt to initialize the adapter via a Firmware Configuration File .
/*
	 * Reset device if necessary.
	 */ /* Enable HASH filter region when support is available. */ /*
	 * Issue a Capability Configuration command to the firmware to get it
	 * to parse the Configuration File.  We don't use t4_fw_config_file()
	 * because we want the ability to modify various features after we've
	 * processed the configuration file ...
	 */ /*
	 * If the CAPS_CONFIG failed with an ENOENT (for a Firmware
	 * Configuration File in FLASH), our last gasp effort is to use the
	 * Firmware Configuration File which is embedded in the firmware.  A
	 * very few early versions of the firmware didn't have one embedded
	 * but we can ignore those.
	 */ /*
	 * If we're a pure NIC driver then disable all offloading facilities.
	 * This will allow the firmware to optimize aspects of the hardware
	 * configuration which will result in improved performance.
	 */ /*
	 * And now tell the firmware to use the configuration we just loaded.
	 */ /*
	 * Tweak configuration based on system architecture, etc.
	 */ /*
	 * And finally tell the firmware to initialize itself using the
	 * parameters from the Configuration File.
	 */ /*
	 * Return successfully and note that we're operating with parameters
	 * not supplied by the driver, rather than from hard-wired
	 * initialization constants buried in the driver.
	 */ /*
	 * Something bad happened.  Return the error ...  (If the "error"
	 * is that there's no Configuration File on the adapter we don't
	 * want to issue a warning since this is fairly common.)
	 */