aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial')
0 files changed, 0 insertions, 0 deletions
3:48 -0400 [PATCH] mipsnet: Virtual ethernet driver for MIPSsim.' href='/cgit/cgit.cgi/litmus-rt-budgetable-locks.git/.git/commit/drivers/net/mipsnet.c?h=update_litmus_2019&id=dcbf8477567c312c9f0512545d07e05175d740a4'>dcbf8477567c
c2af68e5f550
c800c5c9db9c
dcbf8477567c
c800c5c9db9c
dcbf8477567c

c800c5c9db9c
dcbf8477567c



dcbf8477567c
c800c5c9db9c
dcbf8477567c
c2af68e5f550
c800c5c9db9c
dcbf8477567c
09f75cd7bf13

dcbf8477567c
c800c5c9db9c
dcbf8477567c



f5e42fbab6c6

dcbf8477567c




6ed106549d17
dcbf8477567c

c800c5c9db9c
dcbf8477567c

dcbf8477567c
c800c5c9db9c



c2af68e5f550
09f75cd7bf13
dcbf8477567c


c800c5c9db9c
dcbf8477567c


dcbf8477567c


dcbf8477567c

09f75cd7bf13

dcbf8477567c
c800c5c9db9c
dcbf8477567c

7d12e780e003
dcbf8477567c

c800c5c9db9c






















dcbf8477567c
c800c5c9db9c



b39d66a81fb4
c800c5c9db9c
c2af68e5f550
dcbf8477567c



dcbf8477567c
a0607fd3a25b
1fb9df5d3069
dcbf8477567c
c800c5c9db9c
dcbf8477567c


dcbf8477567c

c2af68e5f550
c800c5c9db9c
dcbf8477567c





dcbf8477567c
c800c5c9db9c
dcbf8477567c


dcbf8477567c

dcbf8477567c

d6771e0b895f









ade2d3db21b0
dcbf8477567c



09f75cd7bf13
dcbf8477567c




7a192ec334ca
dcbf8477567c
d6771e0b895f
dcbf8477567c




3b1d4ed5353a
c800c5c9db9c
dcbf8477567c
c2af68e5f550
c800c5c9db9c

dcbf8477567c


















c800c5c9db9c
dcbf8477567c







7a192ec334ca
dcbf8477567c
7a192ec334ca
dcbf8477567c

c800c5c9db9c
dcbf8477567c
7a192ec334ca
dcbf8477567c



7a192ec334ca






dcbf8477567c

dcbf8477567c

dcbf8477567c




7a192ec334ca
1e2b980fdfb6
dcbf8477567c
dcbf8477567c
dcbf8477567c




7a192ec334ca
dcbf8477567c



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345





                                                                             
                       
                            
                     


                            
                              
                                  

                                   










                                                                       
 





                                                                           
 



































































                                                                             
 







                                                                            
                                       
                                                         
 
                                              

 
                                                               



                                   
 
                                                  
 
                                                     
                                                           
 

                                        
 
                           



                                                                    

                                                                            




                                       
                            

 
                                                                             

                            
 



                                                
                   
                                        


                               
                                       


                                                             


                                                 

                      

                                   
 
                   

 
                                                           

                                        






















                                                                            
         



                                                                 
                                         
                   
 



                                               
 
                                                      
                                                                
                  
                                                                            


                           

                               
                                    
                                                                     





                                                
                              
                                


                 

                                                      

 









                                                         
                                                               



                                  
                                   




                              
                                          
 
                                                 




                                                        
                                                           
                                                          
 
                                                      

                                                                           


















                                                                          
                                                                       







                            
                                                                          
 
                                                              

                               
                                                                    
                         
                                           



                 






                                                             

  

                                           




                                                                     
                                                        
                
                                                                
 




                                            
                                                    



                                 
/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 */

#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/platform_device.h>
#include <asm/mips-boards/simint.h>

#define MIPSNET_VERSION "2007-11-17"

/*
 * Net status/control block as seen by sw in the core.
 */
struct mipsnet_regs {
	/*
	 * Device info for probing, reads as MIPSNET%d where %d is some
	 * form of version.
	 */
	u64 devId;		/*0x00 */

	/*
	 * read only busy flag.
	 * Set and cleared by the Net Device to indicate that an rx or a tx
	 * is in progress.
	 */
	u32 busy;		/*0x08 */

	/*
	 * Set by the Net Device.
	 * The device will set it once data has been received.
	 * The value is the number of bytes that should be read from
	 * rxDataBuffer.  The value will decrease till 0 until all the data
	 * from rxDataBuffer has been read.
	 */
	u32 rxDataCount;	/*0x0c */
#define MIPSNET_MAX_RXTX_DATACOUNT (1 << 16)

	/*
	 * Settable from the MIPS core, cleared by the Net Device.
	 * The core should set the number of bytes it wants to send,
	 * then it should write those bytes of data to txDataBuffer.
	 * The device will clear txDataCount has been processed (not
	 * necessarily sent).
	 */
	u32 txDataCount;	/*0x10 */

