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