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