17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 #include <linux/kernel.h>
22 #include <linux/module.h>
24 #include <linux/pci.h>
26 #include <linux/mii.h>
28 #include <linux/ethtool.h>
32 #include <linux/if_vlan.h>
34 #include <linux/sched.h>
35 #include <linux/slab.h>
40 #define KS_DMA_TX_CTRL 0x0000
41 #define DMA_TX_ENABLE 0x00000001
42 #define DMA_TX_CRC_ENABLE 0x00000002
43 #define DMA_TX_PAD_ENABLE 0x00000004
44 #define DMA_TX_LOOPBACK 0x00000100
45 #define DMA_TX_FLOW_ENABLE 0x00000200
46 #define DMA_TX_CSUM_IP 0x00010000
47 #define DMA_TX_CSUM_TCP 0x00020000
48 #define DMA_TX_CSUM_UDP 0x00040000
49 #define DMA_TX_BURST_SIZE 0x3F000000
51 #define KS_DMA_RX_CTRL 0x0004
52 #define DMA_RX_ENABLE 0x00000001
53 #define KS884X_DMA_RX_MULTICAST 0x00000002
54 #define DMA_RX_PROMISCUOUS 0x00000004
55 #define DMA_RX_ERROR 0x00000008
56 #define DMA_RX_UNICAST 0x00000010
57 #define DMA_RX_ALL_MULTICAST 0x00000020
58 #define DMA_RX_BROADCAST 0x00000040
59 #define DMA_RX_FLOW_ENABLE 0x00000200
60 #define DMA_RX_CSUM_IP 0x00010000
61 #define DMA_RX_CSUM_TCP 0x00020000
62 #define DMA_RX_CSUM_UDP 0x00040000
63 #define DMA_RX_BURST_SIZE 0x3F000000
65 #define DMA_BURST_SHIFT 24
66 #define DMA_BURST_DEFAULT 8
68 #define KS_DMA_TX_START 0x0008
69 #define KS_DMA_RX_START 0x000C
70 #define DMA_START 0x00000001
72 #define KS_DMA_TX_ADDR 0x0010
73 #define KS_DMA_RX_ADDR 0x0014
75 #define DMA_ADDR_LIST_MASK 0xFFFFFFFC
76 #define DMA_ADDR_LIST_SHIFT 2
79 #define KS884X_MULTICAST_0_OFFSET 0x0020
80 #define KS884X_MULTICAST_1_OFFSET 0x0021
81 #define KS884X_MULTICAST_2_OFFSET 0x0022
82 #define KS884x_MULTICAST_3_OFFSET 0x0023
84 #define KS884X_MULTICAST_4_OFFSET 0x0024
85 #define KS884X_MULTICAST_5_OFFSET 0x0025
86 #define KS884X_MULTICAST_6_OFFSET 0x0026
87 #define KS884X_MULTICAST_7_OFFSET 0x0027
92 #define KS884X_INTERRUPTS_ENABLE 0x0028
94 #define KS884X_INTERRUPTS_STATUS 0x002C
96 #define KS884X_INT_RX_STOPPED 0x02000000
97 #define KS884X_INT_TX_STOPPED 0x04000000
98 #define KS884X_INT_RX_OVERRUN 0x08000000
99 #define KS884X_INT_TX_EMPTY 0x10000000
100 #define KS884X_INT_RX 0x20000000
101 #define KS884X_INT_TX 0x40000000
102 #define KS884X_INT_PHY 0x80000000
104 #define KS884X_INT_RX_MASK \
105 (KS884X_INT_RX | KS884X_INT_RX_OVERRUN)
106 #define KS884X_INT_TX_MASK \
107 (KS884X_INT_TX | KS884X_INT_TX_EMPTY)
108 #define KS884X_INT_MASK (KS884X_INT_RX | KS884X_INT_TX | KS884X_INT_PHY)
113 #define KS_ADD_ADDR_0_LO 0x0080
115 #define KS_ADD_ADDR_0_HI 0x0084
117 #define KS_ADD_ADDR_1_LO 0x0088
119 #define KS_ADD_ADDR_1_HI 0x008C
121 #define KS_ADD_ADDR_2_LO 0x0090
123 #define KS_ADD_ADDR_2_HI 0x0094
125 #define KS_ADD_ADDR_3_LO 0x0098
127 #define KS_ADD_ADDR_3_HI 0x009C
129 #define KS_ADD_ADDR_4_LO 0x00A0
131 #define KS_ADD_ADDR_4_HI 0x00A4
133 #define KS_ADD_ADDR_5_LO 0x00A8
135 #define KS_ADD_ADDR_5_HI 0x00AC
137 #define KS_ADD_ADDR_6_LO 0x00B0
139 #define KS_ADD_ADDR_6_HI 0x00B4
141 #define KS_ADD_ADDR_7_LO 0x00B8
143 #define KS_ADD_ADDR_7_HI 0x00BC
145 #define KS_ADD_ADDR_8_LO 0x00C0
147 #define KS_ADD_ADDR_8_HI 0x00C4
149 #define KS_ADD_ADDR_9_LO 0x00C8
151 #define KS_ADD_ADDR_9_HI 0x00CC
153 #define KS_ADD_ADDR_A_LO 0x00D0
155 #define KS_ADD_ADDR_A_HI 0x00D4
157 #define KS_ADD_ADDR_B_LO 0x00D8
159 #define KS_ADD_ADDR_B_HI 0x00DC
161 #define KS_ADD_ADDR_C_LO 0x00E0
163 #define KS_ADD_ADDR_C_HI 0x00E4
165 #define KS_ADD_ADDR_D_LO 0x00E8
167 #define KS_ADD_ADDR_D_HI 0x00EC
169 #define KS_ADD_ADDR_E_LO 0x00F0
171 #define KS_ADD_ADDR_E_HI 0x00F4
173 #define KS_ADD_ADDR_F_LO 0x00F8
175 #define KS_ADD_ADDR_F_HI 0x00FC
177 #define ADD_ADDR_HI_MASK 0x0000FFFF
178 #define ADD_ADDR_ENABLE 0x80000000
179 #define ADD_ADDR_INCR 8
184 #define KS884X_ADDR_0_OFFSET 0x0200
185 #define KS884X_ADDR_1_OFFSET 0x0201
187 #define KS884X_ADDR_2_OFFSET 0x0202
188 #define KS884X_ADDR_3_OFFSET 0x0203
190 #define KS884X_ADDR_4_OFFSET 0x0204
191 #define KS884X_ADDR_5_OFFSET 0x0205
194 #define KS884X_BUS_CTRL_OFFSET 0x0210
196 #define BUS_SPEED_125_MHZ 0x0000
197 #define BUS_SPEED_62_5_MHZ 0x0001
198 #define BUS_SPEED_41_66_MHZ 0x0002
199 #define BUS_SPEED_25_MHZ 0x0003
202 #define KS884X_EEPROM_CTRL_OFFSET 0x0212
204 #define EEPROM_CHIP_SELECT 0x0001
205 #define EEPROM_SERIAL_CLOCK 0x0002
206 #define EEPROM_DATA_OUT 0x0004
207 #define EEPROM_DATA_IN 0x0008
208 #define EEPROM_ACCESS_ENABLE 0x0010
211 #define KS884X_MEM_INFO_OFFSET 0x0214
213 #define RX_MEM_TEST_FAILED 0x0008
214 #define RX_MEM_TEST_FINISHED 0x0010
215 #define TX_MEM_TEST_FAILED 0x0800
216 #define TX_MEM_TEST_FINISHED 0x1000
219 #define KS884X_GLOBAL_CTRL_OFFSET 0x0216
220 #define GLOBAL_SOFTWARE_RESET 0x0001
222 #define KS8841_POWER_MANAGE_OFFSET 0x0218
225 #define KS8841_WOL_CTRL_OFFSET 0x021A
226 #define KS8841_WOL_MAGIC_ENABLE 0x0080
227 #define KS8841_WOL_FRAME3_ENABLE 0x0008
228 #define KS8841_WOL_FRAME2_ENABLE 0x0004
229 #define KS8841_WOL_FRAME1_ENABLE 0x0002
230 #define KS8841_WOL_FRAME0_ENABLE 0x0001
233 #define KS8841_WOL_FRAME_CRC_OFFSET 0x0220
234 #define KS8841_WOL_FRAME_BYTE0_OFFSET 0x0224
235 #define KS8841_WOL_FRAME_BYTE2_OFFSET 0x0228
238 #define KS884X_IACR_P 0x04A0
239 #define KS884X_IACR_OFFSET KS884X_IACR_P
242 #define KS884X_IADR1_P 0x04A2
243 #define KS884X_IADR2_P 0x04A4
244 #define KS884X_IADR3_P 0x04A6
245 #define KS884X_IADR4_P 0x04A8
246 #define KS884X_IADR5_P 0x04AA
248 #define KS884X_ACC_CTRL_SEL_OFFSET KS884X_IACR_P
249 #define KS884X_ACC_CTRL_INDEX_OFFSET (KS884X_ACC_CTRL_SEL_OFFSET + 1)
251 #define KS884X_ACC_DATA_0_OFFSET KS884X_IADR4_P
252 #define KS884X_ACC_DATA_1_OFFSET (KS884X_ACC_DATA_0_OFFSET + 1)
253 #define KS884X_ACC_DATA_2_OFFSET KS884X_IADR5_P
254 #define KS884X_ACC_DATA_3_OFFSET (KS884X_ACC_DATA_2_OFFSET + 1)
255 #define KS884X_ACC_DATA_4_OFFSET KS884X_IADR2_P
256 #define KS884X_ACC_DATA_5_OFFSET (KS884X_ACC_DATA_4_OFFSET + 1)
257 #define KS884X_ACC_DATA_6_OFFSET KS884X_IADR3_P
258 #define KS884X_ACC_DATA_7_OFFSET (KS884X_ACC_DATA_6_OFFSET + 1)
259 #define KS884X_ACC_DATA_8_OFFSET KS884X_IADR1_P
262 #define KS884X_P1MBCR_P 0x04D0
263 #define KS884X_P1MBSR_P 0x04D2
264 #define KS884X_PHY1ILR_P 0x04D4
265 #define KS884X_PHY1IHR_P 0x04D6
266 #define KS884X_P1ANAR_P 0x04D8
267 #define KS884X_P1ANLPR_P 0x04DA
270 #define KS884X_P2MBCR_P 0x04E0
271 #define KS884X_P2MBSR_P 0x04E2
272 #define KS884X_PHY2ILR_P 0x04E4
273 #define KS884X_PHY2IHR_P 0x04E6
274 #define KS884X_P2ANAR_P 0x04E8
275 #define KS884X_P2ANLPR_P 0x04EA
277 #define KS884X_PHY_1_CTRL_OFFSET KS884X_P1MBCR_P
278 #define PHY_CTRL_INTERVAL (KS884X_P2MBCR_P - KS884X_P1MBCR_P)
280 #define KS884X_PHY_CTRL_OFFSET 0x00
283 #define PHY_REG_CTRL 0
285 #define PHY_RESET 0x8000
286 #define PHY_LOOPBACK 0x4000
287 #define PHY_SPEED_100MBIT 0x2000
288 #define PHY_AUTO_NEG_ENABLE 0x1000
289 #define PHY_POWER_DOWN 0x0800
290 #define PHY_MII_DISABLE 0x0400
291 #define PHY_AUTO_NEG_RESTART 0x0200
292 #define PHY_FULL_DUPLEX 0x0100
293 #define PHY_COLLISION_TEST 0x0080
294 #define PHY_HP_MDIX 0x0020
295 #define PHY_FORCE_MDIX 0x0010
296 #define PHY_AUTO_MDIX_DISABLE 0x0008
297 #define PHY_REMOTE_FAULT_DISABLE 0x0004
298 #define PHY_TRANSMIT_DISABLE 0x0002
299 #define PHY_LED_DISABLE 0x0001
301 #define KS884X_PHY_STATUS_OFFSET 0x02
304 #define PHY_REG_STATUS 1
306 #define PHY_100BT4_CAPABLE 0x8000
307 #define PHY_100BTX_FD_CAPABLE 0x4000
308 #define PHY_100BTX_CAPABLE 0x2000
309 #define PHY_10BT_FD_CAPABLE 0x1000
310 #define PHY_10BT_CAPABLE 0x0800
311 #define PHY_MII_SUPPRESS_CAPABLE 0x0040
312 #define PHY_AUTO_NEG_ACKNOWLEDGE 0x0020
313 #define PHY_REMOTE_FAULT 0x0010
314 #define PHY_AUTO_NEG_CAPABLE 0x0008
315 #define PHY_LINK_STATUS 0x0004
316 #define PHY_JABBER_DETECT 0x0002
317 #define PHY_EXTENDED_CAPABILITY 0x0001
319 #define KS884X_PHY_ID_1_OFFSET 0x04
320 #define KS884X_PHY_ID_2_OFFSET 0x06
323 #define PHY_REG_ID_1 2
324 #define PHY_REG_ID_2 3
326 #define KS884X_PHY_AUTO_NEG_OFFSET 0x08
329 #define PHY_REG_AUTO_NEGOTIATION 4
331 #define PHY_AUTO_NEG_NEXT_PAGE 0x8000
332 #define PHY_AUTO_NEG_REMOTE_FAULT 0x2000
334 #define PHY_AUTO_NEG_ASYM_PAUSE 0x0800
335 #define PHY_AUTO_NEG_SYM_PAUSE 0x0400
336 #define PHY_AUTO_NEG_100BT4 0x0200
337 #define PHY_AUTO_NEG_100BTX_FD 0x0100
338 #define PHY_AUTO_NEG_100BTX 0x0080
339 #define PHY_AUTO_NEG_10BT_FD 0x0040
340 #define PHY_AUTO_NEG_10BT 0x0020
341 #define PHY_AUTO_NEG_SELECTOR 0x001F
342 #define PHY_AUTO_NEG_802_3 0x0001
344 #define PHY_AUTO_NEG_PAUSE (PHY_AUTO_NEG_SYM_PAUSE | PHY_AUTO_NEG_ASYM_PAUSE)
346 #define KS884X_PHY_REMOTE_CAP_OFFSET 0x0A
349 #define PHY_REG_REMOTE_CAPABILITY 5
351 #define PHY_REMOTE_NEXT_PAGE 0x8000
352 #define PHY_REMOTE_ACKNOWLEDGE 0x4000
353 #define PHY_REMOTE_REMOTE_FAULT 0x2000
354 #define PHY_REMOTE_SYM_PAUSE 0x0400
355 #define PHY_REMOTE_100BTX_FD 0x0100
356 #define PHY_REMOTE_100BTX 0x0080
357 #define PHY_REMOTE_10BT_FD 0x0040
358 #define PHY_REMOTE_10BT 0x0020
361 #define KS884X_P1VCT_P 0x04F0
362 #define KS884X_P1PHYCTRL_P 0x04F2
365 #define KS884X_P2VCT_P 0x04F4
366 #define KS884X_P2PHYCTRL_P 0x04F6
368 #define KS884X_PHY_SPECIAL_OFFSET KS884X_P1VCT_P
369 #define PHY_SPECIAL_INTERVAL (KS884X_P2VCT_P - KS884X_P1VCT_P)
371 #define KS884X_PHY_LINK_MD_OFFSET 0x00
373 #define PHY_START_CABLE_DIAG 0x8000
374 #define PHY_CABLE_DIAG_RESULT 0x6000
375 #define PHY_CABLE_STAT_NORMAL 0x0000
376 #define PHY_CABLE_STAT_OPEN 0x2000
377 #define PHY_CABLE_STAT_SHORT 0x4000
378 #define PHY_CABLE_STAT_FAILED 0x6000
379 #define PHY_CABLE_10M_SHORT 0x1000
380 #define PHY_CABLE_FAULT_COUNTER 0x01FF
382 #define KS884X_PHY_PHY_CTRL_OFFSET 0x02
384 #define PHY_STAT_REVERSED_POLARITY 0x0020
385 #define PHY_STAT_MDIX 0x0010
386 #define PHY_FORCE_LINK 0x0008
387 #define PHY_POWER_SAVING_DISABLE 0x0004
388 #define PHY_REMOTE_LOOPBACK 0x0002
391 #define KS884X_SIDER_P 0x0400
392 #define KS884X_CHIP_ID_OFFSET KS884X_SIDER_P
393 #define KS884X_FAMILY_ID_OFFSET (KS884X_CHIP_ID_OFFSET + 1)
395 #define REG_FAMILY_ID 0x88
397 #define REG_CHIP_ID_41 0x8810
398 #define REG_CHIP_ID_42 0x8800
400 #define KS884X_CHIP_ID_MASK_41 0xFF10
401 #define KS884X_CHIP_ID_MASK 0xFFF0
402 #define KS884X_CHIP_ID_SHIFT 4
403 #define KS884X_REVISION_MASK 0x000E
404 #define KS884X_REVISION_SHIFT 1
405 #define KS8842_START 0x0001
407 #define CHIP_IP_41_M 0x8810
408 #define CHIP_IP_42_M 0x8800
409 #define CHIP_IP_61_M 0x8890
410 #define CHIP_IP_62_M 0x8880
412 #define CHIP_IP_41_P 0x8850
413 #define CHIP_IP_42_P 0x8840
414 #define CHIP_IP_61_P 0x88D0
415 #define CHIP_IP_62_P 0x88C0
418 #define KS8842_SGCR1_P 0x0402
419 #define KS8842_SWITCH_CTRL_1_OFFSET KS8842_SGCR1_P
421 #define SWITCH_PASS_ALL 0x8000
422 #define SWITCH_TX_FLOW_CTRL 0x2000
423 #define SWITCH_RX_FLOW_CTRL 0x1000
424 #define SWITCH_CHECK_LENGTH 0x0800
425 #define SWITCH_AGING_ENABLE 0x0400
426 #define SWITCH_FAST_AGING 0x0200
427 #define SWITCH_AGGR_BACKOFF 0x0100
428 #define SWITCH_PASS_PAUSE 0x0008
429 #define SWITCH_LINK_AUTO_AGING 0x0001
432 #define KS8842_SGCR2_P 0x0404
433 #define KS8842_SWITCH_CTRL_2_OFFSET KS8842_SGCR2_P
435 #define SWITCH_VLAN_ENABLE 0x8000
436 #define SWITCH_IGMP_SNOOP 0x4000
437 #define IPV6_MLD_SNOOP_ENABLE 0x2000
438 #define IPV6_MLD_SNOOP_OPTION 0x1000
439 #define PRIORITY_SCHEME_SELECT 0x0800
440 #define SWITCH_MIRROR_RX_TX 0x0100
441 #define UNICAST_VLAN_BOUNDARY 0x0080
442 #define MULTICAST_STORM_DISABLE 0x0040
443 #define SWITCH_BACK_PRESSURE 0x0020
444 #define FAIR_FLOW_CTRL 0x0010
445 #define NO_EXC_COLLISION_DROP 0x0008
446 #define SWITCH_HUGE_PACKET 0x0004
447 #define SWITCH_LEGAL_PACKET 0x0002
448 #define SWITCH_BUF_RESERVE 0x0001
451 #define KS8842_SGCR3_P 0x0406
452 #define KS8842_SWITCH_CTRL_3_OFFSET KS8842_SGCR3_P
454 #define BROADCAST_STORM_RATE_LO 0xFF00
455 #define SWITCH_REPEATER 0x0080
456 #define SWITCH_HALF_DUPLEX 0x0040
457 #define SWITCH_FLOW_CTRL 0x0020
458 #define SWITCH_10_MBIT 0x0010
459 #define SWITCH_REPLACE_NULL_VID 0x0008
460 #define BROADCAST_STORM_RATE_HI 0x0007
462 #define BROADCAST_STORM_RATE 0x07FF
465 #define KS8842_SGCR4_P 0x0408
468 #define KS8842_SGCR5_P 0x040A
469 #define KS8842_SWITCH_CTRL_5_OFFSET KS8842_SGCR5_P
471 #define LED_MODE 0x8200
472 #define LED_SPEED_DUPLEX_ACT 0x0000
473 #define LED_SPEED_DUPLEX_LINK_ACT 0x8000
474 #define LED_DUPLEX_10_100 0x0200
477 #define KS8842_SGCR6_P 0x0410
478 #define KS8842_SWITCH_CTRL_6_OFFSET KS8842_SGCR6_P
480 #define KS8842_PRIORITY_MASK 3
481 #define KS8842_PRIORITY_SHIFT 2
484 #define KS8842_SGCR7_P 0x0412
485 #define KS8842_SWITCH_CTRL_7_OFFSET KS8842_SGCR7_P
487 #define SWITCH_UNK_DEF_PORT_ENABLE 0x0008
488 #define SWITCH_UNK_DEF_PORT_3 0x0004
489 #define SWITCH_UNK_DEF_PORT_2 0x0002
490 #define SWITCH_UNK_DEF_PORT_1 0x0001
493 #define KS8842_MACAR1_P 0x0470
494 #define KS8842_MACAR2_P 0x0472
495 #define KS8842_MACAR3_P 0x0474
496 #define KS8842_MAC_ADDR_1_OFFSET KS8842_MACAR1_P
497 #define KS8842_MAC_ADDR_0_OFFSET (KS8842_MAC_ADDR_1_OFFSET + 1)
498 #define KS8842_MAC_ADDR_3_OFFSET KS8842_MACAR2_P
499 #define KS8842_MAC_ADDR_2_OFFSET (KS8842_MAC_ADDR_3_OFFSET + 1)
500 #define KS8842_MAC_ADDR_5_OFFSET KS8842_MACAR3_P
501 #define KS8842_MAC_ADDR_4_OFFSET (KS8842_MAC_ADDR_5_OFFSET + 1)
504 #define KS8842_TOSR1_P 0x0480
505 #define KS8842_TOSR2_P 0x0482
506 #define KS8842_TOSR3_P 0x0484
507 #define KS8842_TOSR4_P 0x0486
508 #define KS8842_TOSR5_P 0x0488
509 #define KS8842_TOSR6_P 0x048A
510 #define KS8842_TOSR7_P 0x0490
511 #define KS8842_TOSR8_P 0x0492
512 #define KS8842_TOS_1_OFFSET KS8842_TOSR1_P
513 #define KS8842_TOS_2_OFFSET KS8842_TOSR2_P
514 #define KS8842_TOS_3_OFFSET KS8842_TOSR3_P
515 #define KS8842_TOS_4_OFFSET KS8842_TOSR4_P
516 #define KS8842_TOS_5_OFFSET KS8842_TOSR5_P
517 #define KS8842_TOS_6_OFFSET KS8842_TOSR6_P
519 #define KS8842_TOS_7_OFFSET KS8842_TOSR7_P
520 #define KS8842_TOS_8_OFFSET KS8842_TOSR8_P
523 #define KS8842_P1CR1_P 0x0500
524 #define KS8842_P1CR2_P 0x0502
525 #define KS8842_P1VIDR_P 0x0504
526 #define KS8842_P1CR3_P 0x0506
527 #define KS8842_P1IRCR_P 0x0508
528 #define KS8842_P1ERCR_P 0x050A
529 #define KS884X_P1SCSLMD_P 0x0510
530 #define KS884X_P1CR4_P 0x0512
531 #define KS884X_P1SR_P 0x0514
534 #define KS8842_P2CR1_P 0x0520
535 #define KS8842_P2CR2_P 0x0522
536 #define KS8842_P2VIDR_P 0x0524
537 #define KS8842_P2CR3_P 0x0526
538 #define KS8842_P2IRCR_P 0x0528
539 #define KS8842_P2ERCR_P 0x052A
540 #define KS884X_P2SCSLMD_P 0x0530
541 #define KS884X_P2CR4_P 0x0532
542 #define KS884X_P2SR_P 0x0534
545 #define KS8842_P3CR1_P 0x0540
546 #define KS8842_P3CR2_P 0x0542
547 #define KS8842_P3VIDR_P 0x0544
548 #define KS8842_P3CR3_P 0x0546
549 #define KS8842_P3IRCR_P 0x0548
550 #define KS8842_P3ERCR_P 0x054A
552 #define KS8842_PORT_1_CTRL_1 KS8842_P1CR1_P
553 #define KS8842_PORT_2_CTRL_1 KS8842_P2CR1_P
554 #define KS8842_PORT_3_CTRL_1 KS8842_P3CR1_P
556 #define PORT_CTRL_ADDR(port, addr) \
557 (addr = KS8842_PORT_1_CTRL_1 + (port) * \
558 (KS8842_PORT_2_CTRL_1 - KS8842_PORT_1_CTRL_1))
560 #define KS8842_PORT_CTRL_1_OFFSET 0x00
562 #define PORT_BROADCAST_STORM 0x0080
563 #define PORT_DIFFSERV_ENABLE 0x0040
564 #define PORT_802_1P_ENABLE 0x0020
565 #define PORT_BASED_PRIORITY_MASK 0x0018
566 #define PORT_BASED_PRIORITY_BASE 0x0003
567 #define PORT_BASED_PRIORITY_SHIFT 3
568 #define PORT_BASED_PRIORITY_0 0x0000
569 #define PORT_BASED_PRIORITY_1 0x0008
570 #define PORT_BASED_PRIORITY_2 0x0010
571 #define PORT_BASED_PRIORITY_3 0x0018
572 #define PORT_INSERT_TAG 0x0004
573 #define PORT_REMOVE_TAG 0x0002
574 #define PORT_PRIO_QUEUE_ENABLE 0x0001
576 #define KS8842_PORT_CTRL_2_OFFSET 0x02
578 #define PORT_INGRESS_VLAN_FILTER 0x4000
579 #define PORT_DISCARD_NON_VID 0x2000
580 #define PORT_FORCE_FLOW_CTRL 0x1000
581 #define PORT_BACK_PRESSURE 0x0800
582 #define PORT_TX_ENABLE 0x0400
583 #define PORT_RX_ENABLE 0x0200
584 #define PORT_LEARN_DISABLE 0x0100
585 #define PORT_MIRROR_SNIFFER 0x0080
586 #define PORT_MIRROR_RX 0x0040
587 #define PORT_MIRROR_TX 0x0020
588 #define PORT_USER_PRIORITY_CEILING 0x0008
589 #define PORT_VLAN_MEMBERSHIP 0x0007
591 #define KS8842_PORT_CTRL_VID_OFFSET 0x04
593 #define PORT_DEFAULT_VID 0x0001
595 #define KS8842_PORT_CTRL_3_OFFSET 0x06
597 #define PORT_INGRESS_LIMIT_MODE 0x000C
598 #define PORT_INGRESS_ALL 0x0000
599 #define PORT_INGRESS_UNICAST 0x0004
600 #define PORT_INGRESS_MULTICAST 0x0008
601 #define PORT_INGRESS_BROADCAST 0x000C
602 #define PORT_COUNT_IFG 0x0002
603 #define PORT_COUNT_PREAMBLE 0x0001
605 #define KS8842_PORT_IN_RATE_OFFSET 0x08
606 #define KS8842_PORT_OUT_RATE_OFFSET 0x0A
608 #define PORT_PRIORITY_RATE 0x0F
609 #define PORT_PRIORITY_RATE_SHIFT 4
611 #define KS884X_PORT_LINK_MD 0x10
613 #define PORT_CABLE_10M_SHORT 0x8000
614 #define PORT_CABLE_DIAG_RESULT 0x6000
615 #define PORT_CABLE_STAT_NORMAL 0x0000
616 #define PORT_CABLE_STAT_OPEN 0x2000
617 #define PORT_CABLE_STAT_SHORT 0x4000
618 #define PORT_CABLE_STAT_FAILED 0x6000
619 #define PORT_START_CABLE_DIAG 0x1000
620 #define PORT_FORCE_LINK 0x0800
621 #define PORT_POWER_SAVING_DISABLE 0x0400
622 #define PORT_PHY_REMOTE_LOOPBACK 0x0200
623 #define PORT_CABLE_FAULT_COUNTER 0x01FF
625 #define KS884X_PORT_CTRL_4_OFFSET 0x12
627 #define PORT_LED_OFF 0x8000
628 #define PORT_TX_DISABLE 0x4000
629 #define PORT_AUTO_NEG_RESTART 0x2000
630 #define PORT_REMOTE_FAULT_DISABLE 0x1000
631 #define PORT_POWER_DOWN 0x0800
632 #define PORT_AUTO_MDIX_DISABLE 0x0400
633 #define PORT_FORCE_MDIX 0x0200
634 #define PORT_LOOPBACK 0x0100
635 #define PORT_AUTO_NEG_ENABLE 0x0080
636 #define PORT_FORCE_100_MBIT 0x0040
637 #define PORT_FORCE_FULL_DUPLEX 0x0020
638 #define PORT_AUTO_NEG_SYM_PAUSE 0x0010
639 #define PORT_AUTO_NEG_100BTX_FD 0x0008
640 #define PORT_AUTO_NEG_100BTX 0x0004
641 #define PORT_AUTO_NEG_10BT_FD 0x0002
642 #define PORT_AUTO_NEG_10BT 0x0001
644 #define KS884X_PORT_STATUS_OFFSET 0x14
646 #define PORT_HP_MDIX 0x8000
647 #define PORT_REVERSED_POLARITY 0x2000
648 #define PORT_RX_FLOW_CTRL 0x0800
649 #define PORT_TX_FLOW_CTRL 0x1000
650 #define PORT_STATUS_SPEED_100MBIT 0x0400
651 #define PORT_STATUS_FULL_DUPLEX 0x0200
652 #define PORT_REMOTE_FAULT 0x0100
653 #define PORT_MDIX_STATUS 0x0080
654 #define PORT_AUTO_NEG_COMPLETE 0x0040
655 #define PORT_STATUS_LINK_GOOD 0x0020
656 #define PORT_REMOTE_SYM_PAUSE 0x0010
657 #define PORT_REMOTE_100BTX_FD 0x0008
658 #define PORT_REMOTE_100BTX 0x0004
659 #define PORT_REMOTE_10BT_FD 0x0002
660 #define PORT_REMOTE_10BT 0x0001
671 #define STATIC_MAC_TABLE_ADDR 0x0000FFFF
672 #define STATIC_MAC_TABLE_FWD_PORTS 0x00070000
673 #define STATIC_MAC_TABLE_VALID 0x00080000
674 #define STATIC_MAC_TABLE_OVERRIDE 0x00100000
675 #define STATIC_MAC_TABLE_USE_FID 0x00200000
676 #define STATIC_MAC_TABLE_FID 0x03C00000
678 #define STATIC_MAC_FWD_PORTS_SHIFT 16
679 #define STATIC_MAC_FID_SHIFT 22
688 #define VLAN_TABLE_VID 0x00000FFF
689 #define VLAN_TABLE_FID 0x0000F000
690 #define VLAN_TABLE_MEMBERSHIP 0x00070000
691 #define VLAN_TABLE_VALID 0x00080000
693 #define VLAN_TABLE_FID_SHIFT 12
694 #define VLAN_TABLE_MEMBERSHIP_SHIFT 16
707 #define DYNAMIC_MAC_TABLE_ADDR 0x0000FFFF
708 #define DYNAMIC_MAC_TABLE_FID 0x000F0000
709 #define DYNAMIC_MAC_TABLE_SRC_PORT 0x00300000
710 #define DYNAMIC_MAC_TABLE_TIMESTAMP 0x00C00000
711 #define DYNAMIC_MAC_TABLE_ENTRIES 0xFF000000
713 #define DYNAMIC_MAC_TABLE_ENTRIES_H 0x03
714 #define DYNAMIC_MAC_TABLE_MAC_EMPTY 0x04
715 #define DYNAMIC_MAC_TABLE_RESERVED 0x78
716 #define DYNAMIC_MAC_TABLE_NOT_READY 0x80
718 #define DYNAMIC_MAC_FID_SHIFT 16
719 #define DYNAMIC_MAC_SRC_PORT_SHIFT 20
720 #define DYNAMIC_MAC_TIMESTAMP_SHIFT 22
721 #define DYNAMIC_MAC_ENTRIES_SHIFT 24
722 #define DYNAMIC_MAC_ENTRIES_H_SHIFT 8
730 #define MIB_COUNTER_VALUE 0x3FFFFFFF
731 #define MIB_COUNTER_VALID 0x40000000
732 #define MIB_COUNTER_OVERFLOW 0x80000000
734 #define MIB_PACKET_DROPPED 0x0000FFFF
736 #define KS_MIB_PACKET_DROPPED_TX_0 0x100
737 #define KS_MIB_PACKET_DROPPED_TX_1 0x101
738 #define KS_MIB_PACKET_DROPPED_TX 0x102
739 #define KS_MIB_PACKET_DROPPED_RX_0 0x103
740 #define KS_MIB_PACKET_DROPPED_RX_1 0x104
741 #define KS_MIB_PACKET_DROPPED_RX 0x105
744 #define SET_DEFAULT_LED LED_SPEED_DUPLEX_ACT
746 #define MAC_ADDR_ORDER(i) (ETH_ALEN - 1 - (i))
748 #define MAX_ETHERNET_BODY_SIZE 1500
749 #define ETHERNET_HEADER_SIZE (14 + VLAN_HLEN)
751 #define MAX_ETHERNET_PACKET_SIZE \
752 (MAX_ETHERNET_BODY_SIZE + ETHERNET_HEADER_SIZE)
754 #define REGULAR_RX_BUF_SIZE (MAX_ETHERNET_PACKET_SIZE + 4)
755 #define MAX_RX_BUF_SIZE (1912 + 4)
757 #define ADDITIONAL_ENTRIES 16
758 #define MAX_MULTICAST_LIST 32
760 #define HW_MULTICAST_SIZE 8
762 #define HW_TO_DEV_PORT(port) (port - 1)
787 #define DESC_ALIGNMENT 16
788 #define BUFFER_ALIGNMENT 8
790 #define NUM_OF_RX_DESC 64
791 #define NUM_OF_TX_DESC 64
793 #define KS_DESC_RX_FRAME_LEN 0x000007FF
794 #define KS_DESC_RX_FRAME_TYPE 0x00008000
795 #define KS_DESC_RX_ERROR_CRC 0x00010000
796 #define KS_DESC_RX_ERROR_RUNT 0x00020000
797 #define KS_DESC_RX_ERROR_TOO_LONG 0x00040000
798 #define KS_DESC_RX_ERROR_PHY 0x00080000
799 #define KS884X_DESC_RX_PORT_MASK 0x00300000
800 #define KS_DESC_RX_MULTICAST 0x01000000
801 #define KS_DESC_RX_ERROR 0x02000000
802 #define KS_DESC_RX_ERROR_CSUM_UDP 0x04000000
803 #define KS_DESC_RX_ERROR_CSUM_TCP 0x08000000
804 #define KS_DESC_RX_ERROR_CSUM_IP 0x10000000
805 #define KS_DESC_RX_LAST 0x20000000
806 #define KS_DESC_RX_FIRST 0x40000000
807 #define KS_DESC_RX_ERROR_COND \
808 (KS_DESC_RX_ERROR_CRC | \
809 KS_DESC_RX_ERROR_RUNT | \
810 KS_DESC_RX_ERROR_PHY | \
811 KS_DESC_RX_ERROR_TOO_LONG)
813 #define KS_DESC_HW_OWNED 0x80000000
815 #define KS_DESC_BUF_SIZE 0x000007FF
816 #define KS884X_DESC_TX_PORT_MASK 0x00300000
817 #define KS_DESC_END_OF_RING 0x02000000
818 #define KS_DESC_TX_CSUM_GEN_UDP 0x04000000
819 #define KS_DESC_TX_CSUM_GEN_TCP 0x08000000
820 #define KS_DESC_TX_CSUM_GEN_IP 0x10000000
821 #define KS_DESC_TX_LAST 0x20000000
822 #define KS_DESC_TX_FIRST 0x40000000
823 #define KS_DESC_TX_INTERRUPT 0x80000000
825 #define KS_DESC_PORT_SHIFT 20
827 #define KS_DESC_RX_MASK (KS_DESC_BUF_SIZE)
829 #define KS_DESC_TX_MASK \
830 (KS_DESC_TX_INTERRUPT | \
833 KS_DESC_TX_CSUM_GEN_IP | \
834 KS_DESC_TX_CSUM_GEN_TCP | \
835 KS_DESC_TX_CSUM_GEN_UDP | \
839 #ifdef __BIG_ENDIAN_BITFIELD
877 #ifdef __BIG_ENDIAN_BITFIELD
887 #ifdef __BIG_ENDIAN_BITFIELD
901 #ifdef __BIG_ENDIAN_BITFIELD
992 #define DMA_BUFFER(desc) ((struct ksz_dma_buf *)(&(desc)->dma_buf))
1031 #define LEARNED_MAC_TABLE_ENTRIES 1024
1032 #define STATIC_MAC_TABLE_ENTRIES 8
1054 #define VLAN_TABLE_ENTRIES 16
1068 #define DIFFSERV_ENTRIES 64
1069 #define PRIO_802_1P_ENTRIES 8
1070 #define PRIO_QUEUES 4
1072 #define SWITCH_PORT_NUM 2
1073 #define TOTAL_PORT_NUM (SWITCH_PORT_NUM + 1)
1074 #define HOST_MASK (1 << SWITCH_PORT_NUM)
1078 #define OTHER_PORT 1
1079 #define HOST_PORT SWITCH_PORT_NUM
1081 #define PORT_COUNTER_NUM 0x20
1082 #define TOTAL_PORT_COUNTER_NUM (PORT_COUNTER_NUM + 2)
1084 #define MIB_COUNTER_RX_LO_PRIORITY 0x00
1085 #define MIB_COUNTER_RX_HI_PRIORITY 0x01
1086 #define MIB_COUNTER_RX_UNDERSIZE 0x02
1087 #define MIB_COUNTER_RX_FRAGMENT 0x03
1088 #define MIB_COUNTER_RX_OVERSIZE 0x04
1089 #define MIB_COUNTER_RX_JABBER 0x05
1090 #define MIB_COUNTER_RX_SYMBOL_ERR 0x06
1091 #define MIB_COUNTER_RX_CRC_ERR 0x07
1092 #define MIB_COUNTER_RX_ALIGNMENT_ERR 0x08
1093 #define MIB_COUNTER_RX_CTRL_8808 0x09
1094 #define MIB_COUNTER_RX_PAUSE 0x0A
1095 #define MIB_COUNTER_RX_BROADCAST 0x0B
1096 #define MIB_COUNTER_RX_MULTICAST 0x0C
1097 #define MIB_COUNTER_RX_UNICAST 0x0D
1098 #define MIB_COUNTER_RX_OCTET_64 0x0E
1099 #define MIB_COUNTER_RX_OCTET_65_127 0x0F
1100 #define MIB_COUNTER_RX_OCTET_128_255 0x10
1101 #define MIB_COUNTER_RX_OCTET_256_511 0x11
1102 #define MIB_COUNTER_RX_OCTET_512_1023 0x12
1103 #define MIB_COUNTER_RX_OCTET_1024_1522 0x13
1104 #define MIB_COUNTER_TX_LO_PRIORITY 0x14
1105 #define MIB_COUNTER_TX_HI_PRIORITY 0x15
1106 #define MIB_COUNTER_TX_LATE_COLLISION 0x16
1107 #define MIB_COUNTER_TX_PAUSE 0x17
1108 #define MIB_COUNTER_TX_BROADCAST 0x18
1109 #define MIB_COUNTER_TX_MULTICAST 0x19
1110 #define MIB_COUNTER_TX_UNICAST 0x1A
1111 #define MIB_COUNTER_TX_DEFERRED 0x1B
1112 #define MIB_COUNTER_TX_TOTAL_COLLISION 0x1C
1113 #define MIB_COUNTER_TX_EXCESS_COLLISION 0x1D
1114 #define MIB_COUNTER_TX_SINGLE_COLLISION 0x1E
1115 #define MIB_COUNTER_TX_MULTI_COLLISION 0x1F
1117 #define MIB_COUNTER_RX_DROPPED_PACKET 0x20
1118 #define MIB_COUNTER_TX_DROPPED_PACKET 0x21
1196 #define TX_RATE_UNIT 10000
1218 #define MAX_TX_HELD_SIZE 52000
1221 #define LINK_INT_WORKING (1 << 0)
1222 #define SMALL_PACKET_TX_BUG (1 << 1)
1223 #define HALF_DUPLEX_SIGNAL_BUG (1 << 2)
1224 #define RX_HUGE_FRAME (1 << 4)
1225 #define STP_SUPPORT (1 << 8)
1228 #define PAUSE_FLOW_CTRL (1 << 0)
1229 #define FAST_AGING (1 << 1)
1485 #define DRV_NAME "KSZ884X PCI"
1486 #define DEVICE_NAME "KSZ884x PCI"
1487 #define DRV_VERSION "1.0.0"
1488 #define DRV_RELDATE "Feb 8, 2010"
1493 static u8 DEFAULT_MAC_ADDRESS[] = { 0x00, 0x10, 0xA1, 0x88, 0x42, 0x01 };
1504 static inline void hw_dis_intr(
struct ksz_hw *
hw)
1517 static inline void hw_ena_intr(
struct ksz_hw *
hw)
1533 hw->
intr_set = read_intr & ~interrupt;
1535 hw_dis_intr_bit(hw, interrupt);
1600 status.
rx.hw_owned = 0;
1606 desc->
sw.ctrl.tx.hw_owned = 1;
1607 if (desc->
sw.buf_size != desc->
sw.buf.data) {
1608 desc->
sw.buf_size = desc->
sw.buf.data;
1628 static inline void set_rx_len(
struct ksz_desc *desc,
u32 len)
1630 desc->
sw.buf.rx.buf_size = len;
1648 static inline void set_tx_len(
struct ksz_desc *desc,
u32 len)
1650 desc->
sw.buf.tx.buf_size = len;
1655 #define TABLE_READ 0x10
1656 #define TABLE_SEL_SHIFT 2
1658 #define HW_DELAY(hw, reg) \
1661 dummy = readw(hw->io + reg); \
1681 interrupt = hw_block_intr(hw);
1687 hw_restore_intr(hw, interrupt);
1709 interrupt = hw_block_intr(hw);
1717 hw_restore_intr(hw, interrupt);
1735 u8 ports,
int override,
int valid,
int use_fid,
u8 fid)
1740 data_lo = ((
u32) mac_addr[2] << 24) |
1741 ((
u32) mac_addr[3] << 16) |
1742 ((
u32) mac_addr[4] << 8) | mac_addr[5];
1743 data_hi = ((
u32) mac_addr[0] << 8) | mac_addr[1];
1806 interrupt = hw_block_intr(hw);
1812 for (timeout = 100; timeout > 0; timeout--) {
1823 hw_restore_intr(hw, interrupt);
1835 static void port_r_mib_pkt(
struct ksz_hw *hw,
int port,
u32 *last,
u64 *cnt)
1845 interrupt = hw_block_intr(hw);
1847 ctrl_addr = (
u16) index;
1854 hw_restore_intr(hw, interrupt);
1883 static int port_r_cnt(
struct ksz_hw *hw,
int port)
1889 port_r_mib_cnt(hw, port, mib->
cnt_ptr,
1894 port_r_mib_pkt(hw, port, mib->
dropped,
1908 static void port_init_cnt(
struct ksz_hw *hw,
int port)
1915 port_r_mib_cnt(hw, port, mib->
cnt_ptr,
1920 port_r_mib_pkt(hw, port, mib->
dropped,
1950 return (data & bits) ==
bits;
1991 static int port_chk_shift(
struct ksz_hw *hw,
int port,
u32 addr,
int shift)
1998 return (data & bit) ==
bit;
2011 static void port_cfg_shift(
struct ksz_hw *hw,
int port,
u32 addr,
int shift,
2035 static void port_r8(
struct ksz_hw *hw,
int port,
int offset,
u8 *data)
2053 static void port_r16(
struct ksz_hw *hw,
int port,
int offset,
u16 *data)
2071 static void port_w16(
struct ksz_hw *hw,
int port,
int offset,
u16 data)
2091 static int sw_chk(
struct ksz_hw *hw,
u32 addr,
u16 bits)
2096 return (data & bits) ==
bits;
2108 static void sw_cfg(
struct ksz_hw *hw,
u32 addr,
u16 bits,
int set)
2122 static inline void port_cfg_broad_storm(
struct ksz_hw *hw,
int p,
int set)
2128 static inline int port_chk_broad_storm(
struct ksz_hw *hw,
int p)
2130 return port_chk(hw, p,
2135 #define BROADCAST_STORM_PROTECTION_RATE 10
2138 #define BROADCAST_STORM_VALUE 9969
2157 data |= ((value & 0x00FF) << 8) | ((value & 0xFF00) >> 8);
2178 *percent = (
u8) num;
2188 static void sw_dis_broad_storm(
struct ksz_hw *hw,
int port)
2190 port_cfg_broad_storm(hw, port, 0);
2200 static void sw_ena_broad_storm(
struct ksz_hw *hw,
int port)
2202 sw_cfg_broad_storm(hw, hw->
ksz_switch->broad_per);
2203 port_cfg_broad_storm(hw, port, 1);
2212 static void sw_init_broad_storm(
struct ksz_hw *hw)
2217 sw_cfg_broad_storm(hw, hw->
ksz_switch->broad_per);
2219 sw_dis_broad_storm(hw, port);
2236 sw_cfg_broad_storm(hw, percent);
2237 sw_get_broad_storm(hw, &percent);
2248 static void sw_dis_prio_rate(
struct ksz_hw *hw,
int port)
2263 static void sw_init_prio_rate(
struct ksz_hw *hw)
2274 sw_dis_prio_rate(hw, port);
2280 static inline void port_cfg_back_pressure(
struct ksz_hw *hw,
int p,
int set)
2286 static inline void port_cfg_force_flow_ctrl(
struct ksz_hw *hw,
int p,
int set)
2292 static inline int port_chk_back_pressure(
struct ksz_hw *hw,
int p)
2294 return port_chk(hw, p,
2298 static inline int port_chk_force_flow_ctrl(
struct ksz_hw *hw,
int p)
2300 return port_chk(hw, p,
2306 static inline void port_cfg_dis_learn(
struct ksz_hw *hw,
int p,
int set)
2312 static inline void port_cfg_rx(
struct ksz_hw *hw,
int p,
int set)
2318 static inline void port_cfg_tx(
struct ksz_hw *hw,
int p,
int set)
2324 static inline void sw_cfg_fast_aging(
struct ksz_hw *hw,
int set)
2329 static inline void sw_flush_dyn_mac_table(
struct ksz_hw *hw)
2332 sw_cfg_fast_aging(hw, 1);
2334 sw_cfg_fast_aging(hw, 0);
2340 static inline void port_cfg_ins_tag(
struct ksz_hw *hw,
int p,
int insert)
2346 static inline void port_cfg_rmv_tag(
struct ksz_hw *hw,
int p,
int remove)
2352 static inline int port_chk_ins_tag(
struct ksz_hw *hw,
int p)
2354 return port_chk(hw, p,
2358 static inline int port_chk_rmv_tag(
struct ksz_hw *hw,
int p)
2360 return port_chk(hw, p,
2364 static inline void port_cfg_dis_non_vid(
struct ksz_hw *hw,
int p,
int set)
2370 static inline void port_cfg_in_filter(
struct ksz_hw *hw,
int p,
int set)
2376 static inline int port_chk_dis_non_vid(
struct ksz_hw *hw,
int p)
2378 return port_chk(hw, p,
2382 static inline int port_chk_in_filter(
struct ksz_hw *hw,
int p)
2384 return port_chk(hw, p,
2390 static inline void port_cfg_mirror_sniffer(
struct ksz_hw *hw,
int p,
int set)
2396 static inline void port_cfg_mirror_rx(
struct ksz_hw *hw,
int p,
int set)
2402 static inline void port_cfg_mirror_tx(
struct ksz_hw *hw,
int p,
int set)
2408 static inline void sw_cfg_mirror_rx_tx(
struct ksz_hw *hw,
int set)
2413 static void sw_init_mirror(
struct ksz_hw *hw)
2418 port_cfg_mirror_sniffer(hw, port, 0);
2419 port_cfg_mirror_rx(hw, port, 0);
2420 port_cfg_mirror_tx(hw, port, 0);
2422 sw_cfg_mirror_rx_tx(hw, 0);
2425 static inline void sw_cfg_unk_def_deliver(
struct ksz_hw *hw,
int set)
2431 static inline int sw_cfg_chk_unk_def_deliver(
struct ksz_hw *hw)
2437 static inline void sw_cfg_unk_def_port(
struct ksz_hw *hw,
int port,
int set)
2442 static inline int sw_chk_unk_def_port(
struct ksz_hw *hw,
int port)
2449 static inline void port_cfg_diffserv(
struct ksz_hw *hw,
int p,
int set)
2455 static inline void port_cfg_802_1p(
struct ksz_hw *hw,
int p,
int set)
2461 static inline void port_cfg_replace_vid(
struct ksz_hw *hw,
int p,
int set)
2467 static inline void port_cfg_prio(
struct ksz_hw *hw,
int p,
int set)
2473 static inline int port_chk_diffserv(
struct ksz_hw *hw,
int p)
2475 return port_chk(hw, p,
2479 static inline int port_chk_802_1p(
struct ksz_hw *hw,
int p)
2481 return port_chk(hw, p,
2485 static inline int port_chk_replace_vid(
struct ksz_hw *hw,
int p)
2487 return port_chk(hw, p,
2491 static inline int port_chk_prio(
struct ksz_hw *hw,
int p)
2493 return port_chk(hw, p,
2504 static void sw_dis_diffserv(
struct ksz_hw *hw,
int port)
2506 port_cfg_diffserv(hw, port, 0);
2516 static void sw_dis_802_1p(
struct ksz_hw *hw,
int port)
2518 port_cfg_802_1p(hw, port, 0);
2527 static void sw_cfg_replace_null_vid(
struct ksz_hw *hw,
int set)
2543 static void sw_cfg_replace_vid(
struct ksz_hw *hw,
int port,
int set)
2545 port_cfg_replace_vid(hw, port,
set);
2556 static void sw_cfg_port_based(
struct ksz_hw *hw,
int port,
u8 prio)
2579 static void sw_dis_multi_queue(
struct ksz_hw *hw,
int port)
2581 port_cfg_prio(hw, port, 0);
2590 static void sw_init_prio(
struct ksz_hw *hw)
2618 sw_dis_multi_queue(hw, port);
2619 sw_dis_diffserv(hw, port);
2620 sw_dis_802_1p(hw, port);
2621 sw_cfg_replace_vid(hw, port, 0);
2624 sw_cfg_port_based(hw, port, sw->
port_cfg[port].port_prio);
2626 sw_cfg_replace_null_vid(hw, 0);
2637 static void port_get_def_vid(
struct ksz_hw *hw,
int port,
u16 *vid)
2652 static void sw_init_vlan(
struct ksz_hw *hw)
2660 sw_r_vlan_table(hw, entry,
2667 port_get_def_vid(hw, port, &sw->
port_cfg[port].vid);
2680 static void sw_cfg_port_base_vlan(
struct ksz_hw *hw,
int port,
u8 member)
2703 static inline void sw_get_addr(
struct ksz_hw *hw,
u8 *mac_addr)
2707 for (i = 0; i < 6; i += 2) {
2720 static void sw_set_addr(
struct ksz_hw *hw,
u8 *mac_addr)
2724 for (i = 0; i < 6; i += 2) {
2736 static void sw_set_global_ctrl(
struct ksz_hw *hw)
2784 static void port_set_stp_state(
struct ksz_hw *hw,
int port,
int state)
2830 #define BROADCAST_ENTRY 1
2831 #define BRIDGE_ADDR_ENTRY 2
2832 #define IPV6_ADDR_ENTRY 3
2840 static void sw_clr_sta_mac_table(
struct ksz_hw *hw)
2847 sw_w_sta_mac_table(hw, i,
2860 static void sw_init_stp(
struct ksz_hw *hw)
2886 static void sw_block_addr(
struct ksz_hw *hw)
2894 sw_w_sta_mac_table(hw, i,
2901 #define PHY_LINK_SUPPORT \
2902 (PHY_AUTO_NEG_ASYM_PAUSE | \
2903 PHY_AUTO_NEG_SYM_PAUSE | \
2904 PHY_AUTO_NEG_100BT4 | \
2905 PHY_AUTO_NEG_100BTX_FD | \
2906 PHY_AUTO_NEG_100BTX | \
2907 PHY_AUTO_NEG_10BT_FD | \
2910 static inline void hw_r_phy_ctrl(
struct ksz_hw *hw,
int phy,
u16 *data)
2915 static inline void hw_w_phy_ctrl(
struct ksz_hw *hw,
int phy,
u16 data)
2920 static inline void hw_r_phy_link_stat(
struct ksz_hw *hw,
int phy,
u16 *data)
2925 static inline void hw_r_phy_auto_neg(
struct ksz_hw *hw,
int phy,
u16 *data)
2930 static inline void hw_w_phy_auto_neg(
struct ksz_hw *hw,
int phy,
u16 data)
2935 static inline void hw_r_phy_rem_cap(
struct ksz_hw *hw,
int phy,
u16 *data)
2940 static inline void hw_r_phy_crossover(
struct ksz_hw *hw,
int phy,
u16 *data)
2945 static inline void hw_w_phy_crossover(
struct ksz_hw *hw,
int phy,
u16 data)
2950 static inline void hw_r_phy_polarity(
struct ksz_hw *hw,
int phy,
u16 *data)
2955 static inline void hw_w_phy_polarity(
struct ksz_hw *hw,
int phy,
u16 data)
2960 static inline void hw_r_phy_link_md(
struct ksz_hw *hw,
int phy,
u16 *data)
2965 static inline void hw_w_phy_link_md(
struct ksz_hw *hw,
int phy,
u16 data)
3008 #define AT93C_CODE 0
3009 #define AT93C_WR_OFF 0x00
3010 #define AT93C_WR_ALL 0x10
3011 #define AT93C_ER_ALL 0x20
3012 #define AT93C_WR_ON 0x30
3014 #define AT93C_WRITE 1
3015 #define AT93C_READ 2
3016 #define AT93C_ERASE 3
3018 #define EEPROM_DELAY 4
3020 static inline void drop_gpio(
struct ksz_hw *hw,
u8 gpio)
3029 static inline void raise_gpio(
struct ksz_hw *hw,
u8 gpio)
3043 return (
u8)(data &
gpio);
3046 static void eeprom_clk(
struct ksz_hw *hw)
3059 for (i = 15; i >= 0; i--) {
3071 static void spi_w(
struct ksz_hw *hw,
u16 data)
3075 for (i = 15; i >= 0; i--) {
3091 for (i = 1; i >= 0; i--) {
3098 for (i = 5; i >= 0; i--) {
3105 #define EEPROM_DATA_RESERVED 0
3106 #define EEPROM_DATA_MAC_ADDR_0 1
3107 #define EEPROM_DATA_MAC_ADDR_1 2
3108 #define EEPROM_DATA_MAC_ADDR_2 3
3109 #define EEPROM_DATA_SUBSYS_ID 4
3110 #define EEPROM_DATA_SUBSYS_VEN_ID 5
3111 #define EEPROM_DATA_PM_CAP 6
3114 #define EEPROM_DATA_OTHER_MAC_ADDR 9
3147 static void eeprom_write(
struct ksz_hw *hw,
u8 reg,
u16 data)
3218 static void set_flow_ctrl(
struct ksz_hw *hw,
int rx,
int tx)
3234 if (rx_cfg != hw->
rx_cfg)
3236 if (tx_cfg != hw->
tx_cfg)
3241 static void determine_flow_ctrl(
struct ksz_hw *hw,
struct ksz_port *port,
3254 if (local & PHY_AUTO_NEG_SYM_PAUSE) {
3258 PHY_AUTO_NEG_ASYM_PAUSE) {
3261 }
else if (remote & PHY_AUTO_NEG_ASYM_PAUSE) {
3266 set_flow_ctrl(hw, rx, tx);
3269 static inline void port_cfg_change(
struct ksz_hw *hw,
struct ksz_port *port,
3291 static void port_get_link_speed(
struct ksz_port *port)
3305 interrupt = hw_block_intr(hw);
3307 for (i = 0, p = port->
first_port; i < port->port_cnt; i++, p++) {
3345 determine_flow_ctrl(hw, port, data, status);
3347 port_cfg_back_pressure(hw, p,
3351 port_cfg_change(hw, port, info, status);
3369 hw_restore_intr(hw, interrupt);
3372 #define PHY_RESET_TIMEOUT 10
3380 static void port_set_link_speed(
struct ksz_port *port)
3390 for (i = 0, p = port->
first_port; i < port->port_cnt; i++, p++) {
3397 if (status & PORT_STATUS_LINK_GOOD)
3401 data = advertised_flow_ctrl(port, data);
3408 if (10 == port->
speed)
3411 else if (100 == port->
speed)
3417 else if (2 == port->
duplex)
3434 static void port_force_link_speed(
struct ksz_port *port)
3442 for (i = 0, p = port->
first_port; i < port->port_cnt; i++, p++) {
3444 hw_r_phy_ctrl(hw, phy, &data);
3448 if (10 == port->
speed)
3450 else if (100 == port->
speed)
3454 else if (2 == port->
duplex)
3456 hw_w_phy_ctrl(hw, phy, data);
3460 static void port_set_power_saving(
struct ksz_port *port,
int enable)
3466 for (i = 0, p = port->
first_port; i < port->port_cnt; i++, p++)
3483 static int hw_chk_wol_pme_status(
struct ksz_hw *hw)
3501 static void hw_clr_wol_pme_status(
struct ksz_hw *hw)
3523 static void hw_cfg_wol_pme(
struct ksz_hw *hw,
int set)
3571 static void hw_set_wol_frame(
struct ksz_hw *hw,
int i,
uint mask_size,
3582 if (frame_size > mask_size * 8)
3583 frame_size = mask_size * 8;
3584 if (frame_size > 64)
3591 bits = len = from = to = 0;
3595 data[to++] = pattern[
from];
3609 }
while (from < (
int) frame_size);
3611 bits = mask[len - 1];
3630 static const u8 mask[6] = { 0x3F, 0xF0, 0x3F, 0x00, 0xC0, 0x03 };
3632 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
3633 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3635 0x00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00, 0x01,
3636 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3637 0x00, 0x00, 0x00, 0x00,
3638 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3639 0x00, 0x00, 0x00, 0x00 };
3641 memcpy(&pattern[38], ip_addr, 4);
3642 hw_set_wol_frame(hw, 3, 6, mask, 42, pattern);
3651 static void hw_add_wol_bcast(
struct ksz_hw *hw)
3653 static const u8 mask[] = { 0x3F };
3654 static const u8 pattern[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
3656 hw_set_wol_frame(hw, 2, 1, mask,
ETH_ALEN, pattern);
3669 static void hw_add_wol_mcast(
struct ksz_hw *hw)
3671 static const u8 mask[] = { 0x3F };
3672 u8 pattern[] = { 0x33, 0x33, 0xFF, 0x00, 0x00, 0x00 };
3675 hw_set_wol_frame(hw, 1, 1, mask, 6, pattern);
3687 static void hw_add_wol_ucast(
struct ksz_hw *hw)
3689 static const u8 mask[] = { 0x3F };
3702 static void hw_enable_wol(
struct ksz_hw *hw,
u32 wol_enable,
const u8 *net_addr)
3706 hw_add_wol_ucast(hw);
3708 hw_add_wol_mcast(hw);
3711 hw_add_wol_arp(hw, net_addr);
3723 static int hw_init(
struct ksz_hw *hw)
3745 if (revision <= 1) {
3759 static void hw_reset(
struct ksz_hw *hw)
3776 static void hw_setup(
struct ksz_hw *hw)
3812 static void hw_setup_intr(
struct ksz_hw *hw)
3819 #define MIN_DESC_SHIFT 2
3821 int alloc = info->
alloc;
3825 while (!(alloc & 1)) {
3829 if (alloc != 1 || shift < MIN_DESC_SHIFT) {
3830 pr_alert(
"Hardware descriptor numbers not right!\n");
3835 if (shift < MIN_DESC_SHIFT)
3838 info->
alloc = alloc;
3843 static void hw_init_desc(
struct ksz_desc_info *desc_info,
int transmit)
3851 for (i = 0; i < desc_info->
alloc; i++) {
3853 phys += desc_info->
size;
3858 previous->
sw.buf.rx.end_of_ring = 1;
3862 desc_info->
last = desc_info->
next = 0;
3864 desc_info->
cur = desc_info->
ring;
3875 static void hw_set_desc_base(
struct ksz_hw *hw,
u32 tx_addr,
u32 rx_addr)
3889 static inline void hw_resume_rx(
struct ksz_hw *hw)
3900 static void hw_start_rx(
struct ksz_hw *hw)
3922 static void hw_stop_rx(
struct ksz_hw *hw)
3935 static void hw_start_tx(
struct ksz_hw *hw)
3946 static void hw_stop_tx(
struct ksz_hw *hw)
3957 static void hw_disable(
struct ksz_hw *hw)
3970 static void hw_enable(
struct ksz_hw *hw)
3987 static int hw_alloc_pkt(
struct ksz_hw *hw,
int length,
int physical)
4017 static void hw_send_pkt(
struct ksz_hw *hw)
4021 cur->
sw.buf.tx.last_seg = 1;
4025 cur->
sw.buf.tx.intr = 1;
4038 static int empty_addr(
u8 *addr)
4043 return 0 == *addr1 && 0 == *
addr2;
4053 static void hw_set_addr(
struct ksz_hw *hw)
4070 static void hw_read_addr(
struct ksz_hw *hw)
4090 static void hw_ena_add_addr(
struct ksz_hw *hw,
int index,
u8 *mac_addr)
4097 for (i = 0; i < 2; i++) {
4099 mac_addr_hi |= mac_addr[
i];
4103 for (i = 2; i < 6; i++) {
4105 mac_addr_lo |= mac_addr[
i];
4113 static void hw_set_add_addr(
struct ksz_hw *hw)
4118 if (empty_addr(hw->
address[i]))
4122 hw_ena_add_addr(hw, i, hw->
address[i]);
4126 static int hw_add_addr(
struct ksz_hw *hw,
u8 *mac_addr)
4136 if (ADDITIONAL_ENTRIES == j && empty_addr(hw->
address[i]))
4139 if (j < ADDITIONAL_ENTRIES) {
4141 hw_ena_add_addr(hw, j, hw->
address[j]);
4147 static int hw_del_addr(
struct ksz_hw *hw,
u8 *mac_addr)
4168 static void hw_clr_multicast(
struct ksz_hw *hw)
4186 static void hw_set_grp_addr(
struct ksz_hw *hw)
4197 index = position >> 3;
4198 value = 1 << (position & 7);
4214 static void hw_set_multicast(
struct ksz_hw *hw,
u8 multicast)
4235 static void hw_set_promiscuous(
struct ksz_hw *hw,
u8 prom)
4256 static void sw_enable(
struct ksz_hw *hw,
int enable)
4263 sw_cfg_port_base_vlan(hw, port,
4267 sw_cfg_port_base_vlan(hw, port,
PORT_MASK);
4287 static void sw_setup(
struct ksz_hw *hw)
4291 sw_set_global_ctrl(hw);
4294 sw_init_broad_storm(hw);
4297 sw_ena_broad_storm(hw, port);
4303 sw_init_prio_rate(hw);
4347 void (*
function)(
unsigned long),
void *data)
4352 info->
timer.function =
function;
4353 info->
timer.data = (
unsigned long) data;
4359 if (info->
max > 0) {
4360 if (info->
cnt < info->
max) {
4365 }
else if (info->
max < 0) {
4381 static int ksz_alloc_soft_desc(
struct ksz_desc_info *desc_info,
int transmit)
4385 if (!desc_info->
ring)
4387 hw_init_desc(desc_info, transmit);
4454 pci_unmap_single(adapter->
pdev, dma_buf->
dma, dma_buf->
len, direction);
4455 dev_kfree_skb(dma_buf->
skb);
4466 static void ksz_init_rx_buffers(
struct dev_info *adapter)
4475 get_rx_pkt(info, &desc);
4478 if (dma_buf->
skb && dma_buf->
len != adapter->
mtu)
4480 dma_buf->
len = adapter->
mtu;
4483 if (dma_buf->
skb && !dma_buf->
dma)
4484 dma_buf->
dma = pci_map_single(
4486 skb_tail_pointer(dma_buf->
skb),
4491 set_rx_buf(desc, dma_buf->
dma);
4492 set_rx_len(desc, dma_buf->
len);
4506 static int ksz_alloc_mem(
struct dev_info *adapter)
4536 pr_alert(
"Hardware descriptor size not right!\n");
4541 if (ksz_alloc_desc(adapter))
4554 static void ksz_free_desc(
struct dev_info *adapter)
4589 static void ksz_free_buffers(
struct dev_info *adapter,
4596 for (i = 0; i < desc_info->
alloc; i++) {
4599 free_dma_buf(adapter, dma_buf, direction);
4610 static void ksz_free_mem(
struct dev_info *adapter)
4613 ksz_free_buffers(adapter, &adapter->
hw.tx_desc_info,
4617 ksz_free_buffers(adapter, &adapter->
hw.rx_desc_info,
4621 ksz_free_desc(adapter);
4624 static void get_mib_counters(
struct ksz_hw *hw,
int first,
int cnt,
4633 for (i = 0, port = first; i <
cnt; i++, port++) {
4635 for (mib = port_mib->
mib_start; mib < hw->mib_cnt; mib++)
4636 counter[mib] += port_mib->
counter[mib];
4657 int last_frag = skb_shinfo(skb)->nr_frags;
4678 dma_buf->
len = skb_headlen(skb);
4680 dma_buf->
dma = pci_map_single(
4683 set_tx_buf(desc, dma_buf->
dma);
4684 set_tx_len(desc, dma_buf->
len);
4688 this_frag = &skb_shinfo(skb)->frags[
frag];
4691 get_tx_pkt(info, &desc);
4697 dma_buf->
len = skb_frag_size(this_frag);
4699 dma_buf->
dma = pci_map_single(
4701 skb_frag_address(this_frag),
4704 set_tx_buf(desc, dma_buf->
dma);
4705 set_tx_len(desc, dma_buf->
len);
4708 if (frag == last_frag)
4719 release_desc(first);
4723 dma_buf->
dma = pci_map_single(
4726 set_tx_buf(desc, dma_buf->
dma);
4727 set_tx_len(desc, dma_buf->
len);
4731 (desc)->sw.buf.tx.csum_gen_tcp = 1;
4732 (desc)->sw.buf.tx.csum_gen_udp = 1;
4744 dev->
stats.tx_packets++;
4754 static void transmit_cleanup(
struct dev_info *hw_priv,
int normal)
4764 spin_lock(&hw_priv->
hwlock);
4769 desc = &info->
ring[last];
4771 if (status.tx.hw_owned) {
4775 reset_desc(desc, status);
4785 dev = dma_buf->
skb->dev;
4798 spin_unlock(&hw_priv->
hwlock);
4817 transmit_cleanup(hw_priv, 1);
4819 for (port = 0; port < hw->
dev_count; port++) {
4822 if (netif_running(dev) && netif_queue_stopped(dev))
4823 netif_wake_queue(dev);
4827 static inline void copy_old_skb(
struct sk_buff *old,
struct sk_buff *skb)
4833 skb_set_network_header(skb,
ETH_HLEN);
4849 struct dev_priv *priv = netdev_priv(dev);
4859 if (skb->
len <= 48) {
4860 if (skb_end_pointer(skb) - skb->
data >= 50) {
4864 skb = netdev_alloc_skb(dev, 50);
4871 copy_old_skb(org_skb, skb);
4876 spin_lock_irq(&hw_priv->
hwlock);
4878 num = skb_shinfo(skb)->nr_frags + 1;
4879 left = hw_alloc_pkt(hw, skb->
len, num);
4886 skb = netdev_alloc_skb(dev, org_skb->
len);
4894 copy_old_skb(org_skb, skb);
4898 netif_stop_queue(dev);
4901 netif_stop_queue(dev);
4905 spin_unlock_irq(&hw_priv->
hwlock);
4919 static void netdev_tx_timeout(
struct net_device *dev)
4921 static unsigned long last_reset;
4923 struct dev_priv *priv = netdev_priv(dev);
4933 if (jiffies - last_reset <= dev->watchdog_timeo)
4942 transmit_cleanup(hw_priv, 0);
4945 ksz_init_rx_buffers(hw_priv);
4949 hw_set_desc_base(hw,
4956 hw_set_grp_addr(hw);
4959 hw_set_add_addr(hw);
4963 port_set_stp_state(hw, port,
4967 if (netif_running(port_dev))
4968 port_set_stp_state(hw, port,
4978 netif_wake_queue(dev);
4981 static inline void csum_verified(
struct sk_buff *skb)
4987 skb_reset_network_header(skb);
4988 iph = (
struct iphdr *) skb_network_header(skb);
4992 iph = (
struct iphdr *) skb_network_header(skb);
5004 struct dev_priv *priv = netdev_priv(dev);
5011 packet_len = status.
rx.frame_len - 4;
5014 pci_dma_sync_single_for_cpu(
5015 hw_priv->
pdev, dma_buf->
dma, packet_len + 4,
5020 skb = netdev_alloc_skb(dev, packet_len + 2);
5022 dev->
stats.rx_dropped++;
5030 skb_reserve(skb, 2);
5033 dma_buf->
skb->data, packet_len);
5042 dev->
stats.rx_packets++;
5043 dev->
stats.rx_bytes += packet_len;
5051 static int dev_rcv_packets(
struct dev_info *hw_priv)
5058 int left = info->
alloc;
5067 if (status.
rx.hw_owned)
5071 if (status.
rx.last_desc && status.
rx.first_desc) {
5072 if (rx_proc(dev, hw, desc, status))
5073 goto release_packet;
5094 int left = info->
alloc;
5103 if (status.
rx.hw_owned)
5111 if (!netif_running(dev))
5112 goto release_packet;
5116 if (status.
rx.last_desc && status.
rx.first_desc) {
5117 if (rx_proc(dev, hw, desc, status))
5118 goto release_packet;
5132 static int dev_rcv_special(
struct dev_info *hw_priv)
5139 int left = info->
alloc;
5148 if (status.
rx.hw_owned)
5156 if (!netif_running(dev))
5157 goto release_packet;
5161 if (status.
rx.last_desc && status.
rx.first_desc) {
5167 if (!status.
rx.error || (status.
data &
5170 if (rx_proc(dev, hw, desc, status))
5171 goto release_packet;
5174 struct dev_priv *priv = netdev_priv(dev);
5191 static void rx_proc_task(
unsigned long data)
5204 spin_lock_irq(&hw_priv->
hwlock);
5206 spin_unlock_irq(&hw_priv->
hwlock);
5213 static void tx_proc_task(
unsigned long data)
5223 spin_lock_irq(&hw_priv->
hwlock);
5225 spin_unlock_irq(&hw_priv->
hwlock);
5228 static inline void handle_rx_stop(
struct ksz_hw *hw)
5258 struct dev_priv *priv = netdev_priv(dev);
5262 hw_read_intr(hw, &int_enable);
5269 hw_ack_intr(hw, int_enable);
5273 hw_dis_intr_bit(hw, KS884X_INT_TX_MASK);
5278 hw_dis_intr_bit(hw, KS884X_INT_RX);
5283 dev->
stats.rx_fifo_errors++;
5291 port_get_link_speed(port);
5302 hw->
intr_mask &= ~KS884X_INT_TX_STOPPED;
5320 static unsigned long next_jiffies;
5322 #ifdef CONFIG_NET_POLL_CONTROLLER
5323 static void netdev_netpoll(
struct net_device *dev)
5325 struct dev_priv *priv = netdev_priv(dev);
5328 hw_dis_intr(&hw_priv->
hw);
5329 netdev_intr(dev->
irq, dev);
5333 static void bridge_change(
struct ksz_hw *hw)
5349 if (member != sw->
port_cfg[port].member)
5350 sw_cfg_port_base_vlan(hw, port, member);
5363 static int netdev_close(
struct net_device *dev)
5365 struct dev_priv *priv = netdev_priv(dev);
5371 netif_stop_queue(dev);
5391 port_set_power_saving(port,
true);
5399 if (!(hw_priv->
opened)) {
5405 hw_clr_multicast(hw);
5414 transmit_cleanup(hw_priv, 0);
5420 sw_clr_sta_mac_table(hw);
5426 static void hw_cfg_huge_frame(
struct dev_info *hw_priv,
struct ksz_hw *hw)
5440 hw_priv->
dev_rcv = dev_rcv_special;
5446 hw_priv->
dev_rcv = dev_rcv_packets;
5450 static int prepare_hardware(
struct net_device *dev)
5452 struct dev_priv *priv = netdev_priv(dev);
5463 (
unsigned long) hw_priv);
5465 (
unsigned long) hw_priv);
5473 hw_set_desc_base(hw,
5476 hw_cfg_huge_frame(hw_priv, hw);
5477 ksz_init_rx_buffers(hw_priv);
5481 static void set_media_state(
struct net_device *dev,
int media_state)
5483 struct dev_priv *priv = netdev_priv(dev);
5502 static int netdev_open(
struct net_device *dev)
5504 struct dev_priv *priv = netdev_priv(dev);
5520 if (!(hw_priv->
opened)) {
5521 rc = prepare_hardware(dev);
5525 if (next_jiffies < jiffies)
5528 next_jiffies += HZ * 1;
5529 hw_priv->
counter[
i].time = next_jiffies;
5531 port_init_cnt(hw, i);
5536 hw_add_wol_bcast(hw);
5537 hw_cfg_wol_pme(hw, 0);
5538 hw_clr_wol_pme_status(&hw_priv->
hw);
5541 port_set_power_saving(port,
false);
5559 port_get_link_speed(port);
5561 port_force_link_speed(port);
5563 port_set_link_speed(port);
5565 if (!(hw_priv->
opened)) {
5583 netif_start_queue(dev);
5609 struct dev_priv *priv = netdev_priv(dev);
5620 dev->
stats.multicast = 0;
5621 dev->
stats.collisions = 0;
5622 dev->
stats.rx_length_errors = 0;
5623 dev->
stats.rx_crc_errors = 0;
5624 dev->
stats.rx_frame_errors = 0;
5625 dev->
stats.tx_window_errors = 0;
5627 for (i = 0, p = port->
first_port; i < port->mib_port_cnt; i++, p++) {
5633 dev->
stats.collisions += (
unsigned long)
5636 dev->
stats.rx_length_errors += (
unsigned long)(
5641 dev->
stats.rx_crc_errors += (
unsigned long)
5643 dev->
stats.rx_frame_errors += (
unsigned long)(
5647 dev->
stats.tx_window_errors += (
unsigned long)
5663 static int netdev_set_mac_address(
struct net_device *dev,
void *addr)
5665 struct dev_priv *priv = netdev_priv(dev);
5671 if (priv->
port.first_port > 0)
5680 interrupt = hw_block_intr(hw);
5682 if (priv->
port.first_port > 0)
5686 hw_restore_intr(hw, interrupt);
5692 struct ksz_hw *hw,
int promiscuous)
5714 int port = priv->
port.first_port;
5726 static void dev_set_multicast(
struct dev_priv *priv,
struct ksz_hw *hw,
5739 if (hw->
all_multi <= 1 && all_multi <= 1)
5751 static void netdev_set_rx_mode(
struct net_device *dev)
5753 struct dev_priv *priv = netdev_priv(dev);
5761 if (hw_priv->
hw.dev_count > 1)
5763 dev_set_multicast(priv, hw, multicast);
5766 if (hw_priv->
hw.dev_count > 1)
5788 hw_set_grp_addr(hw);
5795 hw_clr_multicast(hw);
5799 static int netdev_change_mtu(
struct net_device *dev,
int new_mtu)
5801 struct dev_priv *priv = netdev_priv(dev);
5806 if (netif_running(dev))
5811 if (dev != hw_priv->
dev)
5816 if (dev->
mtu != new_mtu) {
5827 hw_mtu = (hw_mtu + 3) & ~3;
5828 hw_priv->
mtu = hw_mtu;
5846 struct dev_priv *priv = netdev_priv(dev);
5911 struct dev_priv *priv = netdev_priv(dev);
5916 hw_r_phy(hw, port->
linked->port_id, reg_num << 1, &val_out);
5929 static void mdio_write(
struct net_device *dev,
int phy_id,
int reg_num,
int val)
5931 struct dev_priv *priv = netdev_priv(dev);
5937 for (i = 0, pi = port->
first_port; i < port->port_cnt; i++, pi++)
5938 hw_w_phy(hw, pi, reg_num << 1, val);
5945 #define EEPROM_SIZE 0x40
5949 #define ADVERTISED_ALL \
5950 (ADVERTISED_10baseT_Half | \
5951 ADVERTISED_10baseT_Full | \
5952 ADVERTISED_100baseT_Half | \
5953 ADVERTISED_100baseT_Full)
5968 struct dev_priv *priv = netdev_priv(dev);
5992 struct dev_priv *priv = netdev_priv(dev);
5995 u32 speed = ethtool_cmd_speed(cmd);
6008 else if (100 == speed)
6016 else if (1 == cmd->
duplex)
6050 static int netdev_nway_reset(
struct net_device *dev)
6052 struct dev_priv *priv = netdev_priv(dev);
6072 struct dev_priv *priv = netdev_priv(dev);
6086 static void netdev_get_drvinfo(
struct net_device *dev,
6089 struct dev_priv *priv = netdev_priv(dev);
6106 static struct hw_regs {
6109 } hw_regs_range[] = {
6119 static int netdev_get_regs_len(
struct net_device *dev)
6121 struct hw_regs *
range = hw_regs_range;
6122 int regs_len = 0x10 *
sizeof(
u32);
6124 while (range->end > range->start) {
6125 regs_len += (range->end - range->start + 3) / 4 * 4;
6142 struct dev_priv *priv = netdev_priv(dev);
6145 int *
buf = (
int *) ptr;
6146 struct hw_regs *range = hw_regs_range;
6151 for (len = 0; len < 0x40; len += 4) {
6152 pci_read_config_dword(hw_priv->
pdev, len, buf);
6155 while (range->end > range->start) {
6156 for (len = range->start; len < range->
end; len += 4) {
6165 #define WOL_SUPPORT \
6166 (WAKE_PHY | WAKE_MAGIC | \
6167 WAKE_UCAST | WAKE_MCAST | \
6168 WAKE_BCAST | WAKE_ARP)
6177 static void netdev_get_wol(
struct net_device *dev,
6180 struct dev_priv *priv = netdev_priv(dev);
6197 static int netdev_set_wol(
struct net_device *dev,
6200 struct dev_priv *priv = netdev_priv(dev);
6204 static const u8 net_addr[] = { 192, 168, 1, 1 };
6214 hw_enable_wol(&hw_priv->
hw, hw_priv->
wol_enable, net_addr);
6228 struct dev_priv *priv = netdev_priv(dev);
6240 static void netdev_set_msglevel(
struct net_device *dev,
u32 value)
6242 struct dev_priv *priv = netdev_priv(dev);
6255 static int netdev_get_eeprom_len(
struct net_device *dev)
6270 #define EEPROM_MAGIC 0x10A18842
6272 static int netdev_get_eeprom(
struct net_device *dev,
6275 struct dev_priv *priv = netdev_priv(dev);
6277 u8 *eeprom_byte = (
u8 *) eeprom_data;
6281 len = (eeprom->
offset + eeprom->
len + 1) / 2;
6282 for (i = eeprom->
offset / 2; i < len; i++)
6283 eeprom_data[
i] = eeprom_read(&hw_priv->
hw, i);
6300 static int netdev_set_eeprom(
struct net_device *dev,
6303 struct dev_priv *priv = netdev_priv(dev);
6306 u8 *eeprom_byte = (
u8 *) eeprom_word;
6313 len = (eeprom->
offset + eeprom->
len + 1) / 2;
6314 for (i = eeprom->
offset / 2; i < len; i++)
6315 eeprom_data[
i] = eeprom_read(&hw_priv->
hw, i);
6319 if (eeprom_word[i] != eeprom_data[i]) {
6320 eeprom_data[
i] = eeprom_word[
i];
6321 eeprom_write(&hw_priv->
hw, i, eeprom_data[i]);
6334 static void netdev_get_pauseparam(
struct net_device *dev,
6337 struct dev_priv *priv = netdev_priv(dev);
6367 static int netdev_set_pauseparam(
struct net_device *dev,
6370 struct dev_priv *priv = netdev_priv(dev);
6389 port_set_link_speed(port);
6412 static void netdev_get_ringparam(
struct net_device *dev,
6415 struct dev_priv *priv = netdev_priv(dev);
6425 #define STATS_LEN (TOTAL_PORT_COUNTER_NUM)
6430 {
"rx_lo_priority_octets" },
6431 {
"rx_hi_priority_octets" },
6432 {
"rx_undersize_packets" },
6434 {
"rx_oversize_packets" },
6436 {
"rx_symbol_errors" },
6437 {
"rx_crc_errors" },
6438 {
"rx_align_errors" },
6439 {
"rx_mac_ctrl_packets" },
6440 {
"rx_pause_packets" },
6441 {
"rx_bcast_packets" },
6442 {
"rx_mcast_packets" },
6443 {
"rx_ucast_packets" },
6444 {
"rx_64_or_less_octet_packets" },
6445 {
"rx_65_to_127_octet_packets" },
6446 {
"rx_128_to_255_octet_packets" },
6447 {
"rx_256_to_511_octet_packets" },
6448 {
"rx_512_to_1023_octet_packets" },
6449 {
"rx_1024_to_1522_octet_packets" },
6451 {
"tx_lo_priority_octets" },
6452 {
"tx_hi_priority_octets" },
6453 {
"tx_late_collisions" },
6454 {
"tx_pause_packets" },
6455 {
"tx_bcast_packets" },
6456 {
"tx_mcast_packets" },
6457 {
"tx_ucast_packets" },
6459 {
"tx_total_collisions" },
6460 {
"tx_excessive_collisions" },
6461 {
"tx_single_collisions" },
6462 {
"tx_mult_collisions" },
6476 static void netdev_get_strings(
struct net_device *dev,
u32 stringset,
u8 *buf)
6478 struct dev_priv *priv = netdev_priv(dev);
6483 memcpy(buf, ðtool_stats_keys,
6496 static int netdev_get_sset_count(
struct net_device *dev,
int sset)
6498 struct dev_priv *priv = netdev_priv(dev);
6518 static void netdev_get_ethtool_stats(
struct net_device *dev,
6521 struct dev_priv *priv = netdev_priv(dev);
6539 if (n == SWITCH_PORT_NUM)
6545 if (n < SWITCH_PORT_NUM)
6552 2 == hw_priv->
counter[p].read,
6559 2 == hw_priv->
counter[p].read,
6561 }
else if (hw->
port_mib[p].cnt_ptr) {
6564 2 == hw_priv->
counter[p].read,
6574 for (i = 0; i <
n; i++)
6575 *data++ = counter[i];
6587 static int netdev_set_features(
struct net_device *dev,
6590 struct dev_priv *priv = netdev_priv(dev);
6610 static const struct ethtool_ops netdev_ethtool_ops = {
6611 .get_settings = netdev_get_settings,
6612 .set_settings = netdev_set_settings,
6613 .nway_reset = netdev_nway_reset,
6614 .get_link = netdev_get_link,
6615 .get_drvinfo = netdev_get_drvinfo,
6616 .get_regs_len = netdev_get_regs_len,
6617 .get_regs = netdev_get_regs,
6618 .get_wol = netdev_get_wol,
6619 .set_wol = netdev_set_wol,
6620 .get_msglevel = netdev_get_msglevel,
6621 .set_msglevel = netdev_set_msglevel,
6622 .get_eeprom_len = netdev_get_eeprom_len,
6623 .get_eeprom = netdev_get_eeprom,
6624 .set_eeprom = netdev_set_eeprom,
6625 .get_pauseparam = netdev_get_pauseparam,
6626 .set_pauseparam = netdev_set_pauseparam,
6627 .get_ringparam = netdev_get_ringparam,
6628 .get_strings = netdev_get_strings,
6629 .get_sset_count = netdev_get_sset_count,
6630 .get_ethtool_stats = netdev_get_ethtool_stats,
6642 if (netif_running(dev))
6663 if (port_r_cnt(hw, i))
6671 &hw_priv->
counter[i].counter);
6673 }
else if (jiffies >= hw_priv->
counter[i].time) {
6678 hw_priv->
counter[
i].time = next_jiffies;
6690 static void mib_monitor(
unsigned long ptr)
6698 if (hw_priv->
pme_wait <= jiffies) {
6699 hw_clr_wol_pme_status(&hw_priv->
hw);
6702 }
else if (hw_chk_wol_pme_status(&hw_priv->
hw)) {
6717 static void dev_monitor(
unsigned long ptr)
6720 struct dev_priv *priv = netdev_priv(dev);
6726 port_get_link_speed(port);
6727 update_link(dev, priv, port);
6741 static char *mac1addr =
":";
6752 static int multi_dev;
6774 static int fast_aging;
6786 struct dev_priv *priv = netdev_priv(dev);
6807 priv->
mii_if.phy_id_mask = 0x1;
6808 priv->
mii_if.reg_num_mask = 0x7;
6810 priv->
mii_if.mdio_read = mdio_read;
6811 priv->
mii_if.mdio_write = mdio_write;
6812 priv->
mii_if.phy_id = priv->
port.first_port + 1;
6814 priv->
msg_enable = netif_msg_init(msg_enable,
6821 .ndo_init = netdev_init,
6822 .ndo_open = netdev_open,
6823 .ndo_stop = netdev_close,
6824 .ndo_get_stats = netdev_query_statistics,
6826 .ndo_tx_timeout = netdev_tx_timeout,
6827 .ndo_change_mtu = netdev_change_mtu,
6828 .ndo_set_features = netdev_set_features,
6829 .ndo_set_mac_address = netdev_set_mac_address,
6831 .ndo_do_ioctl = netdev_ioctl,
6832 .ndo_set_rx_mode = netdev_set_rx_mode,
6833 #ifdef CONFIG_NET_POLL_CONTROLLER
6834 .ndo_poll_controller = netdev_netpoll,
6838 static void netdev_free(
struct net_device *dev)
6851 static int net_device_present;
6853 static void get_mac_addr(
struct dev_info *hw_priv,
u8 *macaddr,
int port)
6860 i = j = num = got_num = 0;
6861 while (j < ETH_ALEN) {
6868 num = num * 16 + digit;
6869 else if (
':' == macaddr[i])
6879 hw_priv->
hw.override_addr[j++] = (
u8) num;
6880 hw_priv->
hw.override_addr[5] +=
6883 hw_priv->
hw.ksz_switch->other_addr[j++] =
6885 hw_priv->
hw.ksz_switch->other_addr[5] +=
6892 if (ETH_ALEN == j) {
6894 hw_priv->
hw.mac_override = 1;
6898 #define KS884X_DMA_MASK (~0x0UL)
6900 static void read_other_addr(
struct ksz_hw *hw)
6906 for (i = 0; i < 3; i++)
6908 if ((data[0] || data[1] || data[2]) && data[0] != 0xffff) {
6918 #ifndef PCI_VENDOR_ID_MICREL_KS
6919 #define PCI_VENDOR_ID_MICREL_KS 0x16c6
6931 unsigned long reg_base;
6932 unsigned long reg_len;
6965 goto pcidev_init_dev_err;
6968 hw_priv->
pdev = pdev;
6974 goto pcidev_init_io_err;
6981 goto pcidev_init_alloc_err;
6985 banner[13] = cnt +
'0';
7018 goto pcidev_init_alloc_err;
7030 if (ksz_alloc_mem(hw_priv))
7031 goto pcidev_init_mem_err;
7033 hw_priv->
hw.id = net_device_present;
7041 if (macaddr[0] !=
':')
7042 get_mac_addr(hw_priv, macaddr,
MAIN_PORT);
7050 read_other_addr(hw);
7051 if (mac1addr[0] !=
':')
7067 mib_monitor, hw_priv);
7070 dev = alloc_etherdev(
sizeof(
struct dev_priv));
7072 goto pcidev_init_reg_err;
7075 priv = netdev_priv(dev);
7077 priv->
id = net_device_present++;
7088 for (cnt = 0, pi = i; cnt <
port_count; cnt++, pi++) {
7110 goto pcidev_init_reg_err;
7111 port_set_power_saving(port,
true);
7115 pci_set_drvdata(pdev, info);
7118 pcidev_init_reg_err:
7121 netdev_free(info->
netdev[i]);
7126 pcidev_init_mem_err:
7127 ksz_free_mem(hw_priv);
7130 pcidev_init_alloc_err:
7136 pcidev_init_dev_err:
7142 static void pcidev_exit(
struct pci_dev *pdev)
7148 pci_set_drvdata(pdev,
NULL);
7152 for (i = 0; i < hw_priv->
hw.dev_count; i++) {
7154 netdev_free(info->
netdev[i]);
7158 ksz_free_mem(hw_priv);
7159 kfree(hw_priv->
hw.ksz_switch);
7165 static int pcidev_resume(
struct pci_dev *pdev)
7174 pci_enable_wake(pdev,
PCI_D0, 0);
7177 hw_cfg_wol_pme(hw, 0);
7182 if (netif_running(dev)) {
7199 static const u8 net_addr[] = { 192, 168, 1, 1 };
7205 if (netif_running(dev)) {
7212 hw_enable_wol(hw, hw_priv->
wol_enable, net_addr);
7213 hw_cfg_wol_pme(hw, 1);
7223 static char pcidev_name[] =
"ksz884xp";
7235 static struct pci_driver pci_device_driver = {
7237 .suspend = pcidev_suspend,
7238 .resume = pcidev_resume,
7240 .name = pcidev_name,
7241 .id_table = pcidev_table,
7242 .probe = pcidev_init,
7243 .remove = pcidev_exit
7246 static int __init ksz884x_init_module(
void)
7248 return pci_register_driver(&pci_device_driver);
7251 static void __exit ksz884x_cleanup_module(
void)