@@ -547,13 +547,41 @@ static void bnge_free_vnics(struct bnge_net *bn)
547547 bn -> nr_vnics = 0 ;
548548}
549549
550+ static void bnge_free_ring_grps (struct bnge_net * bn )
551+ {
552+ kfree (bn -> grp_info );
553+ bn -> grp_info = NULL ;
554+ }
555+
556+ static int bnge_init_ring_grps (struct bnge_net * bn )
557+ {
558+ struct bnge_dev * bd = bn -> bd ;
559+ int i ;
560+
561+ bn -> grp_info = kcalloc (bd -> nq_nr_rings ,
562+ sizeof (struct bnge_ring_grp_info ),
563+ GFP_KERNEL );
564+ if (!bn -> grp_info )
565+ return - ENOMEM ;
566+ for (i = 0 ; i < bd -> nq_nr_rings ; i ++ ) {
567+ bn -> grp_info [i ].fw_stats_ctx = INVALID_HW_RING_ID ;
568+ bn -> grp_info [i ].fw_grp_id = INVALID_HW_RING_ID ;
569+ bn -> grp_info [i ].rx_fw_ring_id = INVALID_HW_RING_ID ;
570+ bn -> grp_info [i ].agg_fw_ring_id = INVALID_HW_RING_ID ;
571+ bn -> grp_info [i ].nq_fw_ring_id = INVALID_HW_RING_ID ;
572+ }
573+
574+ return 0 ;
575+ }
576+
550577static void bnge_free_core (struct bnge_net * bn )
551578{
552579 bnge_free_vnic_attributes (bn );
553580 bnge_free_tx_rings (bn );
554581 bnge_free_rx_rings (bn );
555582 bnge_free_nq_tree (bn );
556583 bnge_free_nq_arrays (bn );
584+ bnge_free_ring_grps (bn );
557585 bnge_free_vnics (bn );
558586 kfree (bn -> tx_ring_map );
559587 bn -> tx_ring_map = NULL ;
@@ -692,6 +720,167 @@ static irqreturn_t bnge_msix(int irq, void *dev_instance)
692720 return IRQ_HANDLED ;
693721}
694722
723+ static void bnge_init_nq_tree (struct bnge_net * bn )
724+ {
725+ struct bnge_dev * bd = bn -> bd ;
726+ int i , j ;
727+
728+ for (i = 0 ; i < bd -> nq_nr_rings ; i ++ ) {
729+ struct bnge_nq_ring_info * nqr = & bn -> bnapi [i ]-> nq_ring ;
730+ struct bnge_ring_struct * ring = & nqr -> ring_struct ;
731+
732+ ring -> fw_ring_id = INVALID_HW_RING_ID ;
733+ for (j = 0 ; j < nqr -> cp_ring_count ; j ++ ) {
734+ struct bnge_cp_ring_info * cpr = & nqr -> cp_ring_arr [j ];
735+
736+ ring = & cpr -> ring_struct ;
737+ ring -> fw_ring_id = INVALID_HW_RING_ID ;
738+ }
739+ }
740+ }
741+
742+ static void bnge_init_rxbd_pages (struct bnge_ring_struct * ring , u32 type )
743+ {
744+ struct rx_bd * * rx_desc_ring ;
745+ u32 prod ;
746+ int i ;
747+
748+ rx_desc_ring = (struct rx_bd * * )ring -> ring_mem .pg_arr ;
749+ for (i = 0 , prod = 0 ; i < ring -> ring_mem .nr_pages ; i ++ ) {
750+ struct rx_bd * rxbd = rx_desc_ring [i ];
751+ int j ;
752+
753+ for (j = 0 ; j < RX_DESC_CNT ; j ++ , rxbd ++ , prod ++ ) {
754+ rxbd -> rx_bd_len_flags_type = cpu_to_le32 (type );
755+ rxbd -> rx_bd_opaque = prod ;
756+ }
757+ }
758+ }
759+
760+ static void bnge_init_one_rx_ring_rxbd (struct bnge_net * bn ,
761+ struct bnge_rx_ring_info * rxr )
762+ {
763+ struct bnge_ring_struct * ring ;
764+ u32 type ;
765+
766+ type = (bn -> rx_buf_use_size << RX_BD_LEN_SHIFT ) |
767+ RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP ;
768+
769+ if (NET_IP_ALIGN == 2 )
770+ type |= RX_BD_FLAGS_SOP ;
771+
772+ ring = & rxr -> rx_ring_struct ;
773+ bnge_init_rxbd_pages (ring , type );
774+ ring -> fw_ring_id = INVALID_HW_RING_ID ;
775+ }
776+
777+ static void bnge_init_one_agg_ring_rxbd (struct bnge_net * bn ,
778+ struct bnge_rx_ring_info * rxr )
779+ {
780+ struct bnge_ring_struct * ring ;
781+ u32 type ;
782+
783+ ring = & rxr -> rx_agg_ring_struct ;
784+ ring -> fw_ring_id = INVALID_HW_RING_ID ;
785+ if (bnge_is_agg_reqd (bn -> bd )) {
786+ type = ((u32 )BNGE_RX_PAGE_SIZE << RX_BD_LEN_SHIFT ) |
787+ RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP ;
788+
789+ bnge_init_rxbd_pages (ring , type );
790+ }
791+ }
792+
793+ static void bnge_init_one_rx_ring_pair (struct bnge_net * bn , int ring_nr )
794+ {
795+ struct bnge_rx_ring_info * rxr ;
796+
797+ rxr = & bn -> rx_ring [ring_nr ];
798+ bnge_init_one_rx_ring_rxbd (bn , rxr );
799+
800+ netif_queue_set_napi (bn -> netdev , ring_nr , NETDEV_QUEUE_TYPE_RX ,
801+ & rxr -> bnapi -> napi );
802+
803+ bnge_init_one_agg_ring_rxbd (bn , rxr );
804+ }
805+
806+ static void bnge_init_rx_rings (struct bnge_net * bn )
807+ {
808+ int i ;
809+
810+ #define BNGE_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
811+ #define BNGE_RX_DMA_OFFSET NET_SKB_PAD
812+ bn -> rx_offset = BNGE_RX_OFFSET ;
813+ bn -> rx_dma_offset = BNGE_RX_DMA_OFFSET ;
814+
815+ for (i = 0 ; i < bn -> bd -> rx_nr_rings ; i ++ )
816+ bnge_init_one_rx_ring_pair (bn , i );
817+ }
818+
819+ static void bnge_init_tx_rings (struct bnge_net * bn )
820+ {
821+ int i ;
822+
823+ bn -> tx_wake_thresh = max (bn -> tx_ring_size / 2 , BNGE_MIN_TX_DESC_CNT );
824+
825+ for (i = 0 ; i < bn -> bd -> tx_nr_rings ; i ++ ) {
826+ struct bnge_tx_ring_info * txr = & bn -> tx_ring [i ];
827+ struct bnge_ring_struct * ring = & txr -> tx_ring_struct ;
828+
829+ ring -> fw_ring_id = INVALID_HW_RING_ID ;
830+
831+ netif_queue_set_napi (bn -> netdev , i , NETDEV_QUEUE_TYPE_TX ,
832+ & txr -> bnapi -> napi );
833+ }
834+ }
835+
836+ static void bnge_init_vnics (struct bnge_net * bn )
837+ {
838+ struct bnge_vnic_info * vnic0 = & bn -> vnic_info [BNGE_VNIC_DEFAULT ];
839+ int i ;
840+
841+ for (i = 0 ; i < bn -> nr_vnics ; i ++ ) {
842+ struct bnge_vnic_info * vnic = & bn -> vnic_info [i ];
843+ int j ;
844+
845+ vnic -> fw_vnic_id = INVALID_HW_RING_ID ;
846+ vnic -> vnic_id = i ;
847+ for (j = 0 ; j < BNGE_MAX_CTX_PER_VNIC ; j ++ )
848+ vnic -> fw_rss_cos_lb_ctx [j ] = INVALID_HW_RING_ID ;
849+
850+ if (bn -> vnic_info [i ].rss_hash_key ) {
851+ if (i == BNGE_VNIC_DEFAULT ) {
852+ u8 * key = (void * )vnic -> rss_hash_key ;
853+ int k ;
854+
855+ if (!bn -> rss_hash_key_valid &&
856+ !bn -> rss_hash_key_updated ) {
857+ get_random_bytes (bn -> rss_hash_key ,
858+ HW_HASH_KEY_SIZE );
859+ bn -> rss_hash_key_updated = true;
860+ }
861+
862+ memcpy (vnic -> rss_hash_key , bn -> rss_hash_key ,
863+ HW_HASH_KEY_SIZE );
864+
865+ if (!bn -> rss_hash_key_updated )
866+ continue ;
867+
868+ bn -> rss_hash_key_updated = false;
869+ bn -> rss_hash_key_valid = true;
870+
871+ bn -> toeplitz_prefix = 0 ;
872+ for (k = 0 ; k < 8 ; k ++ ) {
873+ bn -> toeplitz_prefix <<= 8 ;
874+ bn -> toeplitz_prefix |= key [k ];
875+ }
876+ } else {
877+ memcpy (vnic -> rss_hash_key , vnic0 -> rss_hash_key ,
878+ HW_HASH_KEY_SIZE );
879+ }
880+ }
881+ }
882+ }
883+
695884static void bnge_setup_msix (struct bnge_net * bn )
696885{
697886 struct net_device * dev = bn -> netdev ;
@@ -836,6 +1025,20 @@ static void bnge_del_napi(struct bnge_net *bn)
8361025 synchronize_net ();
8371026}
8381027
1028+ static int bnge_init_nic (struct bnge_net * bn )
1029+ {
1030+ int rc ;
1031+
1032+ bnge_init_nq_tree (bn );
1033+ bnge_init_rx_rings (bn );
1034+ bnge_init_tx_rings (bn );
1035+ rc = bnge_init_ring_grps (bn );
1036+ if (rc )
1037+ return rc ;
1038+ bnge_init_vnics (bn );
1039+ return rc ;
1040+ }
1041+
8391042static int bnge_open_core (struct bnge_net * bn )
8401043{
8411044 struct bnge_dev * bd = bn -> bd ;
@@ -862,9 +1065,16 @@ static int bnge_open_core(struct bnge_net *bn)
8621065 goto err_del_napi ;
8631066 }
8641067
1068+ rc = bnge_init_nic (bn );
1069+ if (rc ) {
1070+ netdev_err (bn -> netdev , "bnge_init_nic err: %d\n" , rc );
1071+ goto err_free_irq ;
1072+ }
8651073 set_bit (BNGE_STATE_OPEN , & bd -> state );
8661074 return 0 ;
8671075
1076+ err_free_irq :
1077+ bnge_free_irq (bn );
8681078err_del_napi :
8691079 bnge_del_napi (bn );
8701080 bnge_free_core (bn );
0 commit comments