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

📄 mplinitshutdown.c

📁 NATIONAL公司DP83816芯片Linux下驱动
💻 C
📖 第 1 页 / 共 2 页
字号:

//******************************************************************************
//
//  MPLINITSHUTDOWN.C
//
//  Copyright (c) 2004 National Semiconductor Corporation.
//  All Rights Reserved
//
//  MPL Initialization and Shutdown Module.
//
//  This file contains the API implementations for
//     o MPL Initialization and Unload
//     o MPL Device Open and Close
//     o MAC, Transmit and Receive Resets
//     o MPL Capabilities and MTU reporting 
//
//******************************************************************************

#include <mplinternal.h>

// Local helful debug macros
#undef ENTER
#undef EXIT
#undef ASSERT
#undef PRINT
#undef PRINTI
#undef PRINTS
#undef TBREAK

#define ENTER(fn) MPL_CENTER(DZONE_MPL_INIT_DOWN, fn)
#define EXIT(fn) MPL_CEXIT(DZONE_MPL_INIT_DOWN, fn)
#define ASSERT(le) MPL_CASSERT(DZONE_MPL_INIT_DOWN, le)
#define PRINT(fmt) MPL_CTRACE(DZONE_MPL_INIT_DOWN, fmt)
#define PRINTI(v) MPL_CTRACE(DZONE_MPL_INIT_DOWN, (" "#v": %x \n",(NS_UINT)(v)))
#define PRINTS(v) MPL_CTRACE(DZONE_MPL_INIT_DOWN, (" "#v": %s \n", v))
#define TBREAK(fmt) MPL_CTRACEBREAK(DZONE_MPL_INIT_DOWN, fmt)

// Locals
static NS_VOID disableDevice(IN NS_VOID  *pMplHandle);

//*****************************************************************************
//   MplInitialize 
//      Allocate and initialize a MPL context fot the device.
//
//   Parameters
//      pNsmHandle
//         NSM device handle for the device hardware.  This handle is retained 
//          by MPL and passed in to subsequent calls to the NSM.
//      pBaseAddr
//         The logical base address for the device.
//      opMode
//         Specifies the operational mode MPL should go into. The coverage in 
//          each mode is shown in the below table,
//         For most production drivers this should be passed as MPL_MODE_NORMAL.
//   ==========================================================
//  |          ||  NORMAL   |    LOAD_ONLY    |    MONITOR     |
//  | Op  Mode ||(non-Diag) |   (Diag Mode)   |   (Diag Mode)  |
//   ==========================================================
//  | Operation||             O  W  N  E  R                    |
//  |----------------------------------------------------------
//  | H/w Init || NSM       | Diag App        |      NSM       |
//    ---------------------------------------------------------
//  | Tx/Rx    || NSM       | Diag App        | Diag App       |
//   ==========================================================
//
//      pMplHandle
//         MPL handle for the device’s context.  The NSM must retain this handle
//          and pass it for all subsequent MPL calls.
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The device was successfully initialized and the MPL context is 
//          returned
//      NS_STATUS_INVALID_PARAM
//         An invalid parameter value was detected
//      NS_STATUS_RESOURCES
//         Unable to initialize a context (lack of system resources)
//      NS_STATUS_HARDWARE_FAILURE
//         Unable to initialize a context (unexpected h/w error)
//         or failed to detect MacPhyter device
//
//*****************************************************************************
MPL_STATUS
   MplInitialize (
      IN NS_VOID       *pNsmHandle,
      IN NS_VOID       *pBaseAddr,
      IN MPL_MODE       opMode,
      OUT NS_VOID     **pMplHandle
      )
{
   MPL_CONTEXT *pMplCtx = NULL;

   ENTER(MplInitialize);

   // FM: Assert on base addr or nsmhandle being NULL

   // Allocate MPL context memory
   pMplCtx = OaiMalloc(sizeof(MPL_CONTEXT));
   if (pMplCtx == NULL)
   {
      EXIT(MplInitialize);
      return NS_STATUS_RESOURCES;
   }

   // Initialize context
   OaiZeroMem(pMplCtx, sizeof(MPL_CONTEXT));
   pMplCtx->pClientHandle = pNsmHandle;
   pMplCtx->pRegsBase  = pBaseAddr;
   
#ifdef MPL_DIAG_MODE
   pMplCtx->diag.mode = opMode;
   if (pMplCtx->diag.mode == MPL_MODE_LOAD_ONLY)
   {
      // Nothing else to do

      // Set the new state of the adapter context
      pMplCtx->state = MPL_STATE_INIT;

      // Return MPL handle
      *pMplHandle = pMplCtx;

      EXIT(MplInitialize);
      return NS_STATUS_SUCCESS;
   }
#endif //MPL_DIAG_MODE

   // Initialize the MAC and the PHY
   if (MplMacReset(pMplCtx) == NS_STATUS_SUCCESS)
   {
      if ((MplPhyDetect(pMplCtx) == NS_STATUS_SUCCESS) && 
             (MplPhyReset(pMplCtx) == NS_STATUS_SUCCESS))
      {
         // Get MAC Id
         MplGetDeviceId(pMplCtx);

         // Set defaults on the soft config regs maintained in MPL context
         setSoftRegs(pMplCtx, MPL_REGS_DEFAULT);

         // Set defaults on the adapter's config regs
         setHardRegs(pMplCtx);

         // Create Timer object to monitor phy patches
         OaiCreateTimer(phyTimerHandler, pMplCtx, &pMplCtx->phyTimer);

         // Set the new state of the adapter context
         pMplCtx->state = MPL_STATE_INIT;

         // All done
         *pMplHandle = pMplCtx;

         EXIT(MplInitialize);
         return NS_STATUS_SUCCESS;
      }
   }

   // Failed to initialize!
   OaiFree(sizeof(MPL_CONTEXT), pMplCtx);
   EXIT(MplInitialize);
   return NS_STATUS_HARDWARE_FAILURE;
}

//*****************************************************************************
//   MplOpen
//      Opens the device for network operation. 
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize. 
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The device was successfully opened and is ready for network operation
//      NS_STATUS_INVALID_PARAM
//         An invalid parameter value was detected or this function is called 
//          prior to MplInitialize
//      NS_STATUS_HARDWARE_FAILURE
//         Unexpected hardware error
//
//*****************************************************************************
MPL_STATUS
   MplOpen (
      IN NS_VOID       *pMplHandle
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;

   ENTER(MplOpen);

   // Make sure we entered from the right state
   if (pMplCtx->state != MPL_STATE_INIT)
   {
      EXIT(MplOpen);
      return NS_STATUS_INVALID_PARM;
   }

   // Set new state and full POWER
   pMplCtx->state = MPL_STATE_OPEN;
   pMplCtx->pwrState = MPL_POWER_STATE_HIGH;

#ifdef MPL_DIAG_MODE
   if (pMplCtx->diag.mode == MPL_MODE_LOAD_ONLY)
   {
      // Nothing more to do
      EXIT(MplOpen);
      return NS_STATUS_SUCCESS;
   }
#endif //MPL_DIAG_MODE

   // Clear all pending events
   MPL_READ32(pMplCtx, ISR);

   // Enable RX engine
   MPL_WRITE32(pMplCtx, CR, RX_EN);

   // And go!
   MplInterruptEnable(pMplHandle);

   EXIT(MplOpen);
   return NS_STATUS_SUCCESS;
}

//*****************************************************************************
//   MplClose
//      Closes the network device, disabling network transmission/reception and
//       interrupts. 
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The device was successfully closed
//      NS_STATUS_INVALID_PARAM
//         An invalid parameter value was detected or this function is called 
//          prior to MplInitialize or MplOpen
//
//*****************************************************************************
MPL_STATUS
   MplClose (
      IN NS_VOID       *pMplHandle
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
  
   ENTER(MplClose);

   // Make sure we entered from the right states
   if (pMplCtx->state != MPL_STATE_OPEN)
   {
      EXIT(MplClose);
      return NS_STATUS_INVALID_PARM;
   }

   // Disable the device
   disableDevice(pMplCtx);

   // Free Txd ring related mem
   freeTxdRing(pMplCtx);

   // Free Rxd ring related mem
   freeRxdRing(pMplCtx);

   // Set new state
   pMplCtx->state = MPL_STATE_INIT;

   EXIT(MplClose);
   return NS_STATUS_SUCCESS;
}

//*****************************************************************************
//   MplUnload
//      Shuts down the device hardware and frees all allocated resources claimed
//       by MplInitialize. 
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize
//
//   Return Value
//      NS_STATUS_SUCCESS
//         MPL was successfully unloaded and all resources released.
//      NS_STATUS_INVALID_PARAM
//         An invalid parameter value was detected or this function is called 
//          prior to MplInitialize
//
//*****************************************************************************
MPL_STATUS
   MplUnload (
      IN NS_VOID       *pMplHandle
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;

   ENTER(MplUnload);

   // Make sure we entered from the right state
   if (pMplCtx->state != MPL_STATE_INIT)
   {
      EXIT(MplOpen);
      return NS_STATUS_INVALID_PARM;
   }

   // Disable the adapter
   disableDevice(pMplCtx);

   // Free Txd and Rxd Rings
   freeTxdRing(pMplCtx);
   freeRxdRing(pMplCtx);

   // Delete Timer Object
   OaiDeleteTimer(pMplCtx->phyTimer);

   // Free the MPL context
   OaiFree(sizeof(MPL_CONTEXT), pMplCtx);
 
   EXIT(MplUnload);
   return NS_STATUS_SUCCESS;
}

//*****************************************************************************
//   MplMacReset
//      Resets the network device. 
//
//   Parameters
//      pMplHandle
//         MPL device handle returned following a call to MplInitialize
//
//   Return Value
//      NS_STATUS_SUCCESS
//         The network device was successfully reset.
//      NS_STATUS_HARDWARE_FAILURE
//         Unexpected hardware error
//
//*****************************************************************************
MPL_STATUS
   MplMacReset (
      IN NS_VOID   *pMplHandle
      )
{
   MPL_CONTEXT *pMplCtx = (MPL_CONTEXT *)pMplHandle;
   NS_UINT32 i;

⌨️ 快捷键说明

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