-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathax88179a_772d.c
2627 lines (2243 loc) · 63.4 KB
/
ax88179a_772d.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
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
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: GPL-2.0
/*******************************************************************************
* Copyright (c) 2022 ASIX Electronic Corporation All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
******************************************************************************/
#include "ax_main.h"
#include "ax88179a_772d.h"
#ifdef ENABLE_PTP_FUNC
#include "ax_ptp.h"
#endif
#ifdef ENABLE_MACSEC_FUNC
#include "ax_macsec.h"
#endif
struct _ax_buikin_setting AX88179A_BULKIN_SIZE[] = {
{5, 0x7B, 0x00, 0x18, 0x0F}, //1G, SS
{5, 0xC0, 0x02, 0x06, 0x0F}, //1G, HS
{7, 0xF0, 0x00, 0x0C, 0x0F}, //100M, Full, SS
{6, 0x00, 0x00, 0x06, 0x0F}, //100M, Half, SS
{5, 0xC0, 0x04, 0x06, 0x0F}, //100M, Full, HS
{7, 0xC0, 0x04, 0x06, 0x0F}, //100M, Half, HS
{7, 0x00, 0, 0x03, 0x3F}, //FS
};
#ifdef ENABLE_AX88279
struct _ax_buikin_setting AX88279_BULKIN_SIZE[] = {
{5, 0x10, 0x01, 0x11, 0x0F}, //2.5G
{7, 0xB3, 0x01, 0x11, 0x0F}, //1G, SS
{7, 0xC0, 0x02, 0x06, 0x0F}, //1G, HS
{7, 0x80, 0x01, 0x03, 0x0F}, //100M, Full, SS
{7, 0x80, 0x01, 0x03, 0x0F}, //100M, Half, SS
{7, 0x80, 0x01, 0x03, 0x0F}, //100M, Full, HS
{7, 0x80, 0x01, 0x03, 0x0F}, //100M, Half, HS
{7, 0x00, 0, 0x03, 0x3F}, //FS
};
#endif
static int ax88179a_set_phy_power(struct ax_device *axdev, bool on);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)
static int ax88179a_chk_eee(struct ax_device *axdev)
{
struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET };
mii_ethtool_gset(&axdev->mii, &ecmd);
if (ecmd.speed == SPEED_1000) {
int eee_lp, eee_cap, eee_adv;
u32 lp, cap, adv;
eee_cap = ax_mmd_read(axdev->netdev,
MDIO_MMD_PCS, MDIO_PCS_EEE_ABLE);
if (eee_cap < 0)
goto exit;
eee_cap &= ~MDIO_EEE_100TX;
cap = mmd_eee_cap_to_ethtool_sup_t(eee_cap);
if (!cap)
goto exit;
eee_lp = ax_mmd_read(axdev->netdev,
MDIO_MMD_AN, MDIO_AN_EEE_LPABLE);
if (eee_lp < 0)
goto exit;
eee_adv = ax_mmd_read(axdev->netdev,
MDIO_MMD_AN, MDIO_AN_EEE_ADV);
if (eee_adv < 0)
goto exit;
adv = mmd_eee_adv_to_ethtool_adv_t(eee_adv);
lp = mmd_eee_adv_to_ethtool_adv_t(eee_lp);
if (!(lp & adv & SUPPORTED_1000baseT_Full))
goto exit;
axdev->eee_active = 1;
return true;
}
exit:
axdev->eee_active = 0;
return false;
}
static int ax88179a_ethtool_get_eee(struct ax_device *axdev,
struct ethtool_eee *data)
{
int val;
val = ax_mmd_read(axdev->netdev, MDIO_MMD_PCS, MDIO_PCS_EEE_ABLE);
if (val < 0)
return val;
val &= ~MDIO_EEE_100TX;
data->supported = mmd_eee_cap_to_ethtool_sup_t(val);
val = ax_mmd_read(axdev->netdev, MDIO_MMD_AN, MDIO_AN_EEE_ADV);
if (val < 0)
return val;
data->advertised = mmd_eee_adv_to_ethtool_adv_t(val);
val = ax_mmd_read(axdev->netdev, MDIO_MMD_AN, MDIO_AN_EEE_LPABLE);
if (val < 0)
return val;
data->lp_advertised = mmd_eee_adv_to_ethtool_adv_t(val);
return 0;
}
static int ax88179a_get_eee(struct net_device *net, struct ethtool_eee *edata)
{
struct ax_device *axdev = netdev_priv(net);
edata->eee_enabled = axdev->eee_enabled;
edata->eee_active = axdev->eee_active;
return ax88179a_ethtool_get_eee(axdev, edata);
}
static void ax88179a_eee_setting(struct ax_device *axdev, bool enable)
{
ax_write_cmd(axdev, AX88179_GPHY_CTRL, AX_GPHY_EEE_CTRL,
enable, 0, NULL);
}
static int ax88179a_set_eee(struct net_device *net, struct ethtool_eee *edata)
{
struct ax_device *axdev = netdev_priv(net);
if (edata->advertised & MDIO_EEE_100TX)
return -EOPNOTSUPP;
axdev->eee_enabled = edata->eee_enabled;
ax88179a_eee_setting(axdev, axdev->eee_enabled);
if (axdev->eee_enabled) {
axdev->eee_enabled = ax88179a_chk_eee(axdev);
if (!axdev->eee_enabled) {
ax88179a_eee_setting(axdev, false);
return -EOPNOTSUPP;
}
}
mii_nway_restart(&axdev->mii);
return 0;
}
#endif
#if KERNEL_VERSION(5, 15, 0) <= LINUX_VERSION_CODE
static int ax88179a_get_coalesce(struct net_device *netdev,
struct ethtool_coalesce *coalesce,
struct kernel_ethtool_coalesce *kernel_coal,
struct netlink_ext_ack *extack)
#else
static int ax88179a_get_coalesce(struct net_device *netdev,
struct ethtool_coalesce *coalesce)
#endif
{
struct ax_device *axdev = netdev_priv(netdev);
coalesce->rx_coalesce_usecs = axdev->coalesce;
return 0;
}
static u16 ax88179a_usec_to_bin_timer(struct ax_device *axdev)
{
u16 speed_multiple;
switch (axdev->link_info.eth_speed) {
case ETHER_LINK_10:
speed_multiple = 100;
break;
case ETHER_LINK_100:
speed_multiple = 10;
break;
case ETHER_LINK_1000:
default:
speed_multiple = 1;
break;
};
return (axdev->coalesce * US_TO_NS * speed_multiple) /
AX88179A_BIN_TIMER_UINT;
}
static u32 ax88179a_bin_timer_to_usec(struct ax_device *axdev, u16 timer)
{
u16 speed_multiple;
switch (axdev->link_info.eth_speed) {
case ETHER_LINK_10:
speed_multiple = 100;
break;
case ETHER_LINK_100:
speed_multiple = 10;
break;
case ETHER_LINK_1000:
default:
speed_multiple = 1;
break;
};
return (AX88179A_BIN_TIMER_UINT * timer) / (US_TO_NS * speed_multiple);
}
#if KERNEL_VERSION(5, 15, 0) <= LINUX_VERSION_CODE
static int ax88179a_set_coalesce(struct net_device *netdev,
struct ethtool_coalesce *coalesce,
struct kernel_ethtool_coalesce *kernel_coal,
struct netlink_ext_ack *extack)
#else
static int ax88179a_set_coalesce(struct net_device *netdev,
struct ethtool_coalesce *coalesce)
#endif
{
struct ax_device *axdev = netdev_priv(netdev);
u16 timer;
int ret = 0;
ret = usb_autopm_get_interface(axdev->intf);
if (ret < 0)
return ret;
axdev->coalesce = coalesce->rx_coalesce_usecs;
timer = ax88179a_usec_to_bin_timer(axdev);
if (timer > 0) {
timer &= 0x7FFF;
ax_write_cmd(axdev, AX_ACCESS_MAC, AX_RX_BULKIN_QTIMR_LOW,
2, 2, &timer);
}
usb_autopm_put_interface(axdev->intf);
return ret;
}
#ifdef ENABLE_PTP_FUNC
static int ax88179a_set_wol_get_ts_info
(struct net_device *dev, struct ethtool_ts_info *info)
{
struct ax_device *axdev = (struct ax_device *)netdev_priv(dev);
struct ax_ptp_cfg *ptp_cfg = axdev->ptp_cfg;
info->so_timestamping =
SOF_TIMESTAMPING_TX_SOFTWARE |
SOF_TIMESTAMPING_RX_SOFTWARE |
SOF_TIMESTAMPING_SOFTWARE |
SOF_TIMESTAMPING_TX_HARDWARE |
SOF_TIMESTAMPING_RX_HARDWARE |
SOF_TIMESTAMPING_RAW_HARDWARE;
info->phc_index = ptp_cfg->phc_index;
info->tx_types = BIT(HWTSTAMP_TX_OFF) |
BIT(HWTSTAMP_TX_ON) |
BIT(HWTSTAMP_TX_ONESTEP_SYNC) |
BIT(HWTSTAMP_TX_ONESTEP_P2P);
info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
BIT(HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
BIT(HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
BIT(HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
BIT(HWTSTAMP_FILTER_PTP_V2_L2_EVENT) |
BIT(HWTSTAMP_FILTER_PTP_V2_L2_SYNC) |
BIT(HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ);
return 0;
}
#endif
const struct ethtool_ops ax88179a_ethtool_ops = {
#if KERNEL_VERSION(5, 7, 0) < LINUX_VERSION_CODE
.supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS,
#endif
.get_drvinfo = ax_get_drvinfo,
#if KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE
.get_settings = ax_get_settings,
.set_settings = ax_set_settings,
#else
.get_link_ksettings = ax_get_link_ksettings,
.set_link_ksettings = ax_set_link_ksettings,
#endif
.get_link = ethtool_op_get_link,
.get_msglevel = ax_get_msglevel,
.set_msglevel = ax_set_msglevel,
.get_wol = ax_get_wol,
.set_wol = ax_set_wol,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)
.get_eee = ax88179a_get_eee,
.set_eee = ax88179a_set_eee,
#endif
.get_coalesce = ax88179a_get_coalesce,
.set_coalesce = ax88179a_set_coalesce,
.get_strings = ax_get_strings,
.get_sset_count = ax_get_sset_count,
.get_ethtool_stats = ax_get_ethtool_stats,
.get_pauseparam = ax_get_pauseparam,
.set_pauseparam = ax_set_pauseparam,
.get_regs_len = ax_get_regs_len,
.get_regs = ax_get_regs,
#ifdef ENABLE_PTP_FUNC
.get_ts_info = ax88179a_set_wol_get_ts_info,
#else
.get_ts_info = ethtool_op_get_ts_info,
#endif
};
#ifdef ENABLE_AX88279
const struct ethtool_ops ax88279_ethtool_ops = {
#if KERNEL_VERSION(5, 7, 0) < LINUX_VERSION_CODE
.supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS,
#endif
.get_drvinfo = ax_get_drvinfo,
#if KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE
.get_settings = ax_get_settings,
.set_settings = ax_set_settings,
#else
.get_link_ksettings = ax_get_link_ksettings,
.set_link_ksettings = ax_set_link_ksettings,
#endif
.get_link = ethtool_op_get_link,
.get_msglevel = ax_get_msglevel,
.set_msglevel = ax_set_msglevel,
.get_wol = ax_get_wol,
.set_wol = ax_set_wol,
.get_coalesce = ax88179a_get_coalesce,
.set_coalesce = ax88179a_set_coalesce,
.get_strings = ax_get_strings,
.get_sset_count = ax_get_sset_count,
.get_ethtool_stats = ax_get_ethtool_stats,
.get_pauseparam = ax_get_pauseparam,
.set_pauseparam = ax_set_pauseparam,
.get_regs_len = ax_get_regs_len,
.get_regs = ax_get_regs,
#ifdef ENABLE_PTP_FUNC
.get_ts_info = ax88179a_set_wol_get_ts_info,
#else
.get_ts_info = ethtool_op_get_ts_info,
#endif
};
#endif
void ax88179a_get_fw_version(struct ax_device *axdev)
{
int i;
for (i = 0; i < 3; i++) {
if (ax_read_cmd(axdev, AX88179A_ACCESS_BL, (0xFD + i),
1, 1, &axdev->fw_version[i], 1) < 0) {
axdev->fw_version[i] = ~0;
}
}
if (ax_read_cmd(axdev, AX88179A_ACCESS_BL, AX88179A_SW_REVERSION, 1, 1,
&axdev->fw_version[3], 0) < 0)
axdev->fw_version[3] = ~0;
else
axdev->fw_version[3] &= 0xF;
}
int ax88179a_signature(struct ax_device *axdev, struct _ax_ioctl_command *info)
{
strncpy(info->sig, AX88179A_SIGNATURE, strlen(AX88179A_SIGNATURE));
return 0;
}
int ax88179a_read_version(struct ax_device *axdev,
struct _ax_ioctl_command *info)
{
unsigned char temp[16] = {0};
DEBUG_PRINTK("%s - Start", __func__);
sprintf(temp, "v%d.%d.%d.%d",
axdev->fw_version[0], axdev->fw_version[1],
axdev->fw_version[2], axdev->fw_version[3]);
memcpy(&info->version.version, temp, 16);
return 0;
}
int ax88179a_write_flash(struct ax_device *axdev,
struct _ax_ioctl_command *info)
{
int i, ret;
u8 *buf = NULL;
u8 *block;
DEBUG_PRINTK("%s - Start", __func__);
buf = kzalloc(256, GFP_KERNEL);
if (!buf)
return -ENOMEM;
block = buf;
ret = ax_write_cmd(axdev, AX88179A_FLASH_WEN, 0, 0, 0, NULL);
if (ret < 0) {
netdev_err(axdev->netdev, "Flash write enable failed");
info->flash.status = -ERR_FALSH_WRITE_EN;
goto out;
}
for (i = info->flash.offset;
i < (info->flash.length + info->flash.offset);
i += 256) {
if (copy_from_user(block,
(void __user *)&info->flash.buf[i], 256)) {
netdev_err(axdev->netdev,
"copy_from_user offset: 0x%x failed", i);
ret = -EFAULT;
goto out;
}
ret = ax_write_cmd(axdev, AX88179A_FLASH_WRITE,
(u16)((i >> 16) & 0xFFFF),
(u16)(i & 0xFFFF), 256, block);
if (ret < 0) {
netdev_err(axdev->netdev,
"Flash write offset: 0x%x failed", i);
info->flash.status = -ERR_FALSH_WRITE;
goto out;
}
}
ret = ax_write_cmd(axdev, AX88179A_FLASH_WDIS, 0, 0, 0, NULL);
if (ret < 0) {
netdev_err(axdev->netdev, "Flash write disable failed");
info->flash.status = -ERR_FALSH_WRITE_DIS;
return ret;
}
out:
kfree(buf);
return ret;
}
int ax88179a_read_flash(struct ax_device *axdev, struct _ax_ioctl_command *info)
{
int i, ret = 0;
void *buf = NULL;
u8 *block;
DEBUG_PRINTK("%s - Start", __func__);
buf = kzalloc(256, GFP_KERNEL);
if (!buf)
return -ENOMEM;
block = buf;
for (i = info->flash.offset;
i < (info->flash.length + info->flash.offset);
i += 256) {
ret = ax_read_cmd(axdev, AX88179A_FLASH_READ,
(u16)((i >> 16) & 0xFFFF),
(u16)(i & 0xFFFF), 256, block, 0);
if (ret < 0) {
netdev_err(axdev->netdev,
"Flash read offset: 0x%x failed", i);
info->flash.status = -ERR_FALSH_READ;
break;
}
if (copy_to_user((void __user *)&info->flash.buf[i],
block, 256)) {
netdev_err(axdev->netdev,
"copy_to_user offset: 0x%x failed", i);
ret = -EFAULT;
break;
}
}
kfree(buf);
return ret;
}
int ax88179a_program_efuse(struct ax_device *axdev,
struct _ax_ioctl_command *info)
{
int ret = 0;
u16 offset = (u16)(info->flash.offset * 16);
u8 buf[20] = {0};
DEBUG_PRINTK("%s - Start offset: %d (0x%x)", __func__, offset, offset);
ret = copy_from_user(buf, (void __user *)info->flash.buf, 20);
if (ret) {
netdev_err(axdev->netdev,
"copy_from_user efuse offset: 0x%x failed", offset);
return ret;
}
ret = ax_write_cmd(axdev, AX_ACCESS_EFUSE, offset, 0, 20, buf);
if (ret < 0) {
netdev_err(axdev->netdev,
"eFuse write offset: 0x%x failed", offset);
info->flash.status = -ERR_EFUSE_WRITE;
return ret;
}
return ret;
}
int ax88179a_dump_efuse(struct ax_device *axdev, struct _ax_ioctl_command *info)
{
int ret = 0;
u16 offset = (u16)(info->flash.offset * 16);
u8 buf[20] = {0};
DEBUG_PRINTK("%s - Start offset: %d (0x%x)", __func__, offset, offset);
ret = ax_read_cmd(axdev, AX_ACCESS_EFUSE, offset, 0, 20, buf, 0);
if (ret < 0) {
netdev_err(axdev->netdev,
"eFuse read offset: 0x%x failed", offset);
info->flash.status = -ERR_EFUSE_READ;
return ret;
}
ret = copy_to_user((void __user *)info->flash.buf, buf, 20);
if (ret) {
netdev_err(axdev->netdev,
"copy_to_user efuse offset: 0x%x failed", offset);
return ret;
}
return ret;
}
int ax88179a_boot_to_rom(struct ax_device *axdev,
struct _ax_ioctl_command *info)
{
int ret;
u8 reg8;
DEBUG_PRINTK("%s - Start", __func__);
ax_read_cmd(axdev, AX_ACCESS_MAC, AX_MONITOR_MODE, 1, 1, ®8, 1);
ret = usb_control_msg(axdev->udev, usb_sndctrlpipe(axdev->udev, 0),
AX88179A_BOOT_TO_ROM,
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0x5A5A, 0xA5A5, NULL, 0, 1);
if (ret < 0) {
netdev_err(axdev->netdev, "Booting to rom failed");
info->flash.status = -ERR_BOOT_CODE;
return ret;
}
return 0;
}
int ax88179a_erase_flash(struct ax_device *axdev,
struct _ax_ioctl_command *info)
{
int ret = 0;
DEBUG_PRINTK("%s - Start", __func__);
ret = ax_write_cmd(axdev, AX88179A_FLASH_WEN, 0, 0, 0, NULL);
if (ret < 0) {
netdev_err(axdev->netdev, "Flash write enable failed");
info->flash.status = -ERR_FALSH_WRITE_EN;
return ret;
}
ret = usb_control_msg(axdev->udev, usb_sndctrlpipe(axdev->udev, 0),
AX88179A_FLASH_EARSE_ALL,
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0, 0, NULL, 0, 300000);
if (ret < 0) {
netdev_err(axdev->netdev, "Flash erase all failed");
info->flash.status = -ERR_FALSH_ERASE_ALL;
return ret;
}
ret = ax_write_cmd(axdev, AX88179A_FLASH_WDIS, 0, 0, 0, NULL);
if (ret < 0) {
netdev_err(axdev->netdev, "Flash write disable failed");
info->flash.status = -ERR_FALSH_WRITE_DIS;
return ret;
}
return 0;
}
int ax88179a_erase_sector_flash(struct ax_device *axdev,
struct _ax_ioctl_command *info)
{
int ret = 0;
DEBUG_PRINTK("%s - Start", __func__);
ret = ax_write_cmd(axdev, AX88179A_FLASH_WEN, 0, 0, 0, NULL);
if (ret < 0) {
netdev_err(axdev->netdev, "Flash write enable failed");
info->flash.status = -ERR_FALSH_WRITE_EN;
return ret;
}
ret = usb_control_msg(axdev->udev, usb_sndctrlpipe(axdev->udev, 0),
0x28,
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
(info->flash.offset >> 16) & 0xFFFF, info->flash.offset & 0xFFFF, NULL, 0, 300000);
if (ret < 0) {
netdev_err(axdev->netdev, "Flash erase sector failed");
info->flash.status = -ERR_FALSH_ERASE_ALL;
return ret;
}
ret = ax_write_cmd(axdev, AX88179A_FLASH_WDIS, 0, 0, 0, NULL);
if (ret < 0) {
netdev_err(axdev->netdev, "Flash write disable failed");
info->flash.status = -ERR_FALSH_WRITE_DIS;
return ret;
}
return 0;
}
int ax88179a_sw_reset(struct ax_device *axdev, struct _ax_ioctl_command *info)
{
void *buf = NULL;
DEBUG_PRINTK("%s - Start", __func__);
buf = kzalloc(sizeof(u32), GFP_KERNEL);
if (!buf)
return -ENOMEM;
/*
*((u32 *)buf) = 1;
usb_control_msg(axdev->udev, usb_sndctrlpipe(axdev->udev, 0), 0x10,
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
0x18E8, 0x000F, buf, 4, 10);
*/
*((u8 *)buf) = 0x41;
ax_write_cmd(axdev, 0x2A, 0xAA00, 0, 1, buf);
kfree(buf);
return 0;
}
#define _MDIO_WRITE(offset, value) \
ax_mdio_write(netdev, phy_id, offset, value)
int ax88179a_ieee_test(struct ax_device *axdev, struct _ax_ioctl_command *info)
{
struct net_device *netdev = axdev->netdev;
int phy_id = axdev->mii.phy_id;
int ret;
DEBUG_PRINTK("%s - Start", __func__);
DEBUG_PRINTK("Stop: %d", info->ieee.stop);
DEBUG_PRINTK("Speed: %d", info->ieee.speed);
DEBUG_PRINTK("Type: %d", info->ieee.type);
if (info->ieee.speed == 1000 && axdev->chip_pin == CHIP_32PIN) {
netdev_err(axdev->netdev, "Invalid Chip pin");
info->ieee.status = -ERR_IEEE_INVALID_CHIP;
return -EINVAL;
}
if (info->ieee.stop) {
ret = ax88179a_set_phy_power(axdev, false);
if (ret < 0)
return ret;
msleep(500);
ret = ax88179a_set_phy_power(axdev, true);
if (ret < 0)
return ret;
msleep(500);
switch (info->ieee.speed) {
case 1000:
case 100:
break;
case 10:
_MDIO_WRITE(0x00, 0x0100);
_MDIO_WRITE(0x0D, 0x001E);
_MDIO_WRITE(0x0E, 0x0145);
_MDIO_WRITE(0x0D, 0x401E);
_MDIO_WRITE(0x0E, 0x5010);
_MDIO_WRITE(0x0D, 0x001F);
_MDIO_WRITE(0x0E, 0x027B);
_MDIO_WRITE(0x0D, 0x401F);
_MDIO_WRITE(0x0E, 0x1177);
break;
default:
return -EINVAL;
};
} else {
switch (info->ieee.type) {
case IEEE_1000M1:
_MDIO_WRITE(0x09, 0x2700);
break;
case IEEE_1000M2:
_MDIO_WRITE(0x09, 0x4700);
break;
case IEEE_1000M3:
_MDIO_WRITE(0x09, 0x6700);
break;
case IEEE_1000M4:
_MDIO_WRITE(0x09, 0x8700);
break;
case IEEE_100CA:
_MDIO_WRITE(0x00, 0x2100);
_MDIO_WRITE(0x0D, 0x001E);
_MDIO_WRITE(0x0E, 0x0145);
_MDIO_WRITE(0x0D, 0x401E);
_MDIO_WRITE(0x0E, 0x5010);
break;
case IEEE_100CB:
_MDIO_WRITE(0x00, 0x2100);
_MDIO_WRITE(0x0D, 0x001E);
_MDIO_WRITE(0x0E, 0x0145);
_MDIO_WRITE(0x0D, 0x401E);
_MDIO_WRITE(0x0E, 0x5018);
break;
case IEEE_10R:
ret = ax88179a_set_phy_power(axdev, false);
if (ret < 0)
return ret;
msleep(100);
ret = ax88179a_set_phy_power(axdev, true);
if (ret < 0)
return ret;
_MDIO_WRITE(0x00, 0x0100);
_MDIO_WRITE(0x0D, 0x001E);
_MDIO_WRITE(0x0E, 0x0145);
_MDIO_WRITE(0x0D, 0x401E);
_MDIO_WRITE(0x0E, 0x5010);
_MDIO_WRITE(0x0D, 0x001F);
_MDIO_WRITE(0x0E, 0x027B);
_MDIO_WRITE(0x0D, 0x401F);
_MDIO_WRITE(0x0E, 0x1177);
_MDIO_WRITE(0x00, 0x0800);
_MDIO_WRITE(0x1F, 0x0001);
_MDIO_WRITE(0x1D, 0xF842);
ax_mmd_write(axdev->netdev, 0x1E, 0x01A3, 0x2);
ax_mmd_write(axdev->netdev, 0x1E, 0x01A4, 0x110e);
_MDIO_WRITE(0x1F, 0x0000);
_MDIO_WRITE(0x00, 0x0100);
break;
case IEEE_10FF:
ret = ax88179a_set_phy_power(axdev, false);
if (ret < 0)
return ret;
msleep(100);
ret = ax88179a_set_phy_power(axdev, true);
if (ret < 0)
return ret;
_MDIO_WRITE(0x00, 0x0100);
_MDIO_WRITE(0x0D, 0x001E);
_MDIO_WRITE(0x0E, 0x0145);
_MDIO_WRITE(0x0D, 0x401E);
_MDIO_WRITE(0x0E, 0x5010);
_MDIO_WRITE(0x0D, 0x001F);
_MDIO_WRITE(0x0E, 0x027B);
_MDIO_WRITE(0x0D, 0x401F);
_MDIO_WRITE(0x0E, 0x1177);
_MDIO_WRITE(0x00, 0x0800);
_MDIO_WRITE(0x1F, 0x0001);
_MDIO_WRITE(0x1D, 0xF840);
ax_mmd_write(axdev->netdev, 0x1E, 0x01A3, 0x0000);
_MDIO_WRITE(0x1F, 0x0000);
_MDIO_WRITE(0x00, 0x0100);
break;
case IEEE_10MDI:
_MDIO_WRITE(0x00, 0x0100);
_MDIO_WRITE(0x0D, 0x001E);
_MDIO_WRITE(0x0E, 0x0145);
_MDIO_WRITE(0x0D, 0x401E);
_MDIO_WRITE(0x0E, 0x5010);
_MDIO_WRITE(0x0D, 0x001F);
_MDIO_WRITE(0x0E, 0x027B);
_MDIO_WRITE(0x0D, 0x401F);
_MDIO_WRITE(0x0E, 0x1177);
break;
default:
return -EINVAL;
};
}
return 0;
}
int ax88179a_autosuspend_en(struct ax_device *axdev,
struct _ax_ioctl_command *info)
{
DEBUG_PRINTK("%s - Start", __func__);
if (axdev->autosuspend_is_supported) {
if (info->autosuspend.enable)
usb_enable_autosuspend(axdev->udev);
else
usb_disable_autosuspend(axdev->udev);
}
return 0;
}
IOCTRL_TABLE ax88179a_tbl[] = {
ax88179a_signature,
ax_usb_command,
ax88179a_read_version,
ax88179a_write_flash,
ax88179a_boot_to_rom,
ax88179a_erase_flash,
ax88179a_sw_reset,
ax88179a_read_flash,
ax88179a_program_efuse,
ax88179a_dump_efuse,
ax88179a_ieee_test,
ax88179a_autosuspend_en,
ax88179a_erase_sector_flash,
};
#ifdef ENABLE_PTP_FUNC
static int ax88179a_hwtstamp_ioctl
(struct net_device *dev, struct ifreq *ifr, int cmd)
{
struct hwtstamp_config config;
if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
return -EFAULT;
if (config.flags)
return -EINVAL;
switch (config.rx_filter) {
case HWTSTAMP_FILTER_NONE:
break;
case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
case HWTSTAMP_FILTER_ALL:
case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
case HWTSTAMP_FILTER_PTP_V2_EVENT:
case HWTSTAMP_FILTER_PTP_V2_SYNC:
case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
config.rx_filter = HWTSTAMP_FILTER_ALL;
break;
default:
return -ERANGE;
}
return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
-EFAULT : 0;
}
#endif
#if KERNEL_VERSION(5, 15, 0) <= LINUX_VERSION_CODE
int ax88179a_siocdevprivate(struct net_device *netdev, struct ifreq *rq,
void __user *udata, int cmd)
{
struct ax_device *axdev = netdev_priv(netdev);
struct _ax_ioctl_command info;
void __user *uptr = (void __user *) rq->ifr_data;
int ret = 0;
switch (cmd) {
case AX_PRIVATE:
if (copy_from_user(&info, uptr,
sizeof(struct _ax_ioctl_command))) {
netdev_err(netdev, "copy_from_user, return -EFAULT");
return -EFAULT;
}
DEBUG_PRINTK("ioctl_cmd: %d", info.ioctl_cmd);
ret = (*ax88179a_tbl[info.ioctl_cmd])(axdev, &info);
if (ret < 0)
netdev_err(netdev, "ax88179a_tbl, return %d", ret);
if (copy_to_user(uptr, &info,
sizeof(struct _ax_ioctl_command))) {
netdev_err(netdev, "copy_to_user failed");
return ret;
}
break;
default:
ret = -EOPNOTSUPP;
}
return ret;
}
int ax88179a_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
{
struct ax_device *axdev = netdev_priv(netdev);
switch (cmd) {
#ifdef ENABLE_PTP_FUNC
case SIOCSHWTSTAMP:
return ax88179a_hwtstamp_ioctl(netdev, rq, cmd);
#endif
}
return generic_mii_ioctl(&axdev->mii, if_mii(rq), cmd, NULL);
}
#else
int ax88179a_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
{
struct ax_device *axdev = netdev_priv(netdev);
struct _ax_ioctl_command info;
void __user *uptr = (void __user *) rq->ifr_data;
int ret;
switch (cmd) {
case AX_PRIVATE:
if (copy_from_user(&info, uptr,
sizeof(struct _ax_ioctl_command))) {
netdev_err(netdev, "copy_from_user, return -EFAULT");
return -EFAULT;
}
DEBUG_PRINTK("ioctl_cmd: %d", info.ioctl_cmd);
ret = (*ax88179a_tbl[info.ioctl_cmd])(axdev, &info);
if (ret < 0) {
netdev_err(netdev, "ax88179a_tbl, return %d", ret);
return ret;
}
if (copy_to_user(uptr, &info,
sizeof(struct _ax_ioctl_command))) {
netdev_err(netdev, "copy_to_user, return -EFAULT");
return -EFAULT;
}
break;
#ifdef ENABLE_PTP_FUNC
case SIOCSHWTSTAMP:
return ax88179a_hwtstamp_ioctl(netdev, rq, cmd);
#endif
default:
return generic_mii_ioctl(&axdev->mii, if_mii(rq), cmd, NULL);
}
return 0;
}
#endif
static int ax88179a_autodetach(struct ax_device *axdev)
{
u16 value = ((axdev->autodetach) ? 1 : 0) | AX88179A_AUTODETACH_DELAY;
return ax_write_cmd(axdev, AX88179A_AUTODETACH, value, 0, 0, NULL);
}
static bool ax88179a_check_phy_power(struct ax_device *axdev)
{
u8 reg8 = 0;
int ret = 0;
ret = ax_read_cmd_nopm(axdev, AX88179A_PHY_POWER, 0, 0, 1, ®8, 1);
if (ret < 0)
return false;
return (reg8 & AX_PHY_POWER);
}
static int ax88179a_set_phy_power(struct ax_device *axdev, bool on)
{
u8 reg8;
int ret;
reg8 = (on)?AX_PHY_POWER:0;
ret = ax_write_cmd_nopm(axdev, AX88179A_PHY_POWER, 0, 0, 1, ®8);
if (ret < 0)
return ret;
msleep(250);
#ifdef ENABLE_INT_AGGRESSIVE
if (on) {
u16 reg16;
printk("ENABLE_INT_AGGRESSIVE");
ax_write_cmd(axdev, 0x32, 0x3, 0, 0, ®16);
}
#endif
return 0;
}