pub fn create(hca_ptr: *mut ib_device, port: u16) -> KernelResult<Self> {
        // 1. query the port
        let mut port_attr: ib_port_attr = Default::default();
        let err =
            unsafe { ib_query_port(hca_ptr, port as u8, &mut port_attr as *mut ib_port_attr) };
        if err != 0 {
            return Err(Error::from_kernel_errno(err));
        }

        if port_attr.state != ib_port_state::IB_PORT_ACTIVE {
            return Err(Error::from_kernel_errno(err));
        }
        // 2. init dev attr
        let mut data: ib_udata = Default::default();
        let mut dev_attr: ib_device_attr = Default::default();
        let hca: &mut ib_device = &mut unsafe { *hca_ptr };
        let err = unsafe {
            hca.query_device(
                hca_ptr,
                &mut dev_attr as *mut ib_device_attr,
                &mut data as *mut ib_udata,
            )
        };

        if err != 0 {
            return Err(Error::from_kernel_errno(err));
        }

        // 3. init gid
        let mut gid: ib_gid = Default::default();
        let err =
            unsafe { hca.query_gid(hca_ptr, port as u8, 0, &mut gid as *mut ib_gid) };
        if err != 0 {
            return Err(Error::from_kernel_errno(err));
        }

        // 4. setup RNIC properties
        Ok(Self {
            hca: hca_ptr,
            default_gid: gid,
            attr: dev_attr,
            port: port,
            lid: port_attr.lid as u16,
        })
    }
// note: we assume that the nic has only one port
we assume that the nic has only one port
we assume that the nic has only one port
pub fn create(hca_ptr: *mut ib_device, port: u16) -> KernelResult<Self> {
        // 1. query the port
        let mut port_attr: ib_port_attr = Default::default();
        let err =
            unsafe { ib_query_port(hca_ptr, port as u8, &mut port_attr as *mut ib_port_attr) };
        if err != 0 {
            return Err(Error::from_kernel_errno(err));
        }
        if port_attr.state != ib_port_state::IB_PORT_ACTIVE {
            return Err(Error::from_kernel_errno(err));
        }
        // 2. init dev attr
        let mut data: ib_udata = Default::default();
        let mut dev_attr: ib_device_attr = Default::default();
        let hca: &mut ib_device = &mut unsafe { *hca_ptr };
        let err = unsafe {
            hca.query_device(
                hca_ptr,
                &mut dev_attr as *mut ib_device_attr,
                &mut data as *mut ib_udata,
            )
        };
        if err != 0 {
            return Err(Error::from_kernel_errno(err));
        }
        // 3. init gid
        let mut gid: ib_gid = Default::default();
        let err =
            unsafe { hca.query_gid(hca_ptr, port as u8, 0, &mut gid as *mut ib_gid) };
        if err != 0 {
            return Err(Error::from_kernel_errno(err));
        }
        // 4. setup RNIC properties
        Ok(Self {
            hca: hca_ptr,
            default_gid: gid,
            attr: dev_attr,
            port: port,
            lid: port_attr.lid as u16,
        })
    }
pub fn create ( hca_ptr : * mut ib_device , port : u16 ) -> KernelResult < Self > { // 1. query the port let mut port_attr : ib_port_attr = Default :: default ( ) ; let err = unsafe { ib_query_port ( hca_ptr , port as u8 , & mut port_attr as * mut ib_port_attr ) } ; if err != 0 { return Err ( Error :: from_kernel_errno ( err ) ) ; } if port_attr . state != ib_port_state :: IB_PORT_ACTIVE { return Err ( Error :: from_kernel_errno ( err ) ) ; } // 2. init dev attr let mut data : ib_udata = Default :: default ( ) ; let mut dev_attr : ib_device_attr = Default :: default ( ) ; let hca : & mut ib_device = & mut unsafe { * hca_ptr } ; let err = unsafe { hca . query_device ( hca_ptr , & mut dev_attr as * mut ib_device_attr , & mut data as * mut ib_udata , ) } ; if err != 0 { return Err ( Error :: from_kernel_errno ( err ) ) ; } // 3. init gid let mut gid : ib_gid = Default :: default ( ) ; let err = unsafe { hca . query_gid ( hca_ptr , port as u8 , 0 , & mut gid as * mut ib_gid ) } ; if err != 0 { return Err ( Error :: from_kernel_errno ( err ) ) ; } // 4. setup RNIC properties Ok ( Self { hca : hca_ptr , default_gid : gid , attr : dev_attr , port : port , lid : port_attr . lid as u16 , } ) }
note: we assume that the nic has only one port
note : we assume that the nic has only one port
hca_ptr
*mut ib_device
port
u16