📄 dec21143.c
字号:
/* Initialize the TX buffer descriptor and set its base address.
Step 5 */
dec_data->DEC21143_First_TX_Descriptor =
dec_data->DEC21143_Current_TX_Descriptor =
DEC21143_Allocate_Descriptor (DEC21143_MAX_TX_DESCRIPTORS,
&System_Memory,
NU_FALSE);
/* Make sure the allocation worked. */
if (dec_data->DEC21143_First_TX_Descriptor)
/* Store the base address. */
OUTDW (device->dev_io_addr + CSR4, (UINT32) (dec_data->DEC21143_First_TX_Descriptor));
else
{
/* Log the error and get out. */
NU_Tcp_Log_Error (DRV_RESOURCE_ALLOCATION_ERROR, TCP_FATAL, __FILE__, __LINE__);
return (-1);
}
/* Create the initial setup frame used for filtering RX frames. Make
sure this worked. */
if (DEC21143_Init_Setup_Frame (ether_addr, setup_frame =
MEM_Buffer_Dequeue (&MEM_Buffer_Freelist)) != NU_SUCCESS)
{
/* This is a fatal error. */
NU_Tcp_Log_Error (DRV_RESOURCE_ALLOCATION_ERROR, TCP_FATAL, __FILE__, __LINE__);
return (-1);
}
/* Now that we have created the setup frame
give it to the DEC chip for processing. */
ret_status = DEC21143_Process_Setup_Frame (device, setup_frame);
/* Make sure we were able to process the frame. */
if (ret_status != NU_SUCCESS)
{
/* This is a fatal error. */
NU_Tcp_Log_Error (DRV_RESOURCE_ALLOCATION_ERROR, TCP_FATAL, __FILE__, __LINE__);
return (-1);
}
/* Turn on the transmitter so that the setup frame can be proccessed. */
csr6_val |= CSR6_START_TX;
/* Write it to the register. */
OUTDW (device->dev_io_addr + CSR6, csr6_val);
/* Step 6 is currently not needed. */
/* Select the port to use, speed, and the duplex. Step 7 - last step */
ret_status = DEC21143_Negotiate_Link (device, &csr6_val);
/* Make sure the link was correctly negotiated. */
if (ret_status == NU_SUCCESS)
{
/* Turn on the receiver. */
csr6_val |= CSR6_START_RX;
OUTDW (device->dev_io_addr + CSR6, csr6_val);
/* Set the current status to operational. */
SNMP_ifAdminStatus(device->dev_index, 1);
SNMP_ifOperStatus(device->dev_index, 1);
/* Initialize the ring buffer pointers. */
DEC21143_Read = DEC21143_Write = 0;
/* Save CSR6 for later use. */
dec_data->DEC21143_Saved_CSR6 = csr6_val;
/* Sleep for a second and let initialization complete. */
NU_Sleep (TICKS_PER_SECOND);
/* Set the initialization complete flag. */
dec_data->DEC21143_Init_Completed = NU_TRUE;
}
return (ret_status);
} /* end DEC21143_Open */
/****************************************************************************/
/* FUNCTION */
/* */
/* DEC21143_Negotiate_Link */
/* */
/* DESCRIPTION */
/* */
/* This function will start the autonegotiation of the link and wait for */
/* its completion or for a timeout to occur. */
/* */
/* AUTHOR */
/* */
/* Uriah T. Pollock, Accelerated Technology Inc. */
/* */
/* CALLED BY */
/* */
/* DEC21143_Open */
/* DEC21143_Negotiate_Link_HISR */
/* */
/* CALLS */
/* */
/* OUTDW */
/* INDW */
/* NU_Retrieve_Clock */
/* DEC21143_Init_Link */
/* */
/* INPUTS */
/* */
/* DV_DEVICE_ENTRY * : Pointer to the device to be initialized. */
/* UINT32 * : Pointer to the current CSR6 value. */
/* */
/* OUTPUTS */
/* */
/* NU_SUCCESS is returned if no errors occur, otherwise -1 is returned. */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* Uriah T. Pollock 01/12/99 Created initial version 1.0 */
/* */
/****************************************************************************/
STATUS DEC21143_Negotiate_Link (DV_DEVICE_ENTRY *device, UINT32 *csr6_val)
{
STATUS ret_status;
UNSIGNED timeout;
UINT32 csr12_val;
/* This routine currently only supports a SYMbolic PHY. If support for
a MII PHY needs to be added this would be the place. */
/* Autonegotiation, avertising half-duplex, full-duplex,
10BASE-T, and 100BASE-TX. */
/* Make sure the port select is not set. */
*csr6_val &= (~(CSR6_PORT_SELECT));
OUTDW (device->dev_io_addr + CSR6, *csr6_val);
/* Turn on the PCS function for the symbolic PHY. */
OUTDW (device->dev_io_addr + CSR6, (*csr6_val | CSR6_PCS_FUNCTION));
/* Reset the SIA */
OUTDW (device->dev_io_addr + CSR13, CLEAR_ALL);
/* Turn on everything that we want to advertise to the link
partner as well as a few other things needed to get
negotiation going. */
OUTDW (device->dev_io_addr + CSR14, (CSR14_ENCODER_ENABLE |
CSR14_LOOPBACK_ENABLE |
CSR14_DRIVER_ENABLE |
CSR14_LINK_PULSE_SEND_ENABLE |
CSR14_NORMAL_COMPENSATION_MODE |
CSR14_10BASET_HD_ENABLE |
CSR14_AUTONEGOTIATION_ENABLE |
CSR14_RECEIVE_SQUELCH_ENABLE |
CSR14_COLLISION_SQUELCH_ENABLE |
CSR14_COLLISION_DETECT_ENABLE |
CSR14_SIGNAL_QUALITY_ENABLE |
CSR14_LINK_TEST_ENABLE |
CSR14_AUTOPOLARITY_ENABLE |
CSR14_SET_POLARITY_PLUS |
CSR14_10BASET_AUI_AUTOSENSING |
CSR14_100BASE_TX_HD |
CSR14_100BASE_TX_FD |
CSR14_100BASE_T4));
/* Set the SIA to 10BASE-T mode and wake it up. */
OUTDW (device->dev_io_addr + CSR13, CSR13_SIA_RESET);
/* Get the current clock value. */
timeout = NU_Retrieve_Clock();
/* Add to it the negotiation timeout value. */
timeout += DEC21143_NEOGITATION_TIMEOUT;
/* Now wait for negotiation to complete, or for it to timeout. */
do
{
/* Read CSR12. It contains the status of the negotiation. */
csr12_val = INDW (device->dev_io_addr + CSR12);
} while (((csr12_val & CSR12_AUTONEGOTIATION_COMPLETE) !=
CSR12_AUTONEGOTIATION_COMPLETE) &&
(timeout > NU_Retrieve_Clock()));
ret_status = DEC21143_Init_Link (device, csr6_val);
return (ret_status);
} /* end DEC21143_Negotiate_Link */
/****************************************************************************/
/* FUNCTION */
/* */
/* DEC21143_Init_Link */
/* */
/* DESCRIPTION */
/* */
/* This function will read the current link status and initialize it */
/* based on the link partners code word or on the link status. */
/* */
/* AUTHOR */
/* */
/* Uriah T. Pollock, Accelerated Technology Inc. */
/* */
/* CALLED BY */
/* */
/* DEC21143_Negotiate_Link */
/* */
/* CALLS */
/* */
/* OUTDW */
/* INDW */
/* */
/* INPUTS */
/* */
/* DV_DEVICE_ENTRY * : Pointer to the device to be initialized. */
/* UINT32 * : Pointer to the current CSR6 value. */
/* */
/* OUTPUTS */
/* */
/* NU_SUCCESS is returned if no errors occur, otherwise -1 is returned. */
/* */
/* HISTORY */
/* */
/* NAME DATE REMARKS */
/* */
/* Uriah T. Pollock 01/12/99 Created initial version 1.0 */
/* */
/****************************************************************************/
STATUS DEC21143_Init_Link (DV_DEVICE_ENTRY *device, UINT32 *csr6_val)
{
UINT32 csr14_val, csr12_val;
UINT16 link_code_word;
UINT8 use_full_duplex, use_100MB;
/* Read CSR12 */
csr12_val = INDW (device->dev_io_addr + CSR12);
/* Get the link partners code word. It is in the upper 16 bits
of CSR12. */
link_code_word = ((csr12_val >> 16) & 0x00FF);
/* Did negotiation complete and we have a link code or did we timeout? */
if (((csr12_val & CSR12_AUTONEGOTIATION_COMPLETE) ==
CSR12_AUTONEGOTIATION_COMPLETE) &&
(link_code_word != NU_NULL))
{
/* Read in CSR14, this is used below. */
csr14_val = INDW (device->dev_io_addr + CSR14);
/* Check for all valid settings. */
/* 100BASE-TX Full Duplex */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -