usrNetSmBoot.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:6k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* usrNetSmBoot.c - start a shared memory network boot device */
  2. /* Copyright 1992 - 2002 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 01g,26apr02,vvv  fixed incorrect dev name comparison in usrBpInit (SPR #74788)
  7. 01f,02oct01,mas  added support for all 8 NETIF arguments, #7 = SM_MASTER,
  8.  #8 = SM_MAX_WAIT (SPR 4547)
  9. 01e,16nov00,spm  enabled new DHCP lease for runtime device setup (SPR #20438)
  10. 01d,19mar99,dat  SPR 25877, fixed old driver references
  11. 01c,24feb99,ann  added code to extract netmask (SPR# 24197)
  12. 01b,20jan99,scb  modified to use "sm=" before SM_ANCHOR_ADRS (23035)
  13. 01a,05dec97,spm  added DHCP code review modifications
  14. */
  15. /*
  16. DESCRIPTION
  17. This file is included by the configuration tool to initialize a shared memory
  18. network device according to the parameters in the boot line. It contains the 
  19. initialization routine for the INCLUDE_SM_NET component.
  20. NOMANUAL
  21. */
  22. extern NETIF usrNetIfTbl [];
  23. /*******************************************************************************
  24. *
  25. * usrNetSmnetStart - start the shared memory or backplane device
  26. *
  27. * This routine creates a shared memory device as specified in the boot 
  28. * parameters if it is selected as the boot device. It is the initialization
  29. * routine for the INCLUDE_SM_NET component. The device is attached to the
  30. * protocol stack by a later routine unless an error occurs.
  31. * RETURNS: N/A
  32. *
  33. * NOMANUAL
  34. */
  35. void usrNetSmnetStart (void)
  36.     {
  37.     STATUS result;
  38.     /* 
  39.      * Do nothing if another device is already initialized or an
  40.      * error was detected in the boot parameters.
  41.      */
  42.     if (netDevBootFlag)
  43.         return;
  44.     if ((strncmp (sysBootParams.bootDev, "bp", 2) == 0) ||
  45.         (strncmp (sysBootParams.bootDev, "sm", 2) == 0))
  46.         {
  47.         if (usrBpInit (sysBootParams.bootDev, sysBootParams.unitNum, 0) == ERROR)
  48.             result = ERROR;
  49.         if (result == ERROR)
  50.             {
  51.             printf ("Error occurred while attaching bpn");
  52.             netDevBootFlag = TRUE;
  53.             }
  54.         backplaneBoot = TRUE;
  55.         }
  56.     return;
  57.     }
  58. /*******************************************************************************
  59. *
  60. * usrSmNetAddrGet - use backplane address field if necessary
  61. *
  62. * This routine resets the network-related boot parameter processing to
  63. * use the field containing the address for the backplane or shared memory
  64. * device. It is the initialization routine for the INCLUDE_SM_NET_ADDRGET
  65. * component which is automatically added when the INCLUDE_SM_NET component
  66. * is used.
  67. *
  68. * RETURNS: N/A
  69. *
  70. * NOMANUAL
  71. */
  72. void usrSmNetAddrGet (void)
  73.     {
  74.     /* change the address string if a related boot device is used */
  75.     if ((strncmp (sysBootParams.bootDev, "bp", 2) == 0) ||
  76.             (strncmp (sysBootParams.bootDev, "sm", 2) == 0))
  77.         {
  78.         /* booting via backplane */
  79.         pAddrString = sysBootParams.bad;
  80. bootNetmaskExtract (pAddrString, &netmask);
  81.         }
  82.     return;
  83.     }
  84. /******************************************************************************
  85. *
  86. * usrBpInit - initailize backplane driver
  87. *
  88. * usrBpInit initializes the backplane driver shared memory region
  89. * and sets up the backplane parameters to attach.
  90. *
  91. * RETURNS: OK if successful otherwise ERROR
  92. *
  93. * NOMANUAL
  94. */
  95. STATUS usrBpInit
  96.     (
  97.     char *  devName,        /* device name */
  98.     int     unitNum,        /* unit number */
  99.     u_long  startAddr       /* inet address */
  100.     )
  101.     {
  102. #ifdef  INCLUDE_SM_NET
  103.     char *  bpAnchor;       /* anchor address */
  104.     NETIF * pNif;           /* netif struct */
  105.     STATUS  status;         /* status */
  106.     int     procNum;        /* proc num */
  107.     char    buf [BOOT_DEV_LEN];  /* network device + unit number */
  108.     /*
  109.      * Pick off optional "=<anchorAdrs>" from backplane
  110.      * device.  Also truncates devName to just "bp" or "sm"
  111.      */
  112.     if ((strncmp (devName, "bp=", 3) == 0) ||
  113.         (strncmp (devName, "sm=", 3) == 0))
  114.         {
  115.         if (bootBpAnchorExtract (devName, &bpAnchor) < 0)
  116.             {
  117.             printf ("Invalid anchor address specified: "%s"n", devName);
  118.             return (ERROR);
  119.             }
  120.         }
  121.     else
  122.         {
  123. bpAnchor = SM_ANCHOR_ADRS;          /* default anchor */
  124.         }
  125.      procNum = sysProcNumGet ();
  126.     /* if we are master, initialize backplane net */
  127.     if (procNum == 0)
  128.         {
  129.         printf ("Initializing backplane net with anchor at %#x... ",
  130.                 (int) bpAnchor);
  131.         status = smNetInit ((SM_ANCHOR *) bpAnchor, (char *) SM_MEM_ADRS,
  132.                             (int) SM_MEM_SIZE, SM_TAS_TYPE, SM_CPUS_MAX,
  133.                             SM_PKTS_SIZE, startAddr);
  134.         if (status == ERROR)
  135.             {
  136.             printf ("Error: backplane device %s not initializedn", devName);
  137.             return (ERROR);
  138.             }
  139.         printf ("done.n");
  140.         }
  141.     /* Locate NETIF structure for backplane */
  142.     sprintf (buf, "%s%d", devName, unitNum);
  143.     for (pNif = usrNetIfTbl; pNif->ifName != 0; pNif++)
  144.         {
  145.         if (strcmp (buf, pNif->ifName) == 0)
  146.             break;
  147.         }
  148.     /*
  149.      * For backward compatibility, the device name only is acceptable for
  150.      * unit numbers of 0.
  151.      */
  152.     if (pNif->ifName == 0 && unitNum == 0)
  153.         {
  154.         for (pNif = usrNetIfTbl; pNif->ifName != 0; pNif++)
  155.             {
  156.             if (strcmp (devName, pNif->ifName) == 0)
  157.                 break;
  158.             }
  159.         }
  160.     if (pNif->ifName == 0)
  161.         {
  162.         if (strncmp (devName, "bp", 2) == 0)
  163.             printf ("INCLUDE_BP_5_0 not supported - use 'sm' interfacen");
  164.         return (ERROR);
  165.         }
  166.     printf ("Backplane anchor at %#x... ", (int) bpAnchor);
  167.     /* configure all backplane parameters in NETIF struct */
  168.     pNif->arg1 = bpAnchor;      /* anchor address */
  169.     pNif->arg2 = SM_MAX_PKTS;
  170.     pNif->arg3 = SM_INT_TYPE;
  171.     pNif->arg4 = SM_INT_ARG1;
  172.     pNif->arg5 = SM_INT_ARG2;
  173.     pNif->arg6 = SM_INT_ARG3;
  174.     pNif->arg7 = SM_MASTER;
  175.     pNif->arg8 = SM_MAX_WAIT;
  176.     return (OK);
  177. #else   /* INCLUDE_SM_NET */
  178.     printf ("nError: backplane driver referenced but not included.n");
  179.     return (ERROR);
  180. #endif  /* INCLUDE_SM_NET */
  181.     }