--- zzzz-none-000/linux-3.10.107/drivers/atm/nicstar.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/atm/nicstar.c 2021-02-04 17:41:59.000000000 +0000 @@ -52,6 +52,7 @@ #include #include #include +#include #include "nicstar.h" #ifdef CONFIG_ATM_NICSTAR_USE_SUNI #include "suni.h" @@ -72,9 +73,6 @@ #undef GENERAL_DEBUG #undef EXTRA_DEBUG -#undef NS_USE_DESTRUCTORS /* For now keep this undefined unless you know - you're going to use only raw ATM */ - /* Do not touch these */ #ifdef TX_DEBUG @@ -137,11 +135,6 @@ static void drain_scq(ns_dev * card, scq_info * scq, int pos); static void process_rsq(ns_dev * card); static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe); -#ifdef NS_USE_DESTRUCTORS -static void ns_sb_destructor(struct sk_buff *sb); -static void ns_lb_destructor(struct sk_buff *lb); -static void ns_hb_destructor(struct sk_buff *hb); -#endif /* NS_USE_DESTRUCTORS */ static void recycle_rx_buf(ns_dev * card, struct sk_buff *skb); static void recycle_iovec_rx_bufs(ns_dev * card, struct iovec *iov, int count); static void recycle_iov_buf(ns_dev * card, struct sk_buff *iovb); @@ -153,7 +146,6 @@ static void which_list(ns_dev * card, struct sk_buff *skb); #endif static void ns_poll(unsigned long arg); -static int ns_parse_mac(char *mac, unsigned char *esi); static void ns_phy_put(struct atm_dev *dev, unsigned char value, unsigned long addr); static unsigned char ns_phy_get(struct atm_dev *dev, unsigned long addr); @@ -252,10 +244,10 @@ free_scq(card, card->scd2vc[j]->scq, card->scd2vc[j]->tx_vcc); } idr_destroy(&card->idr); - pci_free_consistent(card->pcidev, NS_RSQSIZE + NS_RSQ_ALIGNMENT, - card->rsq.org, card->rsq.dma); - pci_free_consistent(card->pcidev, NS_TSQSIZE + NS_TSQ_ALIGNMENT, - card->tsq.org, card->tsq.dma); + dma_free_coherent(&card->pcidev->dev, NS_RSQSIZE + NS_RSQ_ALIGNMENT, + card->rsq.org, card->rsq.dma); + dma_free_coherent(&card->pcidev->dev, NS_TSQSIZE + NS_TSQ_ALIGNMENT, + card->tsq.org, card->tsq.dma); free_irq(card->pcidev->irq, card); iounmap(card->membase); kfree(card); @@ -370,8 +362,7 @@ ns_init_card_error(card, error); return error; } - if ((pci_set_dma_mask(pcidev, DMA_BIT_MASK(32)) != 0) || - (pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(32)) != 0)) { + if (dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(32)) != 0) { printk(KERN_WARNING "nicstar%d: No suitable DMA available.\n", i); error = 2; @@ -535,9 +526,9 @@ writel(0x00000000, card->membase + VPM); /* Initialize TSQ */ - card->tsq.org = pci_alloc_consistent(card->pcidev, - NS_TSQSIZE + NS_TSQ_ALIGNMENT, - &card->tsq.dma); + card->tsq.org = dma_alloc_coherent(&card->pcidev->dev, + NS_TSQSIZE + NS_TSQ_ALIGNMENT, + &card->tsq.dma, GFP_KERNEL); if (card->tsq.org == NULL) { printk("nicstar%d: can't allocate TSQ.\n", i); error = 10; @@ -554,9 +545,9 @@ PRINTK("nicstar%d: TSQ base at 0x%p.\n", i, card->tsq.base); /* Initialize RSQ */ - card->rsq.org = pci_alloc_consistent(card->pcidev, - NS_RSQSIZE + NS_RSQ_ALIGNMENT, - &card->rsq.dma); + card->rsq.org = dma_alloc_coherent(&card->pcidev->dev, + NS_RSQSIZE + NS_RSQ_ALIGNMENT, + &card->rsq.dma, GFP_KERNEL); if (card->rsq.org == NULL) { printk("nicstar%d: can't allocate RSQ.\n", i); error = 11; @@ -639,9 +630,9 @@ card->hbnr.init = NUM_HB; card->hbnr.max = MAX_HB; - card->sm_handle = 0x00000000; + card->sm_handle = NULL; card->sm_addr = 0x00000000; - card->lg_handle = 0x00000000; + card->lg_handle = NULL; card->lg_addr = 0x00000000; card->efbie = 1; /* To prevent push_rxbufs from enabling the interrupt */ @@ -779,11 +770,10 @@ return error; } - if (ns_parse_mac(mac[i], card->atmdev->esi)) { + if (mac[i] == NULL || !mac_pton(mac[i], card->atmdev->esi)) { nicstar_read_eprom(card->membase, NICSTAR_EPROM_MAC_ADDR_OFFSET, card->atmdev->esi, 6); - if (memcmp(card->atmdev->esi, "\x00\x00\x00\x00\x00\x00", 6) == - 0) { + if (ether_addr_equal(card->atmdev->esi, "\x00\x00\x00\x00\x00\x00")) { nicstar_read_eprom(card->membase, NICSTAR_EPROM_MAC_ADDR_OFFSET_ALT, card->atmdev->esi, 6); @@ -875,7 +865,8 @@ scq = kmalloc(sizeof(scq_info), GFP_KERNEL); if (!scq) return NULL; - scq->org = pci_alloc_consistent(card->pcidev, 2 * size, &scq->dma); + scq->org = dma_alloc_coherent(&card->pcidev->dev, + 2 * size, &scq->dma, GFP_KERNEL); if (!scq->org) { kfree(scq); return NULL; @@ -937,10 +928,10 @@ } } kfree(scq->skb); - pci_free_consistent(card->pcidev, - 2 * (scq->num_entries == VBR_SCQ_NUM_ENTRIES ? - VBR_SCQSIZE : CBR_SCQSIZE), - scq->org, scq->dma); + dma_free_coherent(&card->pcidev->dev, + 2 * (scq->num_entries == VBR_SCQ_NUM_ENTRIES ? + VBR_SCQSIZE : CBR_SCQSIZE), + scq->org, scq->dma); kfree(scq); } @@ -958,11 +949,11 @@ handle2 = NULL; addr2 = 0; handle1 = skb; - addr1 = pci_map_single(card->pcidev, + addr1 = dma_map_single(&card->pcidev->dev, skb->data, (NS_PRV_BUFTYPE(skb) == BUF_SM ? NS_SMSKBSIZE : NS_LGSKBSIZE), - PCI_DMA_TODEVICE); + DMA_TO_DEVICE); NS_PRV_DMA(skb) = addr1; /* save so we can unmap later */ #ifdef GENERAL_DEBUG @@ -980,7 +971,7 @@ addr2 = card->sm_addr; handle2 = card->sm_handle; card->sm_addr = 0x00000000; - card->sm_handle = 0x00000000; + card->sm_handle = NULL; } else { /* (!sm_addr) */ card->sm_addr = addr1; @@ -994,7 +985,7 @@ addr2 = card->lg_addr; handle2 = card->lg_handle; card->lg_addr = 0x00000000; - card->lg_handle = 0x00000000; + card->lg_handle = NULL; } else { /* (!lg_addr) */ card->lg_addr = addr1; @@ -1671,8 +1662,8 @@ ATM_SKB(skb)->vcc = vcc; - NS_PRV_DMA(skb) = pci_map_single(card->pcidev, skb->data, - skb->len, PCI_DMA_TODEVICE); + NS_PRV_DMA(skb) = dma_map_single(&card->pcidev->dev, skb->data, + skb->len, DMA_TO_DEVICE); if (vcc->qos.aal == ATM_AAL5) { buflen = (skb->len + 47 + 8) / 48 * 48; /* Multiple of 48 */ @@ -1740,10 +1731,10 @@ } scq->full = 1; - spin_unlock_irqrestore(&scq->lock, flags); - interruptible_sleep_on_timeout(&scq->scqfull_waitq, - SCQFULL_TIMEOUT); - spin_lock_irqsave(&scq->lock, flags); + wait_event_interruptible_lock_irq_timeout(scq->scqfull_waitq, + scq->tail != scq->next, + scq->lock, + SCQFULL_TIMEOUT); if (scq->full) { spin_unlock_irqrestore(&scq->lock, flags); @@ -1790,10 +1781,10 @@ scq->full = 1; if (has_run++) break; - spin_unlock_irqrestore(&scq->lock, flags); - interruptible_sleep_on_timeout(&scq->scqfull_waitq, - SCQFULL_TIMEOUT); - spin_lock_irqsave(&scq->lock, flags); + wait_event_interruptible_lock_irq_timeout(scq->scqfull_waitq, + scq->tail != scq->next, + scq->lock, + SCQFULL_TIMEOUT); } if (!scq->full) { @@ -1931,10 +1922,10 @@ XPRINTK("nicstar%d: freeing skb at 0x%p (index %d).\n", card->index, skb, i); if (skb != NULL) { - pci_unmap_single(card->pcidev, + dma_unmap_single(&card->pcidev->dev, NS_PRV_DMA(skb), skb->len, - PCI_DMA_TODEVICE); + DMA_TO_DEVICE); vcc = ATM_SKB(skb)->vcc; if (vcc && vcc->pop != NULL) { vcc->pop(vcc, skb); @@ -1993,16 +1984,16 @@ return; } idr_remove(&card->idr, id); - pci_dma_sync_single_for_cpu(card->pcidev, - NS_PRV_DMA(skb), - (NS_PRV_BUFTYPE(skb) == BUF_SM - ? NS_SMSKBSIZE : NS_LGSKBSIZE), - PCI_DMA_FROMDEVICE); - pci_unmap_single(card->pcidev, + dma_sync_single_for_cpu(&card->pcidev->dev, + NS_PRV_DMA(skb), + (NS_PRV_BUFTYPE(skb) == BUF_SM + ? NS_SMSKBSIZE : NS_LGSKBSIZE), + DMA_FROM_DEVICE); + dma_unmap_single(&card->pcidev->dev, NS_PRV_DMA(skb), (NS_PRV_BUFTYPE(skb) == BUF_SM ? NS_SMSKBSIZE : NS_LGSKBSIZE), - PCI_DMA_FROMDEVICE); + DMA_FROM_DEVICE); vpi = ns_rsqe_vpi(rsqe); vci = ns_rsqe_vci(rsqe); if (vpi >= 1UL << card->vpibits || vci >= 1UL << card->vcibits) { @@ -2170,9 +2161,6 @@ } else { skb_put(skb, len); dequeue_sm_buf(card, skb); -#ifdef NS_USE_DESTRUCTORS - skb->destructor = ns_sb_destructor; -#endif /* NS_USE_DESTRUCTORS */ ATM_SKB(skb)->vcc = vcc; __net_timestamp(skb); vcc->push(vcc, skb); @@ -2191,9 +2179,6 @@ } else { skb_put(sb, len); dequeue_sm_buf(card, sb); -#ifdef NS_USE_DESTRUCTORS - sb->destructor = ns_sb_destructor; -#endif /* NS_USE_DESTRUCTORS */ ATM_SKB(sb)->vcc = vcc; __net_timestamp(sb); vcc->push(vcc, sb); @@ -2209,9 +2194,6 @@ atomic_inc(&vcc->stats->rx_drop); } else { dequeue_lg_buf(card, skb); -#ifdef NS_USE_DESTRUCTORS - skb->destructor = ns_lb_destructor; -#endif /* NS_USE_DESTRUCTORS */ skb_push(skb, NS_SMBUFSIZE); skb_copy_from_linear_data(sb, skb->data, NS_SMBUFSIZE); @@ -2323,9 +2305,6 @@ card->index); #endif /* EXTRA_DEBUG */ ATM_SKB(hb)->vcc = vcc; -#ifdef NS_USE_DESTRUCTORS - hb->destructor = ns_hb_destructor; -#endif /* NS_USE_DESTRUCTORS */ __net_timestamp(hb); vcc->push(vcc, hb); atomic_inc(&vcc->stats->rx); @@ -2338,68 +2317,6 @@ } -#ifdef NS_USE_DESTRUCTORS - -static void ns_sb_destructor(struct sk_buff *sb) -{ - ns_dev *card; - u32 stat; - - card = (ns_dev *) ATM_SKB(sb)->vcc->dev->dev_data; - stat = readl(card->membase + STAT); - card->sbfqc = ns_stat_sfbqc_get(stat); - card->lbfqc = ns_stat_lfbqc_get(stat); - - do { - sb = __dev_alloc_skb(NS_SMSKBSIZE, GFP_KERNEL); - if (sb == NULL) - break; - NS_PRV_BUFTYPE(sb) = BUF_SM; - skb_queue_tail(&card->sbpool.queue, sb); - skb_reserve(sb, NS_AAL0_HEADER); - push_rxbufs(card, sb); - } while (card->sbfqc < card->sbnr.min); -} - -static void ns_lb_destructor(struct sk_buff *lb) -{ - ns_dev *card; - u32 stat; - - card = (ns_dev *) ATM_SKB(lb)->vcc->dev->dev_data; - stat = readl(card->membase + STAT); - card->sbfqc = ns_stat_sfbqc_get(stat); - card->lbfqc = ns_stat_lfbqc_get(stat); - - do { - lb = __dev_alloc_skb(NS_LGSKBSIZE, GFP_KERNEL); - if (lb == NULL) - break; - NS_PRV_BUFTYPE(lb) = BUF_LG; - skb_queue_tail(&card->lbpool.queue, lb); - skb_reserve(lb, NS_SMBUFSIZE); - push_rxbufs(card, lb); - } while (card->lbfqc < card->lbnr.min); -} - -static void ns_hb_destructor(struct sk_buff *hb) -{ - ns_dev *card; - - card = (ns_dev *) ATM_SKB(hb)->vcc->dev->dev_data; - - while (card->hbpool.count < card->hbnr.init) { - hb = __dev_alloc_skb(NS_HBUFSIZE, GFP_KERNEL); - if (hb == NULL) - break; - NS_PRV_BUFTYPE(hb) = BUF_NONE; - skb_queue_tail(&card->hbpool.queue, hb); - card->hbpool.count++; - } -} - -#endif /* NS_USE_DESTRUCTORS */ - static void recycle_rx_buf(ns_dev * card, struct sk_buff *skb) { if (unlikely(NS_PRV_BUFTYPE(skb) == BUF_NONE)) { @@ -2428,9 +2345,6 @@ static void dequeue_sm_buf(ns_dev * card, struct sk_buff *sb) { skb_unlink(sb, &card->sbpool.queue); -#ifdef NS_USE_DESTRUCTORS - if (card->sbfqc < card->sbnr.min) -#else if (card->sbfqc < card->sbnr.init) { struct sk_buff *new_sb; if ((new_sb = dev_alloc_skb(NS_SMSKBSIZE)) != NULL) { @@ -2441,7 +2355,6 @@ } } if (card->sbfqc < card->sbnr.init) -#endif /* NS_USE_DESTRUCTORS */ { struct sk_buff *new_sb; if ((new_sb = dev_alloc_skb(NS_SMSKBSIZE)) != NULL) { @@ -2456,9 +2369,6 @@ static void dequeue_lg_buf(ns_dev * card, struct sk_buff *lb) { skb_unlink(lb, &card->lbpool.queue); -#ifdef NS_USE_DESTRUCTORS - if (card->lbfqc < card->lbnr.min) -#else if (card->lbfqc < card->lbnr.init) { struct sk_buff *new_lb; if ((new_lb = dev_alloc_skb(NS_LGSKBSIZE)) != NULL) { @@ -2469,7 +2379,6 @@ } } if (card->lbfqc < card->lbnr.init) -#endif /* NS_USE_DESTRUCTORS */ { struct sk_buff *new_lb; if ((new_lb = dev_alloc_skb(NS_LGSKBSIZE)) != NULL) { @@ -2802,29 +2711,6 @@ PRINTK("nicstar: Leaving ns_poll().\n"); } -static int ns_parse_mac(char *mac, unsigned char *esi) -{ - int i, j; - short byte1, byte0; - - if (mac == NULL || esi == NULL) - return -1; - j = 0; - for (i = 0; i < 6; i++) { - if ((byte1 = hex_to_bin(mac[j++])) < 0) - return -1; - if ((byte0 = hex_to_bin(mac[j++])) < 0) - return -1; - esi[i] = (unsigned char)(byte1 * 16 + byte0); - if (i < 5) { - if (mac[j++] != ':') - return -1; - } - } - return 0; -} - - static void ns_phy_put(struct atm_dev *dev, unsigned char value, unsigned long addr) {