	/*
	 * Interrupt control
	 *
	 * Used to clear the interrupted generated by this dev.
	 * Write a 1 to clear the interrupt. (except bit31).
	 *
	 * Bit0 is set if it was a tx-done interrupt.
	 * Bit1 is set when new rx-data is available.
	 *    Until this bit is cleared there will be no other RXs.
	 *
	 * Bit31 is used for testing, it clears after a read.
	 *    Writing 1 to this bit will cause an interrupt to be generated.
	 *    To clear the test interrupt, write 0 to this register.
	 */
	u32 interruptControl;	/*0x14 */
#define MIPSNET_INTCTL_TXDONE     (1u << 0)
#define MIPSNET_INTCTL_RXDONE     (1u << 1)
#define MIPSNET_INTCTL_TESTBIT    (1u << 31)

	/*
	 * Readonly core-specific interrupt info for the device to signal
	 * the core. The meaning of the contents of this field might change.
	 */
	/* XXX: the whole memIntf interrupt scheme is messy: the device
	 * should have no control what so ever of what VPE/register set is
	 * being used.
	 * The MemIntf should only expose interrupt lines, and something in
	 * the config should be responsible for the line<->core/vpe bindings.
	 */
	u32 interruptInfo;	/*0x18 */

	/*
	 * This is where the received data is read out.
	 * There is more data to read until rxDataReady is 0.
	 * Only 1 byte at this regs offset is used.
	 */
	u32 rxDataBuffer;	/*0x1c */

	/*
	 * This is where the data to transmit is written.
	 * Data should be written for the amount specified in the
	 * txDataCount register.
	 * Only 1 byte at this regs offset is used.
	 */
	u32 txDataBuffer;	/*0x20 */
};

#define regaddr(dev, field) \
  (dev->base_addr + offsetof(struct mipsnet_regs, field))

static char mipsnet_string[] = "mipsnet";

/*
 * Copy data from the MIPSNET rx data port
 */
static int ioiocpy_frommipsnet(struct net_device *dev, unsigned char *kdata,
			int len)
{
	for (; len > 0; len--, kdata++)
		*kdata = inb(regaddr(dev, rxDataBuffer));

	return inl(regaddr(dev, rxDataCount));
}

static inline void mipsnet_put_todevice(struct net_device *dev,
	struct sk_buff *skb)
{
	int count_to_go = skb->len;
	char *buf_ptr = skb->data;

	outl(skb->len, regaddr(dev, txDataCount));

	for (; count_to_go; buf_ptr++, count_to_go--)
		outb(*buf_ptr, regaddr(dev, txDataBuffer));

	dev->stats.tx_packets++;
	dev->stats.tx_bytes += skb->len;

	dev_kfree_skb(skb);
}

static int mipsnet_xmit(struct sk_buff *skb, struct net_device *dev)
{
	/*
	 * Only one packet at a time. Once TXDONE interrupt is serviced, the
	 * queue will be restarted.
	 */
	netif_stop_queue(dev);
	mipsnet_put_todevice(dev, skb);

	return NETDEV_TX_OK;
}

static inline ssize_t mipsnet_get_fromdev(struct net_device *dev, size_t len)
{
	struct sk_buff *skb;

	if (!len)
		return len;

	skb = dev_alloc_skb(len + NET_IP_ALIGN);
	if (!skb) {
		dev->stats.rx_dropped++;
		return -ENOMEM;
	}

	skb_reserve(skb, NET_IP_ALIGN);
	if (ioiocpy_frommipsnet(dev, skb_put(skb, len), len))
		return -EFAULT;

	skb->protocol = eth_type_trans(skb, dev);
	skb->ip_summed = CHECKSUM_UNNECESSARY;

	netif_rx(skb);

	dev->stats.rx_packets++;
	dev->stats.rx_bytes += len;

	return len;
}

static irqreturn_t mipsnet_interrupt(int irq, void *dev_id)
{
	struct net_device *dev = dev_id;
	u32 int_flags;
	irqreturn_t ret = IRQ_NONE;

	if (irq != dev->irq)
		goto out_badirq;

	/* TESTBIT is cleared on read. */
	int_flags = inl(regaddr(dev, interruptControl));
	if (int_flags & MIPSNET_INTCTL_TESTBIT) {
		/* TESTBIT takes effect after a write with 0. */
		outl(0, regaddr(dev, interruptControl));
		ret = IRQ_HANDLED;
	} else if (int_flags & MIPSNET_INTCTL_TXDONE) {
		/* Only one packet at a time, we are done. */
		dev->stats.tx_packets++;
		netif_wake_queue(dev);
		outl(MIPSNET_INTCTL_TXDONE,
		     regaddr(dev, interruptControl));
		ret = IRQ_HANDLED;
	} else if (int_flags & MIPSNET_INTCTL_RXDONE) {
		mipsnet_get_fromdev(dev, inl(regaddr(dev, rxDataCount)));
		outl(MIPSNET_INTCTL_RXDONE, regaddr(dev, interruptControl));
		ret = IRQ_HANDLED;
	}
	return ret;

out_badirq:
	printk(KERN_INFO "%s: %s(): irq %d for unknown device\n",