| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2006-2007 PA Semi, Inc | 
|  | 3 | * | 
|  | 4 | * Driver for the PA Semi PWRficient onchip 1G/10G Ethernet MACs | 
|  | 5 | * | 
|  | 6 | * This program is free software; you can redistribute it and/or modify | 
|  | 7 | * it under the terms of the GNU General Public License version 2 as | 
|  | 8 | * published by the Free Software Foundation. | 
|  | 9 | * | 
|  | 10 | * This program is distributed in the hope that it will be useful, | 
|  | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|  | 13 | * GNU General Public License for more details. | 
|  | 14 | * | 
|  | 15 | * You should have received a copy of the GNU General Public License | 
|  | 16 | * along with this program; if not, write to the Free Software | 
|  | 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA | 
|  | 18 | */ | 
|  | 19 |  | 
|  | 20 | #include <linux/init.h> | 
|  | 21 | #include <linux/module.h> | 
|  | 22 | #include <linux/pci.h> | 
|  | 23 | #include <linux/interrupt.h> | 
|  | 24 | #include <linux/dmaengine.h> | 
|  | 25 | #include <linux/delay.h> | 
|  | 26 | #include <linux/netdevice.h> | 
|  | 27 | #include <linux/etherdevice.h> | 
|  | 28 | #include <asm/dma-mapping.h> | 
|  | 29 | #include <linux/in.h> | 
|  | 30 | #include <linux/skbuff.h> | 
|  | 31 |  | 
|  | 32 | #include <linux/ip.h> | 
|  | 33 | #include <linux/tcp.h> | 
|  | 34 | #include <net/checksum.h> | 
|  | 35 |  | 
| Olof Johansson | 771f740 | 2007-05-08 00:47:21 -0500 | [diff] [blame] | 36 | #include <asm/irq.h> | 
|  | 37 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 38 | #include "pasemi_mac.h" | 
|  | 39 |  | 
|  | 40 |  | 
|  | 41 | /* TODO list | 
|  | 42 | * | 
|  | 43 | * - Get rid of pci_{read,write}_config(), map registers with ioremap | 
|  | 44 | *   for performance | 
|  | 45 | * - PHY support | 
|  | 46 | * - Multicast support | 
|  | 47 | * - Large MTU support | 
|  | 48 | * - Other performance improvements | 
|  | 49 | */ | 
|  | 50 |  | 
|  | 51 |  | 
|  | 52 | /* Must be a power of two */ | 
|  | 53 | #define RX_RING_SIZE 512 | 
|  | 54 | #define TX_RING_SIZE 512 | 
|  | 55 |  | 
| Olof Johansson | ceb5136 | 2007-05-08 00:47:49 -0500 | [diff] [blame] | 56 | #define DEFAULT_MSG_ENABLE	  \ | 
|  | 57 | (NETIF_MSG_DRV		| \ | 
|  | 58 | NETIF_MSG_PROBE	| \ | 
|  | 59 | NETIF_MSG_LINK		| \ | 
|  | 60 | NETIF_MSG_TIMER	| \ | 
|  | 61 | NETIF_MSG_IFDOWN	| \ | 
|  | 62 | NETIF_MSG_IFUP		| \ | 
|  | 63 | NETIF_MSG_RX_ERR	| \ | 
|  | 64 | NETIF_MSG_TX_ERR) | 
|  | 65 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 66 | #define TX_RING(mac, num)	((mac)->tx->ring[(num) & (TX_RING_SIZE-1)]) | 
|  | 67 | #define TX_RING_INFO(mac, num)	((mac)->tx->ring_info[(num) & (TX_RING_SIZE-1)]) | 
|  | 68 | #define RX_RING(mac, num)	((mac)->rx->ring[(num) & (RX_RING_SIZE-1)]) | 
|  | 69 | #define RX_RING_INFO(mac, num)	((mac)->rx->ring_info[(num) & (RX_RING_SIZE-1)]) | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 70 | #define RX_BUFF(mac, num)	((mac)->rx->buffers[(num) & (RX_RING_SIZE-1)]) | 
|  | 71 |  | 
| Olof Johansson | 021fa22 | 2007-08-22 09:13:11 -0500 | [diff] [blame] | 72 | #define RING_USED(ring)		(((ring)->next_to_fill - (ring)->next_to_clean) \ | 
|  | 73 | & ((ring)->size - 1)) | 
|  | 74 | #define RING_AVAIL(ring)	((ring->size) - RING_USED(ring)) | 
|  | 75 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 76 | #define BUF_SIZE 1646 /* 1500 MTU + ETH_HLEN + VLAN_HLEN + 2 64B cachelines */ | 
|  | 77 |  | 
| Olof Johansson | ceb5136 | 2007-05-08 00:47:49 -0500 | [diff] [blame] | 78 | MODULE_LICENSE("GPL"); | 
|  | 79 | MODULE_AUTHOR ("Olof Johansson <olof@lixom.net>"); | 
|  | 80 | MODULE_DESCRIPTION("PA Semi PWRficient Ethernet driver"); | 
|  | 81 |  | 
|  | 82 | static int debug = -1;	/* -1 == use DEFAULT_MSG_ENABLE as value */ | 
|  | 83 | module_param(debug, int, 0); | 
|  | 84 | MODULE_PARM_DESC(debug, "PA Semi MAC bitmapped debugging message enable value"); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 85 |  | 
|  | 86 | static struct pasdma_status *dma_status; | 
|  | 87 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 88 | static void write_iob_reg(struct pasemi_mac *mac, unsigned int reg, | 
|  | 89 | unsigned int val) | 
|  | 90 | { | 
| Olof Johansson | b6e05a1 | 2007-09-15 13:44:07 -0700 | [diff] [blame] | 91 | out_le32(mac->iob_regs+reg, val); | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 92 | } | 
|  | 93 |  | 
|  | 94 | static unsigned int read_mac_reg(struct pasemi_mac *mac, unsigned int reg) | 
|  | 95 | { | 
| Olof Johansson | b6e05a1 | 2007-09-15 13:44:07 -0700 | [diff] [blame] | 96 | return in_le32(mac->regs+reg); | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 97 | } | 
|  | 98 |  | 
|  | 99 | static void write_mac_reg(struct pasemi_mac *mac, unsigned int reg, | 
|  | 100 | unsigned int val) | 
|  | 101 | { | 
| Olof Johansson | b6e05a1 | 2007-09-15 13:44:07 -0700 | [diff] [blame] | 102 | out_le32(mac->regs+reg, val); | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 103 | } | 
|  | 104 |  | 
|  | 105 | static unsigned int read_dma_reg(struct pasemi_mac *mac, unsigned int reg) | 
|  | 106 | { | 
| Olof Johansson | b6e05a1 | 2007-09-15 13:44:07 -0700 | [diff] [blame] | 107 | return in_le32(mac->dma_regs+reg); | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 108 | } | 
|  | 109 |  | 
|  | 110 | static void write_dma_reg(struct pasemi_mac *mac, unsigned int reg, | 
|  | 111 | unsigned int val) | 
|  | 112 | { | 
| Olof Johansson | b6e05a1 | 2007-09-15 13:44:07 -0700 | [diff] [blame] | 113 | out_le32(mac->dma_regs+reg, val); | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 114 | } | 
|  | 115 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 116 | static int pasemi_get_mac_addr(struct pasemi_mac *mac) | 
|  | 117 | { | 
|  | 118 | struct pci_dev *pdev = mac->pdev; | 
|  | 119 | struct device_node *dn = pci_device_to_OF_node(pdev); | 
| olof@lixom.net | 1af7f05 | 2007-05-12 14:57:46 -0500 | [diff] [blame] | 120 | int len; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 121 | const u8 *maddr; | 
|  | 122 | u8 addr[6]; | 
|  | 123 |  | 
|  | 124 | if (!dn) { | 
|  | 125 | dev_dbg(&pdev->dev, | 
|  | 126 | "No device node for mac, not configuring\n"); | 
|  | 127 | return -ENOENT; | 
|  | 128 | } | 
|  | 129 |  | 
| olof@lixom.net | 1af7f05 | 2007-05-12 14:57:46 -0500 | [diff] [blame] | 130 | maddr = of_get_property(dn, "local-mac-address", &len); | 
| Olof Johansson | a5fd22e | 2007-05-08 00:48:02 -0500 | [diff] [blame] | 131 |  | 
| olof@lixom.net | 1af7f05 | 2007-05-12 14:57:46 -0500 | [diff] [blame] | 132 | if (maddr && len == 6) { | 
|  | 133 | memcpy(mac->mac_addr, maddr, 6); | 
|  | 134 | return 0; | 
|  | 135 | } | 
|  | 136 |  | 
|  | 137 | /* Some old versions of firmware mistakenly uses mac-address | 
|  | 138 | * (and as a string) instead of a byte array in local-mac-address. | 
|  | 139 | */ | 
|  | 140 |  | 
| Olof Johansson | a5fd22e | 2007-05-08 00:48:02 -0500 | [diff] [blame] | 141 | if (maddr == NULL) | 
| Linus Torvalds | 9028780 | 2007-05-08 11:57:17 -0700 | [diff] [blame] | 142 | maddr = of_get_property(dn, "mac-address", NULL); | 
| Olof Johansson | a5fd22e | 2007-05-08 00:48:02 -0500 | [diff] [blame] | 143 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 144 | if (maddr == NULL) { | 
|  | 145 | dev_warn(&pdev->dev, | 
|  | 146 | "no mac address in device tree, not configuring\n"); | 
|  | 147 | return -ENOENT; | 
|  | 148 | } | 
|  | 149 |  | 
| olof@lixom.net | 1af7f05 | 2007-05-12 14:57:46 -0500 | [diff] [blame] | 150 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 151 | if (sscanf(maddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &addr[0], | 
|  | 152 | &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]) != 6) { | 
|  | 153 | dev_warn(&pdev->dev, | 
|  | 154 | "can't parse mac address, not configuring\n"); | 
|  | 155 | return -EINVAL; | 
|  | 156 | } | 
|  | 157 |  | 
| olof@lixom.net | 1af7f05 | 2007-05-12 14:57:46 -0500 | [diff] [blame] | 158 | memcpy(mac->mac_addr, addr, 6); | 
|  | 159 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 160 | return 0; | 
|  | 161 | } | 
|  | 162 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 163 | static int pasemi_mac_unmap_tx_skb(struct pasemi_mac *mac, | 
|  | 164 | struct sk_buff *skb, | 
|  | 165 | dma_addr_t *dmas) | 
|  | 166 | { | 
|  | 167 | int f; | 
|  | 168 | int nfrags = skb_shinfo(skb)->nr_frags; | 
|  | 169 |  | 
|  | 170 | pci_unmap_single(mac->dma_pdev, dmas[0], skb_headlen(skb), | 
|  | 171 | PCI_DMA_TODEVICE); | 
|  | 172 |  | 
|  | 173 | for (f = 0; f < nfrags; f++) { | 
|  | 174 | skb_frag_t *frag = &skb_shinfo(skb)->frags[f]; | 
|  | 175 |  | 
|  | 176 | pci_unmap_page(mac->dma_pdev, dmas[f+1], frag->size, | 
|  | 177 | PCI_DMA_TODEVICE); | 
|  | 178 | } | 
|  | 179 | dev_kfree_skb_irq(skb); | 
|  | 180 |  | 
|  | 181 | /* Freed descriptor slot + main SKB ptr + nfrags additional ptrs, | 
|  | 182 | * aligned up to a power of 2 | 
|  | 183 | */ | 
|  | 184 | return (nfrags + 3) & ~1; | 
|  | 185 | } | 
|  | 186 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 187 | static int pasemi_mac_setup_rx_resources(struct net_device *dev) | 
|  | 188 | { | 
|  | 189 | struct pasemi_mac_rxring *ring; | 
|  | 190 | struct pasemi_mac *mac = netdev_priv(dev); | 
|  | 191 | int chan_id = mac->dma_rxch; | 
|  | 192 |  | 
|  | 193 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); | 
|  | 194 |  | 
|  | 195 | if (!ring) | 
|  | 196 | goto out_ring; | 
|  | 197 |  | 
|  | 198 | spin_lock_init(&ring->lock); | 
|  | 199 |  | 
| Olof Johansson | 021fa22 | 2007-08-22 09:13:11 -0500 | [diff] [blame] | 200 | ring->size = RX_RING_SIZE; | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 201 | ring->ring_info = kzalloc(sizeof(struct pasemi_mac_buffer) * | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 202 | RX_RING_SIZE, GFP_KERNEL); | 
|  | 203 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 204 | if (!ring->ring_info) | 
|  | 205 | goto out_ring_info; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 206 |  | 
|  | 207 | /* Allocate descriptors */ | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 208 | ring->ring = dma_alloc_coherent(&mac->dma_pdev->dev, | 
|  | 209 | RX_RING_SIZE * sizeof(u64), | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 210 | &ring->dma, GFP_KERNEL); | 
|  | 211 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 212 | if (!ring->ring) | 
|  | 213 | goto out_ring_desc; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 214 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 215 | memset(ring->ring, 0, RX_RING_SIZE * sizeof(u64)); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 216 |  | 
|  | 217 | ring->buffers = dma_alloc_coherent(&mac->dma_pdev->dev, | 
|  | 218 | RX_RING_SIZE * sizeof(u64), | 
|  | 219 | &ring->buf_dma, GFP_KERNEL); | 
|  | 220 | if (!ring->buffers) | 
|  | 221 | goto out_buffers; | 
|  | 222 |  | 
|  | 223 | memset(ring->buffers, 0, RX_RING_SIZE * sizeof(u64)); | 
|  | 224 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 225 | write_dma_reg(mac, PAS_DMA_RXCHAN_BASEL(chan_id), PAS_DMA_RXCHAN_BASEL_BRBL(ring->dma)); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 226 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 227 | write_dma_reg(mac, PAS_DMA_RXCHAN_BASEU(chan_id), | 
|  | 228 | PAS_DMA_RXCHAN_BASEU_BRBH(ring->dma >> 32) | | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 229 | PAS_DMA_RXCHAN_BASEU_SIZ(RX_RING_SIZE >> 3)); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 230 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 231 | write_dma_reg(mac, PAS_DMA_RXCHAN_CFG(chan_id), | 
| Olof Johansson | c0efd52 | 2007-08-22 09:12:52 -0500 | [diff] [blame] | 232 | PAS_DMA_RXCHAN_CFG_HBU(2)); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 233 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 234 | write_dma_reg(mac, PAS_DMA_RXINT_BASEL(mac->dma_if), | 
|  | 235 | PAS_DMA_RXINT_BASEL_BRBL(__pa(ring->buffers))); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 236 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 237 | write_dma_reg(mac, PAS_DMA_RXINT_BASEU(mac->dma_if), | 
|  | 238 | PAS_DMA_RXINT_BASEU_BRBH(__pa(ring->buffers) >> 32) | | 
|  | 239 | PAS_DMA_RXINT_BASEU_SIZ(RX_RING_SIZE >> 3)); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 240 |  | 
| Olof Johansson | c0efd52 | 2007-08-22 09:12:52 -0500 | [diff] [blame] | 241 | write_dma_reg(mac, PAS_DMA_RXINT_CFG(mac->dma_if), | 
|  | 242 | PAS_DMA_RXINT_CFG_DHL(2)); | 
|  | 243 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 244 | ring->next_to_fill = 0; | 
|  | 245 | ring->next_to_clean = 0; | 
|  | 246 |  | 
|  | 247 | snprintf(ring->irq_name, sizeof(ring->irq_name), | 
|  | 248 | "%s rx", dev->name); | 
|  | 249 | mac->rx = ring; | 
|  | 250 |  | 
|  | 251 | return 0; | 
|  | 252 |  | 
|  | 253 | out_buffers: | 
|  | 254 | dma_free_coherent(&mac->dma_pdev->dev, | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 255 | RX_RING_SIZE * sizeof(u64), | 
|  | 256 | mac->rx->ring, mac->rx->dma); | 
|  | 257 | out_ring_desc: | 
|  | 258 | kfree(ring->ring_info); | 
|  | 259 | out_ring_info: | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 260 | kfree(ring); | 
|  | 261 | out_ring: | 
|  | 262 | return -ENOMEM; | 
|  | 263 | } | 
|  | 264 |  | 
|  | 265 |  | 
|  | 266 | static int pasemi_mac_setup_tx_resources(struct net_device *dev) | 
|  | 267 | { | 
|  | 268 | struct pasemi_mac *mac = netdev_priv(dev); | 
|  | 269 | u32 val; | 
|  | 270 | int chan_id = mac->dma_txch; | 
|  | 271 | struct pasemi_mac_txring *ring; | 
|  | 272 |  | 
|  | 273 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); | 
|  | 274 | if (!ring) | 
|  | 275 | goto out_ring; | 
|  | 276 |  | 
|  | 277 | spin_lock_init(&ring->lock); | 
|  | 278 |  | 
| Olof Johansson | 021fa22 | 2007-08-22 09:13:11 -0500 | [diff] [blame] | 279 | ring->size = TX_RING_SIZE; | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 280 | ring->ring_info = kzalloc(sizeof(struct pasemi_mac_buffer) * | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 281 | TX_RING_SIZE, GFP_KERNEL); | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 282 | if (!ring->ring_info) | 
|  | 283 | goto out_ring_info; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 284 |  | 
|  | 285 | /* Allocate descriptors */ | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 286 | ring->ring = dma_alloc_coherent(&mac->dma_pdev->dev, | 
|  | 287 | TX_RING_SIZE * sizeof(u64), | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 288 | &ring->dma, GFP_KERNEL); | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 289 | if (!ring->ring) | 
|  | 290 | goto out_ring_desc; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 291 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 292 | memset(ring->ring, 0, TX_RING_SIZE * sizeof(u64)); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 293 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 294 | write_dma_reg(mac, PAS_DMA_TXCHAN_BASEL(chan_id), | 
|  | 295 | PAS_DMA_TXCHAN_BASEL_BRBL(ring->dma)); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 296 | val = PAS_DMA_TXCHAN_BASEU_BRBH(ring->dma >> 32); | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 297 | val |= PAS_DMA_TXCHAN_BASEU_SIZ(TX_RING_SIZE >> 3); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 298 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 299 | write_dma_reg(mac, PAS_DMA_TXCHAN_BASEU(chan_id), val); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 300 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 301 | write_dma_reg(mac, PAS_DMA_TXCHAN_CFG(chan_id), | 
|  | 302 | PAS_DMA_TXCHAN_CFG_TY_IFACE | | 
|  | 303 | PAS_DMA_TXCHAN_CFG_TATTR(mac->dma_if) | | 
|  | 304 | PAS_DMA_TXCHAN_CFG_UP | | 
|  | 305 | PAS_DMA_TXCHAN_CFG_WT(2)); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 306 |  | 
| Olof Johansson | 021fa22 | 2007-08-22 09:13:11 -0500 | [diff] [blame] | 307 | ring->next_to_fill = 0; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 308 | ring->next_to_clean = 0; | 
|  | 309 |  | 
|  | 310 | snprintf(ring->irq_name, sizeof(ring->irq_name), | 
|  | 311 | "%s tx", dev->name); | 
|  | 312 | mac->tx = ring; | 
|  | 313 |  | 
|  | 314 | return 0; | 
|  | 315 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 316 | out_ring_desc: | 
|  | 317 | kfree(ring->ring_info); | 
|  | 318 | out_ring_info: | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 319 | kfree(ring); | 
|  | 320 | out_ring: | 
|  | 321 | return -ENOMEM; | 
|  | 322 | } | 
|  | 323 |  | 
|  | 324 | static void pasemi_mac_free_tx_resources(struct net_device *dev) | 
|  | 325 | { | 
|  | 326 | struct pasemi_mac *mac = netdev_priv(dev); | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 327 | unsigned int i, j; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 328 | struct pasemi_mac_buffer *info; | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 329 | dma_addr_t dmas[MAX_SKB_FRAGS+1]; | 
|  | 330 | int freed; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 331 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 332 | for (i = 0; i < TX_RING_SIZE; i += freed) { | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 333 | info = &TX_RING_INFO(mac, i+1); | 
|  | 334 | if (info->dma && info->skb) { | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 335 | for (j = 0; j <= skb_shinfo(info->skb)->nr_frags; j++) | 
|  | 336 | dmas[j] = TX_RING_INFO(mac, i+1+j).dma; | 
|  | 337 | freed = pasemi_mac_unmap_tx_skb(mac, info->skb, dmas); | 
|  | 338 | } else | 
|  | 339 | freed = 2; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 340 | } | 
|  | 341 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 342 | for (i = 0; i < TX_RING_SIZE; i++) | 
|  | 343 | TX_RING(mac, i) = 0; | 
|  | 344 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 345 | dma_free_coherent(&mac->dma_pdev->dev, | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 346 | TX_RING_SIZE * sizeof(u64), | 
|  | 347 | mac->tx->ring, mac->tx->dma); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 348 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 349 | kfree(mac->tx->ring_info); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 350 | kfree(mac->tx); | 
|  | 351 | mac->tx = NULL; | 
|  | 352 | } | 
|  | 353 |  | 
|  | 354 | static void pasemi_mac_free_rx_resources(struct net_device *dev) | 
|  | 355 | { | 
|  | 356 | struct pasemi_mac *mac = netdev_priv(dev); | 
|  | 357 | unsigned int i; | 
|  | 358 | struct pasemi_mac_buffer *info; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 359 |  | 
|  | 360 | for (i = 0; i < RX_RING_SIZE; i++) { | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 361 | info = &RX_RING_INFO(mac, i); | 
|  | 362 | if (info->skb && info->dma) { | 
|  | 363 | pci_unmap_single(mac->dma_pdev, | 
|  | 364 | info->dma, | 
|  | 365 | info->skb->len, | 
|  | 366 | PCI_DMA_FROMDEVICE); | 
|  | 367 | dev_kfree_skb_any(info->skb); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 368 | } | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 369 | info->dma = 0; | 
|  | 370 | info->skb = NULL; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 371 | } | 
|  | 372 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 373 | for (i = 0; i < RX_RING_SIZE; i++) | 
|  | 374 | RX_RING(mac, i) = 0; | 
|  | 375 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 376 | dma_free_coherent(&mac->dma_pdev->dev, | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 377 | RX_RING_SIZE * sizeof(u64), | 
|  | 378 | mac->rx->ring, mac->rx->dma); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 379 |  | 
|  | 380 | dma_free_coherent(&mac->dma_pdev->dev, RX_RING_SIZE * sizeof(u64), | 
|  | 381 | mac->rx->buffers, mac->rx->buf_dma); | 
|  | 382 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 383 | kfree(mac->rx->ring_info); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 384 | kfree(mac->rx); | 
|  | 385 | mac->rx = NULL; | 
|  | 386 | } | 
|  | 387 |  | 
| Olof Johansson | 928773c | 2007-09-26 16:25:06 -0500 | [diff] [blame] | 388 | static void pasemi_mac_replenish_rx_ring(struct net_device *dev, int limit) | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 389 | { | 
|  | 390 | struct pasemi_mac *mac = netdev_priv(dev); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 391 | int start = mac->rx->next_to_fill; | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 392 | unsigned int fill, count; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 393 |  | 
| Olof Johansson | cd4ceb2 | 2007-05-08 00:47:45 -0500 | [diff] [blame] | 394 | if (limit <= 0) | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 395 | return; | 
|  | 396 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 397 | fill = start; | 
| Olof Johansson | 928773c | 2007-09-26 16:25:06 -0500 | [diff] [blame] | 398 | for (count = 0; count < limit; count++) { | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 399 | struct pasemi_mac_buffer *info = &RX_RING_INFO(mac, fill); | 
|  | 400 | u64 *buff = &RX_BUFF(mac, fill); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 401 | struct sk_buff *skb; | 
|  | 402 | dma_addr_t dma; | 
|  | 403 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 404 | /* Entry in use? */ | 
|  | 405 | WARN_ON(*buff); | 
|  | 406 |  | 
| Olof Johansson | 9f05cfe | 2007-05-08 00:47:37 -0500 | [diff] [blame] | 407 | /* skb might still be in there for recycle on short receives */ | 
|  | 408 | if (info->skb) | 
|  | 409 | skb = info->skb; | 
|  | 410 | else | 
|  | 411 | skb = dev_alloc_skb(BUF_SIZE); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 412 |  | 
| Olof Johansson | 9f05cfe | 2007-05-08 00:47:37 -0500 | [diff] [blame] | 413 | if (unlikely(!skb)) | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 414 | break; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 415 |  | 
| Olof Johansson | 18eec69 | 2007-10-02 16:25:14 -0500 | [diff] [blame] | 416 | dma = pci_map_single(mac->dma_pdev, skb->data, BUF_SIZE, | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 417 | PCI_DMA_FROMDEVICE); | 
|  | 418 |  | 
| Olof Johansson | cd4ceb2 | 2007-05-08 00:47:45 -0500 | [diff] [blame] | 419 | if (unlikely(dma_mapping_error(dma))) { | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 420 | dev_kfree_skb_irq(info->skb); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 421 | break; | 
|  | 422 | } | 
|  | 423 |  | 
|  | 424 | info->skb = skb; | 
|  | 425 | info->dma = dma; | 
|  | 426 | *buff = XCT_RXB_LEN(BUF_SIZE) | XCT_RXB_ADDR(dma); | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 427 | fill++; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 428 | } | 
|  | 429 |  | 
|  | 430 | wmb(); | 
|  | 431 |  | 
| Olof Johansson | 928773c | 2007-09-26 16:25:06 -0500 | [diff] [blame] | 432 | write_dma_reg(mac, PAS_DMA_RXCHAN_INCR(mac->dma_rxch), count); | 
|  | 433 | write_dma_reg(mac, PAS_DMA_RXINT_INCR(mac->dma_if), count); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 434 |  | 
| Olof Johansson | 928773c | 2007-09-26 16:25:06 -0500 | [diff] [blame] | 435 | mac->rx->next_to_fill += count; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 436 | } | 
|  | 437 |  | 
| Olof Johansson | 1b0335ea | 2007-05-08 00:47:26 -0500 | [diff] [blame] | 438 | static void pasemi_mac_restart_rx_intr(struct pasemi_mac *mac) | 
|  | 439 | { | 
| Olof Johansson | 52a9435 | 2007-05-12 18:01:09 -0500 | [diff] [blame] | 440 | unsigned int reg, pcnt; | 
| Olof Johansson | 1b0335ea | 2007-05-08 00:47:26 -0500 | [diff] [blame] | 441 | /* Re-enable packet count interrupts: finally | 
|  | 442 | * ack the packet count interrupt we got in rx_intr. | 
|  | 443 | */ | 
|  | 444 |  | 
| Olof Johansson | 52a9435 | 2007-05-12 18:01:09 -0500 | [diff] [blame] | 445 | pcnt = *mac->rx_status & PAS_STATUS_PCNT_M; | 
| Olof Johansson | 1b0335ea | 2007-05-08 00:47:26 -0500 | [diff] [blame] | 446 |  | 
| Olof Johansson | 52a9435 | 2007-05-12 18:01:09 -0500 | [diff] [blame] | 447 | reg = PAS_IOB_DMA_RXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_RXCH_RESET_PINTC; | 
| Olof Johansson | 1b0335ea | 2007-05-08 00:47:26 -0500 | [diff] [blame] | 448 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 449 | write_iob_reg(mac, PAS_IOB_DMA_RXCH_RESET(mac->dma_rxch), reg); | 
| Olof Johansson | 1b0335ea | 2007-05-08 00:47:26 -0500 | [diff] [blame] | 450 | } | 
|  | 451 |  | 
|  | 452 | static void pasemi_mac_restart_tx_intr(struct pasemi_mac *mac) | 
|  | 453 | { | 
| Olof Johansson | 52a9435 | 2007-05-12 18:01:09 -0500 | [diff] [blame] | 454 | unsigned int reg, pcnt; | 
| Olof Johansson | 1b0335ea | 2007-05-08 00:47:26 -0500 | [diff] [blame] | 455 |  | 
|  | 456 | /* Re-enable packet count interrupts */ | 
| Olof Johansson | 52a9435 | 2007-05-12 18:01:09 -0500 | [diff] [blame] | 457 | pcnt = *mac->tx_status & PAS_STATUS_PCNT_M; | 
| Olof Johansson | 1b0335ea | 2007-05-08 00:47:26 -0500 | [diff] [blame] | 458 |  | 
| Olof Johansson | 52a9435 | 2007-05-12 18:01:09 -0500 | [diff] [blame] | 459 | reg = PAS_IOB_DMA_TXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_TXCH_RESET_PINTC; | 
| Olof Johansson | 1b0335ea | 2007-05-08 00:47:26 -0500 | [diff] [blame] | 460 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 461 | write_iob_reg(mac, PAS_IOB_DMA_TXCH_RESET(mac->dma_txch), reg); | 
| Olof Johansson | 1b0335ea | 2007-05-08 00:47:26 -0500 | [diff] [blame] | 462 | } | 
|  | 463 |  | 
|  | 464 |  | 
| Olof Johansson | 69c29d8 | 2007-10-02 16:24:51 -0500 | [diff] [blame] | 465 | static inline void pasemi_mac_rx_error(struct pasemi_mac *mac, u64 macrx) | 
|  | 466 | { | 
|  | 467 | unsigned int rcmdsta, ccmdsta; | 
|  | 468 |  | 
|  | 469 | if (!netif_msg_rx_err(mac)) | 
|  | 470 | return; | 
|  | 471 |  | 
|  | 472 | rcmdsta = read_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if)); | 
|  | 473 | ccmdsta = read_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch)); | 
|  | 474 |  | 
|  | 475 | printk(KERN_ERR "pasemi_mac: rx error. macrx %016lx, rx status %lx\n", | 
|  | 476 | macrx, *mac->rx_status); | 
|  | 477 |  | 
|  | 478 | printk(KERN_ERR "pasemi_mac: rcmdsta %08x ccmdsta %08x\n", | 
|  | 479 | rcmdsta, ccmdsta); | 
|  | 480 | } | 
|  | 481 |  | 
|  | 482 | static inline void pasemi_mac_tx_error(struct pasemi_mac *mac, u64 mactx) | 
|  | 483 | { | 
|  | 484 | unsigned int cmdsta; | 
|  | 485 |  | 
|  | 486 | if (!netif_msg_tx_err(mac)) | 
|  | 487 | return; | 
|  | 488 |  | 
|  | 489 | cmdsta = read_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch)); | 
|  | 490 |  | 
|  | 491 | printk(KERN_ERR "pasemi_mac: tx error. mactx 0x%016lx, "\ | 
|  | 492 | "tx status 0x%016lx\n", mactx, *mac->tx_status); | 
|  | 493 |  | 
|  | 494 | printk(KERN_ERR "pasemi_mac: tcmdsta 0x%08x\n", cmdsta); | 
|  | 495 | } | 
|  | 496 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 497 | static int pasemi_mac_clean_rx(struct pasemi_mac *mac, int limit) | 
|  | 498 | { | 
| Olof Johansson | cd4ceb2 | 2007-05-08 00:47:45 -0500 | [diff] [blame] | 499 | unsigned int n; | 
|  | 500 | int count; | 
| Olof Johansson | cd4ceb2 | 2007-05-08 00:47:45 -0500 | [diff] [blame] | 501 | struct pasemi_mac_buffer *info; | 
|  | 502 | struct sk_buff *skb; | 
|  | 503 | unsigned int i, len; | 
|  | 504 | u64 macrx; | 
|  | 505 | dma_addr_t dma; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 506 |  | 
|  | 507 | spin_lock(&mac->rx->lock); | 
|  | 508 |  | 
| Olof Johansson | cd4ceb2 | 2007-05-08 00:47:45 -0500 | [diff] [blame] | 509 | n = mac->rx->next_to_clean; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 510 |  | 
| Olof Johansson | cd4ceb2 | 2007-05-08 00:47:45 -0500 | [diff] [blame] | 511 | for (count = limit; count; count--) { | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 512 |  | 
|  | 513 | rmb(); | 
|  | 514 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 515 | macrx = RX_RING(mac, n); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 516 |  | 
| Olof Johansson | 69c29d8 | 2007-10-02 16:24:51 -0500 | [diff] [blame] | 517 | if ((macrx & XCT_MACRX_E) || | 
|  | 518 | (*mac->rx_status & PAS_STATUS_ERROR)) | 
|  | 519 | pasemi_mac_rx_error(mac, macrx); | 
|  | 520 |  | 
| Olof Johansson | cd4ceb2 | 2007-05-08 00:47:45 -0500 | [diff] [blame] | 521 | if (!(macrx & XCT_MACRX_O)) | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 522 | break; | 
|  | 523 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 524 | info = NULL; | 
|  | 525 |  | 
|  | 526 | /* We have to scan for our skb since there's no way | 
|  | 527 | * to back-map them from the descriptor, and if we | 
|  | 528 | * have several receive channels then they might not | 
|  | 529 | * show up in the same order as they were put on the | 
|  | 530 | * interface ring. | 
|  | 531 | */ | 
|  | 532 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 533 | dma = (RX_RING(mac, n+1) & XCT_PTR_ADDR_M); | 
|  | 534 | for (i = mac->rx->next_to_fill; | 
|  | 535 | i < (mac->rx->next_to_fill + RX_RING_SIZE); | 
|  | 536 | i++) { | 
|  | 537 | info = &RX_RING_INFO(mac, i); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 538 | if (info->dma == dma) | 
|  | 539 | break; | 
|  | 540 | } | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 541 |  | 
| Olof Johansson | 26fcfa9 | 2007-08-22 09:12:59 -0500 | [diff] [blame] | 542 | prefetchw(info); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 543 |  | 
| Olof Johansson | 9f05cfe | 2007-05-08 00:47:37 -0500 | [diff] [blame] | 544 | skb = info->skb; | 
| Olof Johansson | 26fcfa9 | 2007-08-22 09:12:59 -0500 | [diff] [blame] | 545 | prefetchw(skb); | 
| Olof Johansson | 9f05cfe | 2007-05-08 00:47:37 -0500 | [diff] [blame] | 546 | info->dma = 0; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 547 |  | 
| Olof Johansson | cd4ceb2 | 2007-05-08 00:47:45 -0500 | [diff] [blame] | 548 | pci_unmap_single(mac->dma_pdev, dma, skb->len, | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 549 | PCI_DMA_FROMDEVICE); | 
|  | 550 |  | 
| Olof Johansson | cd4ceb2 | 2007-05-08 00:47:45 -0500 | [diff] [blame] | 551 | len = (macrx & XCT_MACRX_LLEN_M) >> XCT_MACRX_LLEN_S; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 552 |  | 
| Olof Johansson | 9f05cfe | 2007-05-08 00:47:37 -0500 | [diff] [blame] | 553 | if (len < 256) { | 
|  | 554 | struct sk_buff *new_skb = | 
|  | 555 | netdev_alloc_skb(mac->netdev, len + NET_IP_ALIGN); | 
|  | 556 | if (new_skb) { | 
|  | 557 | skb_reserve(new_skb, NET_IP_ALIGN); | 
| Olof Johansson | 7334486 | 2007-08-22 09:12:55 -0500 | [diff] [blame] | 558 | memcpy(new_skb->data, skb->data, len); | 
| Olof Johansson | 9f05cfe | 2007-05-08 00:47:37 -0500 | [diff] [blame] | 559 | /* save the skb in buffer_info as good */ | 
|  | 560 | skb = new_skb; | 
|  | 561 | } | 
|  | 562 | /* else just continue with the old one */ | 
|  | 563 | } else | 
|  | 564 | info->skb = NULL; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 565 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 566 | /* Need to zero it out since hardware doesn't, since the | 
|  | 567 | * replenish loop uses it to tell when it's done. | 
|  | 568 | */ | 
|  | 569 | RX_BUFF(mac, i) = 0; | 
|  | 570 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 571 | skb_put(skb, len); | 
|  | 572 |  | 
| Olof Johansson | 26fcfa9 | 2007-08-22 09:12:59 -0500 | [diff] [blame] | 573 | if (likely((macrx & XCT_MACRX_HTY_M) == XCT_MACRX_HTY_IPV4_OK)) { | 
| Olof Johansson | 38bf318 | 2007-08-22 09:13:24 -0500 | [diff] [blame] | 574 | skb->ip_summed = CHECKSUM_UNNECESSARY; | 
| Olof Johansson | cd4ceb2 | 2007-05-08 00:47:45 -0500 | [diff] [blame] | 575 | skb->csum = (macrx & XCT_MACRX_CSUM_M) >> | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 576 | XCT_MACRX_CSUM_S; | 
|  | 577 | } else | 
|  | 578 | skb->ip_summed = CHECKSUM_NONE; | 
|  | 579 |  | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 580 | mac->netdev->stats.rx_bytes += len; | 
|  | 581 | mac->netdev->stats.rx_packets++; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 582 |  | 
| Olof Johansson | 26fcfa9 | 2007-08-22 09:12:59 -0500 | [diff] [blame] | 583 | skb->protocol = eth_type_trans(skb, mac->netdev); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 584 | netif_receive_skb(skb); | 
|  | 585 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 586 | RX_RING(mac, n) = 0; | 
|  | 587 | RX_RING(mac, n+1) = 0; | 
| Olof Johansson | cd4ceb2 | 2007-05-08 00:47:45 -0500 | [diff] [blame] | 588 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 589 | n += 2; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 590 | } | 
|  | 591 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 592 | mac->rx->next_to_clean = n; | 
| Olof Johansson | 928773c | 2007-09-26 16:25:06 -0500 | [diff] [blame] | 593 | pasemi_mac_replenish_rx_ring(mac->netdev, limit-count); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 594 |  | 
|  | 595 | spin_unlock(&mac->rx->lock); | 
|  | 596 |  | 
|  | 597 | return count; | 
|  | 598 | } | 
|  | 599 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 600 | /* Can't make this too large or we blow the kernel stack limits */ | 
|  | 601 | #define TX_CLEAN_BATCHSIZE (128/MAX_SKB_FRAGS) | 
|  | 602 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 603 | static int pasemi_mac_clean_tx(struct pasemi_mac *mac) | 
|  | 604 | { | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 605 | int i, j; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 606 | struct pasemi_mac_buffer *info; | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 607 | unsigned int start, descr_count, buf_count, limit; | 
| Olof Johansson | 02df6cf | 2007-08-22 09:13:03 -0500 | [diff] [blame] | 608 | unsigned int total_count; | 
| Olof Johansson | ca7e235 | 2007-09-26 16:23:59 -0500 | [diff] [blame] | 609 | unsigned long flags; | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 610 | struct sk_buff *skbs[TX_CLEAN_BATCHSIZE]; | 
|  | 611 | dma_addr_t dmas[TX_CLEAN_BATCHSIZE][MAX_SKB_FRAGS+1]; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 612 |  | 
| Olof Johansson | 02df6cf | 2007-08-22 09:13:03 -0500 | [diff] [blame] | 613 | total_count = 0; | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 614 | limit = TX_CLEAN_BATCHSIZE; | 
| Olof Johansson | 02df6cf | 2007-08-22 09:13:03 -0500 | [diff] [blame] | 615 | restart: | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 616 | spin_lock_irqsave(&mac->tx->lock, flags); | 
|  | 617 |  | 
|  | 618 | start = mac->tx->next_to_clean; | 
| Olof Johansson | 02df6cf | 2007-08-22 09:13:03 -0500 | [diff] [blame] | 619 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 620 | buf_count = 0; | 
|  | 621 | descr_count = 0; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 622 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 623 | for (i = start; | 
|  | 624 | descr_count < limit && i < mac->tx->next_to_fill; | 
|  | 625 | i += buf_count) { | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 626 | u64 mactx = TX_RING(mac, i); | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 627 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 628 | if ((mactx  & XCT_MACTX_E) || | 
| Olof Johansson | 69c29d8 | 2007-10-02 16:24:51 -0500 | [diff] [blame] | 629 | (*mac->tx_status & PAS_STATUS_ERROR)) | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 630 | pasemi_mac_tx_error(mac, mactx); | 
| Olof Johansson | 69c29d8 | 2007-10-02 16:24:51 -0500 | [diff] [blame] | 631 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 632 | if (unlikely(mactx & XCT_MACTX_O)) | 
| Olof Johansson | 02df6cf | 2007-08-22 09:13:03 -0500 | [diff] [blame] | 633 | /* Not yet transmitted */ | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 634 | break; | 
|  | 635 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 636 | info = &TX_RING_INFO(mac, i+1); | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 637 | skbs[descr_count] = info->skb; | 
|  | 638 |  | 
|  | 639 | buf_count = 2 + skb_shinfo(info->skb)->nr_frags; | 
|  | 640 | for (j = 0; j <= skb_shinfo(info->skb)->nr_frags; j++) | 
|  | 641 | dmas[descr_count][j] = TX_RING_INFO(mac, i+1+j).dma; | 
|  | 642 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 643 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 644 | info->dma = 0; | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 645 | TX_RING(mac, i) = 0; | 
|  | 646 | TX_RING(mac, i+1) = 0; | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 647 | TX_RING_INFO(mac, i+1).skb = 0; | 
|  | 648 | TX_RING_INFO(mac, i+1).dma = 0; | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 649 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 650 | /* Since we always fill with an even number of entries, make | 
|  | 651 | * sure we skip any unused one at the end as well. | 
|  | 652 | */ | 
|  | 653 | if (buf_count & 1) | 
|  | 654 | buf_count++; | 
|  | 655 | descr_count++; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 656 | } | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 657 | mac->tx->next_to_clean = i; | 
|  | 658 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 659 | spin_unlock_irqrestore(&mac->tx->lock, flags); | 
| Olof Johansson | 0ce68c7 | 2007-04-28 15:36:40 -0500 | [diff] [blame] | 660 | netif_wake_queue(mac->netdev); | 
|  | 661 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 662 | for (i = 0; i < descr_count; i++) | 
|  | 663 | pasemi_mac_unmap_tx_skb(mac, skbs[i], dmas[i]); | 
| Olof Johansson | 02df6cf | 2007-08-22 09:13:03 -0500 | [diff] [blame] | 664 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 665 | total_count += descr_count; | 
| Olof Johansson | 02df6cf | 2007-08-22 09:13:03 -0500 | [diff] [blame] | 666 |  | 
|  | 667 | /* If the batch was full, try to clean more */ | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 668 | if (descr_count == limit) | 
| Olof Johansson | 02df6cf | 2007-08-22 09:13:03 -0500 | [diff] [blame] | 669 | goto restart; | 
|  | 670 |  | 
|  | 671 | return total_count; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 672 | } | 
|  | 673 |  | 
|  | 674 |  | 
|  | 675 | static irqreturn_t pasemi_mac_rx_intr(int irq, void *data) | 
|  | 676 | { | 
|  | 677 | struct net_device *dev = data; | 
|  | 678 | struct pasemi_mac *mac = netdev_priv(dev); | 
|  | 679 | unsigned int reg; | 
|  | 680 |  | 
| Olof Johansson | 6dfa752 | 2007-05-08 00:47:32 -0500 | [diff] [blame] | 681 | if (!(*mac->rx_status & PAS_STATUS_CAUSE_M)) | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 682 | return IRQ_NONE; | 
|  | 683 |  | 
| Olof Johansson | 6dfa752 | 2007-05-08 00:47:32 -0500 | [diff] [blame] | 684 | /* Don't reset packet count so it won't fire again but clear | 
|  | 685 | * all others. | 
|  | 686 | */ | 
|  | 687 |  | 
| Olof Johansson | 6dfa752 | 2007-05-08 00:47:32 -0500 | [diff] [blame] | 688 | reg = 0; | 
|  | 689 | if (*mac->rx_status & PAS_STATUS_SOFT) | 
|  | 690 | reg |= PAS_IOB_DMA_RXCH_RESET_SINTC; | 
|  | 691 | if (*mac->rx_status & PAS_STATUS_ERROR) | 
|  | 692 | reg |= PAS_IOB_DMA_RXCH_RESET_DINTC; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 693 | if (*mac->rx_status & PAS_STATUS_TIMER) | 
|  | 694 | reg |= PAS_IOB_DMA_RXCH_RESET_TINTC; | 
|  | 695 |  | 
| Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 696 | netif_rx_schedule(dev, &mac->napi); | 
| Olof Johansson | 6dfa752 | 2007-05-08 00:47:32 -0500 | [diff] [blame] | 697 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 698 | write_iob_reg(mac, PAS_IOB_DMA_RXCH_RESET(mac->dma_rxch), reg); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 699 |  | 
|  | 700 | return IRQ_HANDLED; | 
|  | 701 | } | 
|  | 702 |  | 
|  | 703 | static irqreturn_t pasemi_mac_tx_intr(int irq, void *data) | 
|  | 704 | { | 
|  | 705 | struct net_device *dev = data; | 
|  | 706 | struct pasemi_mac *mac = netdev_priv(dev); | 
| Olof Johansson | 52a9435 | 2007-05-12 18:01:09 -0500 | [diff] [blame] | 707 | unsigned int reg, pcnt; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 708 |  | 
| Olof Johansson | 6dfa752 | 2007-05-08 00:47:32 -0500 | [diff] [blame] | 709 | if (!(*mac->tx_status & PAS_STATUS_CAUSE_M)) | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 710 | return IRQ_NONE; | 
|  | 711 |  | 
|  | 712 | pasemi_mac_clean_tx(mac); | 
|  | 713 |  | 
| Olof Johansson | 52a9435 | 2007-05-12 18:01:09 -0500 | [diff] [blame] | 714 | pcnt = *mac->tx_status & PAS_STATUS_PCNT_M; | 
|  | 715 |  | 
|  | 716 | reg = PAS_IOB_DMA_TXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_TXCH_RESET_PINTC; | 
| Olof Johansson | 6dfa752 | 2007-05-08 00:47:32 -0500 | [diff] [blame] | 717 |  | 
|  | 718 | if (*mac->tx_status & PAS_STATUS_SOFT) | 
|  | 719 | reg |= PAS_IOB_DMA_TXCH_RESET_SINTC; | 
|  | 720 | if (*mac->tx_status & PAS_STATUS_ERROR) | 
|  | 721 | reg |= PAS_IOB_DMA_TXCH_RESET_DINTC; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 722 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 723 | write_iob_reg(mac, PAS_IOB_DMA_TXCH_RESET(mac->dma_txch), reg); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 724 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 725 | return IRQ_HANDLED; | 
|  | 726 | } | 
|  | 727 |  | 
| Olof Johansson | bb6e959 | 2007-05-08 00:47:54 -0500 | [diff] [blame] | 728 | static void pasemi_adjust_link(struct net_device *dev) | 
|  | 729 | { | 
|  | 730 | struct pasemi_mac *mac = netdev_priv(dev); | 
|  | 731 | int msg; | 
|  | 732 | unsigned int flags; | 
|  | 733 | unsigned int new_flags; | 
|  | 734 |  | 
|  | 735 | if (!mac->phydev->link) { | 
|  | 736 | /* If no link, MAC speed settings don't matter. Just report | 
|  | 737 | * link down and return. | 
|  | 738 | */ | 
|  | 739 | if (mac->link && netif_msg_link(mac)) | 
|  | 740 | printk(KERN_INFO "%s: Link is down.\n", dev->name); | 
|  | 741 |  | 
|  | 742 | netif_carrier_off(dev); | 
|  | 743 | mac->link = 0; | 
|  | 744 |  | 
|  | 745 | return; | 
|  | 746 | } else | 
|  | 747 | netif_carrier_on(dev); | 
|  | 748 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 749 | flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG); | 
| Olof Johansson | bb6e959 | 2007-05-08 00:47:54 -0500 | [diff] [blame] | 750 | new_flags = flags & ~(PAS_MAC_CFG_PCFG_HD | PAS_MAC_CFG_PCFG_SPD_M | | 
|  | 751 | PAS_MAC_CFG_PCFG_TSR_M); | 
|  | 752 |  | 
|  | 753 | if (!mac->phydev->duplex) | 
|  | 754 | new_flags |= PAS_MAC_CFG_PCFG_HD; | 
|  | 755 |  | 
|  | 756 | switch (mac->phydev->speed) { | 
|  | 757 | case 1000: | 
|  | 758 | new_flags |= PAS_MAC_CFG_PCFG_SPD_1G | | 
|  | 759 | PAS_MAC_CFG_PCFG_TSR_1G; | 
|  | 760 | break; | 
|  | 761 | case 100: | 
|  | 762 | new_flags |= PAS_MAC_CFG_PCFG_SPD_100M | | 
|  | 763 | PAS_MAC_CFG_PCFG_TSR_100M; | 
|  | 764 | break; | 
|  | 765 | case 10: | 
|  | 766 | new_flags |= PAS_MAC_CFG_PCFG_SPD_10M | | 
|  | 767 | PAS_MAC_CFG_PCFG_TSR_10M; | 
|  | 768 | break; | 
|  | 769 | default: | 
|  | 770 | printk("Unsupported speed %d\n", mac->phydev->speed); | 
|  | 771 | } | 
|  | 772 |  | 
|  | 773 | /* Print on link or speed/duplex change */ | 
|  | 774 | msg = mac->link != mac->phydev->link || flags != new_flags; | 
|  | 775 |  | 
|  | 776 | mac->duplex = mac->phydev->duplex; | 
|  | 777 | mac->speed = mac->phydev->speed; | 
|  | 778 | mac->link = mac->phydev->link; | 
|  | 779 |  | 
|  | 780 | if (new_flags != flags) | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 781 | write_mac_reg(mac, PAS_MAC_CFG_PCFG, new_flags); | 
| Olof Johansson | bb6e959 | 2007-05-08 00:47:54 -0500 | [diff] [blame] | 782 |  | 
|  | 783 | if (msg && netif_msg_link(mac)) | 
|  | 784 | printk(KERN_INFO "%s: Link is up at %d Mbps, %s duplex.\n", | 
|  | 785 | dev->name, mac->speed, mac->duplex ? "full" : "half"); | 
|  | 786 | } | 
|  | 787 |  | 
|  | 788 | static int pasemi_mac_phy_init(struct net_device *dev) | 
|  | 789 | { | 
|  | 790 | struct pasemi_mac *mac = netdev_priv(dev); | 
|  | 791 | struct device_node *dn, *phy_dn; | 
|  | 792 | struct phy_device *phydev; | 
|  | 793 | unsigned int phy_id; | 
|  | 794 | const phandle *ph; | 
|  | 795 | const unsigned int *prop; | 
|  | 796 | struct resource r; | 
|  | 797 | int ret; | 
|  | 798 |  | 
|  | 799 | dn = pci_device_to_OF_node(mac->pdev); | 
| Linus Torvalds | 9028780 | 2007-05-08 11:57:17 -0700 | [diff] [blame] | 800 | ph = of_get_property(dn, "phy-handle", NULL); | 
| Olof Johansson | bb6e959 | 2007-05-08 00:47:54 -0500 | [diff] [blame] | 801 | if (!ph) | 
|  | 802 | return -ENODEV; | 
|  | 803 | phy_dn = of_find_node_by_phandle(*ph); | 
|  | 804 |  | 
| Linus Torvalds | 9028780 | 2007-05-08 11:57:17 -0700 | [diff] [blame] | 805 | prop = of_get_property(phy_dn, "reg", NULL); | 
| Olof Johansson | bb6e959 | 2007-05-08 00:47:54 -0500 | [diff] [blame] | 806 | ret = of_address_to_resource(phy_dn->parent, 0, &r); | 
|  | 807 | if (ret) | 
|  | 808 | goto err; | 
|  | 809 |  | 
|  | 810 | phy_id = *prop; | 
|  | 811 | snprintf(mac->phy_id, BUS_ID_SIZE, PHY_ID_FMT, (int)r.start, phy_id); | 
|  | 812 |  | 
|  | 813 | of_node_put(phy_dn); | 
|  | 814 |  | 
|  | 815 | mac->link = 0; | 
|  | 816 | mac->speed = 0; | 
|  | 817 | mac->duplex = -1; | 
|  | 818 |  | 
|  | 819 | phydev = phy_connect(dev, mac->phy_id, &pasemi_adjust_link, 0, PHY_INTERFACE_MODE_SGMII); | 
|  | 820 |  | 
|  | 821 | if (IS_ERR(phydev)) { | 
|  | 822 | printk(KERN_ERR "%s: Could not attach to phy\n", dev->name); | 
|  | 823 | return PTR_ERR(phydev); | 
|  | 824 | } | 
|  | 825 |  | 
|  | 826 | mac->phydev = phydev; | 
|  | 827 |  | 
|  | 828 | return 0; | 
|  | 829 |  | 
|  | 830 | err: | 
|  | 831 | of_node_put(phy_dn); | 
|  | 832 | return -ENODEV; | 
|  | 833 | } | 
|  | 834 |  | 
|  | 835 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 836 | static int pasemi_mac_open(struct net_device *dev) | 
|  | 837 | { | 
|  | 838 | struct pasemi_mac *mac = netdev_priv(dev); | 
| Olof Johansson | 771f740 | 2007-05-08 00:47:21 -0500 | [diff] [blame] | 839 | int base_irq; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 840 | unsigned int flags; | 
|  | 841 | int ret; | 
|  | 842 |  | 
|  | 843 | /* enable rx section */ | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 844 | write_dma_reg(mac, PAS_DMA_COM_RXCMD, PAS_DMA_COM_RXCMD_EN); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 845 |  | 
|  | 846 | /* enable tx section */ | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 847 | write_dma_reg(mac, PAS_DMA_COM_TXCMD, PAS_DMA_COM_TXCMD_EN); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 848 |  | 
|  | 849 | flags = PAS_MAC_CFG_TXP_FCE | PAS_MAC_CFG_TXP_FPC(3) | | 
|  | 850 | PAS_MAC_CFG_TXP_SL(3) | PAS_MAC_CFG_TXP_COB(0xf) | | 
|  | 851 | PAS_MAC_CFG_TXP_TIFT(8) | PAS_MAC_CFG_TXP_TIFG(12); | 
|  | 852 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 853 | write_mac_reg(mac, PAS_MAC_CFG_TXP, flags); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 854 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 855 | write_iob_reg(mac, PAS_IOB_DMA_RXCH_CFG(mac->dma_rxch), | 
|  | 856 | PAS_IOB_DMA_RXCH_CFG_CNTTH(0)); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 857 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 858 | write_iob_reg(mac, PAS_IOB_DMA_TXCH_CFG(mac->dma_txch), | 
| Olof Johansson | 02df6cf | 2007-08-22 09:13:03 -0500 | [diff] [blame] | 859 | PAS_IOB_DMA_TXCH_CFG_CNTTH(128)); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 860 |  | 
| Olof Johansson | 1b0335ea | 2007-05-08 00:47:26 -0500 | [diff] [blame] | 861 | /* Clear out any residual packet count state from firmware */ | 
|  | 862 | pasemi_mac_restart_rx_intr(mac); | 
|  | 863 | pasemi_mac_restart_tx_intr(mac); | 
|  | 864 |  | 
| Olof Johansson | 6dfa752 | 2007-05-08 00:47:32 -0500 | [diff] [blame] | 865 | /* 0xffffff is max value, about 16ms */ | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 866 | write_iob_reg(mac, PAS_IOB_DMA_COM_TIMEOUTCFG, | 
|  | 867 | PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT(0xffffff)); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 868 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 869 | ret = pasemi_mac_setup_rx_resources(dev); | 
|  | 870 | if (ret) | 
|  | 871 | goto out_rx_resources; | 
|  | 872 |  | 
|  | 873 | ret = pasemi_mac_setup_tx_resources(dev); | 
|  | 874 | if (ret) | 
|  | 875 | goto out_tx_resources; | 
|  | 876 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 877 | write_mac_reg(mac, PAS_MAC_IPC_CHNL, | 
|  | 878 | PAS_MAC_IPC_CHNL_DCHNO(mac->dma_rxch) | | 
|  | 879 | PAS_MAC_IPC_CHNL_BCH(mac->dma_rxch)); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 880 |  | 
|  | 881 | /* enable rx if */ | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 882 | write_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if), | 
|  | 883 | PAS_DMA_RXINT_RCMDSTA_EN); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 884 |  | 
|  | 885 | /* enable rx channel */ | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 886 | write_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch), | 
|  | 887 | PAS_DMA_RXCHAN_CCMDSTA_EN | | 
|  | 888 | PAS_DMA_RXCHAN_CCMDSTA_DU); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 889 |  | 
|  | 890 | /* enable tx channel */ | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 891 | write_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch), | 
|  | 892 | PAS_DMA_TXCHAN_TCMDSTA_EN); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 893 |  | 
| Olof Johansson | 928773c | 2007-09-26 16:25:06 -0500 | [diff] [blame] | 894 | pasemi_mac_replenish_rx_ring(dev, RX_RING_SIZE); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 895 |  | 
| Olof Johansson | 3603376 | 2007-09-26 16:24:42 -0500 | [diff] [blame] | 896 | flags = PAS_MAC_CFG_PCFG_S1 | PAS_MAC_CFG_PCFG_PE | | 
|  | 897 | PAS_MAC_CFG_PCFG_PR | PAS_MAC_CFG_PCFG_CE; | 
|  | 898 |  | 
|  | 899 | if (mac->type == MAC_TYPE_GMAC) | 
|  | 900 | flags |= PAS_MAC_CFG_PCFG_TSR_1G | PAS_MAC_CFG_PCFG_SPD_1G; | 
|  | 901 | else | 
|  | 902 | flags |= PAS_MAC_CFG_PCFG_TSR_10G | PAS_MAC_CFG_PCFG_SPD_10G; | 
|  | 903 |  | 
|  | 904 | /* Enable interface in MAC */ | 
|  | 905 | write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags); | 
|  | 906 |  | 
| Olof Johansson | bb6e959 | 2007-05-08 00:47:54 -0500 | [diff] [blame] | 907 | ret = pasemi_mac_phy_init(dev); | 
|  | 908 | /* Some configs don't have PHYs (XAUI etc), so don't complain about | 
|  | 909 | * failed init due to -ENODEV. | 
|  | 910 | */ | 
|  | 911 | if (ret && ret != -ENODEV) | 
|  | 912 | dev_warn(&mac->pdev->dev, "phy init failed: %d\n", ret); | 
|  | 913 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 914 | netif_start_queue(dev); | 
| Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 915 | napi_enable(&mac->napi); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 916 |  | 
| Olof Johansson | 771f740 | 2007-05-08 00:47:21 -0500 | [diff] [blame] | 917 | /* Interrupts are a bit different for our DMA controller: While | 
|  | 918 | * it's got one a regular PCI device header, the interrupt there | 
|  | 919 | * is really the base of the range it's using. Each tx and rx | 
|  | 920 | * channel has it's own interrupt source. | 
|  | 921 | */ | 
|  | 922 |  | 
|  | 923 | base_irq = virq_to_hw(mac->dma_pdev->irq); | 
|  | 924 |  | 
|  | 925 | mac->tx_irq = irq_create_mapping(NULL, base_irq + mac->dma_txch); | 
|  | 926 | mac->rx_irq = irq_create_mapping(NULL, base_irq + 20 + mac->dma_txch); | 
|  | 927 |  | 
|  | 928 | ret = request_irq(mac->tx_irq, &pasemi_mac_tx_intr, IRQF_DISABLED, | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 929 | mac->tx->irq_name, dev); | 
|  | 930 | if (ret) { | 
|  | 931 | dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n", | 
| Olof Johansson | 771f740 | 2007-05-08 00:47:21 -0500 | [diff] [blame] | 932 | base_irq + mac->dma_txch, ret); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 933 | goto out_tx_int; | 
|  | 934 | } | 
|  | 935 |  | 
| Olof Johansson | 771f740 | 2007-05-08 00:47:21 -0500 | [diff] [blame] | 936 | ret = request_irq(mac->rx_irq, &pasemi_mac_rx_intr, IRQF_DISABLED, | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 937 | mac->rx->irq_name, dev); | 
|  | 938 | if (ret) { | 
|  | 939 | dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n", | 
| Olof Johansson | 771f740 | 2007-05-08 00:47:21 -0500 | [diff] [blame] | 940 | base_irq + 20 + mac->dma_rxch, ret); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 941 | goto out_rx_int; | 
|  | 942 | } | 
|  | 943 |  | 
| Olof Johansson | bb6e959 | 2007-05-08 00:47:54 -0500 | [diff] [blame] | 944 | if (mac->phydev) | 
|  | 945 | phy_start(mac->phydev); | 
|  | 946 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 947 | return 0; | 
|  | 948 |  | 
|  | 949 | out_rx_int: | 
| Olof Johansson | 771f740 | 2007-05-08 00:47:21 -0500 | [diff] [blame] | 950 | free_irq(mac->tx_irq, dev); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 951 | out_tx_int: | 
| Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 952 | napi_disable(&mac->napi); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 953 | netif_stop_queue(dev); | 
|  | 954 | pasemi_mac_free_tx_resources(dev); | 
|  | 955 | out_tx_resources: | 
|  | 956 | pasemi_mac_free_rx_resources(dev); | 
|  | 957 | out_rx_resources: | 
|  | 958 |  | 
|  | 959 | return ret; | 
|  | 960 | } | 
|  | 961 |  | 
|  | 962 | #define MAX_RETRIES 5000 | 
|  | 963 |  | 
|  | 964 | static int pasemi_mac_close(struct net_device *dev) | 
|  | 965 | { | 
|  | 966 | struct pasemi_mac *mac = netdev_priv(dev); | 
|  | 967 | unsigned int stat; | 
|  | 968 | int retries; | 
|  | 969 |  | 
| Olof Johansson | bb6e959 | 2007-05-08 00:47:54 -0500 | [diff] [blame] | 970 | if (mac->phydev) { | 
|  | 971 | phy_stop(mac->phydev); | 
|  | 972 | phy_disconnect(mac->phydev); | 
|  | 973 | } | 
|  | 974 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 975 | netif_stop_queue(dev); | 
| Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 976 | napi_disable(&mac->napi); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 977 |  | 
|  | 978 | /* Clean out any pending buffers */ | 
|  | 979 | pasemi_mac_clean_tx(mac); | 
|  | 980 | pasemi_mac_clean_rx(mac, RX_RING_SIZE); | 
|  | 981 |  | 
|  | 982 | /* Disable interface */ | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 983 | write_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch), PAS_DMA_TXCHAN_TCMDSTA_ST); | 
|  | 984 | write_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if), PAS_DMA_RXINT_RCMDSTA_ST); | 
|  | 985 | write_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch), PAS_DMA_RXCHAN_CCMDSTA_ST); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 986 |  | 
|  | 987 | for (retries = 0; retries < MAX_RETRIES; retries++) { | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 988 | stat = read_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch)); | 
| Olof Johansson | 0ce68c7 | 2007-04-28 15:36:40 -0500 | [diff] [blame] | 989 | if (!(stat & PAS_DMA_TXCHAN_TCMDSTA_ACT)) | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 990 | break; | 
|  | 991 | cond_resched(); | 
|  | 992 | } | 
|  | 993 |  | 
| Olof Johansson | 0ce68c7 | 2007-04-28 15:36:40 -0500 | [diff] [blame] | 994 | if (stat & PAS_DMA_TXCHAN_TCMDSTA_ACT) | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 995 | dev_err(&mac->dma_pdev->dev, "Failed to stop tx channel\n"); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 996 |  | 
|  | 997 | for (retries = 0; retries < MAX_RETRIES; retries++) { | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 998 | stat = read_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch)); | 
| Olof Johansson | 0ce68c7 | 2007-04-28 15:36:40 -0500 | [diff] [blame] | 999 | if (!(stat & PAS_DMA_RXCHAN_CCMDSTA_ACT)) | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1000 | break; | 
|  | 1001 | cond_resched(); | 
|  | 1002 | } | 
|  | 1003 |  | 
| Olof Johansson | 0ce68c7 | 2007-04-28 15:36:40 -0500 | [diff] [blame] | 1004 | if (stat & PAS_DMA_RXCHAN_CCMDSTA_ACT) | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1005 | dev_err(&mac->dma_pdev->dev, "Failed to stop rx channel\n"); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1006 |  | 
|  | 1007 | for (retries = 0; retries < MAX_RETRIES; retries++) { | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 1008 | stat = read_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if)); | 
| Olof Johansson | 0ce68c7 | 2007-04-28 15:36:40 -0500 | [diff] [blame] | 1009 | if (!(stat & PAS_DMA_RXINT_RCMDSTA_ACT)) | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1010 | break; | 
|  | 1011 | cond_resched(); | 
|  | 1012 | } | 
|  | 1013 |  | 
| Olof Johansson | 0ce68c7 | 2007-04-28 15:36:40 -0500 | [diff] [blame] | 1014 | if (stat & PAS_DMA_RXINT_RCMDSTA_ACT) | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1015 | dev_err(&mac->dma_pdev->dev, "Failed to stop rx interface\n"); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1016 |  | 
|  | 1017 | /* Then, disable the channel. This must be done separately from | 
|  | 1018 | * stopping, since you can't disable when active. | 
|  | 1019 | */ | 
|  | 1020 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 1021 | write_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch), 0); | 
|  | 1022 | write_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch), 0); | 
|  | 1023 | write_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if), 0); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1024 |  | 
| Olof Johansson | 771f740 | 2007-05-08 00:47:21 -0500 | [diff] [blame] | 1025 | free_irq(mac->tx_irq, dev); | 
|  | 1026 | free_irq(mac->rx_irq, dev); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1027 |  | 
|  | 1028 | /* Free resources */ | 
|  | 1029 | pasemi_mac_free_rx_resources(dev); | 
|  | 1030 | pasemi_mac_free_tx_resources(dev); | 
|  | 1031 |  | 
|  | 1032 | return 0; | 
|  | 1033 | } | 
|  | 1034 |  | 
|  | 1035 | static int pasemi_mac_start_tx(struct sk_buff *skb, struct net_device *dev) | 
|  | 1036 | { | 
|  | 1037 | struct pasemi_mac *mac = netdev_priv(dev); | 
|  | 1038 | struct pasemi_mac_txring *txring; | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 1039 | u64 dflags, mactx; | 
|  | 1040 | dma_addr_t map[MAX_SKB_FRAGS+1]; | 
|  | 1041 | unsigned int map_size[MAX_SKB_FRAGS+1]; | 
| Olof Johansson | ca7e235 | 2007-09-26 16:23:59 -0500 | [diff] [blame] | 1042 | unsigned long flags; | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 1043 | int i, nfrags; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1044 |  | 
|  | 1045 | dflags = XCT_MACTX_O | XCT_MACTX_ST | XCT_MACTX_SS | XCT_MACTX_CRC_PAD; | 
|  | 1046 |  | 
|  | 1047 | if (skb->ip_summed == CHECKSUM_PARTIAL) { | 
| Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 1048 | const unsigned char *nh = skb_network_header(skb); | 
|  | 1049 |  | 
| Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1050 | switch (ip_hdr(skb)->protocol) { | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1051 | case IPPROTO_TCP: | 
|  | 1052 | dflags |= XCT_MACTX_CSUM_TCP; | 
| Arnaldo Carvalho de Melo | cfe1fc7 | 2007-03-16 17:26:39 -0300 | [diff] [blame] | 1053 | dflags |= XCT_MACTX_IPH(skb_network_header_len(skb) >> 2); | 
| Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 1054 | dflags |= XCT_MACTX_IPO(nh - skb->data); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1055 | break; | 
|  | 1056 | case IPPROTO_UDP: | 
|  | 1057 | dflags |= XCT_MACTX_CSUM_UDP; | 
| Arnaldo Carvalho de Melo | cfe1fc7 | 2007-03-16 17:26:39 -0300 | [diff] [blame] | 1058 | dflags |= XCT_MACTX_IPH(skb_network_header_len(skb) >> 2); | 
| Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 1059 | dflags |= XCT_MACTX_IPO(nh - skb->data); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1060 | break; | 
|  | 1061 | } | 
|  | 1062 | } | 
|  | 1063 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 1064 | nfrags = skb_shinfo(skb)->nr_frags; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1065 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 1066 | map[0] = pci_map_single(mac->dma_pdev, skb->data, skb_headlen(skb), | 
|  | 1067 | PCI_DMA_TODEVICE); | 
|  | 1068 | map_size[0] = skb_headlen(skb); | 
|  | 1069 | if (dma_mapping_error(map[0])) | 
|  | 1070 | goto out_err_nolock; | 
|  | 1071 |  | 
|  | 1072 | for (i = 0; i < nfrags; i++) { | 
|  | 1073 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; | 
|  | 1074 |  | 
|  | 1075 | map[i+1] = pci_map_page(mac->dma_pdev, frag->page, | 
|  | 1076 | frag->page_offset, frag->size, | 
|  | 1077 | PCI_DMA_TODEVICE); | 
|  | 1078 | map_size[i+1] = frag->size; | 
|  | 1079 | if (dma_mapping_error(map[i+1])) { | 
|  | 1080 | nfrags = i; | 
|  | 1081 | goto out_err_nolock; | 
|  | 1082 | } | 
|  | 1083 | } | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1084 |  | 
| Olof Johansson | 26fcfa9 | 2007-08-22 09:12:59 -0500 | [diff] [blame] | 1085 | mactx = dflags | XCT_MACTX_LLEN(skb->len); | 
| Olof Johansson | 26fcfa9 | 2007-08-22 09:12:59 -0500 | [diff] [blame] | 1086 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1087 | txring = mac->tx; | 
|  | 1088 |  | 
|  | 1089 | spin_lock_irqsave(&txring->lock, flags); | 
|  | 1090 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 1091 | if (RING_AVAIL(txring) <= nfrags+3) { | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1092 | spin_unlock_irqrestore(&txring->lock, flags); | 
|  | 1093 | pasemi_mac_clean_tx(mac); | 
| Olof Johansson | 52a9435 | 2007-05-12 18:01:09 -0500 | [diff] [blame] | 1094 | pasemi_mac_restart_tx_intr(mac); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1095 | spin_lock_irqsave(&txring->lock, flags); | 
|  | 1096 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 1097 | if (RING_AVAIL(txring) <= nfrags+3) { | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1098 | /* Still no room -- stop the queue and wait for tx | 
|  | 1099 | * intr when there's room. | 
|  | 1100 | */ | 
|  | 1101 | netif_stop_queue(dev); | 
|  | 1102 | goto out_err; | 
|  | 1103 | } | 
|  | 1104 | } | 
|  | 1105 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 1106 | TX_RING(mac, txring->next_to_fill) = mactx; | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 1107 | txring->next_to_fill++; | 
|  | 1108 | TX_RING_INFO(mac, txring->next_to_fill).skb = skb; | 
|  | 1109 | for (i = 0; i <= nfrags; i++) { | 
|  | 1110 | TX_RING(mac, txring->next_to_fill+i) = | 
|  | 1111 | XCT_PTR_LEN(map_size[i]) | XCT_PTR_ADDR(map[i]); | 
|  | 1112 | TX_RING_INFO(mac, txring->next_to_fill+i).dma = map[i]; | 
|  | 1113 | } | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1114 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 1115 | /* We have to add an even number of 8-byte entries to the ring | 
|  | 1116 | * even if the last one is unused. That means always an odd number | 
|  | 1117 | * of pointers + one mactx descriptor. | 
|  | 1118 | */ | 
|  | 1119 | if (nfrags & 1) | 
|  | 1120 | nfrags++; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1121 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 1122 | txring->next_to_fill += nfrags + 1; | 
|  | 1123 |  | 
| Olof Johansson | fc9e4d2 | 2007-10-02 16:25:53 -0500 | [diff] [blame] | 1124 |  | 
| Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 1125 | dev->stats.tx_packets++; | 
|  | 1126 | dev->stats.tx_bytes += skb->len; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1127 |  | 
|  | 1128 | spin_unlock_irqrestore(&txring->lock, flags); | 
|  | 1129 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 1130 | write_dma_reg(mac, PAS_DMA_TXCHAN_INCR(mac->dma_txch), (nfrags+2) >> 1); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1131 |  | 
|  | 1132 | return NETDEV_TX_OK; | 
|  | 1133 |  | 
|  | 1134 | out_err: | 
|  | 1135 | spin_unlock_irqrestore(&txring->lock, flags); | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 1136 | out_err_nolock: | 
|  | 1137 | while (nfrags--) | 
|  | 1138 | pci_unmap_single(mac->dma_pdev, map[nfrags], map_size[nfrags], | 
|  | 1139 | PCI_DMA_TODEVICE); | 
|  | 1140 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1141 | return NETDEV_TX_BUSY; | 
|  | 1142 | } | 
|  | 1143 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1144 | static void pasemi_mac_set_rx_mode(struct net_device *dev) | 
|  | 1145 | { | 
|  | 1146 | struct pasemi_mac *mac = netdev_priv(dev); | 
|  | 1147 | unsigned int flags; | 
|  | 1148 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 1149 | flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1150 |  | 
|  | 1151 | /* Set promiscuous */ | 
|  | 1152 | if (dev->flags & IFF_PROMISC) | 
|  | 1153 | flags |= PAS_MAC_CFG_PCFG_PR; | 
|  | 1154 | else | 
|  | 1155 | flags &= ~PAS_MAC_CFG_PCFG_PR; | 
|  | 1156 |  | 
| Olof Johansson | a85b942 | 2007-09-15 13:40:59 -0700 | [diff] [blame] | 1157 | write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1158 | } | 
|  | 1159 |  | 
|  | 1160 |  | 
| Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1161 | static int pasemi_mac_poll(struct napi_struct *napi, int budget) | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1162 | { | 
| Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1163 | struct pasemi_mac *mac = container_of(napi, struct pasemi_mac, napi); | 
|  | 1164 | struct net_device *dev = mac->netdev; | 
|  | 1165 | int pkts; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1166 |  | 
| Olof Johansson | 829185e | 2007-09-15 13:53:19 -0700 | [diff] [blame] | 1167 | pasemi_mac_clean_tx(mac); | 
| Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1168 | pkts = pasemi_mac_clean_rx(mac, budget); | 
|  | 1169 | if (pkts < budget) { | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1170 | /* all done, no more packets present */ | 
| Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1171 | netif_rx_complete(dev, napi); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1172 |  | 
| Olof Johansson | 1b0335ea | 2007-05-08 00:47:26 -0500 | [diff] [blame] | 1173 | pasemi_mac_restart_rx_intr(mac); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1174 | } | 
| Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1175 | return pkts; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1176 | } | 
|  | 1177 |  | 
| Olof Johansson | b6e05a1 | 2007-09-15 13:44:07 -0700 | [diff] [blame] | 1178 | static void __iomem * __devinit map_onedev(struct pci_dev *p, int index) | 
|  | 1179 | { | 
|  | 1180 | struct device_node *dn; | 
|  | 1181 | void __iomem *ret; | 
|  | 1182 |  | 
|  | 1183 | dn = pci_device_to_OF_node(p); | 
|  | 1184 | if (!dn) | 
|  | 1185 | goto fallback; | 
|  | 1186 |  | 
|  | 1187 | ret = of_iomap(dn, index); | 
|  | 1188 | if (!ret) | 
|  | 1189 | goto fallback; | 
|  | 1190 |  | 
|  | 1191 | return ret; | 
|  | 1192 | fallback: | 
|  | 1193 | /* This is hardcoded and ugly, but we have some firmware versions | 
|  | 1194 | * that don't provide the register space in the device tree. Luckily | 
|  | 1195 | * they are at well-known locations so we can just do the math here. | 
|  | 1196 | */ | 
|  | 1197 | return ioremap(0xe0000000 + (p->devfn << 12), 0x2000); | 
|  | 1198 | } | 
|  | 1199 |  | 
|  | 1200 | static int __devinit pasemi_mac_map_regs(struct pasemi_mac *mac) | 
|  | 1201 | { | 
|  | 1202 | struct resource res; | 
|  | 1203 | struct device_node *dn; | 
|  | 1204 | int err; | 
|  | 1205 |  | 
|  | 1206 | mac->dma_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa007, NULL); | 
|  | 1207 | if (!mac->dma_pdev) { | 
|  | 1208 | dev_err(&mac->pdev->dev, "Can't find DMA Controller\n"); | 
|  | 1209 | return -ENODEV; | 
|  | 1210 | } | 
|  | 1211 |  | 
|  | 1212 | mac->iob_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL); | 
|  | 1213 | if (!mac->iob_pdev) { | 
|  | 1214 | dev_err(&mac->pdev->dev, "Can't find I/O Bridge\n"); | 
|  | 1215 | return -ENODEV; | 
|  | 1216 | } | 
|  | 1217 |  | 
|  | 1218 | mac->regs = map_onedev(mac->pdev, 0); | 
|  | 1219 | mac->dma_regs = map_onedev(mac->dma_pdev, 0); | 
|  | 1220 | mac->iob_regs = map_onedev(mac->iob_pdev, 0); | 
|  | 1221 |  | 
|  | 1222 | if (!mac->regs || !mac->dma_regs || !mac->iob_regs) { | 
|  | 1223 | dev_err(&mac->pdev->dev, "Can't map registers\n"); | 
|  | 1224 | return -ENODEV; | 
|  | 1225 | } | 
|  | 1226 |  | 
|  | 1227 | /* The dma status structure is located in the I/O bridge, and | 
|  | 1228 | * is cache coherent. | 
|  | 1229 | */ | 
|  | 1230 | if (!dma_status) { | 
|  | 1231 | dn = pci_device_to_OF_node(mac->iob_pdev); | 
|  | 1232 | if (dn) | 
|  | 1233 | err = of_address_to_resource(dn, 1, &res); | 
|  | 1234 | if (!dn || err) { | 
|  | 1235 | /* Fallback for old firmware */ | 
|  | 1236 | res.start = 0xfd800000; | 
|  | 1237 | res.end = res.start + 0x1000; | 
|  | 1238 | } | 
|  | 1239 | dma_status = __ioremap(res.start, res.end-res.start, 0); | 
|  | 1240 | } | 
|  | 1241 |  | 
|  | 1242 | return 0; | 
|  | 1243 | } | 
|  | 1244 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1245 | static int __devinit | 
|  | 1246 | pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | 
|  | 1247 | { | 
|  | 1248 | static int index = 0; | 
|  | 1249 | struct net_device *dev; | 
|  | 1250 | struct pasemi_mac *mac; | 
|  | 1251 | int err; | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1252 | DECLARE_MAC_BUF(mac_buf); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1253 |  | 
|  | 1254 | err = pci_enable_device(pdev); | 
|  | 1255 | if (err) | 
|  | 1256 | return err; | 
|  | 1257 |  | 
|  | 1258 | dev = alloc_etherdev(sizeof(struct pasemi_mac)); | 
|  | 1259 | if (dev == NULL) { | 
|  | 1260 | dev_err(&pdev->dev, | 
|  | 1261 | "pasemi_mac: Could not allocate ethernet device.\n"); | 
|  | 1262 | err = -ENOMEM; | 
|  | 1263 | goto out_disable_device; | 
|  | 1264 | } | 
|  | 1265 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1266 | pci_set_drvdata(pdev, dev); | 
|  | 1267 | SET_NETDEV_DEV(dev, &pdev->dev); | 
|  | 1268 |  | 
|  | 1269 | mac = netdev_priv(dev); | 
|  | 1270 |  | 
|  | 1271 | mac->pdev = pdev; | 
|  | 1272 | mac->netdev = dev; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1273 |  | 
| Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1274 | netif_napi_add(dev, &mac->napi, pasemi_mac_poll, 64); | 
|  | 1275 |  | 
| Olof Johansson | ad3c20d | 2007-10-02 16:26:13 -0500 | [diff] [blame^] | 1276 | dev->features = NETIF_F_HW_CSUM | NETIF_F_LLTX | NETIF_F_SG; | 
| Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1277 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1278 | /* These should come out of the device tree eventually */ | 
|  | 1279 | mac->dma_txch = index; | 
|  | 1280 | mac->dma_rxch = index; | 
|  | 1281 |  | 
|  | 1282 | /* We probe GMAC before XAUI, but the DMA interfaces are | 
|  | 1283 | * in XAUI, GMAC order. | 
|  | 1284 | */ | 
|  | 1285 | if (index < 4) | 
|  | 1286 | mac->dma_if = index + 2; | 
|  | 1287 | else | 
|  | 1288 | mac->dma_if = index - 4; | 
|  | 1289 | index++; | 
|  | 1290 |  | 
|  | 1291 | switch (pdev->device) { | 
|  | 1292 | case 0xa005: | 
|  | 1293 | mac->type = MAC_TYPE_GMAC; | 
|  | 1294 | break; | 
|  | 1295 | case 0xa006: | 
|  | 1296 | mac->type = MAC_TYPE_XAUI; | 
|  | 1297 | break; | 
|  | 1298 | default: | 
|  | 1299 | err = -ENODEV; | 
|  | 1300 | goto out; | 
|  | 1301 | } | 
|  | 1302 |  | 
|  | 1303 | /* get mac addr from device tree */ | 
|  | 1304 | if (pasemi_get_mac_addr(mac) || !is_valid_ether_addr(mac->mac_addr)) { | 
|  | 1305 | err = -ENODEV; | 
|  | 1306 | goto out; | 
|  | 1307 | } | 
|  | 1308 | memcpy(dev->dev_addr, mac->mac_addr, sizeof(mac->mac_addr)); | 
|  | 1309 |  | 
|  | 1310 | dev->open = pasemi_mac_open; | 
|  | 1311 | dev->stop = pasemi_mac_close; | 
|  | 1312 | dev->hard_start_xmit = pasemi_mac_start_tx; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1313 | dev->set_multicast_list = pasemi_mac_set_rx_mode; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1314 |  | 
| Olof Johansson | b6e05a1 | 2007-09-15 13:44:07 -0700 | [diff] [blame] | 1315 | err = pasemi_mac_map_regs(mac); | 
|  | 1316 | if (err) | 
|  | 1317 | goto out; | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1318 |  | 
|  | 1319 | mac->rx_status = &dma_status->rx_sta[mac->dma_rxch]; | 
|  | 1320 | mac->tx_status = &dma_status->tx_sta[mac->dma_txch]; | 
|  | 1321 |  | 
| Olof Johansson | ceb5136 | 2007-05-08 00:47:49 -0500 | [diff] [blame] | 1322 | mac->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); | 
|  | 1323 |  | 
| Olof Johansson | bb6e959 | 2007-05-08 00:47:54 -0500 | [diff] [blame] | 1324 | /* Enable most messages by default */ | 
|  | 1325 | mac->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1; | 
|  | 1326 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1327 | err = register_netdev(dev); | 
|  | 1328 |  | 
|  | 1329 | if (err) { | 
|  | 1330 | dev_err(&mac->pdev->dev, "register_netdev failed with error %d\n", | 
|  | 1331 | err); | 
|  | 1332 | goto out; | 
| Olof Johansson | 69c29d8 | 2007-10-02 16:24:51 -0500 | [diff] [blame] | 1333 | } else if netif_msg_probe(mac) | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1334 | printk(KERN_INFO "%s: PA Semi %s: intf %d, txch %d, rxch %d, " | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1335 | "hw addr %s\n", | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1336 | dev->name, mac->type == MAC_TYPE_GMAC ? "GMAC" : "XAUI", | 
|  | 1337 | mac->dma_if, mac->dma_txch, mac->dma_rxch, | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1338 | print_mac(mac_buf, dev->dev_addr)); | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1339 |  | 
|  | 1340 | return err; | 
|  | 1341 |  | 
|  | 1342 | out: | 
| Olof Johansson | b6e05a1 | 2007-09-15 13:44:07 -0700 | [diff] [blame] | 1343 | if (mac->iob_pdev) | 
|  | 1344 | pci_dev_put(mac->iob_pdev); | 
|  | 1345 | if (mac->dma_pdev) | 
|  | 1346 | pci_dev_put(mac->dma_pdev); | 
|  | 1347 | if (mac->dma_regs) | 
|  | 1348 | iounmap(mac->dma_regs); | 
|  | 1349 | if (mac->iob_regs) | 
|  | 1350 | iounmap(mac->iob_regs); | 
|  | 1351 | if (mac->regs) | 
|  | 1352 | iounmap(mac->regs); | 
|  | 1353 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1354 | free_netdev(dev); | 
|  | 1355 | out_disable_device: | 
|  | 1356 | pci_disable_device(pdev); | 
|  | 1357 | return err; | 
|  | 1358 |  | 
|  | 1359 | } | 
|  | 1360 |  | 
|  | 1361 | static void __devexit pasemi_mac_remove(struct pci_dev *pdev) | 
|  | 1362 | { | 
|  | 1363 | struct net_device *netdev = pci_get_drvdata(pdev); | 
|  | 1364 | struct pasemi_mac *mac; | 
|  | 1365 |  | 
|  | 1366 | if (!netdev) | 
|  | 1367 | return; | 
|  | 1368 |  | 
|  | 1369 | mac = netdev_priv(netdev); | 
|  | 1370 |  | 
|  | 1371 | unregister_netdev(netdev); | 
|  | 1372 |  | 
|  | 1373 | pci_disable_device(pdev); | 
|  | 1374 | pci_dev_put(mac->dma_pdev); | 
|  | 1375 | pci_dev_put(mac->iob_pdev); | 
|  | 1376 |  | 
| Olof Johansson | b6e05a1 | 2007-09-15 13:44:07 -0700 | [diff] [blame] | 1377 | iounmap(mac->regs); | 
|  | 1378 | iounmap(mac->dma_regs); | 
|  | 1379 | iounmap(mac->iob_regs); | 
|  | 1380 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1381 | pci_set_drvdata(pdev, NULL); | 
|  | 1382 | free_netdev(netdev); | 
|  | 1383 | } | 
|  | 1384 |  | 
|  | 1385 | static struct pci_device_id pasemi_mac_pci_tbl[] = { | 
|  | 1386 | { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa005) }, | 
|  | 1387 | { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa006) }, | 
| olof@lixom.net | fd17825 | 2007-05-12 14:57:36 -0500 | [diff] [blame] | 1388 | { }, | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1389 | }; | 
|  | 1390 |  | 
|  | 1391 | MODULE_DEVICE_TABLE(pci, pasemi_mac_pci_tbl); | 
|  | 1392 |  | 
|  | 1393 | static struct pci_driver pasemi_mac_driver = { | 
|  | 1394 | .name		= "pasemi_mac", | 
|  | 1395 | .id_table	= pasemi_mac_pci_tbl, | 
|  | 1396 | .probe		= pasemi_mac_probe, | 
|  | 1397 | .remove		= __devexit_p(pasemi_mac_remove), | 
|  | 1398 | }; | 
|  | 1399 |  | 
|  | 1400 | static void __exit pasemi_mac_cleanup_module(void) | 
|  | 1401 | { | 
|  | 1402 | pci_unregister_driver(&pasemi_mac_driver); | 
|  | 1403 | __iounmap(dma_status); | 
|  | 1404 | dma_status = NULL; | 
|  | 1405 | } | 
|  | 1406 |  | 
|  | 1407 | int pasemi_mac_init_module(void) | 
|  | 1408 | { | 
|  | 1409 | return pci_register_driver(&pasemi_mac_driver); | 
|  | 1410 | } | 
|  | 1411 |  | 
| Olof Johansson | f5cd787 | 2007-01-31 21:43:54 -0600 | [diff] [blame] | 1412 | module_init(pasemi_mac_init_module); | 
|  | 1413 | module_exit(pasemi_mac_cleanup_module); |