20 |
20 |
21 #ifndef _CCAT_H_ |
21 #ifndef _CCAT_H_ |
22 #define _CCAT_H_ |
22 #define _CCAT_H_ |
23 |
23 |
24 #include <linux/cdev.h> |
24 #include <linux/cdev.h> |
|
25 #include <linux/fs.h> |
25 #include <linux/hrtimer.h> |
26 #include <linux/hrtimer.h> |
26 #include <linux/kernel.h> |
27 #include <linux/kernel.h> |
27 #include <linux/pci.h> |
28 #include <linux/pci.h> |
28 #include "../ecdev.h" |
29 #include "../ecdev.h" |
29 |
30 |
30 #define DRV_EXTRAVERSION "-ec" |
31 #define DRV_EXTRAVERSION "-ec" |
31 #define DRV_VERSION "0.10" DRV_EXTRAVERSION |
32 #define DRV_VERSION "0.14" DRV_EXTRAVERSION |
32 #define DRV_DESCRIPTION "Beckhoff CCAT Ethernet/EtherCAT Network Driver" |
33 #define DRV_DESCRIPTION "Beckhoff CCAT Ethernet/EtherCAT Network Driver" |
33 |
34 |
34 #undef pr_fmt |
35 #undef pr_fmt |
35 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
36 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
|
37 |
|
38 extern const struct ccat_driver eth_eim_driver; |
|
39 extern const struct ccat_driver eth_dma_driver; |
|
40 extern const struct ccat_driver gpio_driver; |
|
41 extern const struct ccat_driver sram_driver; |
|
42 extern const struct ccat_driver update_driver; |
36 |
43 |
37 /** |
44 /** |
38 * CCAT function type identifiers (u16) |
45 * CCAT function type identifiers (u16) |
39 */ |
46 */ |
40 enum ccat_info_t { |
47 enum ccat_info_t { |
41 CCATINFO_NOTUSED = 0, |
48 CCATINFO_NOTUSED = 0, |
|
49 CCATINFO_ETHERCAT_NODMA = 0x3, |
|
50 CCATINFO_GPIO = 0xd, |
42 CCATINFO_EPCS_PROM = 0xf, |
51 CCATINFO_EPCS_PROM = 0xf, |
43 CCATINFO_ETHERCAT_MASTER_DMA = 0x14, |
52 CCATINFO_ETHERCAT_MASTER_DMA = 0x14, |
44 CCATINFO_COPY_BLOCK = 0x17, |
53 CCATINFO_SRAM = 0x16, |
45 CCATINFO_MAX |
54 }; |
|
55 |
|
56 struct ccat_cdev { |
|
57 atomic_t in_use; |
|
58 void __iomem *ioaddr; |
|
59 size_t iosize; |
|
60 dev_t dev; |
|
61 struct cdev cdev; |
|
62 struct ccat_class *class; |
46 }; |
63 }; |
47 |
64 |
48 /** |
65 /** |
49 * struct ccat_bar - CCAT PCI Base Address Register(BAR) configuration |
66 * struct cdev_buffer |
50 * @start: start address of this BAR |
67 * @ccdev: referenced character device |
51 * @end: end address of this BAR |
68 * @data: buffer used for write operations |
52 * @len: length of this BAR |
69 * @size: number of bytes written to the data buffer |
53 * @flags: flags set on this BAR |
|
54 * @ioaddr: ioremapped address of this bar |
|
55 */ |
70 */ |
56 struct ccat_bar { |
71 struct cdev_buffer { |
57 unsigned long start; |
72 struct ccat_cdev *ccdev; |
58 unsigned long end; |
73 size_t size; |
59 unsigned long len; |
74 char data[]; |
60 unsigned long flags; |
|
61 void __iomem *ioaddr; |
|
62 }; |
75 }; |
63 |
76 |
64 /** |
77 extern int ccat_cdev_open(struct inode *const i, struct file *const f); |
65 * struct ccat_dma - CCAT DMA channel configuration |
78 extern int ccat_cdev_release(struct inode *const i, struct file *const f); |
66 * @phys: device-viewed address(physical) of the associated DMA memory |
|
67 * @virt: CPU-viewed address(virtual) of the associated DMA memory |
|
68 * @size: number of bytes in the associated DMA memory |
|
69 * @channel: CCAT DMA channel number |
|
70 * @dev: valid struct device pointer |
|
71 */ |
|
72 struct ccat_dma { |
|
73 dma_addr_t phys; |
|
74 void *virt; |
|
75 size_t size; |
|
76 size_t channel; |
|
77 struct device *dev; |
|
78 }; |
|
79 |
|
80 extern void ccat_dma_free(struct ccat_dma *const dma); |
|
81 extern int ccat_dma_init(struct ccat_dma *const dma, size_t channel, |
|
82 void __iomem * const ioaddr, struct device *const dev); |
|
83 |
|
84 /** |
|
85 * struct ccat_eth_frame - Ethernet frame with DMA descriptor header in front |
|
86 * @reservedn: is not used and should always be set to 0 |
|
87 * @received: used for reception, is set to 1 by the CCAT when data was written |
|
88 * @length: number of bytes in the frame including the DMA header |
|
89 * @sent: is set to 1 by the CCAT when data was transmitted |
|
90 * @timestamp: a 64 bit EtherCAT timestamp |
|
91 * @data: the bytes of the ethernet frame |
|
92 */ |
|
93 struct ccat_eth_frame { |
|
94 __le32 reserved1; |
|
95 __le32 rx_flags; |
|
96 #define CCAT_FRAME_RECEIVED 0x1 |
|
97 __le16 length; |
|
98 __le16 reserved3; |
|
99 __le32 tx_flags; |
|
100 #define CCAT_FRAME_SENT 0x1 |
|
101 __le64 timestamp; |
|
102 u8 data[0x800 - 3 * sizeof(u64)]; |
|
103 #define CCAT_ETH_FRAME_HEAD_LEN offsetof(struct ccat_eth_frame, data) |
|
104 }; |
|
105 |
|
106 /** |
|
107 * struct ccat_eth_register - CCAT register addresses in the PCI BAR |
|
108 * @mii: address of the CCAT management interface register |
|
109 * @tx_fifo: address of the CCAT TX DMA fifo register |
|
110 * @rx_fifo: address of the CCAT RX DMA fifo register |
|
111 * @mac: address of the CCAT media access control register |
|
112 * @rx_mem: address of the CCAT register holding the RX DMA address |
|
113 * @tx_mem: address of the CCAT register holding the TX DMA address |
|
114 * @misc: address of a CCAT register holding miscellaneous information |
|
115 */ |
|
116 struct ccat_eth_register { |
|
117 void __iomem *mii; |
|
118 void __iomem *tx_fifo; |
|
119 void __iomem *rx_fifo; |
|
120 void __iomem *mac; |
|
121 void __iomem *rx_mem; |
|
122 void __iomem *tx_mem; |
|
123 void __iomem *misc; |
|
124 }; |
|
125 |
|
126 /** |
|
127 * struct ccat_eth_dma_fifo - CCAT RX or TX DMA fifo |
|
128 * @add: callback used to add a frame to this fifo |
|
129 * @reg: PCI register address of this DMA fifo |
|
130 * @dma: information about the associated DMA memory |
|
131 */ |
|
132 struct ccat_eth_dma_fifo { |
|
133 void (*add) (struct ccat_eth_dma_fifo *, struct ccat_eth_frame *); |
|
134 void __iomem *reg; |
|
135 const struct ccat_eth_frame *end; |
|
136 struct ccat_eth_frame *next; |
|
137 struct ccat_dma dma; |
|
138 }; |
|
139 |
79 |
140 /** |
80 /** |
141 * struct ccat_device - CCAT device representation |
81 * struct ccat_device - CCAT device representation |
142 * @pdev: pointer to the pci object allocated by the kernel |
82 * @pdev: pointer to the pci object allocated by the kernel |
143 * @ethdev: CCAT Ethernet/EtherCAT Master (with DMA) function, NULL if function is not available or failed to initialize |
83 * @bar_0: holding information about PCI BAR 0 |
144 * @update: CCAT Update function, NULL if function is not available or failed to initialize |
84 * @bar_2: holding information about PCI BAR 2 (optional) |
145 * @bar [0] and [2] holding information about PCI BARs 0 and 2. |
85 * @functions: list of available (driver loaded) FPGA functions |
146 * |
86 * |
147 * One instance of a ccat_device should represent a physical CCAT. Since |
87 * One instance of a ccat_device should represent a physical CCAT. Since |
148 * a CCAT is implemented as FPGA the available functions can vary so |
88 * a CCAT is implemented as FPGA the available functions can vary. |
149 * the function object pointers can be NULL. |
|
150 * Extra note: you will recognize that PCI BAR1 is not used and is a |
|
151 * waste of memory, thats true but right now, its very easy to use it |
|
152 * this way. So we might optimize it later. |
|
153 */ |
89 */ |
154 struct ccat_device { |
90 struct ccat_device { |
155 struct pci_dev *pdev; |
91 void *pdev; |
156 struct ccat_eth_priv *ethdev; |
92 void __iomem *bar_0; |
157 struct ccat_update *update; |
93 void __iomem *bar_2; |
158 struct ccat_bar bar[3]; //TODO optimize this |
94 struct list_head functions; |
159 }; |
95 }; |
160 |
96 |
161 struct ccat_info_block { |
97 struct ccat_info_block { |
162 u16 type; |
98 u16 type; |
163 u16 rev; |
99 u16 rev; |
164 union { |
100 union { |
165 u32 config; |
101 u32 config; |
|
102 u8 num_gpios; |
|
103 struct { |
|
104 u16 tx_size; |
|
105 u16 rx_size; |
|
106 }; |
166 struct { |
107 struct { |
167 u8 tx_dma_chan; |
108 u8 tx_dma_chan; |
168 u8 rx_dma_chan; |
109 u8 rx_dma_chan; |
|
110 }; |
|
111 struct { |
|
112 u8 sram_width; |
|
113 u8 sram_size; |
|
114 u16 reserved; |
169 }; |
115 }; |
170 }; |
116 }; |
171 u32 addr; |
117 u32 addr; |
172 u32 size; |
118 u32 size; |
173 }; |
119 }; |
174 |
120 |
175 /** |
121 struct ccat_function { |
176 * struct ccat_eth_priv - CCAT Ethernet/EtherCAT Master function (netdev) |
122 const struct ccat_driver *drv; |
177 * @ccatdev: pointer to the parent struct ccat_device |
123 struct ccat_device *ccat; |
178 * @netdev: the net_device structure used by the kernel networking stack |
|
179 * @info: holds a copy of the CCAT Ethernet/EtherCAT Master function information block (read from PCI config space) |
|
180 * @reg: register addresses in PCI config space of the Ethernet/EtherCAT Master function |
|
181 * @rx_fifo: DMA fifo used for RX DMA descriptors |
|
182 * @tx_fifo: DMA fifo used for TX DMA descriptors |
|
183 * @poll_timer: interval timer used to poll CCAT for events like link changed, rx done, tx done |
|
184 * @rx_bytes: number of bytes received -> reported with ndo_get_stats64() |
|
185 * @rx_dropped: number of received frames, which were dropped -> reported with ndo_get_stats64() |
|
186 * @tx_bytes: number of bytes send -> reported with ndo_get_stats64() |
|
187 * @tx_dropped: number of frames requested to send, which were dropped -> reported with ndo_get_stats64() |
|
188 */ |
|
189 struct ccat_eth_priv { |
|
190 const struct ccat_device *ccatdev; |
|
191 struct net_device *netdev; |
|
192 struct ccat_info_block info; |
124 struct ccat_info_block info; |
193 struct ccat_eth_register reg; |
125 struct list_head list; |
194 struct ccat_eth_dma_fifo rx_fifo; |
126 void *private_data; |
195 struct ccat_eth_dma_fifo tx_fifo; |
|
196 struct hrtimer poll_timer; |
|
197 atomic64_t rx_bytes; |
|
198 atomic64_t rx_dropped; |
|
199 atomic64_t tx_bytes; |
|
200 atomic64_t tx_dropped; |
|
201 ec_device_t *ecdev; |
|
202 void (*carrier_off) (struct net_device * netdev); |
|
203 bool (*carrier_ok) (const struct net_device * netdev); |
|
204 void (*carrier_on) (struct net_device * netdev); |
|
205 void (*kfree_skb_any) (struct sk_buff * skb); |
|
206 void (*start_queue) (struct net_device * netdev); |
|
207 void (*stop_queue) (struct net_device * netdev); |
|
208 void (*unregister) (struct net_device * netdev); |
|
209 }; |
127 }; |
210 |
128 |
211 /** |
129 struct ccat_class { |
212 * same as: typedef struct _CCatInfoBlockOffs from CCatDefinitions.h |
130 dev_t dev; |
213 * TODO add some checking facility outside of the linux tree |
131 struct class *class; |
214 */ |
132 atomic_t instances; |
215 struct ccat_mac_infoblock { |
133 const unsigned count; |
216 u32 reserved; |
134 struct ccat_cdev *devices; |
217 u32 mii; |
135 const char *name; |
218 u32 tx_fifo; |
136 struct file_operations fops; |
219 u32 mac; |
|
220 u32 rx_mem; |
|
221 u32 tx_mem; |
|
222 u32 misc; |
|
223 }; |
137 }; |
224 |
138 |
225 struct ccat_mac_register { |
139 extern void ccat_cdev_remove(struct ccat_function *func); |
226 /** MAC error register @+0x0 */ |
140 extern int ccat_cdev_probe(struct ccat_function *func, |
227 u8 frame_len_err; |
141 struct ccat_class *cdev_class, size_t iosize); |
228 u8 rx_err; |
142 |
229 u8 crc_err; |
143 /** |
230 u8 link_lost_err; |
144 * struct ccat_driver - CCAT FPGA function |
231 u32 reserved1; |
145 * @probe: add device instance |
232 /** Buffer overflow errors @+0x8 */ |
146 * @remove: remove device instance |
233 u8 rx_mem_full; |
147 * @type: type of the FPGA function supported by this driver |
234 u8 reserved2[7]; |
148 * @cdev_class: if not NULL that driver supports ccat_class_init()/_exit() |
235 /** MAC frame counter @+0x10 */ |
149 */ |
236 u32 tx_frames; |
150 struct ccat_driver { |
237 u32 rx_frames; |
151 int (*probe) (struct ccat_function * func); |
238 u64 reserved3; |
152 void (*remove) (struct ccat_function * drv); |
239 /** MAC fifo level @+0x20 */ |
153 enum ccat_info_t type; |
240 u8 tx_fifo_level:7; |
154 struct ccat_class *cdev_class; |
241 u8 reserved4:1; |
|
242 u8 reserved5[7]; |
|
243 /** TX memory full error @+0x28 */ |
|
244 u8 tx_mem_full; |
|
245 u8 reserved6[7]; |
|
246 u64 reserved8[9]; |
|
247 /** Connection @+0x78 */ |
|
248 u8 mii_connected; |
|
249 }; |
155 }; |
250 |
156 |
251 /** |
|
252 * struct ccat_update - CCAT Update function (update) |
|
253 * @ccatdev: pointer to the parent struct ccat_device |
|
254 * @ioaddr: PCI base address of the CCAT Update function |
|
255 * dev: device number for this update function |
|
256 * cdev: character device used for the CCAT Update function |
|
257 * class: pointer to a device class used when registering the CCAT Update device |
|
258 * @info: holds a copy of the CCAT Update function information block (read from PCI config space) |
|
259 */ |
|
260 struct ccat_update { |
|
261 struct kref refcount; |
|
262 void __iomem *ioaddr; |
|
263 dev_t dev; |
|
264 struct cdev cdev; |
|
265 struct class *class; |
|
266 struct ccat_info_block info; |
|
267 }; |
|
268 #endif /* #ifndef _CCAT_H_ */ |
157 #endif /* #ifndef _CCAT_H_ */ |