const mboard_eeprom_t& e300_eeprom_manager::read_mb_eeprom(void)
{
    boost::mutex::scoped_lock(_mutex);

    std::vector<boost::uint8_t> bytes;
    bytes.resize(sizeof(mb_eeprom_map_t));
    mb_eeprom_map_t *map_ptr = reinterpret_cast<mb_eeprom_map_t*>(&bytes[0]);
    memset(map_ptr, 0xff, sizeof(mb_eeprom_map_t));

    // get the old contents
    for(size_t i = 0; i < sizeof(mb_eeprom_map_t); i++)
        bytes[i] = _i2c->get_i2c_reg8(MB_ADDR, i);

    mb_eeprom_map_t &map = *map_ptr;

    _mb_eeprom["product"] = boost::lexical_cast<std::string>(
        uhd::ntohx<boost::uint16_t>(map.hw_product));
    _mb_eeprom["revision"] = boost::lexical_cast<std::string>(
        uhd::ntohx<boost::uint16_t>(map.hw_revision));
    _mb_eeprom["serial"] = _bytes_to_string(
        map.serial, MB_SERIAL_LEN);

    byte_vector_t mac_addr(map.mac_addr, map.mac_addr + 6);
    _mb_eeprom["mac-addr"] = mac_addr_t::from_bytes(mac_addr).to_string();

    _mb_eeprom["name"] = _bytes_to_string(
        map.user_name, MB_NAME_LEN);

    return _mb_eeprom;
}
Exemple #2
0
static ssize_t aoedisk_show_mac(struct gendisk * disk, char *page)
{
	struct aoedev *d = disk->private_data;

	return snprintf(page, PAGE_SIZE, "%012llx\n",
			(unsigned long long)mac_addr(d->addr));
}
static void
ataid_complete(struct aoedev *d, unsigned char *id)
{
	u64 ssize;
	u16 n;

	/* word 83: command set supported */
	n = le16_to_cpu(get_unaligned((__le16 *) &id[83<<1]));

	/* word 86: command set/feature enabled */
	n |= le16_to_cpu(get_unaligned((__le16 *) &id[86<<1]));

	if (n & (1<<10)) {	/* bit 10: LBA 48 */
		d->flags |= DEVFL_EXT;

		/* word 100: number lba48 sectors */
		ssize = le64_to_cpu(get_unaligned((__le64 *) &id[100<<1]));

		/* set as in ide-disk.c:init_idedisk_capacity */
		d->geo.cylinders = ssize;
		d->geo.cylinders /= (255 * 63);
		d->geo.heads = 255;
		d->geo.sectors = 63;
	} else {
		d->flags &= ~DEVFL_EXT;

		/* number lba28 sectors */
		ssize = le32_to_cpu(get_unaligned((__le32 *) &id[60<<1]));

		/* NOTE: obsolete in ATA 6 */
		d->geo.cylinders = le16_to_cpu(get_unaligned((__le16 *) &id[54<<1]));
		d->geo.heads = le16_to_cpu(get_unaligned((__le16 *) &id[55<<1]));
		d->geo.sectors = le16_to_cpu(get_unaligned((__le16 *) &id[56<<1]));
	}

	if (d->ssize != ssize)
		printk(KERN_INFO "aoe: %012llx e%lu.%lu v%04x has %llu sectors\n",
			(unsigned long long)mac_addr(d->addr),
			d->aoemajor, d->aoeminor,
			d->fw_ver, (long long)ssize);
	d->ssize = ssize;
	d->geo.start = 0;
	if (d->gd != NULL) {
		d->gd->capacity = ssize;
		d->flags |= DEVFL_NEWSIZE;
	} else {
		if (d->flags & DEVFL_GDALLOC) {
			printk(KERN_ERR "aoe: can't schedule work for e%lu.%lu, %s\n",
			       d->aoemajor, d->aoeminor,
			       "it's already on!  This shouldn't happen.\n");
			return;
		}
		d->flags |= DEVFL_GDALLOC;
	}
	schedule_work(&d->work);
}
Exemple #4
0
/* alloc_disk and add_disk can sleep */
void
aoeblk_gdalloc(void *vp)
{
	struct aoedev *d = vp;
	struct gendisk *gd;
	ulong flags;

	gd = alloc_disk(AOE_PARTITIONS);
	if (gd == NULL) {
		printk(KERN_ERR "aoe: aoeblk_gdalloc: cannot allocate disk "
			"structure for %ld.%ld\n", d->aoemajor, d->aoeminor);
		spin_lock_irqsave(&d->lock, flags);
		d->flags &= ~DEVFL_WORKON;
		spin_unlock_irqrestore(&d->lock, flags);
		return;
	}

	d->bufpool = mempool_create(MIN_BUFS,
				    mempool_alloc_slab, mempool_free_slab,
				    buf_pool_cache);
	if (d->bufpool == NULL) {
		printk(KERN_ERR "aoe: aoeblk_gdalloc: cannot allocate bufpool "
			"for %ld.%ld\n", d->aoemajor, d->aoeminor);
		put_disk(gd);
		spin_lock_irqsave(&d->lock, flags);
		d->flags &= ~DEVFL_WORKON;
		spin_unlock_irqrestore(&d->lock, flags);
		return;
	}

	spin_lock_irqsave(&d->lock, flags);
	blk_queue_make_request(&d->blkq, aoeblk_make_request);
	gd->major = AOE_MAJOR;
	gd->first_minor = d->sysminor * AOE_PARTITIONS;
	gd->fops = &aoe_bdops;
	gd->private_data = d;
	gd->capacity = d->ssize;
	snprintf(gd->disk_name, sizeof gd->disk_name, "etherd/e%ld.%ld",
		d->aoemajor, d->aoeminor);

	gd->queue = &d->blkq;
	d->gd = gd;
	d->flags &= ~DEVFL_WORKON;
	d->flags |= DEVFL_UP;

	spin_unlock_irqrestore(&d->lock, flags);

	add_disk(gd);
	aoedisk_add_sysfs(d);
	
	printk(KERN_INFO "aoe: %012llx e%lu.%lu v%04x has %llu "
		"sectors\n", (unsigned long long)mac_addr(d->addr),
		d->aoemajor, d->aoeminor,
		d->fw_ver, (long long)d->ssize);
}
static ssize_t aoedisk_show_mac(struct device *dev,
				struct device_attribute *attr, char *page)
{
	struct gendisk *disk = dev_to_disk(dev);
	struct aoedev *d = disk->private_data;
	struct aoetgt *t = d->targets[0];

