2 * SBE 2T3E3 synchronous serial card driver for Linux
4 * Copyright (C) 2009-2010 Krzysztof Halasa <khc@pm.waw.pl>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License
8 * as published by the Free Software Foundation.
10 * This code is based on a driver written by SBE Inc.
13 #include <linux/interrupt.h>
14 #include <linux/netdevice.h>
17 void t3e3_init(struct channel
*sc
)
26 int t3e3_if_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
28 struct channel
*sc
= dev_to_priv(dev
);
29 u32 current_write
, last_write
;
38 if (sc
->p
.transmitter_on
!= SBE_2T3E3_ON
) {
41 dev_kfree_skb_any(skb
);
45 if (sc
->s
.OOF
&& sc
->p
.loopback
== SBE_2T3E3_LOOPBACK_NONE
) {
47 dev_kfree_skb_any(skb
);
51 spin_lock_irqsave(&sc
->ether
.tx_lock
, flags
);
53 current_write
= sc
->ether
.tx_ring_current_write
;
54 for (skb2
= skb
; skb2
!= NULL
; skb2
= NULL
) {
56 if ((sc
->ether
.tx_ring
[current_write
].tdes1
&
57 SBE_2T3E3_TX_DESC_BUFFER_1_SIZE
) > 0)
59 current_write
= (current_write
+ 1) % SBE_2T3E3_TX_DESC_RING_SIZE
;
61 * Leave at least 1 tx desc free so that dc_intr_tx() can
64 if (current_write
== sc
->ether
.tx_ring_current_read
)
69 netif_stop_queue(sc
->dev
);
70 sc
->ether
.tx_full
= 1;
71 dev_dbg(&sc
->pdev
->dev
, "SBE 2T3E3: out of descriptors\n");
72 spin_unlock_irqrestore(&sc
->ether
.tx_lock
, flags
);
73 return NETDEV_TX_BUSY
;
76 current_write
= last_write
= sc
->ether
.tx_ring_current_write
;
77 dev_dbg(&sc
->pdev
->dev
, "sending mbuf (current_write = %d)\n",
80 for (skb2
= skb
; skb2
!= NULL
; skb2
= NULL
) {
82 dev_dbg(&sc
->pdev
->dev
,
83 "sending mbuf (len = %d, next = %p)\n",
86 sc
->ether
.tx_free_cnt
--;
87 sc
->ether
.tx_ring
[current_write
].tdes0
= 0;
88 sc
->ether
.tx_ring
[current_write
].tdes1
&=
89 SBE_2T3E3_TX_DESC_END_OF_RING
|
90 SBE_2T3E3_TX_DESC_SECOND_ADDRESS_CHAINED
;
91 /* DISABLE_PADDING sometimes gets lost somehow, hands off... */
92 sc
->ether
.tx_ring
[current_write
].tdes1
|=
93 SBE_2T3E3_TX_DESC_DISABLE_PADDING
| skb2
->len
;
95 if (current_write
== sc
->ether
.tx_ring_current_write
) {
96 sc
->ether
.tx_ring
[current_write
].tdes1
|=
97 SBE_2T3E3_TX_DESC_FIRST_SEGMENT
;
99 sc
->ether
.tx_ring
[current_write
].tdes0
=
100 SBE_2T3E3_TX_DESC_21143_OWN
;
103 sc
->ether
.tx_ring
[current_write
].tdes2
= virt_to_phys(skb2
->data
);
104 sc
->ether
.tx_data
[current_write
] = NULL
;
106 last_write
= current_write
;
107 current_write
= (current_write
+ 1) % SBE_2T3E3_TX_DESC_RING_SIZE
;
111 sc
->ether
.tx_data
[last_write
] = skb
;
112 sc
->ether
.tx_ring
[last_write
].tdes1
|=
113 SBE_2T3E3_TX_DESC_LAST_SEGMENT
|
114 SBE_2T3E3_TX_DESC_INTERRUPT_ON_COMPLETION
;
115 sc
->ether
.tx_ring
[sc
->ether
.tx_ring_current_write
].tdes0
|=
116 SBE_2T3E3_TX_DESC_21143_OWN
;
117 sc
->ether
.tx_ring_current_write
= current_write
;
119 dev_dbg(&sc
->pdev
->dev
, "txput: tdes0 = %08X tdes1 = %08X\n",
120 sc
->ether
.tx_ring
[last_write
].tdes0
,
121 sc
->ether
.tx_ring
[last_write
].tdes1
);
123 dc_write(sc
->addr
, SBE_2T3E3_21143_REG_TRANSMIT_POLL_DEMAND
,
126 spin_unlock_irqrestore(&sc
->ether
.tx_lock
, flags
);
131 void t3e3_read_card_serial_number(struct channel
*sc
)
135 for (i
= 0; i
< 3; i
++)
136 sc
->ether
.card_serial_number
[i
] = t3e3_eeprom_read_word(sc
, 10 + i
);
138 printk(KERN_INFO
"SBE wanPMC-2T3E3 serial number: %04X%04X%04X\n",
139 sc
->ether
.card_serial_number
[0], sc
->ether
.card_serial_number
[1],
140 sc
->ether
.card_serial_number
[2]);
157 void update_led(struct channel
*sc
, int blinker
)
161 leds
= 0; /* led1 = off */
163 leds
= 2; /* led1 = yellow */
164 else if ((blinker
& 1) && sc
->rcv_count
) {
165 leds
= 0; /* led1 = off */
168 leds
= 1; /* led1 = green */
169 cpld_write(sc
, SBE_2T3E3_CPLD_REG_LEDR
, leds
);