Пример #1
0
END_OBJ*
NetdrvLoad(char* initString, void *ap)
{
    END_DEVICE    *pDrvCtrl;

    /* parse the init string, filling in the device structure */
    if(initString == NULL) {
        return (NULL);
    }

    if (initString[0] == 0) {
        strcpy(initString,"netdrv");
        return (NULL);
    }

    /* allocate the device structure */
    pDrvCtrl = (END_DEVICE *)calloc (sizeof(END_DEVICE), 1);
    if (pDrvCtrl == NULL) {
        goto errorExit;
    }

    /* Parse */
    pDrvCtrl->unit = 0;
    pDrvCtrl->ivec = 0;
    pDrvCtrl->ilevel = 7;

    /*Ask the BSP to provide the ethernet address.*/
    GetMacFromFlash(pDrvCtrl->enetAddr);

    /* initialize the END and MIB2 parts of the structure */
    /*
     * The M2 element must come from m2Lib.h
     * This Netdrv is set up for a DIX type ethernet device.
     */

    if ((END_OBJ_INIT (&pDrvCtrl->end, (DEV_OBJ *)pDrvCtrl, "netdrv",
        pDrvCtrl->unit, &NetdrvFuncTable,
        "END Net Driver.") == ERROR)
        || (END_MIB_INIT (&pDrvCtrl->end, M2_ifType_ethernet_csmacd,
        &pDrvCtrl->enetAddr[0], 6, ETHERMTU /*END_BUFSIZ*/, END_SPEED) == ERROR)) {
        goto errorExit;
    }

    /* Perform memory allocation/distribution */
    if (NetdrvMemInit (pDrvCtrl) == ERROR) {
        goto errorExit;
    }

    /* reset and reconfigure the device */
    /* NetdrvReset (pDrvCtrl);
       NetdrvConfig (pDrvCtrl);
    */

    /* set the flags to indicate readiness */
    END_OBJ_READY (&pDrvCtrl->end,
        IFF_UP | IFF_RUNNING | IFF_NOTRAILERS | IFF_BROADCAST
        | IFF_MULTICAST);

#ifdef POLLING_MODE
     /* NetdrvStart(pDrvCtrl); */
#endif
    DRV_LOG (1, "Net driver is loaded successfully!\n",1,2,3,4,5,6);

    return (&pDrvCtrl->end);

    errorExit:
    DRV_LOG (1, "FATAL ERROR :: fail to load net driver!\n",1,2,3,4,5,6);

    if (pDrvCtrl != NULL) {
        free ((char *)pDrvCtrl);
    }

    return NULL;
}
END_OBJ* mirrorEndLoad
    (
    char*   initString
    )
    {
    END_CTRL*   pDrvCtrl;

    if (initString == NULL)
        return NULL;
    
    if (initString[0] == 0)
        {
        bcopy((char *)MIRROR_DEV_NAME, initString, MIRROR_DEV_NAME_LEN);
        return NULL;
        }

    /* Parse InitString */
    switch (initString[0])
        {
        case '0':
            pDrvCtrl = &drvCtrl[0];
	    bzero((char *)pDrvCtrl,sizeof(END_CTRL)); 
            pDrvCtrl->unit = 0;
            SYS_ENET_ADDR_GET((char *) pDrvCtrl->enetAddr);

            break;
        
        case '1':
            pDrvCtrl = &drvCtrl[1];
	    bzero((char *)pDrvCtrl,sizeof(END_CTRL)); 
            pDrvCtrl->unit = 1;
            
            /* if unit ever REALLY needs a MAC address, change this appropriately */
            SYS_ENET_ADDR_GET((char *) pDrvCtrl->enetAddr);  
            
            break;
        
        default:
            return NULL;
        }

    /* Check if we are already attached */
    if (pDrvCtrl->endObject.attached == TRUE)
        return &pDrvCtrl->endObject;

    /* endObject initializations */
    if (END_OBJ_INIT(&pDrvCtrl->endObject, 
                     (void*)pDrvCtrl, 
                     MIRROR_DEV_NAME,
                     pDrvCtrl->unit, 
                     &netFuncs,
                     MIRROR_END_OBJ_STRING) == ERROR)
        {
        return NULL;
        }

    /* Initialize MIB2 entries */
    if (END_MIB_INIT(&pDrvCtrl->endObject, 
                     M2_ifType_ethernet_csmacd,
                     (UCHAR *) pDrvCtrl->enetAddr, 
                     6, 
                     ETHERMTU,
                     SPEED) == ERROR)
        {
        return NULL;
        }

    /* we need to import the memory pool from a real physical driver. At least
     * the WDB end driver is using it
     */

    if (pDrvCtrl->unit == 0)
        {
        char devName[END_NAME_MAX];
        int unit = 0;
        bzero(devName,END_NAME_MAX);

	if (bridgeNextPhyDevEndGet(devName,&unit) == ERROR)
            {
            printf("mirrorEndLoad: No physical device found\n");
            }
        else
	    {
	    END_OBJ * pEnd;

	    pEnd = endFindByName(devName,unit);

            if (pEnd != NULL)
	        pDrvCtrl->endObject.pNetPool = pEnd->pNetPool;

            pDrvCtrl->pPhyEnd = pEnd;
	    }
        }

    /* Mark the device ready */
    /* IFF_SCAT is not defined by default */
/*
    END_OBJ_READY(&pDrvCtrl->endObject,
                  IFF_NOTRAILERS | IP_IFF_BROADCAST | IFF_MULTICAST);
*/
    END_OBJ_READY(&pDrvCtrl->endObject,
                  IP_IFF_BROADCAST | IP_IFF_MULTICAST);

    /* Successful return */
    return &pDrvCtrl->endObject;
    }
