FreeBSD/sys/dev/cxgbe/t4_main.c
/*
 * Partition chip resources for use between various PFs, VFs, etc.
 */
Partition chip resources for use between various PFs, VFs, etc.
Partition chip resources for use between various PFs VFs etc .
static int
partition_resources(struct adapter *sc, const struct firmware *default_cfg,
    const char *name_prefix)
{
	const struct firmware *cfg = NULL;
	int rc = 0;
	struct fw_caps_config_cmd caps;
	uint32_t mtype, moff, finicsum, cfcsum;
	snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", t4_cfg_file);
	if (strncmp(t4_cfg_file, DEFAULT_CF, sizeof(t4_cfg_file)) == 0) {
		if (pci_get_device(sc->dev) == 0x440a)
			snprintf(sc->cfg_file, sizeof(sc->cfg_file), UWIRE_CF);
		if (is_fpga(sc))
			snprintf(sc->cfg_file, sizeof(sc->cfg_file), FPGA_CF);
	}
	if (strncmp(sc->cfg_file, DEFAULT_CF, sizeof(sc->cfg_file)) != 0 &&
	    strncmp(sc->cfg_file, FLASH_CF, sizeof(sc->cfg_file)) != 0) {
		char s[32];
		snprintf(s, sizeof(s), "%s_%s", name_prefix, sc->cfg_file);
		cfg = firmware_get(s);
		if (cfg == NULL) {
			if (default_cfg != NULL) {
				device_printf(sc->dev,
				    "unable to load module \"%s\" for "
				    "configuration profile \"%s\", will use "
				    "the default config file instead.\n",
				    s, sc->cfg_file);
				snprintf(sc->cfg_file, sizeof(sc->cfg_file),
				    "%s", DEFAULT_CF);
			} else {
				device_printf(sc->dev,
				    "unable to load module \"%s\" for "
				    "configuration profile \"%s\", will use "
				    "the config file on the card's flash "
				    "instead.\n", s, sc->cfg_file);
				snprintf(sc->cfg_file, sizeof(sc->cfg_file),
				    "%s", FLASH_CF);
			}
		}
	}
	if (strncmp(sc->cfg_file, DEFAULT_CF, sizeof(sc->cfg_file)) == 0 &&
	    default_cfg == NULL) {
		device_printf(sc->dev,
		    "default config file not available, will use the config "
		    "file on the card's flash instead.\n");
		snprintf(sc->cfg_file, sizeof(sc->cfg_file), "%s", FLASH_CF);
	}
	if (strncmp(sc->cfg_file, FLASH_CF, sizeof(sc->cfg_file)) != 0) {
		u_int cflen;
		const uint32_t *cfdata;
		uint32_t param, val, addr;
		KASSERT(cfg != NULL || default_cfg != NULL,
		    ("%s: no config to upload", __func__));
		param = FW_PARAM_DEV(CF);
		rc = -t4_query_params(sc, sc->mbox, sc->pf, 0, 1, &param, &val);
		if (rc != 0) {
			device_printf(sc->dev,
			    "failed to query config file location: %d.\n", rc);
			goto done;
		}
		mtype = G_FW_PARAMS_PARAM_Y(val);
		moff = G_FW_PARAMS_PARAM_Z(val) << 16;
		if (cfg != NULL) {
			cflen = cfg->datasize & ~3;
			cfdata = cfg->data;
		} else {
			cflen = default_cfg->datasize & ~3;
			cfdata = default_cfg->data;
		}
		if (cflen > FLASH_CFG_MAX_SIZE) {
			device_printf(sc->dev,
			    "config file too long (%d, max allowed is %d).  "
			    "Will try to use the config on the card, if any.\n",
			    cflen, FLASH_CFG_MAX_SIZE);
			goto use_config_on_flash;
		}
		rc = validate_mt_off_len(sc, mtype, moff, cflen, &addr);
		if (rc != 0) {
			device_printf(sc->dev,
			    "%s: addr (%d/0x%x) or len %d is not valid: %d.  "
			    "Will try to use the config on the card, if any.\n",
			    __func__, mtype, moff, cflen, rc);
			goto use_config_on_flash;
		}
		write_via_memwin(sc, 2, addr, cfdata, cflen);
	} else {
use_config_on_flash:
		mtype = FW_MEMTYPE_FLASH;
		moff = t4_flash_cfg_addr(sc);
	}
	bzero(&caps, sizeof(caps));
	caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
	    F_FW_CMD_REQUEST | F_FW_CMD_READ);
	caps.cfvalid_to_len16 = htobe32(F_FW_CAPS_CONFIG_CMD_CFVALID |
	    V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF(mtype) |
	    V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF(moff >> 16) | FW_LEN16(caps));
	rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), &caps);
	if (rc != 0) {
		device_printf(sc->dev,
		    "failed to pre-process config file: %d "
		    "(mtype %d, moff 0x%x).\n", rc, mtype, moff);
		goto done;
	}
	finicsum = be32toh(caps.finicsum);
	cfcsum = be32toh(caps.cfcsum);
	if (finicsum != cfcsum) {
		device_printf(sc->dev,
		    "WARNING: config file checksum mismatch: %08x %08x\n",
		    finicsum, cfcsum);
	}
	sc->cfcsum = cfcsum;
