2020 * or rx, so this should be okay.
2121 *
2222 * TODO:
23- * - Fix driver to work on more than just Virtex5. Right now the driver
24- * assumes that the locallink DMA registers are accessed via DCR
25- * instructions.
2623 * - Factor out locallink DMA code into separate driver
2724 * - Fix multicast assignment.
2825 * - Fix support for hardware checksumming.
@@ -116,16 +113,85 @@ void temac_indirect_out32(struct temac_local *lp, int reg, u32 value)
116113 temac_iow (lp , XTE_CTL0_OFFSET , CNTLREG_WRITE_ENABLE_MASK | reg );
117114}
118115
116+ /**
117+ * temac_dma_in32 - Memory mapped DMA read, this function expects a
118+ * register input that is based on DCR word addresses which
119+ * are then converted to memory mapped byte addresses
120+ */
119121static u32 temac_dma_in32 (struct temac_local * lp , int reg )
120122{
121- return dcr_read ( lp -> sdma_dcrs , reg );
123+ return in_be32 (( u32 * )( lp -> sdma_regs + ( reg << 2 )) );
122124}
123125
126+ /**
127+ * temac_dma_out32 - Memory mapped DMA read, this function expects a
128+ * register input that is based on DCR word addresses which
129+ * are then converted to memory mapped byte addresses
130+ */
124131static void temac_dma_out32 (struct temac_local * lp , int reg , u32 value )
132+ {
133+ out_be32 ((u32 * )(lp -> sdma_regs + (reg << 2 )), value );
134+ }
135+
136+ /* DMA register access functions can be DCR based or memory mapped.
137+ * The PowerPC 440 is DCR based, the PowerPC 405 and MicroBlaze are both
138+ * memory mapped.
139+ */
140+ #ifdef CONFIG_PPC_DCR
141+
142+ /**
143+ * temac_dma_dcr_in32 - DCR based DMA read
144+ */
145+ static u32 temac_dma_dcr_in (struct temac_local * lp , int reg )
146+ {
147+ return dcr_read (lp -> sdma_dcrs , reg );
148+ }
149+
150+ /**
151+ * temac_dma_dcr_out32 - DCR based DMA write
152+ */
153+ static void temac_dma_dcr_out (struct temac_local * lp , int reg , u32 value )
125154{
126155 dcr_write (lp -> sdma_dcrs , reg , value );
127156}
128157
158+ /**
159+ * temac_dcr_setup - If the DMA is DCR based, then setup the address and
160+ * I/O functions
161+ */
162+ static int temac_dcr_setup (struct temac_local * lp , struct of_device * op ,
163+ struct device_node * np )
164+ {
165+ unsigned int dcrs ;
166+
167+ /* setup the dcr address mapping if it's in the device tree */
168+
169+ dcrs = dcr_resource_start (np , 0 );
170+ if (dcrs != 0 ) {
171+ lp -> sdma_dcrs = dcr_map (np , dcrs , dcr_resource_len (np , 0 ));
172+ lp -> dma_in = temac_dma_dcr_in ;
173+ lp -> dma_out = temac_dma_dcr_out ;
174+ dev_dbg (& op -> dev , "DCR base: %x\n" , dcrs );
175+ return 0 ;
176+ }
177+ /* no DCR in the device tree, indicate a failure */
178+ return -1 ;
179+ }
180+
181+ #else
182+
183+ /*
184+ * temac_dcr_setup - This is a stub for when DCR is not supported,
185+ * such as with MicroBlaze
186+ */
187+ static int temac_dcr_setup (struct temac_local * lp , struct of_device * op ,
188+ struct device_node * np )
189+ {
190+ return -1 ;
191+ }
192+
193+ #endif
194+
129195/**
130196 * temac_dma_bd_init - Setup buffer descriptor rings
131197 */
@@ -156,14 +222,14 @@ static int temac_dma_bd_init(struct net_device *ndev)
156222 lp -> rx_bd_v [i ].next = lp -> rx_bd_p +
157223 sizeof (* lp -> rx_bd_v ) * ((i + 1 ) % RX_BD_NUM );
158224
159- skb = alloc_skb (XTE_MAX_JUMBO_FRAME_SIZE
160- + XTE_ALIGN , GFP_ATOMIC );
225+ skb = netdev_alloc_skb_ip_align (ndev ,
226+ XTE_MAX_JUMBO_FRAME_SIZE );
227+
161228 if (skb == 0 ) {
162229 dev_err (& ndev -> dev , "alloc_skb error %d\n" , i );
163230 return -1 ;
164231 }
165232 lp -> rx_skb [i ] = skb ;
166- skb_reserve (skb , BUFFER_ALIGN (skb -> data ));
167233 /* returns physical address of skb->data */
168234 lp -> rx_bd_v [i ].phys = dma_map_single (ndev -> dev .parent ,
169235 skb -> data ,
@@ -173,23 +239,23 @@ static int temac_dma_bd_init(struct net_device *ndev)
173239 lp -> rx_bd_v [i ].app0 = STS_CTRL_APP0_IRQONEND ;
174240 }
175241
176- temac_dma_out32 (lp , TX_CHNL_CTRL , 0x10220400 |
242+ lp -> dma_out (lp , TX_CHNL_CTRL , 0x10220400 |
177243 CHNL_CTRL_IRQ_EN |
178244 CHNL_CTRL_IRQ_DLY_EN |
179245 CHNL_CTRL_IRQ_COAL_EN );
180246 /* 0x10220483 */
181247 /* 0x00100483 */
182- temac_dma_out32 (lp , RX_CHNL_CTRL , 0xff010000 |
248+ lp -> dma_out (lp , RX_CHNL_CTRL , 0xff010000 |
183249 CHNL_CTRL_IRQ_EN |
184250 CHNL_CTRL_IRQ_DLY_EN |
185251 CHNL_CTRL_IRQ_COAL_EN |
186252 CHNL_CTRL_IRQ_IOE );
187253 /* 0xff010283 */
188254
189- temac_dma_out32 (lp , RX_CURDESC_PTR , lp -> rx_bd_p );
190- temac_dma_out32 (lp , RX_TAILDESC_PTR ,
255+ lp -> dma_out (lp , RX_CURDESC_PTR , lp -> rx_bd_p );
256+ lp -> dma_out (lp , RX_TAILDESC_PTR ,
191257 lp -> rx_bd_p + (sizeof (* lp -> rx_bd_v ) * (RX_BD_NUM - 1 )));
192- temac_dma_out32 (lp , TX_CURDESC_PTR , lp -> tx_bd_p );
258+ lp -> dma_out (lp , TX_CURDESC_PTR , lp -> tx_bd_p );
193259
194260 return 0 ;
195261}
@@ -427,17 +493,17 @@ static void temac_device_reset(struct net_device *ndev)
427493 temac_indirect_out32 (lp , XTE_RXC1_OFFSET , val & ~XTE_RXC1_RXEN_MASK );
428494
429495 /* Reset Local Link (DMA) */
430- temac_dma_out32 (lp , DMA_CONTROL_REG , DMA_CONTROL_RST );
496+ lp -> dma_out (lp , DMA_CONTROL_REG , DMA_CONTROL_RST );
431497 timeout = 1000 ;
432- while (temac_dma_in32 (lp , DMA_CONTROL_REG ) & DMA_CONTROL_RST ) {
498+ while (lp -> dma_in (lp , DMA_CONTROL_REG ) & DMA_CONTROL_RST ) {
433499 udelay (1 );
434500 if (-- timeout == 0 ) {
435501 dev_err (& ndev -> dev ,
436502 "temac_device_reset DMA reset timeout!!\n" );
437503 break ;
438504 }
439505 }
440- temac_dma_out32 (lp , DMA_CONTROL_REG , DMA_TAIL_ENABLE );
506+ lp -> dma_out (lp , DMA_CONTROL_REG , DMA_TAIL_ENABLE );
441507
442508 temac_dma_bd_init (ndev );
443509
@@ -598,7 +664,7 @@ static int temac_start_xmit(struct sk_buff *skb, struct net_device *ndev)
598664 lp -> tx_bd_tail = 0 ;
599665
600666 /* Kick off the transfer */
601- temac_dma_out32 (lp , TX_TAILDESC_PTR , tail_p ); /* DMA start */
667+ lp -> dma_out (lp , TX_TAILDESC_PTR , tail_p ); /* DMA start */
602668
603669 return NETDEV_TX_OK ;
604670}
@@ -638,16 +704,15 @@ static void ll_temac_recv(struct net_device *ndev)
638704 ndev -> stats .rx_packets ++ ;
639705 ndev -> stats .rx_bytes += length ;
640706
641- new_skb = alloc_skb (XTE_MAX_JUMBO_FRAME_SIZE + XTE_ALIGN ,
642- GFP_ATOMIC );
707+ new_skb = netdev_alloc_skb_ip_align (ndev ,
708+ XTE_MAX_JUMBO_FRAME_SIZE );
709+
643710 if (new_skb == 0 ) {
644711 dev_err (& ndev -> dev , "no memory for new sk_buff\n" );
645712 spin_unlock_irqrestore (& lp -> rx_lock , flags );
646713 return ;
647714 }
648715
649- skb_reserve (new_skb , BUFFER_ALIGN (new_skb -> data ));
650-
651716 cur_p -> app0 = STS_CTRL_APP0_IRQONEND ;
652717 cur_p -> phys = dma_map_single (ndev -> dev .parent , new_skb -> data ,
653718 XTE_MAX_JUMBO_FRAME_SIZE ,
@@ -662,7 +727,7 @@ static void ll_temac_recv(struct net_device *ndev)
662727 cur_p = & lp -> rx_bd_v [lp -> rx_bd_ci ];
663728 bdstat = cur_p -> app0 ;
664729 }
665- temac_dma_out32 (lp , RX_TAILDESC_PTR , tail_p );
730+ lp -> dma_out (lp , RX_TAILDESC_PTR , tail_p );
666731
667732 spin_unlock_irqrestore (& lp -> rx_lock , flags );
668733}
@@ -673,8 +738,8 @@ static irqreturn_t ll_temac_tx_irq(int irq, void *_ndev)
673738 struct temac_local * lp = netdev_priv (ndev );
674739 unsigned int status ;
675740
676- status = temac_dma_in32 (lp , TX_IRQ_REG );
677- temac_dma_out32 (lp , TX_IRQ_REG , status );
741+ status = lp -> dma_in (lp , TX_IRQ_REG );
742+ lp -> dma_out (lp , TX_IRQ_REG , status );
678743
679744 if (status & (IRQ_COAL | IRQ_DLY ))
680745 temac_start_xmit_done (lp -> ndev );
@@ -691,8 +756,8 @@ static irqreturn_t ll_temac_rx_irq(int irq, void *_ndev)
691756 unsigned int status ;
692757
693758 /* Read and clear the status registers */
694- status = temac_dma_in32 (lp , RX_IRQ_REG );
695- temac_dma_out32 (lp , RX_IRQ_REG , status );
759+ status = lp -> dma_in (lp , RX_IRQ_REG );
760+ lp -> dma_out (lp , RX_IRQ_REG , status );
696761
697762 if (status & (IRQ_COAL | IRQ_DLY ))
698763 ll_temac_recv (lp -> ndev );
@@ -793,7 +858,7 @@ static ssize_t temac_show_llink_regs(struct device *dev,
793858 int i , len = 0 ;
794859
795860 for (i = 0 ; i < 0x11 ; i ++ )
796- len += sprintf (buf + len , "%.8x%s" , temac_dma_in32 (lp , i ),
861+ len += sprintf (buf + len , "%.8x%s" , lp -> dma_in (lp , i ),
797862 (i % 8 ) == 7 ? "\n" : " " );
798863 len += sprintf (buf + len , "\n" );
799864
@@ -819,7 +884,6 @@ temac_of_probe(struct of_device *op, const struct of_device_id *match)
819884 struct net_device * ndev ;
820885 const void * addr ;
821886 int size , rc = 0 ;
822- unsigned int dcrs ;
823887
824888 /* Init network device structure */
825889 ndev = alloc_etherdev (sizeof (* lp ));
@@ -869,13 +933,20 @@ temac_of_probe(struct of_device *op, const struct of_device_id *match)
869933 goto nodev ;
870934 }
871935
872- dcrs = dcr_resource_start (np , 0 );
873- if (dcrs == 0 ) {
874- dev_err (& op -> dev , "could not get DMA register address\n" );
875- goto nodev ;
936+ /* Setup the DMA register accesses, could be DCR or memory mapped */
937+ if (temac_dcr_setup (lp , op , np )) {
938+
939+ /* no DCR in the device tree, try non-DCR */
940+ lp -> sdma_regs = of_iomap (np , 0 );
941+ if (lp -> sdma_regs ) {
942+ lp -> dma_in = temac_dma_in32 ;
943+ lp -> dma_out = temac_dma_out32 ;
944+ dev_dbg (& op -> dev , "MEM base: %p\n" , lp -> sdma_regs );
945+ } else {
946+ dev_err (& op -> dev , "unable to map DMA registers\n" );
947+ goto nodev ;
948+ }
876949 }
877- lp -> sdma_dcrs = dcr_map (np , dcrs , dcr_resource_len (np , 0 ));
878- dev_dbg (& op -> dev , "DCR base: %x\n" , dcrs );
879950
880951 lp -> rx_irq = irq_of_parse_and_map (np , 0 );
881952 lp -> tx_irq = irq_of_parse_and_map (np , 1 );
0 commit comments