/* VA device load function. */
static END_OBJ *vxworks_va_load(char *init_string, void *arg)
{
  VxWorksVa *va;
  char *token, *last;
  int unit, end_initialized;

  if (!init_string)
    return NULL;

  /* Empty init string indicates driver name query */
  if (!*init_string)
    {
      strcpy(init_string, vxworks_va_devname);
      return NULL;
    }

  /* Otherwise begin loading */
  end_initialized = 0;

  /* Get VA pointer given by us to muxDevLoad() */
  va = arg;
  unit = (int)(va - vxworks_va_tab);

  /* Verify unit number in the beginning of the init string */
  if (!(token = strtok_r(init_string, ":", &last)) || atoi(token) != unit)
    {
      SSH_TRACE(SSH_D_ERROR, ("%s: bad unit number in init string", va->name));
      return NULL;
    }

  SSH_DEBUG(SSH_D_HIGHOK, ("loading %s", va->name));

  if (END_OBJ_INIT(&va->end, &va->end.devObject, vxworks_va_devname, unit,
                   &vxworks_va_funcs, vxworks_va_desc) != OK)
    {
      SSH_TRACE(SSH_D_ERROR, ("%s: END_OBJ_INIT failed", va->name));
      goto fail;
    }
  end_initialized = 1;

#if VXWORKS_NETVER < 55122
#ifdef INCLUDE_RFC_2233

  /* Initialize MIB-II entries (for RFC 2233 ifXTable) */
  if (!(va->end.pMib2Tbl =
        m2IfAlloc(M2_ifType_ethernet_csmacd,
                  va->enet_addr, sizeof va->enet_addr,
                  vxworks_va_mtu, vxworks_va_speed,
                  vxworks_va_devname, unit)))
    {
      SSH_TRACE(SSH_D_ERROR, ("%s: m2IfAlloc failed", va->name));
      goto fail;
    }
        
    /* 
     * Set the RFC2233 flag bit in the END object flags field and
     * install the counter update routines.
     */
    m2IfPktCountRtnInstall(va->end.pMib2Tbl, m2If8023PacketCount);

    /*
     * Make a copy of the data in mib2Tbl struct as well. We do this
     * mainly for backward compatibility issues. There might be some
     * code that might be referencing the END pointer and might
     * possibly do lookups on the mib2Tbl, which will cause all sorts
     * of problems.
     */
    bcopy(&va->end.pMib2Tbl->m2Data.mibIfTbl,
          &va->end.mib2Tbl, sizeof va->end.mib2Tbl);

    /* Mark the device ready */
    END_OBJ_READY (&va->end,
                   IFF_NOTRAILERS | IFF_MULTICAST | IFF_BROADCAST |
                   END_MIB_2233);

#else /* INCLUDE_RFC_2233 */

    /* Old RFC 1213 mib2 interface */
    if (END_MIB_INIT (&va->end, M2_ifType_ethernet_csmacd,
                      va->enet_addr, sizeof va->enet_addr,
                      vxworks_va_mtu, vxworks_va_speed) == ERROR)
    {
      SSH_TRACE(SSH_D_ERROR, ("%s: END_MIB_INIT failed", va->name));
      goto fail;
    }

    /* Mark the device ready */
    END_OBJ_READY (&va->end, IFF_NOTRAILERS | IFF_MULTICAST | IFF_BROADCAST);

#endif /* INCLUDE_RFC_2233 */
#else /* VXWORKS_NETVER < 55122 */

  if (endM2Init(&va->end, M2_ifType_ethernet_csmacd,
                va->enet_addr, sizeof va->enet_addr,
                vxworks_va_mtu, vxworks_va_speed,
                IFF_NOTRAILERS | IFF_MULTICAST | IFF_BROADCAST) != OK)
    {
      SSH_TRACE(SSH_D_ERROR, ("%s: endM2Init failed", va->name));
      goto fail;
    }

#endif /* VXWORKS_NETVER < 55122 */

  return &va->end;

 fail:
  if (end_initialized)
    END_OBJECT_UNLOAD(&va->end);
  return NULL;
}
Пример #4
0
struct end_object *
socend_load(char *is, void* ap)
/*
 * Function: 	socend_load
 * Purpose:	Provides SENS load routine for SOC device.
 * Parameters:	is - initialization string.
 * Returns:	Pointer to VxWorks end_obj structure or NULL
 */
{
    struct end_object	*eo;
    socend_t		*se;		/* Sock End Structure */
    seu_t		*seu;
    char		dev_name[sizeof(eo->devObject.name)];
    char		mac[6];		/* MAC address parsing */
    int			net_unit;
    char	        mac_str[MACADDR_STR_LEN];
    int 		i, column_count, rt;

    if (NULL == is) {
	LOG_CLI((BSL_META("socend_load: unexpected NULL pointer for device name\n")));
	return(NULL);
    } else if ('\0' == *is) {		/* Copy in our device name */
	strcpy(is, "sc");
	return(NULL);
    }
    LOG_INFO(BSL_LS_SYS_END,
             (BSL_META("socend_load: %s\n"), is));

    /*
     * Setup END structure
     *
     * NOTE NOTE NOTE: 	This call MUST use calloc or malloc, since the object
     * 		   	is freed by VxWorks using free();
     */

    if (NULL == (se = malloc(sizeof(*se)))) {
      LOG_CLI((BSL_META("socend_load: failed to allocate memory for %s\n"), is));
      return(NULL);
    }

    bzero((void *)se, sizeof(*se));
    eo = &se->se_eo;

    net_unit = atoi(is);
    is = index(is, ':') + 1;

    /* Parse init string, format is "net_unit:bcm_unit:MAC_ADDR:vlan" */

    se->se_unit = atoi(is);
    seu = &socend_seu[se->se_unit];
    is = index(is, ':') + 1;		/* Onto net unit # */

    if ((se->se_unit >= BCM_MAX_NUM_UNITS) || !*is) {
	LOG_CLI((BSL_META("socend_load: Invalid soc device: %d\n"), se->se_unit));
	free(se);
	return(NULL);
    }

    /* Check if optional VLAN/MAC address */

    se->se_vlan = VLAN_ID_INVALID;
    if (is) {
	column_count = 0;
	i = 0;
	while (*is && i < MACADDR_STR_LEN - 1 && column_count <= 5) {
	    mac_str[i++] = *is;
	    if (*is++ == ':') {
		column_count++;
	    }
	}
	mac_str[i] = '\0';
	if (column_count == 6) {
	    mac_str[i-1] = '\0';
	}
	if (5 <= column_count) {
	    rt = parse_macaddr(mac_str, se->se_mac);
	} else {
	    rt = -1;
	}
	if (rt) {
	    LOG_CLI((BSL_META("socend_load: Invalid MAC address specified: %s\n"),
                     mac_str));
	    free(se);
	    return(NULL);
	}
	if (column_count == 6) {
	    se->se_vlan = atoi(is);
	}
    } else {
	ENET_COPY_MACADDR(mac_zero, se->se_mac);
    }

    if (se->se_vlan == VLAN_ID_INVALID) {
	bcm_vlan_t	vid;
	bcm_vlan_default_get(se->se_unit, &vid);
	se->se_vlan = vid;
    }

    if (ERROR == END_OBJ_INIT(eo, (DEV_OBJ *)se, "sc", net_unit,
			      &socend_netfuncs, SOC_END_STRING)) {
	LOG_CLI((BSL_META("socend_load: END_OBJ_INIT failed for %s\n"), dev_name));
    }
    if (ERROR == END_MIB_INIT(eo, M2_ifType_ethernet_csmacd, (UCHAR *)mac,
			      sizeof(mac), ETHERMTU, SOC_END_SPEED)) {
	LOG_CLI((BSL_META("socend_load: END_MIB_INIT failed for %s\n"), dev_name));
    }

    socend_mempool_alloc(se, SOC_END_PK_SZ, SOC_END_CLBLKS, SOC_END_CLBUFS,
			 SOC_END_MBLKS);

    /* Set Ready */

    END_OBJ_READY (eo, IFF_NOTRAILERS | IFF_MULTICAST | IFF_BROADCAST);

    /* Queue off of seu structure */

    se->se_next = seu->seu_devices;
    seu->seu_devices = se;
#if defined(__mips__)
    if(SOC_IS_ESW(se->se_unit)) {
        socend_packet_alloc(se->se_unit, SOC_END_PK_SZ, 0, 
                               &seu->pkt_align_buf);
    }
#endif /* __mips__ */
    return(eo);
}