#define LIMIT_CAPS(x) do { \
	caps.x &= htobe16(t4_##x##_allowed); \
} while (0)
	LIMIT_CAPS(nbmcaps);
	LIMIT_CAPS(linkcaps);
	LIMIT_CAPS(switchcaps);
	LIMIT_CAPS(niccaps);
	LIMIT_CAPS(toecaps);
	LIMIT_CAPS(rdmacaps);
	LIMIT_CAPS(tlscaps);
	LIMIT_CAPS(iscsicaps);
	LIMIT_CAPS(fcoecaps);
#undef LIMIT_CAPS
	caps.op_to_write = htobe32(V_FW_CMD_OP(FW_CAPS_CONFIG_CMD) |
	    F_FW_CMD_REQUEST | F_FW_CMD_WRITE);
	caps.cfvalid_to_len16 = htobe32(FW_LEN16(caps));
	rc = -t4_wr_mbox(sc, sc->mbox, &caps, sizeof(caps), NULL);
	if (rc != 0) {
		device_printf(sc->dev,
		    "failed to process config file: %d.\n", rc);
	}
done:
	if (cfg != NULL)
		firmware_put(cfg, FIRMWARE_UNLOAD);
	return (rc);
}
static int partition_resources ( struct adapter * sc , const struct firmware * default_cfg , const char * name_prefix ) { const struct firmware * cfg = NULL ; int rc = 0 ; struct fw_caps_config_cmd caps ; uint32_t mtype , moff , finicsum , cfcsum ; snprintf ( sc -> cfg_file , sizeof ( sc -> cfg_file ) , " " , t4_cfg_file ) ; if ( strncmp ( t4_cfg_file , DEFAULT_CF , sizeof ( t4_cfg_file ) ) == 0 ) { if ( pci_get_device ( sc -> dev ) == 0x440a ) snprintf ( sc -> cfg_file , sizeof ( sc -> cfg_file ) , UWIRE_CF ) ; if ( is_fpga ( sc ) ) snprintf ( sc -> cfg_file , sizeof ( sc -> cfg_file ) , FPGA_CF ) ; } if ( strncmp ( sc -> cfg_file , DEFAULT_CF , sizeof ( sc -> cfg_file ) ) != 0 && strncmp ( sc -> cfg_file , FLASH_CF , sizeof ( sc -> cfg_file ) ) != 0 ) { char s [ 32 ] ; snprintf ( s , sizeof ( s ) , " " , name_prefix , sc -> cfg_file ) ; cfg = firmware_get ( s ) ; if ( cfg == NULL ) { if ( default_cfg != NULL ) { device_printf ( sc -> dev , " \" \" " " \" \" " " \n " , s , sc -> cfg_file ) ; snprintf ( sc -> cfg_file , sizeof ( sc -> cfg_file ) , " " , DEFAULT_CF ) ; } else { device_printf ( sc -> dev , " \" \" " " \" \" " " " " \n " , s , sc -> cfg_file ) ; snprintf ( sc -> cfg_file , sizeof ( sc -> cfg_file ) , " " , FLASH_CF ) ; } } } if ( strncmp ( sc -> cfg_file , DEFAULT_CF , sizeof ( sc -> cfg_file ) ) == 0 && default_cfg == NULL ) { device_printf ( sc -> dev , " " " \n " ) ; snprintf ( sc -> cfg_file , sizeof ( sc -> cfg_file ) , " " , FLASH_CF ) ; } if ( strncmp ( sc -> cfg_file , FLASH_CF , sizeof ( sc -> cfg_file ) ) != 0 ) { u_int cflen ; const uint32_t * cfdata ; uint32_t param , val , addr ; KASSERT ( cfg != NULL || default_cfg != NULL , ( " " , __func__ ) ) ; param = FW_PARAM_DEV ( CF ) ; rc = - t4_query_params ( sc , sc -> mbox , sc -> pf , 0 , 1 , & param , & val ) ; if ( rc != 0 ) { device_printf ( sc -> dev , " \n " , rc ) ; goto done ; } mtype = G_FW_PARAMS_PARAM_Y ( val ) ; moff = G_FW_PARAMS_PARAM_Z ( val ) << 16 ; if ( cfg != NULL ) { cflen = cfg -> datasize & ~ 3 ; cfdata = cfg -> data ; } else { cflen = default_cfg -> datasize & ~ 3 ; cfdata = default_cfg -> data ; } if ( cflen > FLASH_CFG_MAX_SIZE ) { device_printf ( sc -> dev , " " " \n " , cflen , FLASH_CFG_MAX_SIZE ) ; goto use_config_on_flash ; } rc = validate_mt_off_len ( sc , mtype , moff , cflen , & addr ) ; if ( rc != 0 ) { device_printf ( sc -> dev , " " " \n " , __func__ , mtype , moff , cflen , rc ) ; goto use_config_on_flash ; } write_via_memwin ( sc , 2 , addr , cfdata , cflen ) ; } else { use_config_on_flash : mtype = FW_MEMTYPE_FLASH ; moff = t4_flash_cfg_addr ( sc ) ; } bzero ( & caps , sizeof ( caps ) ) ; caps . op_to_write = htobe32 ( V_FW_CMD_OP ( FW_CAPS_CONFIG_CMD ) | F_FW_CMD_REQUEST | F_FW_CMD_READ ) ; caps . cfvalid_to_len16 = htobe32 ( F_FW_CAPS_CONFIG_CMD_CFVALID | V_FW_CAPS_CONFIG_CMD_MEMTYPE_CF ( mtype ) | V_FW_CAPS_CONFIG_CMD_MEMADDR64K_CF ( moff >> 16 ) | FW_LEN16 ( caps ) ) ; rc = - t4_wr_mbox ( sc , sc -> mbox , & caps , sizeof ( caps ) , & caps ) ; if ( rc != 0 ) { device_printf ( sc -> dev , " " " \n " , rc , mtype , moff ) ; goto done ; } finicsum = be32toh ( caps . finicsum ) ; cfcsum = be32toh ( caps . cfcsum ) ; if ( finicsum != cfcsum ) { device_printf ( sc -> dev , " \n " , finicsum , cfcsum ) ; } sc -> cfcsum = cfcsum ; #define LIMIT_CAPS ( x )  do { \
	caps.x &= htobe16(t4_##x##_allowed); \
} while (0) LIMIT_CAPS ( nbmcaps ) ; LIMIT_CAPS ( linkcaps ) ; LIMIT_CAPS ( switchcaps ) ; LIMIT_CAPS ( niccaps ) ; LIMIT_CAPS ( toecaps ) ; LIMIT_CAPS ( rdmacaps ) ; LIMIT_CAPS ( tlscaps ) ; LIMIT_CAPS ( iscsicaps ) ; LIMIT_CAPS ( fcoecaps ) ; #undef  LIMIT_CAPS caps . op_to_write = htobe32 ( V_FW_CMD_OP ( FW_CAPS_CONFIG_CMD ) | F_FW_CMD_REQUEST | F_FW_CMD_WRITE ) ; caps . cfvalid_to_len16 = htobe32 ( FW_LEN16 ( caps ) ) ; rc = - t4_wr_mbox ( sc , sc -> mbox , & caps , sizeof ( caps ) , NULL ) ; if ( rc != 0 ) { device_printf ( sc -> dev , " \n " , rc ) ; } done : if ( cfg != NULL ) firmware_put ( cfg , FIRMWARE_UNLOAD ) ; return ( rc ) ; }
Partition chip resources for use between various PFs, VFs, etc.
Partition chip resources for use between various PFs VFs etc .
/*
	 * Figure out what configuration file to use.  Pick the default config
	 * file for the card if the user hasn't specified one explicitly.
	 */ /* Card specific overrides go here. */ /*
	 * We need to load another module if the profile is anything except
	 * "default" or "flash".
	 */ /*
		 * Ask the firmware where it wants us to upload the config file.
		 */ /* No support for config file?  Shouldn't happen. */ /*
		 * XXX: sheer laziness.  We deliberately added 4 bytes of
		 * useless stuffing/comments at the end of the config file so
		 * it's ok to simply throw away the last remaining bytes when
		 * the config file is not an exact multiple of 4.  This also
		 * helps with the validate_mt_off_len check.
		 */ /*
	 * Let the firmware know what features will (not) be used so it can tune
	 * things accordingly.
	 */