4949#define E1000_RX_INTPT_TIME 128
5050#define E1000_RX_PKT_CNT 8
5151
52- static char ident [] = "Intel PRO/1000 Ethernet 5.2.0 " ;
52+ static char ident [] = "Intel PRO/1000 Ethernet 5.2.1 " ;
5353static char e1000g_string [] = "Intel(R) PRO/1000 Network Connection" ;
54- static char e1000g_version [] = "Driver Ver. 5.2.0 " ;
54+ static char e1000g_version [] = "Driver Ver. 5.2.1 " ;
5555
5656/*
5757 * Proto types for DDI entry points
@@ -142,6 +142,7 @@ static boolean_t e1000g_link_up(struct e1000g *);
142142#ifdef __sparc
143143static boolean_t e1000g_find_mac_address (struct e1000g * );
144144#endif
145+ static void e1000g_free_priv_devi_node (struct e1000g * , boolean_t );
145146
146147static struct cb_ops cb_ws_ops = {
147148 nulldev , /* cb_open */
@@ -214,6 +215,7 @@ static mac_callbacks_t e1000g_m_callbacks = {
214215/*
215216 * Global variables
216217 */
218+
217219uint32_t e1000g_mblks_pending = 0 ;
218220/*
219221 * Workaround for Dynamic Reconfiguration support, for x86 platform only.
@@ -393,25 +395,6 @@ e1000g_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd)
393395
394396 ddi_set_driver_private (devinfo , (caddr_t )Adapter );
395397
396- if (e1000g_force_detach ) {
397- private_devi_list_t * devi_node ;
398-
399- Adapter -> priv_dip =
400- kmem_zalloc (sizeof (struct dev_info ), KM_SLEEP );
401- bcopy (DEVI (devinfo ), DEVI (Adapter -> priv_dip ),
402- sizeof (struct dev_info ));
403-
404- devi_node =
405- kmem_zalloc (sizeof (private_devi_list_t ), KM_SLEEP );
406-
407- rw_enter (& e1000g_rx_detach_lock , RW_WRITER );
408- devi_node -> dip = devinfo ;
409- devi_node -> priv_dip = Adapter -> priv_dip ;
410- devi_node -> next = e1000g_private_devi_list ;
411- e1000g_private_devi_list = devi_node ;
412- rw_exit (& e1000g_rx_detach_lock );
413- }
414-
415398 /*
416399 * PCI Configure
417400 */
@@ -519,6 +502,30 @@ e1000g_attach(dev_info_t *devinfo, ddi_attach_cmd_t cmd)
519502 }
520503 Adapter -> attach_progress |= ATTACH_PROGRESS_ENABLE_INTR ;
521504
505+ /*
506+ * If e1000g_force_detach is enabled, in global private dip list,
507+ * we will create a new entry, which maintains the priv_dip for DR
508+ * supports after driver detached.
509+ */
510+ if (e1000g_force_detach ) {
511+ private_devi_list_t * devi_node ;
512+
513+ Adapter -> priv_dip =
514+ kmem_zalloc (sizeof (struct dev_info ), KM_SLEEP );
515+ bcopy (DEVI (devinfo ), DEVI (Adapter -> priv_dip ),
516+ sizeof (struct dev_info ));
517+
518+ devi_node =
519+ kmem_zalloc (sizeof (private_devi_list_t ), KM_SLEEP );
520+
521+ rw_enter (& e1000g_rx_detach_lock , RW_WRITER );
522+ devi_node -> priv_dip = Adapter -> priv_dip ;
523+ devi_node -> flag = E1000G_PRIV_DEVI_ATTACH ;
524+ devi_node -> next = e1000g_private_devi_list ;
525+ e1000g_private_devi_list = devi_node ;
526+ rw_exit (& e1000g_rx_detach_lock );
527+ }
528+
522529 cmn_err (CE_CONT , "!%s, %s\n" , e1000g_string , e1000g_version );
523530
524531 return (DDI_SUCCESS );
@@ -840,6 +847,7 @@ static int
840847e1000g_detach (dev_info_t * devinfo , ddi_detach_cmd_t cmd )
841848{
842849 struct e1000g * Adapter ;
850+ boolean_t rx_drain ;
843851
844852 switch (cmd ) {
845853 default :
@@ -865,8 +873,18 @@ e1000g_detach(dev_info_t *devinfo, ddi_detach_cmd_t cmd)
865873 if (Adapter -> started )
866874 e1000g_stop (Adapter , B_TRUE );
867875
868- if (!e1000g_rx_drain (Adapter )) {
869- if (!e1000g_force_detach )
876+ rx_drain = e1000g_rx_drain (Adapter );
877+
878+ /*
879+ * If e1000g_force_detach is enabled, driver detach is safe.
880+ * We will let e1000g_free_priv_devi_node routine determine
881+ * whether we need to free the priv_dip entry for current
882+ * driver instance.
883+ */
884+ if (e1000g_force_detach ) {
885+ e1000g_free_priv_devi_node (Adapter , rx_drain );
886+ } else {
887+ if (!rx_drain )
870888 return (DDI_FAILURE );
871889 }
872890
@@ -875,6 +893,66 @@ e1000g_detach(dev_info_t *devinfo, ddi_detach_cmd_t cmd)
875893 return (DDI_SUCCESS );
876894}
877895
896+ /*
897+ * e1000g_free_priv_devi_node - free a priv_dip entry for driver instance
898+ *
899+ * If free_flag is true, that indicates the upper layer is not holding
900+ * the rx buffers, we could free the priv_dip entry safely.
901+ *
902+ * Otherwise, we have to keep this entry even after driver detached,
903+ * and we also need to mark this entry with E1000G_PRIV_DEVI_DETACH flag,
904+ * so that driver could free it while all of rx buffers are returned
905+ * by upper layer later.
906+ */
907+ static void
908+ e1000g_free_priv_devi_node (struct e1000g * Adapter , boolean_t free_flag )
909+ {
910+ private_devi_list_t * devi_node , * devi_del ;
911+
912+ rw_enter (& e1000g_rx_detach_lock , RW_WRITER );
913+ ASSERT (e1000g_private_devi_list != NULL );
914+ ASSERT (Adapter -> priv_dip != NULL );
915+
916+ devi_node = e1000g_private_devi_list ;
917+ if (devi_node -> priv_dip == Adapter -> priv_dip ) {
918+ if (free_flag ) {
919+ e1000g_private_devi_list =
920+ devi_node -> next ;
921+ kmem_free (devi_node -> priv_dip ,
922+ sizeof (struct dev_info ));
923+ kmem_free (devi_node ,
924+ sizeof (private_devi_list_t ));
925+ } else {
926+ ASSERT (e1000g_mblks_pending != 0 );
927+ devi_node -> flag =
928+ E1000G_PRIV_DEVI_DETACH ;
929+ }
930+ rw_exit (& e1000g_rx_detach_lock );
931+ return ;
932+ }
933+
934+ devi_node = e1000g_private_devi_list ;
935+ while (devi_node -> next != NULL ) {
936+ if (devi_node -> next -> priv_dip == Adapter -> priv_dip ) {
937+ if (free_flag ) {
938+ devi_del = devi_node -> next ;
939+ devi_node -> next = devi_del -> next ;
940+ kmem_free (devi_del -> priv_dip ,
941+ sizeof (struct dev_info ));
942+ kmem_free (devi_del ,
943+ sizeof (private_devi_list_t ));
944+ } else {
945+ ASSERT (e1000g_mblks_pending != 0 );
946+ devi_node -> next -> flag =
947+ E1000G_PRIV_DEVI_DETACH ;
948+ }
949+ break ;
950+ }
951+ devi_node = devi_node -> next ;
952+ }
953+ rw_exit (& e1000g_rx_detach_lock );
954+ }
955+
878956static void
879957e1000g_unattach (dev_info_t * devinfo , struct e1000g * Adapter )
880958{
0 commit comments