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#include "et131x_version.h"
59#include "et131x_defs.h"
60
61#include <linux/init.h>
62#include <linux/module.h>
63#include <linux/types.h>
64#include <linux/kernel.h>
65
66#include <linux/sched.h>
67#include <linux/ptrace.h>
68#include <linux/slab.h>
69#include <linux/ctype.h>
70#include <linux/string.h>
71#include <linux/timer.h>
72#include <linux/interrupt.h>
73#include <linux/in.h>
74#include <linux/delay.h>
75#include <linux/io.h>
76#include <linux/bitops.h>
77#include <linux/pci.h>
78#include <asm/system.h>
79
80#include <linux/mii.h>
81#include <linux/netdevice.h>
82#include <linux/etherdevice.h>
83#include <linux/skbuff.h>
84#include <linux/if_arp.h>
85#include <linux/ioport.h>
86
87#include "et1310_phy.h"
88#include "et1310_pm.h"
89#include "et1310_jagcore.h"
90#include "et1310_mac.h"
91#include "et1310_tx.h"
92
93#include "et131x_adapter.h"
94#include "et131x_isr.h"
95#include "et131x_initpci.h"
96
97struct net_device_stats *et131x_stats(struct net_device *netdev);
98int et131x_open(struct net_device *netdev);
99int et131x_close(struct net_device *netdev);
100int et131x_ioctl(struct net_device *netdev, struct ifreq *reqbuf, int cmd);
101void et131x_multicast(struct net_device *netdev);
102int et131x_tx(struct sk_buff *skb, struct net_device *netdev);
103void et131x_tx_timeout(struct net_device *netdev);
104int et131x_change_mtu(struct net_device *netdev, int new_mtu);
105int et131x_set_mac_addr(struct net_device *netdev, void *new_mac);
106void et131x_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp);
107void et131x_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
108void et131x_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
109
110static const struct net_device_ops et131x_netdev_ops = {
111 .ndo_open = et131x_open,
112 .ndo_stop = et131x_close,
113 .ndo_start_xmit = et131x_tx,
114 .ndo_set_multicast_list = et131x_multicast,
115 .ndo_tx_timeout = et131x_tx_timeout,
116 .ndo_change_mtu = et131x_change_mtu,
117 .ndo_set_mac_address = et131x_set_mac_addr,
118 .ndo_validate_addr = eth_validate_addr,
119 .ndo_get_stats = et131x_stats,
120 .ndo_do_ioctl = et131x_ioctl,
121};
122
123
124
125
126
127
128
129
130
131
132struct net_device *et131x_device_alloc(void)
133{
134 struct net_device *netdev;
135
136
137 netdev = alloc_etherdev(sizeof(struct et131x_adapter));
138
139 if (netdev == NULL) {
140 printk(KERN_ERR "et131x: Alloc of net_device struct failed\n");
141 return NULL;
142 }
143
144
145
146
147
148
149 netdev->watchdog_timeo = ET131X_TX_TIMEOUT;
150 netdev->netdev_ops = &et131x_netdev_ops;
151
152
153
154
155
156
157 return netdev;
158}
159
160
161
162
163
164
165
166struct net_device_stats *et131x_stats(struct net_device *netdev)
167{
168 struct et131x_adapter *adapter = netdev_priv(netdev);
169 struct net_device_stats *stats = &adapter->net_stats;
170 CE_STATS_t *devstat = &adapter->Stats;
171
172 stats->rx_packets = devstat->ipackets;
173 stats->tx_packets = devstat->opackets;
174 stats->rx_errors = devstat->length_err + devstat->alignment_err +
175 devstat->crc_err + devstat->code_violations + devstat->other_errors;
176 stats->tx_errors = devstat->max_pkt_error;
177 stats->multicast = devstat->multircv;
178 stats->collisions = devstat->collisions;
179
180 stats->rx_length_errors = devstat->length_err;
181 stats->rx_over_errors = devstat->rx_ov_flow;
182 stats->rx_crc_errors = devstat->crc_err;
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203 return stats;
204}
205
206
207
208
209
210
211
212int et131x_open(struct net_device *netdev)
213{
214 int result = 0;
215 struct et131x_adapter *adapter = netdev_priv(netdev);
216
217
218 add_timer(&adapter->ErrorTimer);
219
220
221 result = request_irq(netdev->irq, et131x_isr, IRQF_SHARED,
222 netdev->name, netdev);
223 if (result) {
224 dev_err(&adapter->pdev->dev, "c ould not register IRQ %d\n",
225 netdev->irq);
226 return result;
227 }
228
229
230 et131x_rx_dma_enable(adapter);
231 et131x_tx_dma_enable(adapter);
232
233
234 et131x_enable_interrupts(adapter);
235
236 adapter->Flags |= fMP_ADAPTER_INTERRUPT_IN_USE;
237
238
239 netif_start_queue(netdev);
240 return result;
241}
242
243
244
245
246
247
248
249int et131x_close(struct net_device *netdev)
250{
251 struct et131x_adapter *adapter = netdev_priv(netdev);
252
253
254 netif_stop_queue(netdev);
255
256
257 et131x_rx_dma_disable(adapter);
258 et131x_tx_dma_disable(adapter);
259
260
261 et131x_disable_interrupts(adapter);
262
263
264 adapter->Flags &= ~fMP_ADAPTER_INTERRUPT_IN_USE;
265 free_irq(netdev->irq, netdev);
266
267
268 del_timer_sync(&adapter->ErrorTimer);
269 return 0;
270}
271
272
273
274
275
276
277
278
279
280int et131x_ioctl_mii(struct net_device *netdev, struct ifreq *reqbuf, int cmd)
281{
282 int status = 0;
283 struct et131x_adapter *etdev = netdev_priv(netdev);
284 struct mii_ioctl_data *data = if_mii(reqbuf);
285
286 switch (cmd) {
287 case SIOCGMIIPHY:
288 data->phy_id = etdev->Stats.xcvr_addr;
289 break;
290
291 case SIOCGMIIREG:
292 if (!capable(CAP_NET_ADMIN))
293 status = -EPERM;
294 else
295 status = MiRead(etdev,
296 data->reg_num, &data->val_out);
297 break;
298
299 case SIOCSMIIREG:
300 if (!capable(CAP_NET_ADMIN))
301 status = -EPERM;
302 else
303 status = MiWrite(etdev, data->reg_num,
304 data->val_in);
305 break;
306
307 default:
308 status = -EOPNOTSUPP;
309 }
310 return status;
311}
312
313
314
315
316
317
318
319
320
321int et131x_ioctl(struct net_device *netdev, struct ifreq *reqbuf, int cmd)
322{
323 int status = 0;
324
325 switch (cmd) {
326 case SIOCGMIIPHY:
327 case SIOCGMIIREG:
328 case SIOCSMIIREG:
329 status = et131x_ioctl_mii(netdev, reqbuf, cmd);
330 break;
331
332 default:
333 status = -EOPNOTSUPP;
334 }
335 return status;
336}
337
338
339
340
341
342
343
344int et131x_set_packet_filter(struct et131x_adapter *adapter)
345{
346 int status = 0;
347 uint32_t filter = adapter->PacketFilter;
348 RXMAC_CTRL_t ctrl;
349 RXMAC_PF_CTRL_t pf_ctrl;
350
351 ctrl.value = readl(&adapter->regs->rxmac.ctrl.value);
352 pf_ctrl.value = readl(&adapter->regs->rxmac.pf_ctrl.value);
353
354
355
356
357 ctrl.bits.pkt_filter_disable = 1;
358
359
360
361
362 if ((filter & ET131X_PACKET_TYPE_PROMISCUOUS) || filter == 0) {
363 pf_ctrl.bits.filter_broad_en = 0;
364 pf_ctrl.bits.filter_multi_en = 0;
365 pf_ctrl.bits.filter_uni_en = 0;
366 } else {
367
368
369
370
371
372 if (filter & ET131X_PACKET_TYPE_ALL_MULTICAST) {
373 pf_ctrl.bits.filter_multi_en = 0;
374 } else {
375 SetupDeviceForMulticast(adapter);
376 pf_ctrl.bits.filter_multi_en = 1;
377 ctrl.bits.pkt_filter_disable = 0;
378 }
379
380
381 if (filter & ET131X_PACKET_TYPE_DIRECTED) {
382 SetupDeviceForUnicast(adapter);
383 pf_ctrl.bits.filter_uni_en = 1;
384 ctrl.bits.pkt_filter_disable = 0;
385 }
386
387
388 if (filter & ET131X_PACKET_TYPE_BROADCAST) {
389 pf_ctrl.bits.filter_broad_en = 1;
390 ctrl.bits.pkt_filter_disable = 0;
391 } else {
392 pf_ctrl.bits.filter_broad_en = 0;
393 }
394
395
396
397
398
399 writel(pf_ctrl.value,
400 &adapter->regs->rxmac.pf_ctrl.value);
401 writel(ctrl.value, &adapter->regs->rxmac.ctrl.value);
402 }
403 return status;
404}
405
406
407
408
409
410void et131x_multicast(struct net_device *netdev)
411{
412 struct et131x_adapter *adapter = netdev_priv(netdev);
413 uint32_t PacketFilter = 0;
414 uint32_t count;
415 unsigned long flags;
416 struct dev_mc_list *mclist = netdev->mc_list;
417
418 spin_lock_irqsave(&adapter->Lock, flags);
419
420
421
422
423
424 PacketFilter = adapter->PacketFilter;
425
426
427
428
429
430
431 PacketFilter &= ~ET131X_PACKET_TYPE_MULTICAST;
432
433
434
435
436
437 if (netdev->flags & IFF_PROMISC) {
438 adapter->PacketFilter |= ET131X_PACKET_TYPE_PROMISCUOUS;
439 } else {
440 adapter->PacketFilter &= ~ET131X_PACKET_TYPE_PROMISCUOUS;
441 }
442
443 if (netdev->flags & IFF_ALLMULTI) {
444 adapter->PacketFilter |= ET131X_PACKET_TYPE_ALL_MULTICAST;
445 }
446
447 if (netdev->mc_count > NIC_MAX_MCAST_LIST) {
448 adapter->PacketFilter |= ET131X_PACKET_TYPE_ALL_MULTICAST;
449 }
450
451 if (netdev->mc_count < 1) {
452 adapter->PacketFilter &= ~ET131X_PACKET_TYPE_ALL_MULTICAST;
453 adapter->PacketFilter &= ~ET131X_PACKET_TYPE_MULTICAST;
454 } else {
455 adapter->PacketFilter |= ET131X_PACKET_TYPE_MULTICAST;
456 }
457
458
459 adapter->MCAddressCount = netdev->mc_count;
460
461 if (netdev->mc_count) {
462 count = netdev->mc_count - 1;
463 memcpy(adapter->MCList[count], mclist->dmi_addr, ETH_ALEN);
464 }
465
466
467
468
469
470
471
472 if (PacketFilter != adapter->PacketFilter) {
473
474 et131x_set_packet_filter(adapter);
475 }
476 spin_unlock_irqrestore(&adapter->Lock, flags);
477}
478
479
480
481
482
483
484
485
486int et131x_tx(struct sk_buff *skb, struct net_device *netdev)
487{
488 int status = 0;
489
490
491 netdev->trans_start = jiffies;
492
493
494 status = et131x_send_packets(skb, netdev);
495
496
497 if (status != 0) {
498 if (status == -ENOMEM) {
499
500
501
502 netif_stop_queue(netdev);
503 status = NETDEV_TX_BUSY;
504 } else {
505 status = NETDEV_TX_OK;
506 }
507 }
508 return status;
509}
510
511
512
513
514
515
516
517
518
519void et131x_tx_timeout(struct net_device *netdev)
520{
521 struct et131x_adapter *etdev = netdev_priv(netdev);
522 PMP_TCB pMpTcb;
523 unsigned long flags;
524
525
526 if (etdev->Flags & fMP_ADAPTER_LINK_DETECTION)
527 return;
528
529
530
531
532 if (etdev->Flags & fMP_ADAPTER_NON_RECOVER_ERROR)
533 return;
534
535
536 if (etdev->Flags & fMP_ADAPTER_HARDWARE_ERROR) {
537 dev_err(&etdev->pdev->dev, "hardware error - reset\n");
538 return;
539 }
540
541
542 spin_lock_irqsave(&etdev->TCBSendQLock, flags);
543
544 pMpTcb = etdev->TxRing.CurrSendHead;
545
546 if (pMpTcb != NULL) {
547 pMpTcb->Count++;
548
549 if (pMpTcb->Count > NIC_SEND_HANG_THRESHOLD) {
550 TX_DESC_ENTRY_t StuckDescriptors[10];
551
552 if (INDEX10(pMpTcb->WrIndex) > 7) {
553 memcpy(StuckDescriptors,
554 etdev->TxRing.pTxDescRingVa +
555 INDEX10(pMpTcb->WrIndex) - 6,
556 sizeof(TX_DESC_ENTRY_t) * 10);
557 }
558
559 spin_unlock_irqrestore(&etdev->TCBSendQLock,
560 flags);
561
562 dev_warn(&etdev->pdev->dev,
563 "Send stuck - reset. pMpTcb->WrIndex %x, Flags 0x%08x\n",
564 pMpTcb->WrIndex,
565 pMpTcb->Flags);
566
567 et131x_close(netdev);
568 et131x_open(netdev);
569
570 return;
571 }
572 }
573
574 spin_unlock_irqrestore(&etdev->TCBSendQLock, flags);
575}
576
577
578
579
580
581
582
583
584int et131x_change_mtu(struct net_device *netdev, int new_mtu)
585{
586 int result = 0;
587 struct et131x_adapter *adapter = netdev_priv(netdev);
588
589
590 if (new_mtu < 64 || new_mtu > 9216)
591 return -EINVAL;
592
593
594 netif_stop_queue(netdev);
595
596
597 et131x_rx_dma_disable(adapter);
598 et131x_tx_dma_disable(adapter);
599
600
601 et131x_disable_interrupts(adapter);
602 et131x_handle_send_interrupt(adapter);
603 et131x_handle_recv_interrupt(adapter);
604
605
606 netdev->mtu = new_mtu;
607
608
609 et131x_adapter_memory_free(adapter);
610
611
612 adapter->RegistryJumboPacket = new_mtu + 14;
613 et131x_soft_reset(adapter);
614
615
616 result = et131x_adapter_memory_alloc(adapter);
617 if (result != 0) {
618 dev_warn(&adapter->pdev->dev,
619 "Change MTU failed; couldn't re-alloc DMA memory\n");
620 return result;
621 }
622
623 et131x_init_send(adapter);
624
625 et131x_setup_hardware_properties(adapter);
626 memcpy(netdev->dev_addr, adapter->CurrentAddress, ETH_ALEN);
627
628
629 et131x_adapter_setup(adapter);
630
631
632 if (adapter->Flags & fMP_ADAPTER_INTERRUPT_IN_USE)
633 et131x_enable_interrupts(adapter);
634
635
636 et131x_rx_dma_enable(adapter);
637 et131x_tx_dma_enable(adapter);
638
639
640 netif_wake_queue(netdev);
641 return result;
642}
643
644
645
646
647
648
649
650
651
652
653int et131x_set_mac_addr(struct net_device *netdev, void *new_mac)
654{
655 int result = 0;
656 struct et131x_adapter *adapter = netdev_priv(netdev);
657 struct sockaddr *address = new_mac;
658
659
660
661 if (adapter == NULL)
662 return -ENODEV;
663
664
665 if (!is_valid_ether_addr(address->sa_data))
666 return -EINVAL;
667
668
669 netif_stop_queue(netdev);
670
671
672 et131x_rx_dma_disable(adapter);
673 et131x_tx_dma_disable(adapter);
674
675
676 et131x_disable_interrupts(adapter);
677 et131x_handle_send_interrupt(adapter);
678 et131x_handle_recv_interrupt(adapter);
679
680
681
682
683
684 memcpy(netdev->dev_addr, address->sa_data, netdev->addr_len);
685
686 printk(KERN_INFO
687 "%s: Setting MAC address to %02x:%02x:%02x:%02x:%02x:%02x\n",
688 netdev->name,
689 netdev->dev_addr[0], netdev->dev_addr[1],
690 netdev->dev_addr[2], netdev->dev_addr[3],
691 netdev->dev_addr[4], netdev->dev_addr[5]);
692
693
694 et131x_adapter_memory_free(adapter);
695
696
697
698
699
700 et131x_soft_reset(adapter);
701
702
703 result = et131x_adapter_memory_alloc(adapter);
704 if (result != 0) {
705 dev_err(&adapter->pdev->dev,
706 "Change MAC failed; couldn't re-alloc DMA memory\n");
707 return result;
708 }
709
710 et131x_init_send(adapter);
711
712 et131x_setup_hardware_properties(adapter);
713
714
715
716
717 et131x_adapter_setup(adapter);
718
719
720 if (adapter->Flags & fMP_ADAPTER_INTERRUPT_IN_USE)
721 et131x_enable_interrupts(adapter);
722
723
724 et131x_rx_dma_enable(adapter);
725 et131x_tx_dma_enable(adapter);
726
727
728 netif_wake_queue(netdev);
729 return result;
730}
731