diff options
author | Karicheri, Muralidharan <m-karicheri2@ti.com> | 2016-02-19 12:58:44 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-02-21 22:03:15 -0500 |
commit | 0632448134d0ac1450a19d26f90948fde3b558ad (patch) | |
tree | 38e962efb53a918067589c620028491204b94490 | |
parent | b1cb86ae0e5951e9747ec7a5b33d1c1217791b75 (diff) |
net: netcp: rework the code for get/set sw_data in dma desc
SW data field in descriptor can be used by software to hold private
data for the driver. As there are 4 words available for this purpose,
use separate macros to place it or retrieve the same to/from
descriptors. Also do type cast of data types accordingly.
Cc: Wingman Kwok <w-kwok2@ti.com>
Cc: Mugunthan V N <mugunthanvnm@ti.com>
CC: Arnd Bergmann <arnd@arndb.de>
CC: Grygorii Strashko <grygorii.strashko@ti.com>
CC: David Laight <David.Laight@ACULAB.COM>
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/ethernet/ti/netcp_core.c | 72 |
1 files changed, 55 insertions, 17 deletions
diff --git a/drivers/net/ethernet/ti/netcp_core.c b/drivers/net/ethernet/ti/netcp_core.c index 84bab29995fd..029841f98c32 100644 --- a/drivers/net/ethernet/ti/netcp_core.c +++ b/drivers/net/ethernet/ti/netcp_core.c | |||
@@ -117,13 +117,18 @@ static void get_pkt_info(dma_addr_t *buff, u32 *buff_len, dma_addr_t *ndesc, | |||
117 | *ndesc = le32_to_cpu(desc->next_desc); | 117 | *ndesc = le32_to_cpu(desc->next_desc); |
118 | } | 118 | } |
119 | 119 | ||
120 | static void get_sw_data(u32 *data0, u32 *data1, struct knav_dma_desc *desc) | 120 | static u32 get_sw_data(int index, struct knav_dma_desc *desc) |
121 | { | 121 | { |
122 | /* No Endian conversion needed as this data is untouched by hw */ | 122 | /* No Endian conversion needed as this data is untouched by hw */ |
123 | *data0 = desc->sw_data[0]; | 123 | return desc->sw_data[index]; |
124 | *data1 = desc->sw_data[1]; | ||
125 | } | 124 | } |
126 | 125 | ||
126 | /* use these macros to get sw data */ | ||
127 | #define GET_SW_DATA0(desc) get_sw_data(0, desc) | ||
128 | #define GET_SW_DATA1(desc) get_sw_data(1, desc) | ||
129 | #define GET_SW_DATA2(desc) get_sw_data(2, desc) | ||
130 | #define GET_SW_DATA3(desc) get_sw_data(3, desc) | ||
131 | |||
127 | static void get_org_pkt_info(dma_addr_t *buff, u32 *buff_len, | 132 | static void get_org_pkt_info(dma_addr_t *buff, u32 *buff_len, |
128 | struct knav_dma_desc *desc) | 133 | struct knav_dma_desc *desc) |
129 | { | 134 | { |
@@ -154,13 +159,18 @@ static void set_desc_info(u32 desc_info, u32 pkt_info, | |||
154 | desc->packet_info = cpu_to_le32(pkt_info); | 159 | desc->packet_info = cpu_to_le32(pkt_info); |
155 | } | 160 | } |
156 | 161 | ||
157 | static void set_sw_data(u32 data0, u32 data1, struct knav_dma_desc *desc) | 162 | static void set_sw_data(int index, u32 data, struct knav_dma_desc *desc) |
158 | { | 163 | { |
159 | /* No Endian conversion needed as this data is untouched by hw */ | 164 | /* No Endian conversion needed as this data is untouched by hw */ |
160 | desc->sw_data[0] = data0; | 165 | desc->sw_data[index] = data; |
161 | desc->sw_data[1] = data1; | ||
162 | } | 166 | } |
163 | 167 | ||
168 | /* use these macros to set sw data */ | ||
169 | #define SET_SW_DATA0(data, desc) set_sw_data(0, data, desc) | ||
170 | #define SET_SW_DATA1(data, desc) set_sw_data(1, data, desc) | ||
171 | #define SET_SW_DATA2(data, desc) set_sw_data(2, data, desc) | ||
172 | #define SET_SW_DATA3(data, desc) set_sw_data(3, data, desc) | ||
173 | |||
164 | static void set_org_pkt_info(dma_addr_t buff, u32 buff_len, | 174 | static void set_org_pkt_info(dma_addr_t buff, u32 buff_len, |
165 | struct knav_dma_desc *desc) | 175 | struct knav_dma_desc *desc) |
166 | { | 176 | { |
@@ -583,12 +593,20 @@ static void netcp_free_rx_desc_chain(struct netcp_intf *netcp, | |||
583 | break; | 593 | break; |
584 | } | 594 | } |
585 | get_pkt_info(&dma_buf, &tmp, &dma_desc, ndesc); | 595 | get_pkt_info(&dma_buf, &tmp, &dma_desc, ndesc); |
586 | get_sw_data((u32 *)&buf_ptr, &buf_len, ndesc); | 596 | /* warning!!!! We are retrieving the virtual ptr in the sw_data |
597 | * field as a 32bit value. Will not work on 64bit machines | ||
598 | */ | ||
599 | buf_ptr = (void *)GET_SW_DATA0(ndesc); | ||
600 | buf_len = (int)GET_SW_DATA1(desc); | ||
587 | dma_unmap_page(netcp->dev, dma_buf, PAGE_SIZE, DMA_FROM_DEVICE); | 601 | dma_unmap_page(netcp->dev, dma_buf, PAGE_SIZE, DMA_FROM_DEVICE); |
588 | __free_page(buf_ptr); | 602 | __free_page(buf_ptr); |
589 | knav_pool_desc_put(netcp->rx_pool, desc); | 603 | knav_pool_desc_put(netcp->rx_pool, desc); |
590 | } | 604 | } |
591 | get_sw_data((u32 *)&buf_ptr, &buf_len, desc); | 605 | /* warning!!!! We are retrieving the virtual ptr in the sw_data |
606 | * field as a 32bit value. Will not work on 64bit machines | ||
607 | */ | ||
608 | buf_ptr = (void *)GET_SW_DATA0(desc); | ||
609 | buf_len = (int)GET_SW_DATA1(desc); | ||
592 | 610 | ||
593 | if (buf_ptr) | 611 | if (buf_ptr) |
594 | netcp_frag_free(buf_len <= PAGE_SIZE, buf_ptr); | 612 | netcp_frag_free(buf_len <= PAGE_SIZE, buf_ptr); |
@@ -628,7 +646,6 @@ static int netcp_process_one_rx_packet(struct netcp_intf *netcp) | |||
628 | struct netcp_packet p_info; | 646 | struct netcp_packet p_info; |
629 | struct sk_buff *skb; | 647 | struct sk_buff *skb; |
630 | void *org_buf_ptr; | 648 | void *org_buf_ptr; |
631 | u32 tmp; | ||
632 | 649 | ||
633 | dma_desc = knav_queue_pop(netcp->rx_queue, &dma_sz); | 650 | dma_desc = knav_queue_pop(netcp->rx_queue, &dma_sz); |
634 | if (!dma_desc) | 651 | if (!dma_desc) |
@@ -641,7 +658,11 @@ static int netcp_process_one_rx_packet(struct netcp_intf *netcp) | |||
641 | } | 658 | } |
642 | 659 | ||
643 | get_pkt_info(&dma_buff, &buf_len, &dma_desc, desc); | 660 | get_pkt_info(&dma_buff, &buf_len, &dma_desc, desc); |
644 | get_sw_data((u32 *)&org_buf_ptr, &org_buf_len, desc); | 661 | /* warning!!!! We are retrieving the virtual ptr in the sw_data |
662 | * field as a 32bit value. Will not work on 64bit machines | ||
663 | */ | ||
664 | org_buf_ptr = (void *)GET_SW_DATA0(desc); | ||
665 | org_buf_len = (int)GET_SW_DATA1(desc); | ||
645 | 666 | ||
646 | if (unlikely(!org_buf_ptr)) { | 667 | if (unlikely(!org_buf_ptr)) { |
647 | dev_err(netcp->ndev_dev, "NULL bufptr in desc\n"); | 668 | dev_err(netcp->ndev_dev, "NULL bufptr in desc\n"); |
@@ -674,7 +695,10 @@ static int netcp_process_one_rx_packet(struct netcp_intf *netcp) | |||
674 | } | 695 | } |
675 | 696 | ||
676 | get_pkt_info(&dma_buff, &buf_len, &dma_desc, ndesc); | 697 | get_pkt_info(&dma_buff, &buf_len, &dma_desc, ndesc); |
677 | get_sw_data((u32 *)&page, &tmp, ndesc); | 698 | /* warning!!!! We are retrieving the virtual ptr in the sw_data |
699 | * field as a 32bit value. Will not work on 64bit machines | ||
700 | */ | ||
701 | page = (struct page *)GET_SW_DATA0(desc); | ||
678 | 702 | ||
679 | if (likely(dma_buff && buf_len && page)) { | 703 | if (likely(dma_buff && buf_len && page)) { |
680 | dma_unmap_page(netcp->dev, dma_buff, PAGE_SIZE, | 704 | dma_unmap_page(netcp->dev, dma_buff, PAGE_SIZE, |
@@ -752,7 +776,6 @@ static void netcp_free_rx_buf(struct netcp_intf *netcp, int fdq) | |||
752 | unsigned int buf_len, dma_sz; | 776 | unsigned int buf_len, dma_sz; |
753 | dma_addr_t dma; | 777 | dma_addr_t dma; |
754 | void *buf_ptr; | 778 | void *buf_ptr; |
755 | u32 tmp; | ||
756 | 779 | ||
757 | /* Allocate descriptor */ | 780 | /* Allocate descriptor */ |
758 | while ((dma = knav_queue_pop(netcp->rx_fdq[fdq], &dma_sz))) { | 781 | while ((dma = knav_queue_pop(netcp->rx_fdq[fdq], &dma_sz))) { |
@@ -763,7 +786,10 @@ static void netcp_free_rx_buf(struct netcp_intf *netcp, int fdq) | |||
763 | } | 786 | } |
764 | 787 | ||
765 | get_org_pkt_info(&dma, &buf_len, desc); | 788 | get_org_pkt_info(&dma, &buf_len, desc); |
766 | get_sw_data((u32 *)&buf_ptr, &tmp, desc); | 789 | /* warning!!!! We are retrieving the virtual ptr in the sw_data |
790 | * field as a 32bit value. Will not work on 64bit machines | ||
791 | */ | ||
792 | buf_ptr = (void *)GET_SW_DATA0(desc); | ||
767 | 793 | ||
768 | if (unlikely(!dma)) { | 794 | if (unlikely(!dma)) { |
769 | dev_err(netcp->ndev_dev, "NULL orig_buff in desc\n"); | 795 | dev_err(netcp->ndev_dev, "NULL orig_buff in desc\n"); |
@@ -844,6 +870,9 @@ static int netcp_allocate_rx_buf(struct netcp_intf *netcp, int fdq) | |||
844 | if (unlikely(dma_mapping_error(netcp->dev, dma))) | 870 | if (unlikely(dma_mapping_error(netcp->dev, dma))) |
845 | goto fail; | 871 | goto fail; |
846 | 872 | ||
873 | /* warning!!!! We are saving the virtual ptr in the sw_data | ||
874 | * field as a 32bit value. Will not work on 64bit machines | ||
875 | */ | ||
847 | sw_data[0] = (u32)bufptr; | 876 | sw_data[0] = (u32)bufptr; |
848 | } else { | 877 | } else { |
849 | /* Allocate a secondary receive queue entry */ | 878 | /* Allocate a secondary receive queue entry */ |
@@ -854,6 +883,9 @@ static int netcp_allocate_rx_buf(struct netcp_intf *netcp, int fdq) | |||
854 | } | 883 | } |
855 | buf_len = PAGE_SIZE; | 884 | buf_len = PAGE_SIZE; |
856 | dma = dma_map_page(netcp->dev, page, 0, buf_len, DMA_TO_DEVICE); | 885 | dma = dma_map_page(netcp->dev, page, 0, buf_len, DMA_TO_DEVICE); |
886 | /* warning!!!! We are saving the virtual ptr in the sw_data | ||
887 | * field as a 32bit value. Will not work on 64bit machines | ||
888 | */ | ||
857 | sw_data[0] = (u32)page; | 889 | sw_data[0] = (u32)page; |
858 | sw_data[1] = 0; | 890 | sw_data[1] = 0; |
859 | } | 891 | } |
@@ -865,7 +897,8 @@ static int netcp_allocate_rx_buf(struct netcp_intf *netcp, int fdq) | |||
865 | pkt_info |= (netcp->rx_queue_id & KNAV_DMA_DESC_RETQ_MASK) << | 897 | pkt_info |= (netcp->rx_queue_id & KNAV_DMA_DESC_RETQ_MASK) << |
866 | KNAV_DMA_DESC_RETQ_SHIFT; | 898 | KNAV_DMA_DESC_RETQ_SHIFT; |
867 | set_org_pkt_info(dma, buf_len, hwdesc); | 899 | set_org_pkt_info(dma, buf_len, hwdesc); |
868 | set_sw_data(sw_data[0], sw_data[1], hwdesc); | 900 | SET_SW_DATA0(sw_data[0], hwdesc); |
901 | SET_SW_DATA1(sw_data[1], hwdesc); | ||
869 | set_desc_info(desc_info, pkt_info, hwdesc); | 902 | set_desc_info(desc_info, pkt_info, hwdesc); |
870 | 903 | ||
871 | /* Push to FDQs */ | 904 | /* Push to FDQs */ |
@@ -958,7 +991,6 @@ static int netcp_process_tx_compl_packets(struct netcp_intf *netcp, | |||
958 | unsigned int dma_sz; | 991 | unsigned int dma_sz; |
959 | dma_addr_t dma; | 992 | dma_addr_t dma; |
960 | int pkts = 0; | 993 | int pkts = 0; |
961 | u32 tmp; | ||
962 | 994 | ||
963 | while (budget--) { | 995 | while (budget--) { |
964 | dma = knav_queue_pop(netcp->tx_compl_q, &dma_sz); | 996 | dma = knav_queue_pop(netcp->tx_compl_q, &dma_sz); |
@@ -971,7 +1003,10 @@ static int netcp_process_tx_compl_packets(struct netcp_intf *netcp, | |||
971 | continue; | 1003 | continue; |
972 | } | 1004 | } |
973 | 1005 | ||
974 | get_sw_data((u32 *)&skb, &tmp, desc); | 1006 | /* warning!!!! We are retrieving the virtual ptr in the sw_data |
1007 | * field as a 32bit value. Will not work on 64bit machines | ||
1008 | */ | ||
1009 | skb = (struct sk_buff *)GET_SW_DATA0(desc); | ||
975 | netcp_free_tx_desc_chain(netcp, desc, dma_sz); | 1010 | netcp_free_tx_desc_chain(netcp, desc, dma_sz); |
976 | if (!skb) { | 1011 | if (!skb) { |
977 | dev_err(netcp->ndev_dev, "No skb in Tx desc\n"); | 1012 | dev_err(netcp->ndev_dev, "No skb in Tx desc\n"); |
@@ -1176,7 +1211,10 @@ static int netcp_tx_submit_skb(struct netcp_intf *netcp, | |||
1176 | } | 1211 | } |
1177 | 1212 | ||
1178 | set_words(&tmp, 1, &desc->packet_info); | 1213 | set_words(&tmp, 1, &desc->packet_info); |
1179 | set_sw_data((u32)skb, 0, desc); | 1214 | /* warning!!!! We are saving the virtual ptr in the sw_data |
1215 | * field as a 32bit value. Will not work on 64bit machines | ||
1216 | */ | ||
1217 | SET_SW_DATA0((u32)skb, desc); | ||
1180 | 1218 | ||
1181 | if (tx_pipe->flags & SWITCH_TO_PORT_IN_TAGINFO) { | 1219 | if (tx_pipe->flags & SWITCH_TO_PORT_IN_TAGINFO) { |
1182 | tmp = tx_pipe->switch_to_port; | 1220 | tmp = tx_pipe->switch_to_port; |