hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/net/ethernet/3com/typhoon.c
....@@ -127,7 +127,6 @@
127127 #include "typhoon.h"
128128
129129 MODULE_AUTHOR("David Dillow <dave@thedillows.org>");
130
-MODULE_VERSION("1.0");
131130 MODULE_LICENSE("GPL");
132131 MODULE_FIRMWARE(FIRMWARE_NAME);
133132 MODULE_DESCRIPTION("3Com Typhoon Family (3C990, 3CR990, and variants)");
....@@ -311,7 +310,7 @@
311310 * cannot pass a read, so this forces current writes to post.
312311 */
313312 #define typhoon_post_pci_writes(x) \
314
- do { if(likely(use_mmio)) ioread32(x+TYPHOON_REG_HEARTBEAT); } while(0)
313
+ do { if (likely(use_mmio)) ioread32(x+TYPHOON_REG_HEARTBEAT); } while (0)
315314
316315 /* We'll wait up to six seconds for a reset, and half a second normally.
317316 */
....@@ -381,7 +380,7 @@
381380 int i, err = 0;
382381 int timeout;
383382
384
- if(wait_type == WaitNoSleep)
383
+ if (wait_type == WaitNoSleep)
385384 timeout = TYPHOON_RESET_TIMEOUT_NOSLEEP;
386385 else
387386 timeout = TYPHOON_RESET_TIMEOUT_SLEEP;
....@@ -394,13 +393,13 @@
394393 udelay(1);
395394 iowrite32(TYPHOON_RESET_NONE, ioaddr + TYPHOON_REG_SOFT_RESET);
396395
397
- if(wait_type != NoWait) {
398
- for(i = 0; i < timeout; i++) {
399
- if(ioread32(ioaddr + TYPHOON_REG_STATUS) ==
396
+ if (wait_type != NoWait) {
397
+ for (i = 0; i < timeout; i++) {
398
+ if (ioread32(ioaddr + TYPHOON_REG_STATUS) ==
400399 TYPHOON_STATUS_WAITING_FOR_HOST)
401400 goto out;
402401
403
- if(wait_type == WaitSleep)
402
+ if (wait_type == WaitSleep)
404403 schedule_timeout_uninterruptible(1);
405404 else
406405 udelay(TYPHOON_UDELAY);
....@@ -423,7 +422,7 @@
423422 * which should be enough (I've see it work well at 100us, but still
424423 * saw occasional problems.)
425424 */
426
- if(wait_type == WaitSleep)
425
+ if (wait_type == WaitSleep)
427426 msleep(5);
428427 else
429428 udelay(500);
....@@ -435,8 +434,8 @@
435434 {
436435 int i, err = 0;
437436
438
- for(i = 0; i < TYPHOON_WAIT_TIMEOUT; i++) {
439
- if(ioread32(ioaddr + TYPHOON_REG_STATUS) == wait_value)
437
+ for (i = 0; i < TYPHOON_WAIT_TIMEOUT; i++) {
438
+ if (ioread32(ioaddr + TYPHOON_REG_STATUS) == wait_value)
440439 goto out;
441440 udelay(TYPHOON_UDELAY);
442441 }
....@@ -450,7 +449,7 @@
450449 static inline void
451450 typhoon_media_status(struct net_device *dev, struct resp_desc *resp)
452451 {
453
- if(resp->parm1 & TYPHOON_MEDIA_STAT_NO_LINK)
452
+ if (resp->parm1 & TYPHOON_MEDIA_STAT_NO_LINK)
454453 netif_carrier_off(dev);
455454 else
456455 netif_carrier_on(dev);
....@@ -466,7 +465,7 @@
466465 * card in a long while. If the lock is held, then we're in the
467466 * process of issuing a command, so we don't need to respond.
468467 */
469
- if(spin_trylock(&tp->command_lock)) {
468
+ if (spin_trylock(&tp->command_lock)) {
470469 cmd = (struct cmd_desc *)(ring->ringBase + ring->lastWrite);
471470 typhoon_inc_cmd_index(&ring->lastWrite, 1);
472471
....@@ -490,32 +489,32 @@
490489
491490 cleared = le32_to_cpu(indexes->respCleared);
492491 ready = le32_to_cpu(indexes->respReady);
493
- while(cleared != ready) {
492
+ while (cleared != ready) {
494493 resp = (struct resp_desc *)(base + cleared);
495494 count = resp->numDesc + 1;
496
- if(resp_save && resp->seqNo) {
497
- if(count > resp_size) {
495
+ if (resp_save && resp->seqNo) {
496
+ if (count > resp_size) {
498497 resp_save->flags = TYPHOON_RESP_ERROR;
499498 goto cleanup;
500499 }
501500
502501 wrap_len = 0;
503502 len = count * sizeof(*resp);
504
- if(unlikely(cleared + len > RESPONSE_RING_SIZE)) {
503
+ if (unlikely(cleared + len > RESPONSE_RING_SIZE)) {
505504 wrap_len = cleared + len - RESPONSE_RING_SIZE;
506505 len = RESPONSE_RING_SIZE - cleared;
507506 }
508507
509508 memcpy(resp_save, resp, len);
510
- if(unlikely(wrap_len)) {
509
+ if (unlikely(wrap_len)) {
511510 resp_save += len / sizeof(*resp);
512511 memcpy(resp_save, base, wrap_len);
513512 }
514513
515514 resp_save = NULL;
516
- } else if(resp->cmd == TYPHOON_CMD_READ_MEDIA_STATUS) {
515
+ } else if (resp->cmd == TYPHOON_CMD_READ_MEDIA_STATUS) {
517516 typhoon_media_status(tp->dev, resp);
518
- } else if(resp->cmd == TYPHOON_CMD_HELLO_RESP) {
517
+ } else if (resp->cmd == TYPHOON_CMD_HELLO_RESP) {
519518 typhoon_hello(tp);
520519 } else {
521520 netdev_err(tp->dev,
....@@ -589,19 +588,19 @@
589588 freeCmd = typhoon_num_free_cmd(tp);
590589 freeResp = typhoon_num_free_resp(tp);
591590
592
- if(freeCmd < num_cmd || freeResp < num_resp) {
591
+ if (freeCmd < num_cmd || freeResp < num_resp) {
593592 netdev_err(tp->dev, "no descs for cmd, had (needed) %d (%d) cmd, %d (%d) resp\n",
594593 freeCmd, num_cmd, freeResp, num_resp);
595594 err = -ENOMEM;
596595 goto out;
597596 }
598597
599
- if(cmd->flags & TYPHOON_CMD_RESPOND) {
598
+ if (cmd->flags & TYPHOON_CMD_RESPOND) {
600599 /* If we're expecting a response, but the caller hasn't given
601600 * us a place to put it, we'll provide one.
602601 */
603602 tp->awaiting_resp = 1;
604
- if(resp == NULL) {
603
+ if (resp == NULL) {
605604 resp = &local_resp;
606605 num_resp = 1;
607606 }
....@@ -609,13 +608,13 @@
609608
610609 wrap_len = 0;
611610 len = num_cmd * sizeof(*cmd);
612
- if(unlikely(ring->lastWrite + len > COMMAND_RING_SIZE)) {
611
+ if (unlikely(ring->lastWrite + len > COMMAND_RING_SIZE)) {
613612 wrap_len = ring->lastWrite + len - COMMAND_RING_SIZE;
614613 len = COMMAND_RING_SIZE - ring->lastWrite;
615614 }
616615
617616 memcpy(ring->ringBase + ring->lastWrite, cmd, len);
618
- if(unlikely(wrap_len)) {
617
+ if (unlikely(wrap_len)) {
619618 struct cmd_desc *wrap_ptr = cmd;
620619 wrap_ptr += len / sizeof(*cmd);
621620 memcpy(ring->ringBase, wrap_ptr, wrap_len);
....@@ -629,7 +628,7 @@
629628 iowrite32(ring->lastWrite, tp->ioaddr + TYPHOON_REG_CMD_READY);
630629 typhoon_post_pci_writes(tp->ioaddr);
631630
632
- if((cmd->flags & TYPHOON_CMD_RESPOND) == 0)
631
+ if ((cmd->flags & TYPHOON_CMD_RESPOND) == 0)
633632 goto out;
634633
635634 /* Ugh. We'll be here about 8ms, spinning our thumbs, unable to
....@@ -649,14 +648,14 @@
649648 * wait here.
650649 */
651650 got_resp = 0;
652
- for(i = 0; i < TYPHOON_WAIT_TIMEOUT && !got_resp; i++) {
653
- if(indexes->respCleared != indexes->respReady)
651
+ for (i = 0; i < TYPHOON_WAIT_TIMEOUT && !got_resp; i++) {
652
+ if (indexes->respCleared != indexes->respReady)
654653 got_resp = typhoon_process_response(tp, num_resp,
655654 resp);
656655 udelay(TYPHOON_UDELAY);
657656 }
658657
659
- if(!got_resp) {
658
+ if (!got_resp) {
660659 err = -ETIMEDOUT;
661660 goto out;
662661 }
....@@ -664,11 +663,11 @@
664663 /* Collect the error response even if we don't care about the
665664 * rest of the response
666665 */
667
- if(resp->flags & TYPHOON_RESP_ERROR)
666
+ if (resp->flags & TYPHOON_RESP_ERROR)
668667 err = -EIO;
669668
670669 out:
671
- if(tp->awaiting_resp) {
670
+ if (tp->awaiting_resp) {
672671 tp->awaiting_resp = 0;
673672 smp_wmb();
674673
....@@ -679,7 +678,7 @@
679678 * time. So, check for it, and interrupt ourselves if this
680679 * is the case.
681680 */
682
- if(indexes->respCleared != indexes->respReady)
681
+ if (indexes->respCleared != indexes->respReady)
683682 iowrite32(1, tp->ioaddr + TYPHOON_REG_SELF_INTERRUPT);
684683 }
685684
....@@ -749,7 +748,7 @@
749748 * between marking the queue awake and updating the cleared index.
750749 * Just loop and it will appear. This comes from the acenic driver.
751750 */
752
- while(unlikely(typhoon_num_free_tx(txRing) < (numDesc + 2)))
751
+ while (unlikely(typhoon_num_free_tx(txRing) < (numDesc + 2)))
753752 smp_rmb();
754753
755754 first_txd = (struct tx_desc *) (txRing->ringBase + txRing->lastWrite);
....@@ -761,7 +760,7 @@
761760 first_txd->tx_addr = (u64)((unsigned long) skb);
762761 first_txd->processFlags = 0;
763762
764
- if(skb->ip_summed == CHECKSUM_PARTIAL) {
763
+ if (skb->ip_summed == CHECKSUM_PARTIAL) {
765764 /* The 3XP will figure out if this is UDP/TCP */
766765 first_txd->processFlags |= TYPHOON_TX_PF_TCP_CHKSUM;
767766 first_txd->processFlags |= TYPHOON_TX_PF_UDP_CHKSUM;
....@@ -789,9 +788,9 @@
789788 /* No need to worry about padding packet -- the firmware pads
790789 * it with zeros to ETH_ZLEN for us.
791790 */
792
- if(skb_shinfo(skb)->nr_frags == 0) {
793
- skb_dma = pci_map_single(tp->tx_pdev, skb->data, skb->len,
794
- PCI_DMA_TODEVICE);
791
+ if (skb_shinfo(skb)->nr_frags == 0) {
792
+ skb_dma = dma_map_single(&tp->tx_pdev->dev, skb->data,
793
+ skb->len, DMA_TO_DEVICE);
795794 txd->flags = TYPHOON_FRAG_DESC | TYPHOON_DESC_VALID;
796795 txd->len = cpu_to_le16(skb->len);
797796 txd->frag.addr = cpu_to_le32(skb_dma);
....@@ -801,8 +800,8 @@
801800 int i, len;
802801
803802 len = skb_headlen(skb);
804
- skb_dma = pci_map_single(tp->tx_pdev, skb->data, len,
805
- PCI_DMA_TODEVICE);
803
+ skb_dma = dma_map_single(&tp->tx_pdev->dev, skb->data, len,
804
+ DMA_TO_DEVICE);
806805 txd->flags = TYPHOON_FRAG_DESC | TYPHOON_DESC_VALID;
807806 txd->len = cpu_to_le16(len);
808807 txd->frag.addr = cpu_to_le32(skb_dma);
....@@ -819,8 +818,8 @@
819818
820819 len = skb_frag_size(frag);
821820 frag_addr = skb_frag_address(frag);
822
- skb_dma = pci_map_single(tp->tx_pdev, frag_addr, len,
823
- PCI_DMA_TODEVICE);
821
+ skb_dma = dma_map_single(&tp->tx_pdev->dev, frag_addr,
822
+ len, DMA_TO_DEVICE);
824823 txd->flags = TYPHOON_FRAG_DESC | TYPHOON_DESC_VALID;
825824 txd->len = cpu_to_le16(len);
826825 txd->frag.addr = cpu_to_le32(skb_dma);
....@@ -841,14 +840,14 @@
841840 */
842841 numDesc = MAX_SKB_FRAGS + TSO_NUM_DESCRIPTORS + 1;
843842
844
- if(typhoon_num_free_tx(txRing) < (numDesc + 2)) {
843
+ if (typhoon_num_free_tx(txRing) < (numDesc + 2)) {
845844 netif_stop_queue(dev);
846845
847846 /* A Tx complete IRQ could have gotten between, making
848847 * the ring free again. Only need to recheck here, since
849848 * Tx is serialized.
850849 */
851
- if(typhoon_num_free_tx(txRing) >= (numDesc + 2))
850
+ if (typhoon_num_free_tx(txRing) >= (numDesc + 2))
852851 netif_wake_queue(dev);
853852 }
854853
....@@ -864,7 +863,7 @@
864863 __le16 filter;
865864
866865 filter = TYPHOON_RX_FILTER_DIRECTED | TYPHOON_RX_FILTER_BROADCAST;
867
- if(dev->flags & IFF_PROMISC) {
866
+ if (dev->flags & IFF_PROMISC) {
868867 filter |= TYPHOON_RX_FILTER_PROMISCOUS;
869868 } else if ((netdev_mc_count(dev) > multicast_filter_limit) ||
870869 (dev->flags & IFF_ALLMULTI)) {
....@@ -906,7 +905,7 @@
906905
907906 INIT_COMMAND_WITH_RESPONSE(&xp_cmd, TYPHOON_CMD_READ_STATS);
908907 err = typhoon_issue_command(tp, 1, &xp_cmd, 7, xp_resp);
909
- if(err < 0)
908
+ if (err < 0)
910909 return err;
911910
912911 /* 3Com's Linux driver uses txMultipleCollisions as it's
....@@ -954,10 +953,10 @@
954953 struct net_device_stats *saved = &tp->stats_saved;
955954
956955 smp_rmb();
957
- if(tp->card_state == Sleeping)
956
+ if (tp->card_state == Sleeping)
958957 return saved;
959958
960
- if(typhoon_do_get_stats(tp) < 0) {
959
+ if (typhoon_do_get_stats(tp) < 0) {
961960 netdev_err(dev, "error getting stats\n");
962961 return saved;
963962 }
....@@ -974,12 +973,12 @@
974973 struct resp_desc xp_resp[3];
975974
976975 smp_rmb();
977
- if(tp->card_state == Sleeping) {
976
+ if (tp->card_state == Sleeping) {
978977 strlcpy(info->fw_version, "Sleep image",
979978 sizeof(info->fw_version));
980979 } else {
981980 INIT_COMMAND_WITH_RESPONSE(&xp_cmd, TYPHOON_CMD_READ_VERSIONS);
982
- if(typhoon_issue_command(tp, 1, &xp_cmd, 3, xp_resp) < 0) {
981
+ if (typhoon_issue_command(tp, 1, &xp_cmd, 3, xp_resp) < 0) {
983982 strlcpy(info->fw_version, "Unknown runtime",
984983 sizeof(info->fw_version));
985984 } else {
....@@ -1026,7 +1025,7 @@
10261025 break;
10271026 }
10281027
1029
- if(tp->capabilities & TYPHOON_FIBER) {
1028
+ if (tp->capabilities & TYPHOON_FIBER) {
10301029 supported |= SUPPORTED_FIBRE;
10311030 advertising |= ADVERTISED_FIBRE;
10321031 cmd->base.port = PORT_FIBRE;
....@@ -1043,7 +1042,7 @@
10431042 cmd->base.speed = tp->speed;
10441043 cmd->base.duplex = tp->duplex;
10451044 cmd->base.phy_address = 0;
1046
- if(tp->xcvr_select == TYPHOON_XCVR_AUTONEG)
1045
+ if (tp->xcvr_select == TYPHOON_XCVR_AUTONEG)
10471046 cmd->base.autoneg = AUTONEG_ENABLE;
10481047 else
10491048 cmd->base.autoneg = AUTONEG_DISABLE;
....@@ -1091,7 +1090,7 @@
10911090 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_XCVR_SELECT);
10921091 xp_cmd.parm1 = xcvr;
10931092 err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
1094
- if(err < 0)
1093
+ if (err < 0)
10951094 goto out;
10961095
10971096 tp->xcvr_select = xcvr;
....@@ -1114,9 +1113,9 @@
11141113
11151114 wol->supported = WAKE_PHY | WAKE_MAGIC;
11161115 wol->wolopts = 0;
1117
- if(tp->wol_events & TYPHOON_WAKE_LINK_EVENT)
1116
+ if (tp->wol_events & TYPHOON_WAKE_LINK_EVENT)
11181117 wol->wolopts |= WAKE_PHY;
1119
- if(tp->wol_events & TYPHOON_WAKE_MAGIC_PKT)
1118
+ if (tp->wol_events & TYPHOON_WAKE_MAGIC_PKT)
11201119 wol->wolopts |= WAKE_MAGIC;
11211120 memset(&wol->sopass, 0, sizeof(wol->sopass));
11221121 }
....@@ -1126,13 +1125,13 @@
11261125 {
11271126 struct typhoon *tp = netdev_priv(dev);
11281127
1129
- if(wol->wolopts & ~(WAKE_PHY | WAKE_MAGIC))
1128
+ if (wol->wolopts & ~(WAKE_PHY | WAKE_MAGIC))
11301129 return -EINVAL;
11311130
11321131 tp->wol_events = 0;
1133
- if(wol->wolopts & WAKE_PHY)
1132
+ if (wol->wolopts & WAKE_PHY)
11341133 tp->wol_events |= TYPHOON_WAKE_LINK_EVENT;
1135
- if(wol->wolopts & WAKE_MAGIC)
1134
+ if (wol->wolopts & WAKE_MAGIC)
11361135 tp->wol_events |= TYPHOON_WAKE_MAGIC_PKT;
11371136
11381137 return 0;
....@@ -1163,8 +1162,8 @@
11631162 {
11641163 int i, err = 0;
11651164
1166
- for(i = 0; i < TYPHOON_WAIT_TIMEOUT; i++) {
1167
- if(ioread32(ioaddr + TYPHOON_REG_INTR_STATUS) &
1165
+ for (i = 0; i < TYPHOON_WAIT_TIMEOUT; i++) {
1166
+ if (ioread32(ioaddr + TYPHOON_REG_INTR_STATUS) &
11681167 TYPHOON_INTR_BOOTCMD)
11691168 goto out;
11701169 udelay(TYPHOON_UDELAY);
....@@ -1350,13 +1349,13 @@
13501349 image_data = typhoon_fw->data;
13511350 fHdr = (struct typhoon_file_header *) image_data;
13521351
1353
- /* Cannot just map the firmware image using pci_map_single() as
1352
+ /* Cannot just map the firmware image using dma_map_single() as
13541353 * the firmware is vmalloc()'d and may not be physically contiguous,
1355
- * so we allocate some consistent memory to copy the sections into.
1354
+ * so we allocate some coherent memory to copy the sections into.
13561355 */
13571356 err = -ENOMEM;
1358
- dpage = pci_alloc_consistent(pdev, PAGE_SIZE, &dpage_dma);
1359
- if(!dpage) {
1357
+ dpage = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, &dpage_dma, GFP_ATOMIC);
1358
+ if (!dpage) {
13601359 netdev_err(tp->dev, "no DMA mem for firmware\n");
13611360 goto err_out;
13621361 }
....@@ -1369,7 +1368,7 @@
13691368 ioaddr + TYPHOON_REG_INTR_MASK);
13701369
13711370 err = -ETIMEDOUT;
1372
- if(typhoon_wait_status(ioaddr, TYPHOON_STATUS_WAITING_FOR_HOST) < 0) {
1371
+ if (typhoon_wait_status(ioaddr, TYPHOON_STATUS_WAITING_FOR_HOST) < 0) {
13731372 netdev_err(tp->dev, "card ready timeout\n");
13741373 goto err_out_irq;
13751374 }
....@@ -1398,16 +1397,16 @@
13981397 * last write to the command register to post, so
13991398 * we don't need a typhoon_post_pci_writes() after it.
14001399 */
1401
- for(i = 0; i < numSections; i++) {
1400
+ for (i = 0; i < numSections; i++) {
14021401 sHdr = (struct typhoon_section_header *) image_data;
14031402 image_data += sizeof(struct typhoon_section_header);
14041403 load_addr = le32_to_cpu(sHdr->startAddr);
14051404 section_len = le32_to_cpu(sHdr->len);
14061405
1407
- while(section_len) {
1406
+ while (section_len) {
14081407 len = min_t(u32, section_len, PAGE_SIZE);
14091408
1410
- if(typhoon_wait_interrupt(ioaddr) < 0 ||
1409
+ if (typhoon_wait_interrupt(ioaddr) < 0 ||
14111410 ioread32(ioaddr + TYPHOON_REG_STATUS) !=
14121411 TYPHOON_STATUS_WAITING_FOR_SEGMENT) {
14131412 netdev_err(tp->dev, "segment ready timeout\n");
....@@ -1420,8 +1419,7 @@
14201419 * the checksum, we can do this once, at the end.
14211420 */
14221421 csum = csum_fold(csum_partial_copy_nocheck(image_data,
1423
- dpage, len,
1424
- 0));
1422
+ dpage, len));
14251423
14261424 iowrite32(len, ioaddr + TYPHOON_REG_BOOT_LENGTH);
14271425 iowrite32(le16_to_cpu((__force __le16)csum),
....@@ -1440,7 +1438,7 @@
14401438 }
14411439 }
14421440
1443
- if(typhoon_wait_interrupt(ioaddr) < 0 ||
1441
+ if (typhoon_wait_interrupt(ioaddr) < 0 ||
14441442 ioread32(ioaddr + TYPHOON_REG_STATUS) !=
14451443 TYPHOON_STATUS_WAITING_FOR_SEGMENT) {
14461444 netdev_err(tp->dev, "final segment ready timeout\n");
....@@ -1449,7 +1447,7 @@
14491447
14501448 iowrite32(TYPHOON_BOOTCMD_DNLD_COMPLETE, ioaddr + TYPHOON_REG_COMMAND);
14511449
1452
- if(typhoon_wait_status(ioaddr, TYPHOON_STATUS_WAITING_FOR_BOOT) < 0) {
1450
+ if (typhoon_wait_status(ioaddr, TYPHOON_STATUS_WAITING_FOR_BOOT) < 0) {
14531451 netdev_err(tp->dev, "boot ready timeout, status 0x%0x\n",
14541452 ioread32(ioaddr + TYPHOON_REG_STATUS));
14551453 goto err_out_irq;
....@@ -1461,7 +1459,7 @@
14611459 iowrite32(irqMasked, ioaddr + TYPHOON_REG_INTR_MASK);
14621460 iowrite32(irqEnabled, ioaddr + TYPHOON_REG_INTR_ENABLE);
14631461
1464
- pci_free_consistent(pdev, PAGE_SIZE, dpage, dpage_dma);
1462
+ dma_free_coherent(&pdev->dev, PAGE_SIZE, dpage, dpage_dma);
14651463
14661464 err_out:
14671465 return err;
....@@ -1472,7 +1470,7 @@
14721470 {
14731471 void __iomem *ioaddr = tp->ioaddr;
14741472
1475
- if(typhoon_wait_status(ioaddr, initial_status) < 0) {
1473
+ if (typhoon_wait_status(ioaddr, initial_status) < 0) {
14761474 netdev_err(tp->dev, "boot ready timeout\n");
14771475 goto out_timeout;
14781476 }
....@@ -1483,7 +1481,7 @@
14831481 iowrite32(TYPHOON_BOOTCMD_REG_BOOT_RECORD,
14841482 ioaddr + TYPHOON_REG_COMMAND);
14851483
1486
- if(typhoon_wait_status(ioaddr, TYPHOON_STATUS_RUNNING) < 0) {
1484
+ if (typhoon_wait_status(ioaddr, TYPHOON_STATUS_RUNNING) < 0) {
14871485 netdev_err(tp->dev, "boot finish timeout (status 0x%x)\n",
14881486 ioread32(ioaddr + TYPHOON_REG_STATUS));
14891487 goto out_timeout;
....@@ -1513,23 +1511,23 @@
15131511 int dma_len;
15141512 int type;
15151513
1516
- while(lastRead != le32_to_cpu(*index)) {
1514
+ while (lastRead != le32_to_cpu(*index)) {
15171515 tx = (struct tx_desc *) (txRing->ringBase + lastRead);
15181516 type = tx->flags & TYPHOON_TYPE_MASK;
15191517
1520
- if(type == TYPHOON_TX_DESC) {
1518
+ if (type == TYPHOON_TX_DESC) {
15211519 /* This tx_desc describes a packet.
15221520 */
15231521 unsigned long ptr = tx->tx_addr;
15241522 struct sk_buff *skb = (struct sk_buff *) ptr;
15251523 dev_kfree_skb_irq(skb);
1526
- } else if(type == TYPHOON_FRAG_DESC) {
1524
+ } else if (type == TYPHOON_FRAG_DESC) {
15271525 /* This tx_desc describes a memory mapping. Free it.
15281526 */
15291527 skb_dma = (dma_addr_t) le32_to_cpu(tx->frag.addr);
15301528 dma_len = le16_to_cpu(tx->len);
1531
- pci_unmap_single(tp->pdev, skb_dma, dma_len,
1532
- PCI_DMA_TODEVICE);
1529
+ dma_unmap_single(&tp->pdev->dev, skb_dma, dma_len,
1530
+ DMA_TO_DEVICE);
15331531 }
15341532
15351533 tx->flags = 0;
....@@ -1548,7 +1546,7 @@
15481546
15491547 /* This will need changing if we start to use the Hi Tx ring. */
15501548 lastRead = typhoon_clean_tx(tp, txRing, index);
1551
- if(netif_queue_stopped(tp->dev) && typhoon_num_free(txRing->lastWrite,
1549
+ if (netif_queue_stopped(tp->dev) && typhoon_num_free(txRing->lastWrite,
15521550 lastRead, TXLO_ENTRIES) > (numDesc + 2))
15531551 netif_wake_queue(tp->dev);
15541552
....@@ -1564,7 +1562,7 @@
15641562 struct basic_ring *ring = &tp->rxBuffRing;
15651563 struct rx_free *r;
15661564
1567
- if((ring->lastWrite + sizeof(*r)) % (RXFREE_ENTRIES * sizeof(*r)) ==
1565
+ if ((ring->lastWrite + sizeof(*r)) % (RXFREE_ENTRIES * sizeof(*r)) ==
15681566 le32_to_cpu(indexes->rxBuffCleared)) {
15691567 /* no room in ring, just drop the skb
15701568 */
....@@ -1595,12 +1593,12 @@
15951593
15961594 rxb->skb = NULL;
15971595
1598
- if((ring->lastWrite + sizeof(*r)) % (RXFREE_ENTRIES * sizeof(*r)) ==
1596
+ if ((ring->lastWrite + sizeof(*r)) % (RXFREE_ENTRIES * sizeof(*r)) ==
15991597 le32_to_cpu(indexes->rxBuffCleared))
16001598 return -ENOMEM;
16011599
16021600 skb = netdev_alloc_skb(tp->dev, PKT_BUF_SZ);
1603
- if(!skb)
1601
+ if (!skb)
16041602 return -ENOMEM;
16051603
16061604 #if 0
....@@ -1610,8 +1608,8 @@
16101608 skb_reserve(skb, 2);
16111609 #endif
16121610
1613
- dma_addr = pci_map_single(tp->pdev, skb->data,
1614
- PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
1611
+ dma_addr = dma_map_single(&tp->pdev->dev, skb->data, PKT_BUF_SZ,
1612
+ DMA_FROM_DEVICE);
16151613
16161614 /* Since no card does 64 bit DAC, the high bits will never
16171615 * change from zero.
....@@ -1647,7 +1645,7 @@
16471645 received = 0;
16481646 local_ready = le32_to_cpu(*ready);
16491647 rxaddr = le32_to_cpu(*cleared);
1650
- while(rxaddr != local_ready && budget > 0) {
1648
+ while (rxaddr != local_ready && budget > 0) {
16511649 rx = (struct rx_desc *) (rxRing->ringBase + rxaddr);
16521650 idx = rx->addr;
16531651 rxb = &tp->rxbuffers[idx];
....@@ -1656,36 +1654,35 @@
16561654
16571655 typhoon_inc_rx_index(&rxaddr, 1);
16581656
1659
- if(rx->flags & TYPHOON_RX_ERROR) {
1657
+ if (rx->flags & TYPHOON_RX_ERROR) {
16601658 typhoon_recycle_rx_skb(tp, idx);
16611659 continue;
16621660 }
16631661
16641662 pkt_len = le16_to_cpu(rx->frameLen);
16651663
1666
- if(pkt_len < rx_copybreak &&
1664
+ if (pkt_len < rx_copybreak &&
16671665 (new_skb = netdev_alloc_skb(tp->dev, pkt_len + 2)) != NULL) {
16681666 skb_reserve(new_skb, 2);
1669
- pci_dma_sync_single_for_cpu(tp->pdev, dma_addr,
1670
- PKT_BUF_SZ,
1671
- PCI_DMA_FROMDEVICE);
1667
+ dma_sync_single_for_cpu(&tp->pdev->dev, dma_addr,
1668
+ PKT_BUF_SZ, DMA_FROM_DEVICE);
16721669 skb_copy_to_linear_data(new_skb, skb->data, pkt_len);
1673
- pci_dma_sync_single_for_device(tp->pdev, dma_addr,
1674
- PKT_BUF_SZ,
1675
- PCI_DMA_FROMDEVICE);
1670
+ dma_sync_single_for_device(&tp->pdev->dev, dma_addr,
1671
+ PKT_BUF_SZ,
1672
+ DMA_FROM_DEVICE);
16761673 skb_put(new_skb, pkt_len);
16771674 typhoon_recycle_rx_skb(tp, idx);
16781675 } else {
16791676 new_skb = skb;
16801677 skb_put(new_skb, pkt_len);
1681
- pci_unmap_single(tp->pdev, dma_addr, PKT_BUF_SZ,
1682
- PCI_DMA_FROMDEVICE);
1678
+ dma_unmap_single(&tp->pdev->dev, dma_addr, PKT_BUF_SZ,
1679
+ DMA_FROM_DEVICE);
16831680 typhoon_alloc_rx_skb(tp, idx);
16841681 }
16851682 new_skb->protocol = eth_type_trans(new_skb, tp->dev);
16861683 csum_bits = rx->rxStatus & (TYPHOON_RX_IP_CHK_GOOD |
16871684 TYPHOON_RX_UDP_CHK_GOOD | TYPHOON_RX_TCP_CHK_GOOD);
1688
- if(csum_bits ==
1685
+ if (csum_bits ==
16891686 (TYPHOON_RX_IP_CHK_GOOD | TYPHOON_RX_TCP_CHK_GOOD) ||
16901687 csum_bits ==
16911688 (TYPHOON_RX_IP_CHK_GOOD | TYPHOON_RX_UDP_CHK_GOOD)) {
....@@ -1711,11 +1708,11 @@
17111708 {
17121709 u32 i;
17131710
1714
- for(i = 0; i < RXENT_ENTRIES; i++) {
1711
+ for (i = 0; i < RXENT_ENTRIES; i++) {
17151712 struct rxbuff_ent *rxb = &tp->rxbuffers[i];
1716
- if(rxb->skb)
1713
+ if (rxb->skb)
17171714 continue;
1718
- if(typhoon_alloc_rx_skb(tp, i) < 0)
1715
+ if (typhoon_alloc_rx_skb(tp, i) < 0)
17191716 break;
17201717 }
17211718 }
....@@ -1728,25 +1725,25 @@
17281725 int work_done;
17291726
17301727 rmb();
1731
- if(!tp->awaiting_resp && indexes->respReady != indexes->respCleared)
1728
+ if (!tp->awaiting_resp && indexes->respReady != indexes->respCleared)
17321729 typhoon_process_response(tp, 0, NULL);
17331730
1734
- if(le32_to_cpu(indexes->txLoCleared) != tp->txLoRing.lastRead)
1731
+ if (le32_to_cpu(indexes->txLoCleared) != tp->txLoRing.lastRead)
17351732 typhoon_tx_complete(tp, &tp->txLoRing, &indexes->txLoCleared);
17361733
17371734 work_done = 0;
17381735
1739
- if(indexes->rxHiCleared != indexes->rxHiReady) {
1736
+ if (indexes->rxHiCleared != indexes->rxHiReady) {
17401737 work_done += typhoon_rx(tp, &tp->rxHiRing, &indexes->rxHiReady,
17411738 &indexes->rxHiCleared, budget);
17421739 }
17431740
1744
- if(indexes->rxLoCleared != indexes->rxLoReady) {
1741
+ if (indexes->rxLoCleared != indexes->rxLoReady) {
17451742 work_done += typhoon_rx(tp, &tp->rxLoRing, &indexes->rxLoReady,
17461743 &indexes->rxLoCleared, budget - work_done);
17471744 }
17481745
1749
- if(le32_to_cpu(indexes->rxBuffCleared) == tp->rxBuffRing.lastWrite) {
1746
+ if (le32_to_cpu(indexes->rxBuffCleared) == tp->rxBuffRing.lastWrite) {
17501747 /* rxBuff ring is empty, try to fill it. */
17511748 typhoon_fill_free_ring(tp);
17521749 }
....@@ -1770,7 +1767,7 @@
17701767 u32 intr_status;
17711768
17721769 intr_status = ioread32(ioaddr + TYPHOON_REG_INTR_STATUS);
1773
- if(!(intr_status & TYPHOON_INTR_HOST_INT))
1770
+ if (!(intr_status & TYPHOON_INTR_HOST_INT))
17741771 return IRQ_NONE;
17751772
17761773 iowrite32(intr_status, ioaddr + TYPHOON_REG_INTR_STATUS);
....@@ -1790,11 +1787,11 @@
17901787 {
17911788 u32 i;
17921789
1793
- for(i = 0; i < RXENT_ENTRIES; i++) {
1790
+ for (i = 0; i < RXENT_ENTRIES; i++) {
17941791 struct rxbuff_ent *rxb = &tp->rxbuffers[i];
1795
- if(rxb->skb) {
1796
- pci_unmap_single(tp->pdev, rxb->dma_addr, PKT_BUF_SZ,
1797
- PCI_DMA_FROMDEVICE);
1792
+ if (rxb->skb) {
1793
+ dma_unmap_single(&tp->pdev->dev, rxb->dma_addr,
1794
+ PKT_BUF_SZ, DMA_FROM_DEVICE);
17981795 dev_kfree_skb(rxb->skb);
17991796 rxb->skb = NULL;
18001797 }
....@@ -1802,9 +1799,8 @@
18021799 }
18031800
18041801 static int
1805
-typhoon_sleep(struct typhoon *tp, pci_power_t state, __le16 events)
1802
+typhoon_sleep_early(struct typhoon *tp, __le16 events)
18061803 {
1807
- struct pci_dev *pdev = tp->pdev;
18081804 void __iomem *ioaddr = tp->ioaddr;
18091805 struct cmd_desc xp_cmd;
18101806 int err;
....@@ -1812,7 +1808,7 @@
18121808 INIT_COMMAND_WITH_RESPONSE(&xp_cmd, TYPHOON_CMD_ENABLE_WAKE_EVENTS);
18131809 xp_cmd.parm1 = events;
18141810 err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
1815
- if(err < 0) {
1811
+ if (err < 0) {
18161812 netdev_err(tp->dev, "typhoon_sleep(): wake events cmd err %d\n",
18171813 err);
18181814 return err;
....@@ -1820,12 +1816,12 @@
18201816
18211817 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_GOTO_SLEEP);
18221818 err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
1823
- if(err < 0) {
1819
+ if (err < 0) {
18241820 netdev_err(tp->dev, "typhoon_sleep(): sleep cmd err %d\n", err);
18251821 return err;
18261822 }
18271823
1828
- if(typhoon_wait_status(ioaddr, TYPHOON_STATUS_SLEEPING) < 0)
1824
+ if (typhoon_wait_status(ioaddr, TYPHOON_STATUS_SLEEPING) < 0)
18291825 return -ETIMEDOUT;
18301826
18311827 /* Since we cannot monitor the status of the link while sleeping,
....@@ -1833,26 +1829,35 @@
18331829 */
18341830 netif_carrier_off(tp->dev);
18351831
1832
+ return 0;
1833
+}
1834
+
1835
+static int
1836
+typhoon_sleep(struct typhoon *tp, pci_power_t state, __le16 events)
1837
+{
1838
+ int err;
1839
+
1840
+ err = typhoon_sleep_early(tp, events);
1841
+
1842
+ if (err)
1843
+ return err;
1844
+
18361845 pci_enable_wake(tp->pdev, state, 1);
1837
- pci_disable_device(pdev);
1838
- return pci_set_power_state(pdev, state);
1846
+ pci_disable_device(tp->pdev);
1847
+ return pci_set_power_state(tp->pdev, state);
18391848 }
18401849
18411850 static int
18421851 typhoon_wakeup(struct typhoon *tp, int wait_type)
18431852 {
1844
- struct pci_dev *pdev = tp->pdev;
18451853 void __iomem *ioaddr = tp->ioaddr;
1846
-
1847
- pci_set_power_state(pdev, PCI_D0);
1848
- pci_restore_state(pdev);
18491854
18501855 /* Post 2.x.x versions of the Sleep Image require a reset before
18511856 * we can download the Runtime Image. But let's not make users of
18521857 * the old firmware pay for the reset.
18531858 */
18541859 iowrite32(TYPHOON_BOOTCMD_WAKEUP, ioaddr + TYPHOON_REG_COMMAND);
1855
- if(typhoon_wait_status(ioaddr, TYPHOON_STATUS_WAITING_FOR_HOST) < 0 ||
1860
+ if (typhoon_wait_status(ioaddr, TYPHOON_STATUS_WAITING_FOR_HOST) < 0 ||
18561861 (tp->capabilities & TYPHOON_WAKEUP_NEEDS_RESET))
18571862 return typhoon_reset(ioaddr, wait_type);
18581863
....@@ -1871,12 +1876,12 @@
18711876 typhoon_fill_free_ring(tp);
18721877
18731878 err = typhoon_download_firmware(tp);
1874
- if(err < 0) {
1879
+ if (err < 0) {
18751880 netdev_err(tp->dev, "cannot load runtime on 3XP\n");
18761881 goto error_out;
18771882 }
18781883
1879
- if(typhoon_boot_3XP(tp, TYPHOON_STATUS_WAITING_FOR_BOOT) < 0) {
1884
+ if (typhoon_boot_3XP(tp, TYPHOON_STATUS_WAITING_FOR_BOOT) < 0) {
18801885 netdev_err(tp->dev, "cannot boot 3XP\n");
18811886 err = -EIO;
18821887 goto error_out;
....@@ -1885,14 +1890,14 @@
18851890 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_MAX_PKT_SIZE);
18861891 xp_cmd.parm1 = cpu_to_le16(PKT_BUF_SZ);
18871892 err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
1888
- if(err < 0)
1893
+ if (err < 0)
18891894 goto error_out;
18901895
18911896 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_MAC_ADDRESS);
18921897 xp_cmd.parm1 = cpu_to_le16(ntohs(*(__be16 *)&dev->dev_addr[0]));
18931898 xp_cmd.parm2 = cpu_to_le32(ntohl(*(__be32 *)&dev->dev_addr[2]));
18941899 err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
1895
- if(err < 0)
1900
+ if (err < 0)
18961901 goto error_out;
18971902
18981903 /* Disable IRQ coalescing -- we can reenable it when 3Com gives
....@@ -1901,38 +1906,38 @@
19011906 INIT_COMMAND_WITH_RESPONSE(&xp_cmd, TYPHOON_CMD_IRQ_COALESCE_CTRL);
19021907 xp_cmd.parm1 = 0;
19031908 err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
1904
- if(err < 0)
1909
+ if (err < 0)
19051910 goto error_out;
19061911
19071912 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_XCVR_SELECT);
19081913 xp_cmd.parm1 = tp->xcvr_select;
19091914 err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
1910
- if(err < 0)
1915
+ if (err < 0)
19111916 goto error_out;
19121917
19131918 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_VLAN_TYPE_WRITE);
19141919 xp_cmd.parm1 = cpu_to_le16(ETH_P_8021Q);
19151920 err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
1916
- if(err < 0)
1921
+ if (err < 0)
19171922 goto error_out;
19181923
19191924 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_OFFLOAD_TASKS);
19201925 xp_cmd.parm2 = tp->offload;
19211926 xp_cmd.parm3 = tp->offload;
19221927 err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
1923
- if(err < 0)
1928
+ if (err < 0)
19241929 goto error_out;
19251930
19261931 typhoon_set_rx_mode(dev);
19271932
19281933 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_TX_ENABLE);
19291934 err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
1930
- if(err < 0)
1935
+ if (err < 0)
19311936 goto error_out;
19321937
19331938 INIT_COMMAND_WITH_RESPONSE(&xp_cmd, TYPHOON_CMD_RX_ENABLE);
19341939 err = typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
1935
- if(err < 0)
1940
+ if (err < 0)
19361941 goto error_out;
19371942
19381943 tp->card_state = Running;
....@@ -1972,13 +1977,13 @@
19721977 /* Wait 1/2 sec for any outstanding transmits to occur
19731978 * We'll cleanup after the reset if this times out.
19741979 */
1975
- for(i = 0; i < TYPHOON_WAIT_TIMEOUT; i++) {
1976
- if(indexes->txLoCleared == cpu_to_le32(txLo->lastWrite))
1980
+ for (i = 0; i < TYPHOON_WAIT_TIMEOUT; i++) {
1981
+ if (indexes->txLoCleared == cpu_to_le32(txLo->lastWrite))
19771982 break;
19781983 udelay(TYPHOON_UDELAY);
19791984 }
19801985
1981
- if(i == TYPHOON_WAIT_TIMEOUT)
1986
+ if (i == TYPHOON_WAIT_TIMEOUT)
19821987 netdev_err(tp->dev, "halt timed out waiting for Tx to complete\n");
19831988
19841989 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_TX_DISABLE);
....@@ -1995,16 +2000,16 @@
19952000 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_HALT);
19962001 typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL);
19972002
1998
- if(typhoon_wait_status(ioaddr, TYPHOON_STATUS_HALTED) < 0)
2003
+ if (typhoon_wait_status(ioaddr, TYPHOON_STATUS_HALTED) < 0)
19992004 netdev_err(tp->dev, "timed out waiting for 3XP to halt\n");
20002005
2001
- if(typhoon_reset(ioaddr, wait_type) < 0) {
2006
+ if (typhoon_reset(ioaddr, wait_type) < 0) {
20022007 netdev_err(tp->dev, "unable to reset 3XP\n");
20032008 return -ETIMEDOUT;
20042009 }
20052010
20062011 /* cleanup any outstanding Tx packets */
2007
- if(indexes->txLoCleared != cpu_to_le32(txLo->lastWrite)) {
2012
+ if (indexes->txLoCleared != cpu_to_le32(txLo->lastWrite)) {
20082013 indexes->txLoCleared = cpu_to_le32(txLo->lastWrite);
20092014 typhoon_clean_tx(tp, &tp->txLoRing, &indexes->txLoCleared);
20102015 }
....@@ -2013,11 +2018,11 @@
20132018 }
20142019
20152020 static void
2016
-typhoon_tx_timeout(struct net_device *dev)
2021
+typhoon_tx_timeout(struct net_device *dev, unsigned int txqueue)
20172022 {
20182023 struct typhoon *tp = netdev_priv(dev);
20192024
2020
- if(typhoon_reset(tp->ioaddr, WaitNoSleep) < 0) {
2025
+ if (typhoon_reset(tp->ioaddr, WaitNoSleep) < 0) {
20212026 netdev_warn(dev, "could not reset in tx timeout\n");
20222027 goto truly_dead;
20232028 }
....@@ -2026,7 +2031,7 @@
20262031 typhoon_clean_tx(tp, &tp->txLoRing, &tp->indexes->txLoCleared);
20272032 typhoon_free_rx_rings(tp);
20282033
2029
- if(typhoon_start_runtime(tp) < 0) {
2034
+ if (typhoon_start_runtime(tp) < 0) {
20302035 netdev_err(dev, "could not start runtime in tx timeout\n");
20312036 goto truly_dead;
20322037 }
....@@ -2050,21 +2055,24 @@
20502055 if (err)
20512056 goto out;
20522057
2058
+ pci_set_power_state(tp->pdev, PCI_D0);
2059
+ pci_restore_state(tp->pdev);
2060
+
20532061 err = typhoon_wakeup(tp, WaitSleep);
2054
- if(err < 0) {
2062
+ if (err < 0) {
20552063 netdev_err(dev, "unable to wakeup device\n");
20562064 goto out_sleep;
20572065 }
20582066
20592067 err = request_irq(dev->irq, typhoon_interrupt, IRQF_SHARED,
20602068 dev->name, dev);
2061
- if(err < 0)
2069
+ if (err < 0)
20622070 goto out_sleep;
20632071
20642072 napi_enable(&tp->napi);
20652073
20662074 err = typhoon_start_runtime(tp);
2067
- if(err < 0) {
2075
+ if (err < 0) {
20682076 napi_disable(&tp->napi);
20692077 goto out_irq;
20702078 }
....@@ -2076,13 +2084,13 @@
20762084 free_irq(dev->irq, dev);
20772085
20782086 out_sleep:
2079
- if(typhoon_boot_3XP(tp, TYPHOON_STATUS_WAITING_FOR_HOST) < 0) {
2087
+ if (typhoon_boot_3XP(tp, TYPHOON_STATUS_WAITING_FOR_HOST) < 0) {
20802088 netdev_err(dev, "unable to reboot into sleep img\n");
20812089 typhoon_reset(tp->ioaddr, NoWait);
20822090 goto out;
20832091 }
20842092
2085
- if(typhoon_sleep(tp, PCI_D3hot, 0) < 0)
2093
+ if (typhoon_sleep(tp, PCI_D3hot, 0) < 0)
20862094 netdev_err(dev, "unable to go back to sleep\n");
20872095
20882096 out:
....@@ -2097,7 +2105,7 @@
20972105 netif_stop_queue(dev);
20982106 napi_disable(&tp->napi);
20992107
2100
- if(typhoon_stop_runtime(tp, WaitSleep) < 0)
2108
+ if (typhoon_stop_runtime(tp, WaitSleep) < 0)
21012109 netdev_err(dev, "unable to stop runtime\n");
21022110
21032111 /* Make sure there is no irq handler running on a different CPU. */
....@@ -2106,33 +2114,32 @@
21062114 typhoon_free_rx_rings(tp);
21072115 typhoon_init_rings(tp);
21082116
2109
- if(typhoon_boot_3XP(tp, TYPHOON_STATUS_WAITING_FOR_HOST) < 0)
2117
+ if (typhoon_boot_3XP(tp, TYPHOON_STATUS_WAITING_FOR_HOST) < 0)
21102118 netdev_err(dev, "unable to boot sleep image\n");
21112119
2112
- if(typhoon_sleep(tp, PCI_D3hot, 0) < 0)
2120
+ if (typhoon_sleep(tp, PCI_D3hot, 0) < 0)
21132121 netdev_err(dev, "unable to put card to sleep\n");
21142122
21152123 return 0;
21162124 }
21172125
2118
-#ifdef CONFIG_PM
2119
-static int
2120
-typhoon_resume(struct pci_dev *pdev)
2126
+static int __maybe_unused
2127
+typhoon_resume(struct device *dev_d)
21212128 {
2122
- struct net_device *dev = pci_get_drvdata(pdev);
2129
+ struct net_device *dev = dev_get_drvdata(dev_d);
21232130 struct typhoon *tp = netdev_priv(dev);
21242131
21252132 /* If we're down, resume when we are upped.
21262133 */
2127
- if(!netif_running(dev))
2134
+ if (!netif_running(dev))
21282135 return 0;
21292136
2130
- if(typhoon_wakeup(tp, WaitNoSleep) < 0) {
2137
+ if (typhoon_wakeup(tp, WaitNoSleep) < 0) {
21312138 netdev_err(dev, "critical: could not wake up in resume\n");
21322139 goto reset;
21332140 }
21342141
2135
- if(typhoon_start_runtime(tp) < 0) {
2142
+ if (typhoon_start_runtime(tp) < 0) {
21362143 netdev_err(dev, "critical: could not start runtime in resume\n");
21372144 goto reset;
21382145 }
....@@ -2145,25 +2152,26 @@
21452152 return -EBUSY;
21462153 }
21472154
2148
-static int
2149
-typhoon_suspend(struct pci_dev *pdev, pm_message_t state)
2155
+static int __maybe_unused
2156
+typhoon_suspend(struct device *dev_d)
21502157 {
2158
+ struct pci_dev *pdev = to_pci_dev(dev_d);
21512159 struct net_device *dev = pci_get_drvdata(pdev);
21522160 struct typhoon *tp = netdev_priv(dev);
21532161 struct cmd_desc xp_cmd;
21542162
21552163 /* If we're down, we're already suspended.
21562164 */
2157
- if(!netif_running(dev))
2165
+ if (!netif_running(dev))
21582166 return 0;
21592167
21602168 /* TYPHOON_OFFLOAD_VLAN is always on now, so this doesn't work */
2161
- if(tp->wol_events & TYPHOON_WAKE_MAGIC_PKT)
2169
+ if (tp->wol_events & TYPHOON_WAKE_MAGIC_PKT)
21622170 netdev_warn(dev, "cannot do WAKE_MAGIC with VLAN offloading\n");
21632171
21642172 netif_device_detach(dev);
21652173
2166
- if(typhoon_stop_runtime(tp, WaitNoSleep) < 0) {
2174
+ if (typhoon_stop_runtime(tp, WaitNoSleep) < 0) {
21672175 netdev_err(dev, "unable to stop runtime\n");
21682176 goto need_resume;
21692177 }
....@@ -2171,7 +2179,7 @@
21712179 typhoon_free_rx_rings(tp);
21722180 typhoon_init_rings(tp);
21732181
2174
- if(typhoon_boot_3XP(tp, TYPHOON_STATUS_WAITING_FOR_HOST) < 0) {
2182
+ if (typhoon_boot_3XP(tp, TYPHOON_STATUS_WAITING_FOR_HOST) < 0) {
21752183 netdev_err(dev, "unable to boot sleep image\n");
21762184 goto need_resume;
21772185 }
....@@ -2179,30 +2187,31 @@
21792187 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_MAC_ADDRESS);
21802188 xp_cmd.parm1 = cpu_to_le16(ntohs(*(__be16 *)&dev->dev_addr[0]));
21812189 xp_cmd.parm2 = cpu_to_le32(ntohl(*(__be32 *)&dev->dev_addr[2]));
2182
- if(typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL) < 0) {
2190
+ if (typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL) < 0) {
21832191 netdev_err(dev, "unable to set mac address in suspend\n");
21842192 goto need_resume;
21852193 }
21862194
21872195 INIT_COMMAND_NO_RESPONSE(&xp_cmd, TYPHOON_CMD_SET_RX_FILTER);
21882196 xp_cmd.parm1 = TYPHOON_RX_FILTER_DIRECTED | TYPHOON_RX_FILTER_BROADCAST;
2189
- if(typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL) < 0) {
2197
+ if (typhoon_issue_command(tp, 1, &xp_cmd, 0, NULL) < 0) {
21902198 netdev_err(dev, "unable to set rx filter in suspend\n");
21912199 goto need_resume;
21922200 }
21932201
2194
- if(typhoon_sleep(tp, pci_choose_state(pdev, state), tp->wol_events) < 0) {
2202
+ if (typhoon_sleep_early(tp, tp->wol_events) < 0) {
21952203 netdev_err(dev, "unable to put card to sleep\n");
21962204 goto need_resume;
21972205 }
21982206
2207
+ device_wakeup_enable(dev_d);
2208
+
21992209 return 0;
22002210
22012211 need_resume:
2202
- typhoon_resume(pdev);
2212
+ typhoon_resume(dev_d);
22032213 return -EBUSY;
22042214 }
2205
-#endif
22062215
22072216 static int
22082217 typhoon_test_mmio(struct pci_dev *pdev)
....@@ -2211,10 +2220,10 @@
22112220 int mode = 0;
22122221 u32 val;
22132222
2214
- if(!ioaddr)
2223
+ if (!ioaddr)
22152224 goto out;
22162225
2217
- if(ioread32(ioaddr + TYPHOON_REG_STATUS) !=
2226
+ if (ioread32(ioaddr + TYPHOON_REG_STATUS) !=
22182227 TYPHOON_STATUS_WAITING_FOR_HOST)
22192228 goto out_unmap;
22202229
....@@ -2227,12 +2236,12 @@
22272236 * The 50usec delay is arbitrary -- it could probably be smaller.
22282237 */
22292238 val = ioread32(ioaddr + TYPHOON_REG_INTR_STATUS);
2230
- if((val & TYPHOON_INTR_SELF) == 0) {
2239
+ if ((val & TYPHOON_INTR_SELF) == 0) {
22312240 iowrite32(1, ioaddr + TYPHOON_REG_SELF_INTERRUPT);
22322241 ioread32(ioaddr + TYPHOON_REG_INTR_STATUS);
22332242 udelay(50);
22342243 val = ioread32(ioaddr + TYPHOON_REG_INTR_STATUS);
2235
- if(val & TYPHOON_INTR_SELF)
2244
+ if (val & TYPHOON_INTR_SELF)
22362245 mode = 1;
22372246 }
22382247
....@@ -2245,7 +2254,7 @@
22452254 pci_iounmap(pdev, ioaddr);
22462255
22472256 out:
2248
- if(!mode)
2257
+ if (!mode)
22492258 pr_info("%s: falling back to port IO\n", pci_name(pdev));
22502259 return mode;
22512260 }
....@@ -2276,7 +2285,7 @@
22762285 const char *err_msg;
22772286
22782287 dev = alloc_etherdev(sizeof(*tp));
2279
- if(dev == NULL) {
2288
+ if (dev == NULL) {
22802289 err_msg = "unable to alloc new net device";
22812290 err = -ENOMEM;
22822291 goto error_out;
....@@ -2284,55 +2293,55 @@
22842293 SET_NETDEV_DEV(dev, &pdev->dev);
22852294
22862295 err = pci_enable_device(pdev);
2287
- if(err < 0) {
2296
+ if (err < 0) {
22882297 err_msg = "unable to enable device";
22892298 goto error_out_dev;
22902299 }
22912300
22922301 err = pci_set_mwi(pdev);
2293
- if(err < 0) {
2302
+ if (err < 0) {
22942303 err_msg = "unable to set MWI";
22952304 goto error_out_disable;
22962305 }
22972306
2298
- err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2299
- if(err < 0) {
2307
+ err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
2308
+ if (err < 0) {
23002309 err_msg = "No usable DMA configuration";
23012310 goto error_out_mwi;
23022311 }
23032312
23042313 /* sanity checks on IO and MMIO BARs
23052314 */
2306
- if(!(pci_resource_flags(pdev, 0) & IORESOURCE_IO)) {
2315
+ if (!(pci_resource_flags(pdev, 0) & IORESOURCE_IO)) {
23072316 err_msg = "region #1 not a PCI IO resource, aborting";
23082317 err = -ENODEV;
23092318 goto error_out_mwi;
23102319 }
2311
- if(pci_resource_len(pdev, 0) < 128) {
2320
+ if (pci_resource_len(pdev, 0) < 128) {
23122321 err_msg = "Invalid PCI IO region size, aborting";
23132322 err = -ENODEV;
23142323 goto error_out_mwi;
23152324 }
2316
- if(!(pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
2325
+ if (!(pci_resource_flags(pdev, 1) & IORESOURCE_MEM)) {
23172326 err_msg = "region #1 not a PCI MMIO resource, aborting";
23182327 err = -ENODEV;
23192328 goto error_out_mwi;
23202329 }
2321
- if(pci_resource_len(pdev, 1) < 128) {
2330
+ if (pci_resource_len(pdev, 1) < 128) {
23222331 err_msg = "Invalid PCI MMIO region size, aborting";
23232332 err = -ENODEV;
23242333 goto error_out_mwi;
23252334 }
23262335
23272336 err = pci_request_regions(pdev, KBUILD_MODNAME);
2328
- if(err < 0) {
2337
+ if (err < 0) {
23292338 err_msg = "could not request regions";
23302339 goto error_out_mwi;
23312340 }
23322341
23332342 /* map our registers
23342343 */
2335
- if(use_mmio != 0 && use_mmio != 1)
2344
+ if (use_mmio != 0 && use_mmio != 1)
23362345 use_mmio = typhoon_test_mmio(pdev);
23372346
23382347 ioaddr = pci_iomap(pdev, use_mmio, 128);
....@@ -2344,9 +2353,9 @@
23442353
23452354 /* allocate pci dma space for rx and tx descriptor rings
23462355 */
2347
- shared = pci_alloc_consistent(pdev, sizeof(struct typhoon_shared),
2348
- &shared_dma);
2349
- if(!shared) {
2356
+ shared = dma_alloc_coherent(&pdev->dev, sizeof(struct typhoon_shared),
2357
+ &shared_dma, GFP_KERNEL);
2358
+ if (!shared) {
23502359 err_msg = "could not allocate DMA memory";
23512360 err = -ENOMEM;
23522361 goto error_out_remap;
....@@ -2426,7 +2435,7 @@
24262435 * seem to need a little extra help to get started. Since we don't
24272436 * know how to nudge it along, just kick it.
24282437 */
2429
- if(xp_resp[0].numDesc != 0)
2438
+ if (xp_resp[0].numDesc != 0)
24302439 tp->capabilities |= TYPHOON_WAKEUP_NEEDS_RESET;
24312440
24322441 err = typhoon_sleep(tp, PCI_D3hot, 0);
....@@ -2471,14 +2480,14 @@
24712480 /* xp_resp still contains the response to the READ_VERSIONS command.
24722481 * For debugging, let the user know what version he has.
24732482 */
2474
- if(xp_resp[0].numDesc == 0) {
2483
+ if (xp_resp[0].numDesc == 0) {
24752484 /* This is the Typhoon 1.0 type Sleep Image, last 16 bits
24762485 * of version is Month/Day of build.
24772486 */
24782487 u16 monthday = le32_to_cpu(xp_resp[0].parm2) & 0xffff;
24792488 netdev_info(dev, "Typhoon 1.0 Sleep Image built %02u/%02u/2000\n",
24802489 monthday >> 8, monthday & 0xff);
2481
- } else if(xp_resp[0].numDesc == 2) {
2490
+ } else if (xp_resp[0].numDesc == 2) {
24822491 /* This is the Typhoon 1.1+ type Sleep Image
24832492 */
24842493 u32 sleep_ver = le32_to_cpu(xp_resp[0].parm2);
....@@ -2498,8 +2507,8 @@
24982507 typhoon_reset(ioaddr, NoWait);
24992508
25002509 error_out_dma:
2501
- pci_free_consistent(pdev, sizeof(struct typhoon_shared),
2502
- shared, shared_dma);
2510
+ dma_free_coherent(&pdev->dev, sizeof(struct typhoon_shared), shared,
2511
+ shared_dma);
25032512 error_out_remap:
25042513 pci_iounmap(pdev, ioaddr);
25052514 error_out_regions:
....@@ -2526,23 +2535,22 @@
25262535 pci_restore_state(pdev);
25272536 typhoon_reset(tp->ioaddr, NoWait);
25282537 pci_iounmap(pdev, tp->ioaddr);
2529
- pci_free_consistent(pdev, sizeof(struct typhoon_shared),
2530
- tp->shared, tp->shared_dma);
2538
+ dma_free_coherent(&pdev->dev, sizeof(struct typhoon_shared),
2539
+ tp->shared, tp->shared_dma);
25312540 pci_release_regions(pdev);
25322541 pci_clear_mwi(pdev);
25332542 pci_disable_device(pdev);
25342543 free_netdev(dev);
25352544 }
25362545
2546
+static SIMPLE_DEV_PM_OPS(typhoon_pm_ops, typhoon_suspend, typhoon_resume);
2547
+
25372548 static struct pci_driver typhoon_driver = {
25382549 .name = KBUILD_MODNAME,
25392550 .id_table = typhoon_pci_tbl,
25402551 .probe = typhoon_init_one,
25412552 .remove = typhoon_remove_one,
2542
-#ifdef CONFIG_PM
2543
- .suspend = typhoon_suspend,
2544
- .resume = typhoon_resume,
2545
-#endif
2553
+ .driver.pm = &typhoon_pm_ops,
25462554 };
25472555
25482556 static int __init