1
2
3
4
5
6
7
8
9 #ifndef _PCH_GBE_H_
10 #define _PCH_GBE_H_
11
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
14 #include <linux/mii.h>
15 #include <linux/delay.h>
16 #include <linux/pci.h>
17 #include <linux/netdevice.h>
18 #include <linux/etherdevice.h>
19 #include <linux/ethtool.h>
20 #include <linux/vmalloc.h>
21 #include <net/ip.h>
22 #include <net/tcp.h>
23 #include <net/udp.h>
24
25
26
27
28
29
30 struct pch_gbe_regs_mac_adr {
31 u32 high;
32 u32 low;
33 };
34
35
36
37 struct pch_gbe_regs {
38 u32 INT_ST;
39 u32 INT_EN;
40 u32 MODE;
41 u32 RESET;
42 u32 TCPIP_ACC;
43 u32 EX_LIST;
44 u32 INT_ST_HOLD;
45 u32 PHY_INT_CTRL;
46 u32 MAC_RX_EN;
47 u32 RX_FCTRL;
48 u32 PAUSE_REQ;
49 u32 RX_MODE;
50 u32 TX_MODE;
51 u32 RX_FIFO_ST;
52 u32 TX_FIFO_ST;
53 u32 TX_FID;
54 u32 TX_RESULT;
55 u32 PAUSE_PKT1;
56 u32 PAUSE_PKT2;
57 u32 PAUSE_PKT3;
58 u32 PAUSE_PKT4;
59 u32 PAUSE_PKT5;
60 u32 reserve[2];
61 struct pch_gbe_regs_mac_adr mac_adr[16];
62 u32 ADDR_MASK;
63 u32 MIIM;
64 u32 MAC_ADDR_LOAD;
65 u32 RGMII_ST;
66 u32 RGMII_CTRL;
67 u32 reserve3[3];
68 u32 DMA_CTRL;
69 u32 reserve4[3];
70 u32 RX_DSC_BASE;
71 u32 RX_DSC_SIZE;
72 u32 RX_DSC_HW_P;
73 u32 RX_DSC_HW_P_HLD;
74 u32 RX_DSC_SW_P;
75 u32 reserve5[3];
76 u32 TX_DSC_BASE;
77 u32 TX_DSC_SIZE;
78 u32 TX_DSC_HW_P;
79 u32 TX_DSC_HW_P_HLD;
80 u32 TX_DSC_SW_P;
81 u32 reserve6[3];
82 u32 RX_DMA_ST;
83 u32 TX_DMA_ST;
84 u32 reserve7[2];
85 u32 WOL_ST;
86 u32 WOL_CTRL;
87 u32 WOL_ADDR_MASK;
88 };
89
90
91
92
93 #define PCH_GBE_INT_RX_DMA_CMPLT 0x00000001
94 #define PCH_GBE_INT_RX_VALID 0x00000002
95 #define PCH_GBE_INT_RX_FRAME_ERR 0x00000004
96 #define PCH_GBE_INT_RX_FIFO_ERR 0x00000008
97 #define PCH_GBE_INT_RX_DMA_ERR 0x00000010
98 #define PCH_GBE_INT_RX_DSC_EMP 0x00000020
99 #define PCH_GBE_INT_TX_CMPLT 0x00000100
100 #define PCH_GBE_INT_TX_DMA_CMPLT 0x00000200
101 #define PCH_GBE_INT_TX_FIFO_ERR 0x00000400
102 #define PCH_GBE_INT_TX_DMA_ERR 0x00000800
103 #define PCH_GBE_INT_PAUSE_CMPLT 0x00001000
104 #define PCH_GBE_INT_MIIM_CMPLT 0x00010000
105 #define PCH_GBE_INT_PHY_INT 0x00100000
106 #define PCH_GBE_INT_WOL_DET 0x01000000
107 #define PCH_GBE_INT_TCPIP_ERR 0x10000000
108
109
110 #define PCH_GBE_MODE_MII_ETHER 0x00000000
111 #define PCH_GBE_MODE_GMII_ETHER 0x80000000
112 #define PCH_GBE_MODE_HALF_DUPLEX 0x00000000
113 #define PCH_GBE_MODE_FULL_DUPLEX 0x40000000
114 #define PCH_GBE_MODE_FR_BST 0x04000000
115
116
117 #define PCH_GBE_ALL_RST 0x80000000
118 #define PCH_GBE_TX_RST 0x00008000
119 #define PCH_GBE_RX_RST 0x00004000
120
121
122 #define PCH_GBE_EX_LIST_EN 0x00000008
123 #define PCH_GBE_RX_TCPIPACC_OFF 0x00000004
124 #define PCH_GBE_TX_TCPIPACC_EN 0x00000002
125 #define PCH_GBE_RX_TCPIPACC_EN 0x00000001
126
127
128 #define PCH_GBE_MRE_MAC_RX_EN 0x00000001
129
130
131 #define PCH_GBE_FL_CTRL_EN 0x80000000
132
133
134 #define PCH_GBE_PS_PKT_RQ 0x80000000
135
136
137 #define PCH_GBE_ADD_FIL_EN 0x80000000
138
139 #define PCH_GBE_MLT_FIL_EN 0x40000000
140
141 #define PCH_GBE_RH_ALM_EMP_4 0x00000000
142 #define PCH_GBE_RH_ALM_EMP_8 0x00004000
143 #define PCH_GBE_RH_ALM_EMP_16 0x00008000
144 #define PCH_GBE_RH_ALM_EMP_32 0x0000C000
145
146 #define PCH_GBE_RH_ALM_FULL_4 0x00000000
147 #define PCH_GBE_RH_ALM_FULL_8 0x00001000
148 #define PCH_GBE_RH_ALM_FULL_16 0x00002000
149 #define PCH_GBE_RH_ALM_FULL_32 0x00003000
150
151 #define PCH_GBE_RH_RD_TRG_4 0x00000000
152 #define PCH_GBE_RH_RD_TRG_8 0x00000200
153 #define PCH_GBE_RH_RD_TRG_16 0x00000400
154 #define PCH_GBE_RH_RD_TRG_32 0x00000600
155 #define PCH_GBE_RH_RD_TRG_64 0x00000800
156 #define PCH_GBE_RH_RD_TRG_128 0x00000A00
157 #define PCH_GBE_RH_RD_TRG_256 0x00000C00
158 #define PCH_GBE_RH_RD_TRG_512 0x00000E00
159
160
161 #define PCH_GBE_RXD_ACC_STAT_BCAST 0x00000400
162 #define PCH_GBE_RXD_ACC_STAT_MCAST 0x00000200
163 #define PCH_GBE_RXD_ACC_STAT_UCAST 0x00000100
164 #define PCH_GBE_RXD_ACC_STAT_TCPIPOK 0x000000C0
165 #define PCH_GBE_RXD_ACC_STAT_IPOK 0x00000080
166 #define PCH_GBE_RXD_ACC_STAT_TCPOK 0x00000040
167 #define PCH_GBE_RXD_ACC_STAT_IP6ERR 0x00000020
168 #define PCH_GBE_RXD_ACC_STAT_OFLIST 0x00000010
169 #define PCH_GBE_RXD_ACC_STAT_TYPEIP 0x00000008
170 #define PCH_GBE_RXD_ACC_STAT_MACL 0x00000004
171 #define PCH_GBE_RXD_ACC_STAT_PPPOE 0x00000002
172 #define PCH_GBE_RXD_ACC_STAT_VTAGT 0x00000001
173 #define PCH_GBE_RXD_GMAC_STAT_PAUSE 0x0200
174 #define PCH_GBE_RXD_GMAC_STAT_MARBR 0x0100
175 #define PCH_GBE_RXD_GMAC_STAT_MARMLT 0x0080
176 #define PCH_GBE_RXD_GMAC_STAT_MARIND 0x0040
177 #define PCH_GBE_RXD_GMAC_STAT_MARNOTMT 0x0020
178 #define PCH_GBE_RXD_GMAC_STAT_TLONG 0x0010
179 #define PCH_GBE_RXD_GMAC_STAT_TSHRT 0x0008
180 #define PCH_GBE_RXD_GMAC_STAT_NOTOCTAL 0x0004
181 #define PCH_GBE_RXD_GMAC_STAT_NBLERR 0x0002
182 #define PCH_GBE_RXD_GMAC_STAT_CRCERR 0x0001
183
184
185 #define PCH_GBE_TXD_CTRL_TCPIP_ACC_OFF 0x0008
186 #define PCH_GBE_TXD_CTRL_ITAG 0x0004
187 #define PCH_GBE_TXD_CTRL_ICRC 0x0002
188 #define PCH_GBE_TXD_CTRL_APAD 0x0001
189 #define PCH_GBE_TXD_WORDS_SHIFT 2
190 #define PCH_GBE_TXD_GMAC_STAT_CMPLT 0x2000
191 #define PCH_GBE_TXD_GMAC_STAT_ABT 0x1000
192 #define PCH_GBE_TXD_GMAC_STAT_EXCOL 0x0800
193 #define PCH_GBE_TXD_GMAC_STAT_SNGCOL 0x0400
194 #define PCH_GBE_TXD_GMAC_STAT_MLTCOL 0x0200
195 #define PCH_GBE_TXD_GMAC_STAT_CRSER 0x0100
196 #define PCH_GBE_TXD_GMAC_STAT_TLNG 0x0080
197 #define PCH_GBE_TXD_GMAC_STAT_TSHRT 0x0040
198 #define PCH_GBE_TXD_GMAC_STAT_LTCOL 0x0020
199 #define PCH_GBE_TXD_GMAC_STAT_TFUNDFLW 0x0010
200 #define PCH_GBE_TXD_GMAC_STAT_RTYCNT_MASK 0x000F
201
202
203 #define PCH_GBE_TM_NO_RTRY 0x80000000
204 #define PCH_GBE_TM_LONG_PKT 0x40000000
205 #define PCH_GBE_TM_ST_AND_FD 0x20000000
206 #define PCH_GBE_TM_SHORT_PKT 0x10000000
207 #define PCH_GBE_TM_LTCOL_RETX 0x08000000
208
209 #define PCH_GBE_TM_TH_TX_STRT_4 0x00000000
210 #define PCH_GBE_TM_TH_TX_STRT_8 0x00004000
211 #define PCH_GBE_TM_TH_TX_STRT_16 0x00008000
212 #define PCH_GBE_TM_TH_TX_STRT_32 0x0000C000
213
214 #define PCH_GBE_TM_TH_ALM_EMP_4 0x00000000
215 #define PCH_GBE_TM_TH_ALM_EMP_8 0x00000800
216 #define PCH_GBE_TM_TH_ALM_EMP_16 0x00001000
217 #define PCH_GBE_TM_TH_ALM_EMP_32 0x00001800
218 #define PCH_GBE_TM_TH_ALM_EMP_64 0x00002000
219 #define PCH_GBE_TM_TH_ALM_EMP_128 0x00002800
220 #define PCH_GBE_TM_TH_ALM_EMP_256 0x00003000
221 #define PCH_GBE_TM_TH_ALM_EMP_512 0x00003800
222
223 #define PCH_GBE_TM_TH_ALM_FULL_4 0x00000000
224 #define PCH_GBE_TM_TH_ALM_FULL_8 0x00000200
225 #define PCH_GBE_TM_TH_ALM_FULL_16 0x00000400
226 #define PCH_GBE_TM_TH_ALM_FULL_32 0x00000600
227
228
229 #define PCH_GBE_RF_ALM_FULL 0x80000000
230 #define PCH_GBE_RF_ALM_EMP 0x40000000
231 #define PCH_GBE_RF_RD_TRG 0x20000000
232 #define PCH_GBE_RF_STRWD 0x1FFE0000
233 #define PCH_GBE_RF_RCVING 0x00010000
234
235
236 #define PCH_GBE_BUSY 0x80000000
237
238
239 #define PCH_GBE_MIIM_OPER_WRITE 0x04000000
240 #define PCH_GBE_MIIM_OPER_READ 0x00000000
241 #define PCH_GBE_MIIM_OPER_READY 0x04000000
242 #define PCH_GBE_MIIM_PHY_ADDR_SHIFT 21
243 #define PCH_GBE_MIIM_REG_ADDR_SHIFT 16
244
245
246 #define PCH_GBE_LINK_UP 0x80000008
247 #define PCH_GBE_RXC_SPEED_MSK 0x00000006
248 #define PCH_GBE_RXC_SPEED_2_5M 0x00000000
249 #define PCH_GBE_RXC_SPEED_25M 0x00000002
250 #define PCH_GBE_RXC_SPEED_125M 0x00000004
251 #define PCH_GBE_DUPLEX_FULL 0x00000001
252
253
254 #define PCH_GBE_CRS_SEL 0x00000010
255 #define PCH_GBE_RGMII_RATE_125M 0x00000000
256 #define PCH_GBE_RGMII_RATE_25M 0x00000008
257 #define PCH_GBE_RGMII_RATE_2_5M 0x0000000C
258 #define PCH_GBE_RGMII_MODE_GMII 0x00000000
259 #define PCH_GBE_RGMII_MODE_RGMII 0x00000002
260 #define PCH_GBE_CHIP_TYPE_EXTERNAL 0x00000000
261 #define PCH_GBE_CHIP_TYPE_INTERNAL 0x00000001
262
263
264 #define PCH_GBE_RX_DMA_EN 0x00000002
265 #define PCH_GBE_TX_DMA_EN 0x00000001
266
267
268 #define PCH_GBE_IDLE_CHECK 0xFFFFFFFE
269
270
271 #define PCH_GBE_WLS_BR 0x00000008
272 #define PCH_GBE_WLS_MLT 0x00000004
273
274
275 #define PCH_GBE_WLS_IND 0x00000002
276 #define PCH_GBE_WLS_MP 0x00000001
277
278
279 #define PCH_GBE_WLC_WOL_MODE 0x00010000
280 #define PCH_GBE_WLC_IGN_TLONG 0x00000100
281 #define PCH_GBE_WLC_IGN_TSHRT 0x00000080
282 #define PCH_GBE_WLC_IGN_OCTER 0x00000040
283 #define PCH_GBE_WLC_IGN_NBLER 0x00000020
284 #define PCH_GBE_WLC_IGN_CRCER 0x00000010
285 #define PCH_GBE_WLC_BR 0x00000008
286 #define PCH_GBE_WLC_MLT 0x00000004
287 #define PCH_GBE_WLC_IND 0x00000002
288 #define PCH_GBE_WLC_MP 0x00000001
289
290
291 #define PCH_GBE_WLA_BUSY 0x80000000
292
293
294
295
296 #define PCH_GBE_MAX_TXD 4096
297 #define PCH_GBE_DEFAULT_TXD 256
298 #define PCH_GBE_MIN_TXD 8
299 #define PCH_GBE_MAX_RXD 4096
300 #define PCH_GBE_DEFAULT_RXD 256
301 #define PCH_GBE_MIN_RXD 8
302
303
304 #define PCH_GBE_TX_DESC_MULTIPLE 8
305 #define PCH_GBE_RX_DESC_MULTIPLE 8
306
307
308 #define PCH_GBE_HAL_MIIM_READ ((u32)0x00000000)
309 #define PCH_GBE_HAL_MIIM_WRITE ((u32)0x04000000)
310
311
312 #define PCH_GBE_FC_NONE 0
313 #define PCH_GBE_FC_RX_PAUSE 1
314 #define PCH_GBE_FC_TX_PAUSE 2
315 #define PCH_GBE_FC_FULL 3
316 #define PCH_GBE_FC_DEFAULT PCH_GBE_FC_FULL
317
318
319
320
321
322
323
324
325
326
327
328
329
330 struct pch_gbe_mac_info {
331 u8 addr[6];
332 u8 fc;
333 u8 fc_autoneg;
334 u8 tx_fc_enable;
335 u32 max_frame_size;
336 u32 min_frame_size;
337 u8 autoneg;
338 u16 link_speed;
339 u16 link_duplex;
340 };
341
342
343
344
345
346
347
348
349
350 struct pch_gbe_phy_info {
351 u32 addr;
352 u32 id;
353 u32 revision;
354 u32 reset_delay_us;
355 u16 autoneg_advertised;
356 };
357
358
359
360
361
362
363 struct pch_gbe_hw {
364 void *back;
365
366 struct pch_gbe_regs __iomem *reg;
367 spinlock_t miim_lock;
368
369 struct pch_gbe_mac_info mac;
370 struct pch_gbe_phy_info phy;
371 };
372
373
374
375
376
377
378
379
380
381
382
383 struct pch_gbe_rx_desc {
384 u32 buffer_addr;
385 u32 tcp_ip_status;
386 u16 rx_words_eob;
387 u16 gbec_status;
388 u8 dma_status;
389 u8 reserved1;
390 u16 reserved2;
391 };
392
393
394
395
396
397
398
399
400
401
402
403
404 struct pch_gbe_tx_desc {
405 u32 buffer_addr;
406 u16 length;
407 u16 reserved1;
408 u16 tx_words_eob;
409 u16 tx_frame_ctrl;
410 u8 dma_status;
411 u8 reserved2;
412 u16 gbec_status;
413 };
414
415
416
417
418
419
420
421
422
423 struct pch_gbe_buffer {
424 struct sk_buff *skb;
425 dma_addr_t dma;
426 unsigned char *rx_buffer;
427 unsigned long time_stamp;
428 u16 length;
429 bool mapped;
430 };
431
432
433
434
435
436
437
438
439
440
441
442 struct pch_gbe_tx_ring {
443 struct pch_gbe_tx_desc *desc;
444 dma_addr_t dma;
445 unsigned int size;
446 unsigned int count;
447 unsigned int next_to_use;
448 unsigned int next_to_clean;
449 struct pch_gbe_buffer *buffer_info;
450 };
451
452
453
454
455
456
457
458
459
460
461
462 struct pch_gbe_rx_ring {
463 struct pch_gbe_rx_desc *desc;
464 dma_addr_t dma;
465 unsigned char *rx_buff_pool;
466 dma_addr_t rx_buff_pool_logic;
467 unsigned int rx_buff_pool_size;
468 unsigned int size;
469 unsigned int count;
470 unsigned int next_to_use;
471 unsigned int next_to_clean;
472 struct pch_gbe_buffer *buffer_info;
473 };
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503 struct pch_gbe_hw_stats {
504 u32 rx_packets;
505 u32 tx_packets;
506 u32 rx_bytes;
507 u32 tx_bytes;
508 u32 rx_errors;
509 u32 tx_errors;
510 u32 rx_dropped;
511 u32 tx_dropped;
512 u32 multicast;
513 u32 collisions;
514 u32 rx_crc_errors;
515 u32 rx_frame_errors;
516 u32 rx_alloc_buff_failed;
517 u32 tx_length_errors;
518 u32 tx_aborted_errors;
519 u32 tx_carrier_errors;
520 u32 tx_timeout_count;
521 u32 tx_restart_count;
522 u32 intr_rx_dsc_empty_count;
523 u32 intr_rx_frame_err_count;
524 u32 intr_rx_fifo_err_count;
525 u32 intr_rx_dma_err_count;
526 u32 intr_tx_fifo_err_count;
527 u32 intr_tx_dma_err_count;
528 u32 intr_tcpip_err_count;
529 };
530
531
532
533
534
535
536
537
538 struct pch_gbe_privdata {
539 bool phy_tx_clk_delay;
540 bool phy_disable_hibernate;
541 int (*platform_init)(struct pci_dev *pdev);
542 };
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569 struct pch_gbe_adapter {
570 spinlock_t stats_lock;
571 spinlock_t ethtool_lock;
572 atomic_t irq_sem;
573 struct net_device *netdev;
574 struct pci_dev *pdev;
575 int irq;
576 struct net_device *polling_netdev;
577 struct napi_struct napi;
578 struct pch_gbe_hw hw;
579 struct pch_gbe_hw_stats stats;
580 struct work_struct reset_task;
581 struct mii_if_info mii;
582 struct timer_list watchdog_timer;
583 u32 wake_up_evt;
584 u32 *config_space;
585 unsigned long led_status;
586 struct pch_gbe_tx_ring *tx_ring;
587 struct pch_gbe_rx_ring *rx_ring;
588 unsigned long rx_buffer_len;
589 unsigned long tx_queue_len;
590 bool rx_stop_flag;
591 int hwts_tx_en;
592 int hwts_rx_en;
593 struct pci_dev *ptp_pdev;
594 struct pch_gbe_privdata *pdata;
595 };
596
597 #define pch_gbe_hw_to_adapter(hw) container_of(hw, struct pch_gbe_adapter, hw)
598
599 extern const char pch_driver_version[];
600
601
602 int pch_gbe_up(struct pch_gbe_adapter *adapter);
603 void pch_gbe_down(struct pch_gbe_adapter *adapter);
604 void pch_gbe_reinit_locked(struct pch_gbe_adapter *adapter);
605 void pch_gbe_reset(struct pch_gbe_adapter *adapter);
606 int pch_gbe_setup_tx_resources(struct pch_gbe_adapter *adapter,
607 struct pch_gbe_tx_ring *txdr);
608 int pch_gbe_setup_rx_resources(struct pch_gbe_adapter *adapter,
609 struct pch_gbe_rx_ring *rxdr);
610 void pch_gbe_free_tx_resources(struct pch_gbe_adapter *adapter,
611 struct pch_gbe_tx_ring *tx_ring);
612 void pch_gbe_free_rx_resources(struct pch_gbe_adapter *adapter,
613 struct pch_gbe_rx_ring *rx_ring);
614 void pch_gbe_update_stats(struct pch_gbe_adapter *adapter);
615 u32 pch_ch_control_read(struct pci_dev *pdev);
616 void pch_ch_control_write(struct pci_dev *pdev, u32 val);
617 u32 pch_ch_event_read(struct pci_dev *pdev);
618 void pch_ch_event_write(struct pci_dev *pdev, u32 val);
619 u32 pch_src_uuid_lo_read(struct pci_dev *pdev);
620 u32 pch_src_uuid_hi_read(struct pci_dev *pdev);
621 u64 pch_rx_snap_read(struct pci_dev *pdev);
622 u64 pch_tx_snap_read(struct pci_dev *pdev);
623 int pch_set_station_address(u8 *addr, struct pci_dev *pdev);
624
625
626 void pch_gbe_check_options(struct pch_gbe_adapter *adapter);
627
628
629 void pch_gbe_set_ethtool_ops(struct net_device *netdev);
630
631
632 s32 pch_gbe_mac_force_mac_fc(struct pch_gbe_hw *hw);
633 u16 pch_gbe_mac_ctrl_miim(struct pch_gbe_hw *hw, u32 addr, u32 dir, u32 reg,
634 u16 data);
635 #endif