	if (t == NULL)
		return snprintf(page, PAGE_SIZE, "none\n");
	return snprintf(page, PAGE_SIZE, "%012llx\n", mac_addr(t->addr));
}
const mboard_eeprom_t& n230_eeprom_manager::read_mb_eeprom()
{
    boost::mutex::scoped_lock lock(_mutex);

    //Read EEPROM from device
    _transact(N230_FLASH_COMM_CMD_READ_NV_DATA);
    const n230_eeprom_map_t* map_ptr = reinterpret_cast<const n230_eeprom_map_t*>(_response.data);
    const n230_eeprom_map_t& map = *map_ptr;

    uint16_t ver_major = uhd::htonx<uint16_t>(map.data_version_major);
    uint16_t ver_minor = uhd::htonx<uint16_t>(map.data_version_minor);

    _mb_eeprom["product"] = std::to_string(
        uhd::htonx<uint16_t>(map.hw_product));
    _mb_eeprom["revision"] = std::to_string(
        uhd::htonx<uint16_t>(map.hw_revision));
    //The revision_compat field does not exist in version 1.0
    //EEPROM version 1.0 will only exist on HW revision 1 so it is safe to set
    //revision_compat = revision
    if (ver_major == 1 and ver_minor == 0) {
        _mb_eeprom["revision_compat"] = _mb_eeprom["revision"];
    } else {
        _mb_eeprom["revision_compat"] = std::to_string(
            uhd::htonx<uint16_t>(map.hw_revision_compat));
    }
    _mb_eeprom["serial"] = _bytes_to_string(
        map.serial, N230_EEPROM_SERIAL_LEN);

    //Extract ethernet info
    _mb_eeprom["gateway"] = boost::asio::ip::address_v4(
        uhd::htonx<uint32_t>(map.gateway)).to_string();
    for (size_t i = 0; i < N230_MAX_NUM_ETH_PORTS; i++) {
        const std::string n(1, i+'0');
        _mb_eeprom["ip-addr"+n] = boost::asio::ip::address_v4(
            uhd::htonx<uint32_t>(map.eth_info[i].ip_addr)).to_string();
        _mb_eeprom["subnet"+n] = boost::asio::ip::address_v4(
            uhd::htonx<uint32_t>(map.eth_info[i].subnet)).to_string();
        byte_vector_t mac_addr(map.eth_info[i].mac_addr, map.eth_info[i].mac_addr + 6);
        _mb_eeprom["mac-addr"+n] = mac_addr_t::from_bytes(mac_addr).to_string();
    }

    _mb_eeprom["name"] = _bytes_to_string(
        map.user_name, N230_EEPROM_NAME_LEN);

    return _mb_eeprom;
}
Exemple #7
0
void ForceIP( char* strMAC, char* strIP, char* strSubnet, char* strGateway )
{
    VmbError_t          err             = VmbErrorSuccess;
    VmbBool_t           bIsGigE         = 0;
    VmbHandle_t         hCam            = NULL;
    unsigned long long  nMAC            = 0;
    unsigned long       nIP             = 0;
    unsigned long       nSubnet         = 0;
    unsigned long       nGateway        = 0;
    
    err = VmbStartup();                                                                                                     // Initialize the Vimba API
    PrintVimbaVersion();                                                                                                    // Print Vimba Version
    nMAC            = mac_addr( strMAC );                                                                                   // The MAC address of the camera
    nIP             = inet_addr( strIP );                                                                                   // The future IP address of the camera
    nSubnet         = inet_addr( strSubnet );                                                                               // The future subnet mask of the camera
    nGateway        = strGateway != NULL ? inet_addr( strGateway ) : 0;                                                     // A possible gateway

    if ( VmbErrorSuccess == err )
    {
        err = VmbFeatureBoolGet( gVimbaHandle, "GeVTLIsPresent", &bIsGigE );                                                // Is Vimba connected to a GigE transport layer?
        if ( VmbErrorSuccess == err )
        {
            if( bIsGigE )
            {
                if ( 0 != nMAC )
                {
                    err = VmbFeatureIntSet( gVimbaHandle, "GeVForceIPAddressMAC", nMAC );                                   // Send MAC address to TL
                    if ( VmbErrorSuccess == err )
                    {
                        err = VmbFeatureIntSet( gVimbaHandle, "GeVForceIPAddressIP", nIP );                                 // Send new IP address to TL
                        if ( VmbErrorSuccess == err )
                        {
                            err = VmbFeatureIntSet( gVimbaHandle, "GeVForceIPAddressSubnetMask", nSubnet );                 // Send new subnet mask to TL
                            if ( VmbErrorSuccess == err )
                            {
                                if( 0 != nGateway )
                                {
                                    err = VmbFeatureIntSet( gVimbaHandle, "GeVForceIPAddressGateway", nGateway );           // Send gateway address to TL
                                    if ( VmbErrorSuccess != err )
                                    {
                                        printf( "Could not prepare the gateway settings. Reason: %d\n\n", err );
                                    }
                                }

                                if ( VmbErrorSuccess == err )
                                {
                                    err = VmbFeatureCommandRun( gVimbaHandle, "GeVForceIPAddressSend" );                    // Finally execute the command to write all settings to cam
                                    if ( VmbErrorSuccess == err )
                                    {
                                        printf( "IP address successfully changed to %s (%s).\n\n", strIP, strSubnet );
                                    }
                                    else
                                    {
                                        printf( "Could not set a new IP address. Reason: %d\n\n", err );
                                    }
                                }
                            }
                            else
                            {
                                printf( "Could not prepare the subnet settings. Reason: %d\n\n", err );
                            }
                        }
                        else
                        {
                            printf( "Could not prepare the IP address settings. Reason: %d\n\n", err );
                        }
                    }
                    else
                    {
                        printf( "Could not prepare the MAC address settings. Reason: %d\n\n", err );
                    }
                }
                else
                {
                    printf( "Malformed MAC address.\n\n" );
                }
            }
            else
            {
                printf( "No GigE transport layer present.\n\n" );
            }
        }
        else
        {
            printf( "Could not query Vimba for the presence of a GigE transport layer. Reason: %d\n\n", err );
        }

        VmbShutdown();                                                                                                      // Close Vimba
    }
    else
    {
        printf( "Could not start system. Error code: %d\n\n", err );
    }
}