Date: Thu, 17 Jun 2010 14:46:27 GMT From: Alexandre Fiveg <afiveg@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 179713 for review Message-ID: <201006171446.o5HEkRSP022515@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@179713?ac=10 Change 179713 by afiveg@cottonmouth on 2010/06/17 14:46:03 Begin with new design for ringmap: 1. The new structure with pointers to hardware dependent functions: "struct ringmap_functions" (/net/ringmap.h) 2. Pointer to this structure placed in ringmap structure. 3. In the ringmap_attach function look for pci Id of network controller, and then, depending on controllers type, initialize the functions pointers: (ringmap.c: set_ringmap_funcs()) Affected files ... .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_api.h#4 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_hw.h#4 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_em.c#7 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.c#4 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.h#4 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#2 edit .. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#6 edit .. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#6 edit Differences ... ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_api.h#4 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_hw.h#4 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_em.c#7 (text+ko) ==== @@ -86,10 +86,9 @@ #include "if_em.h" #ifdef RINGMAP -#include <net/ringmap.h> -extern int ringmap_attach (struct ringmap **); -extern int ringmap_detach (struct ringmap *); +extern int ringmap_attach (device_t); +extern int ringmap_detach (device_t); #endif /********************************************************************* ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.c#4 (text+ko) ==== @@ -264,10 +264,9 @@ #ifdef RINGMAP -#include <net/ringmap.h> -extern int ringmap_attach (struct ringmap **, device_t); -extern int ringmap_detach (struct ringmap *); +extern int ringmap_attach (device_t); +extern int ringmap_detach (device_t); #endif #ifdef DEVICE_POLLING @@ -721,7 +720,7 @@ INIT_DEBUGOUT("em_detach: begin"); #ifdef RINGMAP - ringmap_detach (adapter->rm); + ringmap_detach (dev); #endif /* Make sure VLANS are not using driver */ ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.h#4 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#2 (text+ko) ==== @@ -1,0 +1,45 @@ +#include <sys/param.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/taskqueue.h> + +#include <machine/bus.h> + +#include <net/if.h> +#include <net/if_var.h> +#include <net/if_types.h> +#include <net/if_media.h> + +#include <net/ringmap.h> + +#include "e1000_api.h" +#include "if_lem.h" + +int rm_8254_set_ringmap_to_adapter(device_t, struct ringmap *); +struct ringmap * rm_8254_get_ringmap_p(device_t); + +/* + * Set pointer to ringmap in the adapter structure. + */ +int +rm_8254_set_ringmap_to_adapter(device_t dev, struct ringmap *rm) +{ + struct adapter *adapter; + + adapter = (struct adapter *)device_get_softc(dev); + adapter->rm = rm; + + return (0); +} + +/* + * Returns pointer to ringmap structure + */ +struct ringmap * +rm_8254_get_ringmap_p(device_t dev) +{ + struct adapter *adapter; + + adapter = (struct adapter *)device_get_softc(dev); + return (adapter->rm); +} ==== //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#6 (text+ko) ==== @@ -27,11 +27,9 @@ #include <vm/vm_param.h> #include <vm/vm_kern.h> +#include <dev/pci/pcivar.h> /* For pci_get macros! */ +#include <dev/pci/pcireg.h> -//#ifdef __E1000_RINGMAP__ -//#include "e1000_api.h" -//#include "if_em.h" -// //extern devclass_t em_devclass; //extern int em_rxeof(struct rx_ring *, int); //extern bool em_txeof(struct tx_ring *); @@ -41,10 +39,17 @@ #include "ringmap.h" -/* F U N C T I O N S */ -int ringmap_attach(device_t); -int ringmap_detach(device_t); -int set_ringmap_to_adapter (device_t, ringmap *); +int ringmap_attach (device_t); +int ringmap_detach (device_t); +int is_supported (unsigned int pci_dev_id); +void ringmap_close_cb (void *data); +int set_ringmap_funcs (struct ringmap *rm, unsigned int controller_type); +struct ringmap *(*get_ringmap_p)(device_t); + +extern int rm_8254_set_ringmap_to_adapter(device_t, struct ringmap *); +extern struct ringmap * rm_8254_get_ringmap_p(device_t); + + //struct adapter* get_adapter_struct(struct cdev *dev); //int ringmap_print_ring_pointers(struct adapter *); //void ringmap_print_ring (struct adapter *adapter, int level); @@ -62,7 +67,6 @@ d_ioctl_t ringmap_ioctl; d_mmap_t ringmap_mmap; -void ringmap_close_cb (void *data); /* * Character Device for access on if_em driver structures @@ -76,16 +80,91 @@ /* name */ .d_name = "ringmap_cdev" }; +struct device_type supported_devices[] = +{ + { 0x1079, 8254 }, /* 8254GB, COPPER, Dual Port */ + { 0x105E, 8257 }, /* 82571EB, COPPER, PCIe Dual Port */ + { 0, 0} /* last entry */ +}; + +/* + * If pci_dev_id is supported by ringmap, then controller_type related to this + * pci_dev_id will be returned. Look for device_type structure in ringmap.h! + * Now only 8254* and 8257* controllers are supported. The list of supported + * controllers doesn't include all of them, but only the controllers that I've + * tested. + */ +int +is_supported (unsigned int pci_dev_id) +{ + struct device_type *dt; + + dt = supported_devices; + while (dt->pci_device_id != 0) { + if (pci_dev_id == dt->pci_device_id){ + return (dt->controller_type); + } + dt++; + } + return (0); +} + /* + * Set hardware-dependent functions + */ +int +set_ringmap_funcs (struct ringmap *rm, unsigned int controller_type) +{ + + switch(controller_type) { + case 8254: + RINGMAP_OUTPUT(Controller Type: 8254); + + /* Set ringmap pointer in the drivrs structure of adapter */ + rm->funcs->set_ringmap_to_adapter = + rm_8254_set_ringmap_to_adapter; + get_ringmap_p = rm_8254_get_ringmap_p; + break; + + case 8257: + RINGMAP_OUTPUT(Controller Type: 8257); + RINGMAP_OUTPUT(Now not supported!); + + break; + + default: + RINGMAP_OUTPUT(Unsupported Controller Type!); + } + return (0); +} + +/* * Will called from if_em.c before returning from * em_attach() function. */ -int ringmap_attach(device_t devt) { +int +ringmap_attach(device_t dev) +{ struct ringmap *rm; struct ring *ring; + struct ringmap_functions *ringmap_functions; + unsigned int pci_dev_id = 0; + unsigned int controller_type = 0; RINGMAP_FUNC_DEBUG(begin); + pci_dev_id = pci_get_device(dev); + controller_type = is_supported(pci_dev_id); + + /* Make sure we are support this controller */ + if (!(controller_type)) + return (-1); + + /* + * Allocate memory for ringmap structures: ringmap and ring. + * Use contigmalloc(9) to get PAGE_SIZE alignment that is needed + * for memory mapping. + */ rm = (struct ringmap *) contigmalloc (sizeof(struct ringmap), M_DEVBUF, M_ZERO, 0, -1L, PAGE_SIZE, 0); @@ -101,7 +180,16 @@ return (-1); } - rm->ring = ring; + ringmap_functions = + (struct ringmap_functions *) contigmalloc (sizeof (struct ringmap_functions), + M_DEVBUF, M_ZERO, 0, -1L, PAGE_SIZE, 0); + if (ringmap_functions == NULL) { + RINGMAP_ERROR(Can not allocate space for ringmap_functions structure); + return (-1); + } + + rm->ring = ring; + rm->funcs = ringmap_functions; /* * Create char device for communication with user space. User space process @@ -112,18 +200,21 @@ * * - controll packet capturing: start, stop, sleep to wait for packets. */ - rm->ringmap_dev = make_dev(&ringmap_devsw, device_get_unit(adapter_dev), - UID_ROOT, GID_WHEEL, 0666, RINGMAP_DEVICE); + rm->cdev = make_dev(&ringmap_devsw, device_get_unit(dev), + UID_ROOT, GID_WHEEL, 0666, RINGMAP_DEVICE); /* Device open counter */ rm->open_cnt = 0; /* Pointer to structure of process wich has opened the device */ - rm->procp = NULL; + rm->td = NULL; + + /* Set functions for ringmap functionality depending on controller type */ + set_ringmap_funcs(rm, controller_type); /* set the pointer to ringmap in the adapters structure */ + rm->funcs->set_ringmap_to_adapter(dev, rm); - RINGMAP_FUNC_DEBUG(end); return (0); @@ -131,16 +222,23 @@ int -ringmap_detach(struct ringmap *rm) +ringmap_detach(device_t devt) { + struct ringmap *rm = NULL; + RINGMAP_FUNC_DEBUG(start); - destroy_dev(rm->ringmap_dev); + rm = get_ringmap_p (devt); + if (rm == NULL){ + RINGMAP_WARN(Can not get pointer to ringmap structure); + return (-1); + } + destroy_dev(rm->cdev); contigfree(rm->ring, sizeof(struct ring), M_DEVBUF); - - contigfree(rm, sizeof(struct ring), M_DEVBUF); + contigfree(rm->funcs, sizeof(struct ringmap_functions), M_DEVBUF); + contigfree(rm, sizeof(struct ringmap), M_DEVBUF); RINGMAP_FUNC_DEBUG(end); @@ -489,3 +587,6 @@ // // return (0); //} + + + ==== //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#6 (text+ko) ==== @@ -1,8 +1,3 @@ -//#ifdef __E1000_RINGMAP__ -//#ifdef _KERNEL -//#include "ringmap_e1000.h" -//#endif -//#endif /* Minimum distance to be kept between the userrp and RDT to provide a * guarantee to userspace processes that the previous n buffer positions @@ -27,9 +22,10 @@ // #define DEV_ID 0x105E #define DEV_ID 0 -#ifndef _KERNEL -#include <machine/bus.h> -#endif +struct device_type { + unsigned int pci_device_id; + unsigned int controller_type; +}; struct address { bus_addr_t phys; @@ -110,15 +106,16 @@ struct ring_slot slot[SLOTS_NUMBER]; }; + #ifdef _KERNEL -struct adapter; +struct ringmap_functions; struct ringmap { /* Device structure of network adapters driver */ device_t devt; /* Char device for communications between user and kernel spaces */ - struct cdev *ringmap_cdev; + struct cdev *cdev; /* Capturing thread */ struct thread *td; @@ -129,10 +126,16 @@ /* How many packets have counted driver in RAM */ unsigned long long pkts_counter; + /* Hardware dependent functions */ + struct ringmap_functions *funcs; + /* Our ring that have to be mapped in space of user process */ struct ring *ring; }; +struct ringmap_functions { + int (*set_ringmap_to_adapter)(device_t, struct ringmap*); +}; #endif /* _KERNEL */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006171446.o5HEkRSP022515>