⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 prism2.c

📁 linux下从网卡远程启动
💻 C
📖 第 1 页 / 共 3 页
字号:
    do {      reg = hfa384x_getreg(hw, HFA384x_OFFSET0);      if ( i > 0 ) udelay(2);      i++;    } while ( i < BAP_TIMEOUT && HFA384x_OFFSET_ISBUSY(reg));    if ( i >= BAP_TIMEOUT ) {      /* failure */      result = reg;    } else if ( HFA384x_OFFSET_ISERR(reg) ){      /* failure */      result = reg;    }  }  return result;}/* * Copy data from BAP to memory. * * Arguments: *	hw		device structure *	id		FID or RID, destined for the select register (host order) *	offset		An _even_ offset into the buffer for the given FID/RID. *	buf		ptr to array of bytes *	len		length of data to transfer in bytes * Returns:  *	0		success */static int hfa384x_copy_from_bap(hfa384x_t *hw, UINT16 id, UINT16 offset,			  void *buf, UINT len){  int result = 0;  UINT8	*d = (UINT8*)buf;  UINT16 i;  UINT16 reg = 0;    /* Prepare BAP */  result = hfa384x_prepare_bap ( hw, id, offset );  if ( result == 0 ) {    /* Read even(len) buf contents from data reg */    for ( i = 0; i < (len & 0xfffe); i+=2 ) {      *(UINT16*)(&(d[i])) = hfa384x_getreg_noswap(hw, HFA384x_DATA0);    }    /* If len odd, handle last byte */    if ( len % 2 ){      reg = hfa384x_getreg_noswap(hw, HFA384x_DATA0);      d[len-1] = ((UINT8*)(&reg))[0];    }  }  if (result) {    printf ( "copy_from_bap(%#hx, %#hx, %d) failed, result=%#hx\n", id, offset, len, result);  }  return result;}/* * Copy data from memory to BAP. * * Arguments: *	hw		device structure *	id		FID or RID, destined for the select register (host order) *	offset		An _even_ offset into the buffer for the given FID/RID. *	buf		ptr to array of bytes *	len		length of data to transfer in bytes * Returns:  *	0		success */static int hfa384x_copy_to_bap(hfa384x_t *hw, UINT16 id, UINT16 offset,			void *buf, UINT len){  int result = 0;  UINT8	*d = (UINT8*)buf;  UINT16 i;  UINT16 savereg;  /* Prepare BAP */  result = hfa384x_prepare_bap ( hw, id, offset );  if ( result == 0 ) {    /* Write even(len) buf contents to data reg */    for ( i = 0; i < (len & 0xfffe); i+=2 ) {      hfa384x_setreg_noswap(hw, *(UINT16*)(&(d[i])), HFA384x_DATA0);    }    /* If len odd, handle last byte */    if ( len % 2 ){      savereg = hfa384x_getreg_noswap(hw, HFA384x_DATA0);      result = hfa384x_prepare_bap ( hw, id, offset + (len & 0xfffe) );      if ( result == 0 ) {	((UINT8*)(&savereg))[0] = d[len-1];	hfa384x_setreg_noswap(hw, savereg, HFA384x_DATA0);      }    }  }  if (result) {    printf ( "copy_to_bap(%#hx, %#hx, %d) failed, result=%#hx\n", id, offset, len, result);  }  return result;}/* * Request a given record to be copied to/from the record buffer. * * Arguments: *	hw		device structure *	write		[0|1] copy the record buffer to the given *			configuration record. (host order) *	rid		RID of the record to read/write. (host order) * * Returns:  *	0		success */static inline int hfa384x_cmd_access(hfa384x_t *hw, UINT16 write, UINT16 rid){  return hfa384x_docmd_wait(hw, HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ACCESS) | HFA384x_CMD_WRITE_SET(write), rid, 0, 0);}/* * Performs the sequence necessary to read a config/info item. * * Arguments: *	hw		device structure *	rid		config/info record id (host order) *	buf		host side record buffer.  Upon return it will *			contain the body portion of the record (minus the  *			RID and len). *	len		buffer length (in bytes, should match record length) * * Returns:  *	0		success */static int hfa384x_drvr_getconfig(hfa384x_t *hw, UINT16 rid, void *buf, UINT16 len){  int result = 0;  hfa384x_rec_t	rec;  /* Request read of RID */  result = hfa384x_cmd_access( hw, 0, rid);  if ( result ) {    printf("Call to hfa384x_cmd_access failed\n");    return -1;  }  /* Copy out record length */  result = hfa384x_copy_from_bap( hw, rid, 0, &rec, sizeof(rec));  if ( result ) {    return -1;  }  /* Validate the record length */  if ( ((hfa384x2host_16(rec.reclen)-1)*2) != len ) {  /* note body len calculation in bytes */    printf ( "RID len mismatch, rid=%#hx hlen=%d fwlen=%d\n", rid, len, (hfa384x2host_16(rec.reclen)-1)*2);    return -1;  }  /* Copy out record data */  result = hfa384x_copy_from_bap( hw, rid, sizeof(rec), buf, len);  return result;}/* * Performs the sequence necessary to read a 16/32 bit config/info item * and convert it to host order. * * Arguments: *	hw		device structure *	rid		config/info record id (in host order) *	val		ptr to 16/32 bit buffer to receive value (in host order) * * Returns:  *	0		success */#if 0 /* Not actually used anywhere */static int hfa384x_drvr_getconfig16(hfa384x_t *hw, UINT16 rid, void *val){  int result = 0;  result = hfa384x_drvr_getconfig(hw, rid, val, sizeof(UINT16));  if ( result == 0 ) {    *((UINT16*)val) = hfa384x2host_16(*((UINT16*)val));  }  return result;}#endif#if 0 /* Not actually used anywhere */static int hfa384x_drvr_getconfig32(hfa384x_t *hw, UINT16 rid, void *val){  int result = 0;  result = hfa384x_drvr_getconfig(hw, rid, val, sizeof(UINT32));  if ( result == 0 ) {    *((UINT32*)val) = hfa384x2host_32(*((UINT32*)val));  }  return result;}#endif/* * Performs the sequence necessary to write a config/info item. * * Arguments: *	hw		device structure *	rid		config/info record id (in host order) *	buf		host side record buffer *	len		buffer length (in bytes) * * Returns:  *	0		success */static int hfa384x_drvr_setconfig(hfa384x_t *hw, UINT16 rid, void *buf, UINT16 len){  int result = 0;  hfa384x_rec_t	rec;  rec.rid = host2hfa384x_16(rid);  rec.reclen = host2hfa384x_16((len/2) + 1); /* note conversion to words, +1 for rid field */  /* write the record header */  result = hfa384x_copy_to_bap( hw, rid, 0, &rec, sizeof(rec));  if ( result ) {    printf("Failure writing record header\n");    return -1;  }  /* write the record data (if there is any) */  if ( len > 0 ) {    result = hfa384x_copy_to_bap( hw, rid, sizeof(rec), buf, len);    if ( result ) {      printf("Failure writing record data\n");      return -1;    }  }  /* Trigger setting of record */  result = hfa384x_cmd_access( hw, 1, rid);  return result;}/* * Performs the sequence necessary to write a 16/32 bit config/info item. * * Arguments: *	hw		device structure *	rid		config/info record id (in host order) *	val		16/32 bit value to store (in host order) * * Returns:  *	0		success */static int hfa384x_drvr_setconfig16(hfa384x_t *hw, UINT16 rid, UINT16 *val){  UINT16 value;  value = host2hfa384x_16(*val);  return hfa384x_drvr_setconfig(hw, rid, &value, sizeof(UINT16));}#if 0 /* Not actually used anywhere */static int hfa384x_drvr_setconfig32(hfa384x_t *hw, UINT16 rid, UINT32 *val){  UINT32 value;  value = host2hfa384x_32(*val);  return hfa384x_drvr_setconfig(hw, rid, &value, sizeof(UINT32));}#endif/* * Wait for an event, with specified checking interval and timeout. * Automatically acknolwedges events. * * Arguments: *	hw		device structure *      event_mask      EVSTAT register mask of events to wait for *	event_ack	EVACK register set of events to be acknowledged if they happen (can be *			used to acknowledge "ignorable" events in addition to the "main" event) *      wait            Time (in us) to wait between each poll of the register *      timeout         Maximum number of polls before timing out *      descr           Descriptive text string of what is being waited for *                      (will be printed out if a timeout happens) * * Returns:  *      value of EVSTAT register, or 0 on failure  */static int hfa384x_wait_for_event(hfa384x_t *hw, UINT16 event_mask, UINT16 event_ack, int wait, int timeout, const char *descr){  UINT16 reg;  int count = 0;    do {    reg = hfa384x_getreg(hw, HFA384x_EVSTAT);    if ( count > 0 ) udelay(wait);    count++;  } while ( !(reg & event_mask) && count < timeout);  if ( count >= timeout ) {    printf("hfa384x: Timed out waiting for %s\n", descr);    return 0; /* Return failure */  }  /* Acknowledge all events that we were waiting on */  hfa384x_setreg(hw, reg & ( event_mask | event_ack ), HFA384x_EVACK);  return reg;}/**************************************************************************POLL - Wait for a frame***************************************************************************/static int prism2_poll(struct nic *nic){  UINT16 reg;  UINT16 rxfid;  UINT16 result;  hfa384x_rx_frame_t rxdesc;  hfa384x_t *hw = &hw_global;    /* Check for received packet */  reg = hfa384x_getreg(hw, HFA384x_EVSTAT);  if ( ! HFA384x_EVSTAT_ISRX(reg) ) {    /* No packet received - return 0 */    return 0;  }  /* Acknowledge RX event */  hfa384x_setreg(hw, HFA384x_EVACK_RX_SET(1), HFA384x_EVACK);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -