FreeBSD/sys/dev/nxge/xgehal/xgehal-device.c
/**
 * __hal_device_get_vpd_data - Getting vpd_data.
 *
 *   @hldev: HAL device handle.
 *
 *   Getting  product name and serial number from vpd capabilites structure
 *
 */


Getting  product name and serial number from vpd capabilites structure
Getting product name and serial number from vpd capabilites structure
void
__hal_device_get_vpd_data(xge_hal_device_t *hldev)
{
	u8 * vpd_data;
	u8   data;
	int  index = 0, count, fail = 0;
	u8   vpd_addr = XGE_HAL_CARD_XENA_VPD_ADDR;
	if (xge_hal_device_check_id(hldev) == XGE_HAL_CARD_HERC)
	    vpd_addr = XGE_HAL_CARD_HERC_VPD_ADDR;
	xge_os_strcpy((char *) hldev->vpd_data.product_name,
	            "10 Gigabit Ethernet Adapter");
	xge_os_strcpy((char *) hldev->vpd_data.serial_num, "not available");
	vpd_data = ( u8*) xge_os_malloc(hldev->pdev, XGE_HAL_VPD_BUFFER_SIZE + 16);
	if ( vpd_data == NULL )
	    return;
	for (index = 0; index < XGE_HAL_VPD_BUFFER_SIZE; index +=4 ) {
	    xge_os_pci_write8(hldev->pdev, hldev->cfgh, (vpd_addr + 2), (u8)index);
	    xge_os_pci_read8(hldev->pdev, hldev->cfgh,(vpd_addr + 2), &data);
	    xge_os_pci_write8(hldev->pdev, hldev->cfgh, (vpd_addr + 3), 0);
	    for (count = 0; count < 5; count++ ) {
	        xge_os_mdelay(2);
	        xge_os_pci_read8(hldev->pdev, hldev->cfgh,(vpd_addr + 3), &data);
	        if (data == XGE_HAL_VPD_READ_COMPLETE)
	            break;
	    }
	    if (count >= 5) {
	        xge_os_printf("ERR, Reading VPD data failed");
	        fail = 1;
	        break;
	    }
	    xge_os_pci_read32(hldev->pdev, hldev->cfgh,(vpd_addr + 4),
	            (u32 *)&vpd_data[index]);
	}
	if(!fail) {
	    for (count = 0; count < XGE_HAL_VPD_BUFFER_SIZE; count++) {
	        if ((vpd_data[count] == 'S')     &&
	            (vpd_data[count + 1] == 'N') &&
	            (vpd_data[count + 2] < XGE_HAL_VPD_LENGTH)) {
	                memset(hldev->vpd_data.serial_num, 0, XGE_HAL_VPD_LENGTH);
	                memcpy(hldev->vpd_data.serial_num, &vpd_data[count + 3],
	                    vpd_data[count + 2]);
	                break;
	        }
	    }
	    if (vpd_data[1] < XGE_HAL_VPD_LENGTH) {
	        memset(hldev->vpd_data.product_name, 0, vpd_data[1]);
	        memcpy(hldev->vpd_data.product_name, &vpd_data[3], vpd_data[1]);
	    }
	}
	xge_os_free(hldev->pdev, vpd_data, XGE_HAL_VPD_BUFFER_SIZE + 16);
}
void __hal_device_get_vpd_data ( xge_hal_device_t * hldev ) { u8 * vpd_data ; u8 data ; int index = 0 , count , fail = 0 ; u8 vpd_addr = XGE_HAL_CARD_XENA_VPD_ADDR ; if ( xge_hal_device_check_id ( hldev ) == XGE_HAL_CARD_HERC ) vpd_addr = XGE_HAL_CARD_HERC_VPD_ADDR ; xge_os_strcpy ( ( char * ) hldev -> vpd_data . product_name , " " ) ; xge_os_strcpy ( ( char * ) hldev -> vpd_data . serial_num , " " ) ; vpd_data = ( u8 * ) xge_os_malloc ( hldev -> pdev , XGE_HAL_VPD_BUFFER_SIZE + 16 ) ; if ( vpd_data == NULL ) return ; for ( index = 0 ; index < XGE_HAL_VPD_BUFFER_SIZE ; index += 4 ) { xge_os_pci_write8 ( hldev -> pdev , hldev -> cfgh , ( vpd_addr + 2 ) , ( u8 ) index ) ; xge_os_pci_read8 ( hldev -> pdev , hldev -> cfgh , ( vpd_addr + 2 ) , & data ) ; xge_os_pci_write8 ( hldev -> pdev , hldev -> cfgh , ( vpd_addr + 3 ) , 0 ) ; for ( count = 0 ; count < 5 ; count ++ ) { xge_os_mdelay ( 2 ) ; xge_os_pci_read8 ( hldev -> pdev , hldev -> cfgh , ( vpd_addr + 3 ) , & data ) ; if ( data == XGE_HAL_VPD_READ_COMPLETE ) break ; } if ( count >= 5 ) { xge_os_printf ( " " ) ; fail = 1 ; break ; } xge_os_pci_read32 ( hldev -> pdev , hldev -> cfgh , ( vpd_addr + 4 ) , ( u32 * ) & vpd_data [ index ] ) ; } if ( ! fail ) { for ( count = 0 ; count < XGE_HAL_VPD_BUFFER_SIZE ; count ++ ) { if ( ( vpd_data [ count ] == ' ' ) && ( vpd_data [ count + 1 ] == ' ' ) && ( vpd_data [ count + 2 ] < XGE_HAL_VPD_LENGTH ) ) { memset ( hldev -> vpd_data . serial_num , 0 , XGE_HAL_VPD_LENGTH ) ; memcpy ( hldev -> vpd_data . serial_num , & vpd_data [ count + 3 ] , vpd_data [ count + 2 ] ) ; break ; } } if ( vpd_data [ 1 ] < XGE_HAL_VPD_LENGTH ) { memset ( hldev -> vpd_data . product_name , 0 , vpd_data [ 1 ] ) ; memcpy ( hldev -> vpd_data . product_name , & vpd_data [ 3 ] , vpd_data [ 1 ] ) ; } } xge_os_free ( hldev -> pdev , vpd_data , XGE_HAL_VPD_BUFFER_SIZE + 16 ) ; }
__hal_device_get_vpd_data - Getting vpd_data.
__hal_device_get_vpd_data - Getting vpd_data .
/* read serial number of adapter */