Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1 | /* |
Dhananjay Phadke | 5d242f1 | 2009-02-25 15:57:56 +0000 | [diff] [blame] | 2 | * Copyright (C) 2003 - 2009 NetXen, Inc. |
Dhananjay Phadke | 13af7a6 | 2009-09-11 11:28:15 +0000 | [diff] [blame] | 3 | * Copyright (C) 2009 - QLogic Corporation. |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 4 | * All rights reserved. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 5 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (at your option) any later version. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 10 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 15 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 19 | * MA 02111-1307, USA. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 20 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 21 | * The full GNU General Public License is included in this distribution |
| 22 | * in the file called LICENSE. |
Amit S. Kale | 80922fb | 2006-12-04 09:18:00 -0800 | [diff] [blame] | 23 | * |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include <linux/netdevice.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include "netxen_nic.h" |
| 29 | #include "netxen_nic_hw.h" |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 30 | |
| 31 | struct crb_addr_pair { |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 32 | u32 addr; |
| 33 | u32 data; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | #define NETXEN_MAX_CRB_XFORM 60 |
| 37 | static unsigned int crb_addr_xform[NETXEN_MAX_CRB_XFORM]; |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 38 | #define NETXEN_ADDR_ERROR (0xffffffff) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 39 | |
| 40 | #define crb_addr_transform(name) \ |
| 41 | crb_addr_xform[NETXEN_HW_PX_MAP_CRB_##name] = \ |
| 42 | NETXEN_HW_CRB_HUB_AGT_ADR_##name << 20 |
| 43 | |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 44 | #define NETXEN_NIC_XDMA_RESET 0x8000ff |
| 45 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 46 | static void |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 47 | netxen_post_rx_buffers_nodb(struct netxen_adapter *adapter, |
| 48 | struct nx_host_rds_ring *rds_ring); |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 49 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 50 | static void crb_addr_transform_setup(void) |
| 51 | { |
| 52 | crb_addr_transform(XDMA); |
| 53 | crb_addr_transform(TIMR); |
| 54 | crb_addr_transform(SRE); |
| 55 | crb_addr_transform(SQN3); |
| 56 | crb_addr_transform(SQN2); |
| 57 | crb_addr_transform(SQN1); |
| 58 | crb_addr_transform(SQN0); |
| 59 | crb_addr_transform(SQS3); |
| 60 | crb_addr_transform(SQS2); |
| 61 | crb_addr_transform(SQS1); |
| 62 | crb_addr_transform(SQS0); |
| 63 | crb_addr_transform(RPMX7); |
| 64 | crb_addr_transform(RPMX6); |
| 65 | crb_addr_transform(RPMX5); |
| 66 | crb_addr_transform(RPMX4); |
| 67 | crb_addr_transform(RPMX3); |
| 68 | crb_addr_transform(RPMX2); |
| 69 | crb_addr_transform(RPMX1); |
| 70 | crb_addr_transform(RPMX0); |
| 71 | crb_addr_transform(ROMUSB); |
| 72 | crb_addr_transform(SN); |
| 73 | crb_addr_transform(QMN); |
| 74 | crb_addr_transform(QMS); |
| 75 | crb_addr_transform(PGNI); |
| 76 | crb_addr_transform(PGND); |
| 77 | crb_addr_transform(PGN3); |
| 78 | crb_addr_transform(PGN2); |
| 79 | crb_addr_transform(PGN1); |
| 80 | crb_addr_transform(PGN0); |
| 81 | crb_addr_transform(PGSI); |
| 82 | crb_addr_transform(PGSD); |
| 83 | crb_addr_transform(PGS3); |
| 84 | crb_addr_transform(PGS2); |
| 85 | crb_addr_transform(PGS1); |
| 86 | crb_addr_transform(PGS0); |
| 87 | crb_addr_transform(PS); |
| 88 | crb_addr_transform(PH); |
| 89 | crb_addr_transform(NIU); |
| 90 | crb_addr_transform(I2Q); |
| 91 | crb_addr_transform(EG); |
| 92 | crb_addr_transform(MN); |
| 93 | crb_addr_transform(MS); |
| 94 | crb_addr_transform(CAS2); |
| 95 | crb_addr_transform(CAS1); |
| 96 | crb_addr_transform(CAS0); |
| 97 | crb_addr_transform(CAM); |
| 98 | crb_addr_transform(C2C1); |
| 99 | crb_addr_transform(C2C0); |
Amit S. Kale | 1fcca1a | 2007-02-05 07:35:26 -0800 | [diff] [blame] | 100 | crb_addr_transform(SMB); |
Dhananjay Phadke | e4c93c8 | 2008-07-21 19:44:02 -0700 | [diff] [blame] | 101 | crb_addr_transform(OCM0); |
| 102 | crb_addr_transform(I2C0); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 103 | } |
| 104 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 105 | void netxen_release_rx_buffers(struct netxen_adapter *adapter) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 106 | { |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 107 | struct netxen_recv_context *recv_ctx; |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 108 | struct nx_host_rds_ring *rds_ring; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 109 | struct netxen_rx_buffer *rx_buf; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 110 | int i, ring; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 111 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 112 | recv_ctx = &adapter->recv_ctx; |
| 113 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 114 | rds_ring = &recv_ctx->rds_rings[ring]; |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 115 | for (i = 0; i < rds_ring->num_desc; ++i) { |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 116 | rx_buf = &(rds_ring->rx_buf_arr[i]); |
| 117 | if (rx_buf->state == NETXEN_BUFFER_FREE) |
| 118 | continue; |
| 119 | pci_unmap_single(adapter->pdev, |
| 120 | rx_buf->dma, |
| 121 | rds_ring->dma_size, |
| 122 | PCI_DMA_FROMDEVICE); |
| 123 | if (rx_buf->skb != NULL) |
| 124 | dev_kfree_skb_any(rx_buf->skb); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | void netxen_release_tx_buffers(struct netxen_adapter *adapter) |
| 130 | { |
| 131 | struct netxen_cmd_buffer *cmd_buf; |
| 132 | struct netxen_skb_frag *buffrag; |
| 133 | int i, j; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 134 | struct nx_host_tx_ring *tx_ring = adapter->tx_ring; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 135 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 136 | cmd_buf = tx_ring->cmd_buf_arr; |
| 137 | for (i = 0; i < tx_ring->num_desc; i++) { |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 138 | buffrag = cmd_buf->frag_array; |
| 139 | if (buffrag->dma) { |
| 140 | pci_unmap_single(adapter->pdev, buffrag->dma, |
| 141 | buffrag->length, PCI_DMA_TODEVICE); |
| 142 | buffrag->dma = 0ULL; |
| 143 | } |
| 144 | for (j = 0; j < cmd_buf->frag_count; j++) { |
| 145 | buffrag++; |
| 146 | if (buffrag->dma) { |
| 147 | pci_unmap_page(adapter->pdev, buffrag->dma, |
| 148 | buffrag->length, |
| 149 | PCI_DMA_TODEVICE); |
| 150 | buffrag->dma = 0ULL; |
| 151 | } |
| 152 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 153 | if (cmd_buf->skb) { |
| 154 | dev_kfree_skb_any(cmd_buf->skb); |
| 155 | cmd_buf->skb = NULL; |
| 156 | } |
| 157 | cmd_buf++; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | void netxen_free_sw_resources(struct netxen_adapter *adapter) |
| 162 | { |
| 163 | struct netxen_recv_context *recv_ctx; |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 164 | struct nx_host_rds_ring *rds_ring; |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 165 | struct nx_host_tx_ring *tx_ring; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 166 | int ring; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 167 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 168 | recv_ctx = &adapter->recv_ctx; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 169 | |
| 170 | if (recv_ctx->rds_rings == NULL) |
| 171 | goto skip_rds; |
| 172 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 173 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 174 | rds_ring = &recv_ctx->rds_rings[ring]; |
Figo.zhang | f2333a0 | 2009-06-11 02:49:10 -0700 | [diff] [blame] | 175 | vfree(rds_ring->rx_buf_arr); |
| 176 | rds_ring->rx_buf_arr = NULL; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 177 | } |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 178 | kfree(recv_ctx->rds_rings); |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 179 | |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 180 | skip_rds: |
| 181 | if (adapter->tx_ring == NULL) |
| 182 | return; |
| 183 | |
| 184 | tx_ring = adapter->tx_ring; |
Figo.zhang | f2333a0 | 2009-06-11 02:49:10 -0700 | [diff] [blame] | 185 | vfree(tx_ring->cmd_buf_arr); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | int netxen_alloc_sw_resources(struct netxen_adapter *adapter) |
| 189 | { |
| 190 | struct netxen_recv_context *recv_ctx; |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 191 | struct nx_host_rds_ring *rds_ring; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 192 | struct nx_host_sds_ring *sds_ring; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 193 | struct nx_host_tx_ring *tx_ring; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 194 | struct netxen_rx_buffer *rx_buf; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 195 | int ring, i, size; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 196 | |
| 197 | struct netxen_cmd_buffer *cmd_buf_arr; |
| 198 | struct net_device *netdev = adapter->netdev; |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 199 | struct pci_dev *pdev = adapter->pdev; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 200 | |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 201 | size = sizeof(struct nx_host_tx_ring); |
| 202 | tx_ring = kzalloc(size, GFP_KERNEL); |
| 203 | if (tx_ring == NULL) { |
| 204 | dev_err(&pdev->dev, "%s: failed to allocate tx ring struct\n", |
| 205 | netdev->name); |
| 206 | return -ENOMEM; |
| 207 | } |
| 208 | adapter->tx_ring = tx_ring; |
| 209 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 210 | tx_ring->num_desc = adapter->num_txd; |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 211 | tx_ring->txq = netdev_get_tx_queue(netdev, 0); |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 212 | |
| 213 | cmd_buf_arr = vmalloc(TX_BUFF_RINGSIZE(tx_ring)); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 214 | if (cmd_buf_arr == NULL) { |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 215 | dev_err(&pdev->dev, "%s: failed to allocate cmd buffer ring\n", |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 216 | netdev->name); |
| 217 | return -ENOMEM; |
| 218 | } |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 219 | memset(cmd_buf_arr, 0, TX_BUFF_RINGSIZE(tx_ring)); |
| 220 | tx_ring->cmd_buf_arr = cmd_buf_arr; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 221 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 222 | recv_ctx = &adapter->recv_ctx; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 223 | |
| 224 | size = adapter->max_rds_rings * sizeof (struct nx_host_rds_ring); |
| 225 | rds_ring = kzalloc(size, GFP_KERNEL); |
| 226 | if (rds_ring == NULL) { |
| 227 | dev_err(&pdev->dev, "%s: failed to allocate rds ring struct\n", |
| 228 | netdev->name); |
| 229 | return -ENOMEM; |
| 230 | } |
| 231 | recv_ctx->rds_rings = rds_ring; |
| 232 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 233 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 234 | rds_ring = &recv_ctx->rds_rings[ring]; |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 235 | switch (ring) { |
| 236 | case RCV_RING_NORMAL: |
| 237 | rds_ring->num_desc = adapter->num_rxd; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 238 | if (adapter->ahw.cut_through) { |
| 239 | rds_ring->dma_size = |
| 240 | NX_CT_DEFAULT_RX_BUF_LEN; |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 241 | rds_ring->skb_size = |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 242 | NX_CT_DEFAULT_RX_BUF_LEN; |
| 243 | } else { |
Dhananjay Phadke | 9b08beb | 2009-07-26 20:07:44 +0000 | [diff] [blame] | 244 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 245 | rds_ring->dma_size = |
| 246 | NX_P3_RX_BUF_MAX_LEN; |
| 247 | else |
| 248 | rds_ring->dma_size = |
| 249 | NX_P2_RX_BUF_MAX_LEN; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 250 | rds_ring->skb_size = |
Dhananjay Phadke | 9b08beb | 2009-07-26 20:07:44 +0000 | [diff] [blame] | 251 | rds_ring->dma_size + NET_IP_ALIGN; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 252 | } |
| 253 | break; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 254 | |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 255 | case RCV_RING_JUMBO: |
| 256 | rds_ring->num_desc = adapter->num_jumbo_rxd; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 257 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 258 | rds_ring->dma_size = |
| 259 | NX_P3_RX_JUMBO_BUF_MAX_LEN; |
| 260 | else |
| 261 | rds_ring->dma_size = |
| 262 | NX_P2_RX_JUMBO_BUF_MAX_LEN; |
Dhananjay Phadke | bc75e5b | 2009-09-03 13:10:53 +0000 | [diff] [blame] | 263 | |
| 264 | if (adapter->capabilities & NX_CAP0_HW_LRO) |
| 265 | rds_ring->dma_size += NX_LRO_BUFFER_EXTRA; |
| 266 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 267 | rds_ring->skb_size = |
| 268 | rds_ring->dma_size + NET_IP_ALIGN; |
| 269 | break; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 270 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 271 | case RCV_RING_LRO: |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 272 | rds_ring->num_desc = adapter->num_lro_rxd; |
Dhananjay Phadke | 9b08beb | 2009-07-26 20:07:44 +0000 | [diff] [blame] | 273 | rds_ring->dma_size = NX_RX_LRO_BUFFER_LENGTH; |
| 274 | rds_ring->skb_size = rds_ring->dma_size + NET_IP_ALIGN; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 275 | break; |
| 276 | |
| 277 | } |
| 278 | rds_ring->rx_buf_arr = (struct netxen_rx_buffer *) |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 279 | vmalloc(RCV_BUFF_RINGSIZE(rds_ring)); |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 280 | if (rds_ring->rx_buf_arr == NULL) { |
| 281 | printk(KERN_ERR "%s: Failed to allocate " |
| 282 | "rx buffer ring %d\n", |
| 283 | netdev->name, ring); |
| 284 | /* free whatever was already allocated */ |
| 285 | goto err_out; |
| 286 | } |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 287 | memset(rds_ring->rx_buf_arr, 0, RCV_BUFF_RINGSIZE(rds_ring)); |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 288 | INIT_LIST_HEAD(&rds_ring->free_list); |
| 289 | /* |
| 290 | * Now go through all of them, set reference handles |
| 291 | * and put them in the queues. |
| 292 | */ |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 293 | rx_buf = rds_ring->rx_buf_arr; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 294 | for (i = 0; i < rds_ring->num_desc; i++) { |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 295 | list_add_tail(&rx_buf->list, |
| 296 | &rds_ring->free_list); |
| 297 | rx_buf->ref_handle = i; |
| 298 | rx_buf->state = NETXEN_BUFFER_FREE; |
| 299 | rx_buf++; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 300 | } |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 301 | spin_lock_init(&rds_ring->lock); |
| 302 | } |
| 303 | |
| 304 | for (ring = 0; ring < adapter->max_sds_rings; ring++) { |
| 305 | sds_ring = &recv_ctx->sds_rings[ring]; |
| 306 | sds_ring->irq = adapter->msix_entries[ring].vector; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 307 | sds_ring->adapter = adapter; |
| 308 | sds_ring->num_desc = adapter->num_rxd; |
| 309 | |
| 310 | for (i = 0; i < NUM_RCV_DESC_RINGS; i++) |
| 311 | INIT_LIST_HEAD(&sds_ring->free_list[i]); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 312 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 313 | |
| 314 | return 0; |
| 315 | |
| 316 | err_out: |
| 317 | netxen_free_sw_resources(adapter); |
| 318 | return -ENOMEM; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 319 | } |
| 320 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 321 | /* |
| 322 | * netxen_decode_crb_addr(0 - utility to translate from internal Phantom CRB |
| 323 | * address to external PCI CRB address. |
| 324 | */ |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 325 | static u32 netxen_decode_crb_addr(u32 addr) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 326 | { |
| 327 | int i; |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 328 | u32 base_addr, offset, pci_base; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 329 | |
| 330 | crb_addr_transform_setup(); |
| 331 | |
| 332 | pci_base = NETXEN_ADDR_ERROR; |
| 333 | base_addr = addr & 0xfff00000; |
| 334 | offset = addr & 0x000fffff; |
| 335 | |
| 336 | for (i = 0; i < NETXEN_MAX_CRB_XFORM; i++) { |
| 337 | if (crb_addr_xform[i] == base_addr) { |
| 338 | pci_base = i << 20; |
| 339 | break; |
| 340 | } |
| 341 | } |
| 342 | if (pci_base == NETXEN_ADDR_ERROR) |
| 343 | return pci_base; |
| 344 | else |
| 345 | return (pci_base + offset); |
| 346 | } |
| 347 | |
Dhananjay Phadke | c9517e5 | 2009-08-24 19:23:26 +0000 | [diff] [blame] | 348 | #define NETXEN_MAX_ROM_WAIT_USEC 100 |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 349 | |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 350 | static int netxen_wait_rom_done(struct netxen_adapter *adapter) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 351 | { |
| 352 | long timeout = 0; |
| 353 | long done = 0; |
| 354 | |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 355 | cond_resched(); |
| 356 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 357 | while (done == 0) { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 358 | done = NXRD32(adapter, NETXEN_ROMUSB_GLB_STATUS); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 359 | done &= 2; |
Dhananjay Phadke | c9517e5 | 2009-08-24 19:23:26 +0000 | [diff] [blame] | 360 | if (++timeout >= NETXEN_MAX_ROM_WAIT_USEC) { |
| 361 | dev_err(&adapter->pdev->dev, |
| 362 | "Timeout reached waiting for rom done"); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 363 | return -EIO; |
| 364 | } |
Dhananjay Phadke | c9517e5 | 2009-08-24 19:23:26 +0000 | [diff] [blame] | 365 | udelay(1); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 366 | } |
| 367 | return 0; |
| 368 | } |
| 369 | |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 370 | static int do_rom_fast_read(struct netxen_adapter *adapter, |
| 371 | int addr, int *valp) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 372 | { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 373 | NXWR32(adapter, NETXEN_ROMUSB_ROM_ADDRESS, addr); |
| 374 | NXWR32(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); |
| 375 | NXWR32(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 3); |
| 376 | NXWR32(adapter, NETXEN_ROMUSB_ROM_INSTR_OPCODE, 0xb); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 377 | if (netxen_wait_rom_done(adapter)) { |
| 378 | printk("Error waiting for rom done\n"); |
| 379 | return -EIO; |
| 380 | } |
| 381 | /* reset abyte_cnt and dummy_byte_cnt */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 382 | NXWR32(adapter, NETXEN_ROMUSB_ROM_ABYTE_CNT, 0); |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 383 | udelay(10); |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 384 | NXWR32(adapter, NETXEN_ROMUSB_ROM_DUMMY_BYTE_CNT, 0); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 385 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 386 | *valp = NXRD32(adapter, NETXEN_ROMUSB_ROM_RDATA); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 387 | return 0; |
| 388 | } |
| 389 | |
Adrian Bunk | 993fb90 | 2007-11-05 18:07:31 +0100 | [diff] [blame] | 390 | static int do_rom_fast_read_words(struct netxen_adapter *adapter, int addr, |
| 391 | u8 *bytes, size_t size) |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 392 | { |
| 393 | int addridx; |
| 394 | int ret = 0; |
| 395 | |
| 396 | for (addridx = addr; addridx < (addr + size); addridx += 4) { |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 397 | int v; |
| 398 | ret = do_rom_fast_read(adapter, addridx, &v); |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 399 | if (ret != 0) |
| 400 | break; |
Al Viro | f305f78 | 2007-12-22 19:44:00 +0000 | [diff] [blame] | 401 | *(__le32 *)bytes = cpu_to_le32(v); |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 402 | bytes += 4; |
| 403 | } |
| 404 | |
| 405 | return ret; |
| 406 | } |
| 407 | |
| 408 | int |
Jeff Garzik | 4790654 | 2007-11-23 21:23:36 -0500 | [diff] [blame] | 409 | netxen_rom_fast_read_words(struct netxen_adapter *adapter, int addr, |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 410 | u8 *bytes, size_t size) |
| 411 | { |
| 412 | int ret; |
| 413 | |
Dhananjay Phadke | c9517e5 | 2009-08-24 19:23:26 +0000 | [diff] [blame] | 414 | ret = netxen_rom_lock(adapter); |
Amit S. Kale | 27d2ab5 | 2007-02-05 07:40:49 -0800 | [diff] [blame] | 415 | if (ret < 0) |
| 416 | return ret; |
| 417 | |
| 418 | ret = do_rom_fast_read_words(adapter, addr, bytes, size); |
| 419 | |
| 420 | netxen_rom_unlock(adapter); |
| 421 | return ret; |
| 422 | } |
| 423 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 424 | int netxen_rom_fast_read(struct netxen_adapter *adapter, int addr, int *valp) |
| 425 | { |
| 426 | int ret; |
| 427 | |
Dhananjay Phadke | c9517e5 | 2009-08-24 19:23:26 +0000 | [diff] [blame] | 428 | if (netxen_rom_lock(adapter) != 0) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 429 | return -EIO; |
| 430 | |
| 431 | ret = do_rom_fast_read(adapter, addr, valp); |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 432 | netxen_rom_unlock(adapter); |
| 433 | return ret; |
| 434 | } |
| 435 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 436 | #define NETXEN_BOARDTYPE 0x4008 |
| 437 | #define NETXEN_BOARDNUM 0x400c |
| 438 | #define NETXEN_CHIPNUM 0x4010 |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 439 | |
| 440 | int netxen_pinit_from_rom(struct netxen_adapter *adapter, int verbose) |
| 441 | { |
Dhananjay Phadke | dcd56fd | 2008-06-15 22:59:45 -0700 | [diff] [blame] | 442 | int addr, val; |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 443 | int i, n, init_delay = 0; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 444 | struct crb_addr_pair *buf; |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 445 | unsigned offset; |
Linsys Contractor Mithlesh Thukral | e0e20a1 | 2007-02-28 05:16:40 -0800 | [diff] [blame] | 446 | u32 off; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 447 | |
| 448 | /* resetall */ |
Dhananjay Phadke | c9517e5 | 2009-08-24 19:23:26 +0000 | [diff] [blame] | 449 | netxen_rom_lock(adapter); |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 450 | NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0xffffffff); |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 451 | netxen_rom_unlock(adapter); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 452 | |
| 453 | if (verbose) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 454 | if (netxen_rom_fast_read(adapter, NETXEN_BOARDTYPE, &val) == 0) |
| 455 | printk("P2 ROM board type: 0x%08x\n", val); |
| 456 | else |
| 457 | printk("Could not read board type\n"); |
| 458 | if (netxen_rom_fast_read(adapter, NETXEN_BOARDNUM, &val) == 0) |
| 459 | printk("P2 ROM board num: 0x%08x\n", val); |
| 460 | else |
| 461 | printk("Could not read board number\n"); |
| 462 | if (netxen_rom_fast_read(adapter, NETXEN_CHIPNUM, &val) == 0) |
| 463 | printk("P2 ROM chip num: 0x%08x\n", val); |
| 464 | else |
| 465 | printk("Could not read chip number\n"); |
| 466 | } |
| 467 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 468 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
| 469 | if (netxen_rom_fast_read(adapter, 0, &n) != 0 || |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 470 | (n != 0xcafecafe) || |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 471 | netxen_rom_fast_read(adapter, 4, &n) != 0) { |
| 472 | printk(KERN_ERR "%s: ERROR Reading crb_init area: " |
| 473 | "n: %08x\n", netxen_nic_driver_name, n); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 474 | return -EIO; |
| 475 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 476 | offset = n & 0xffffU; |
| 477 | n = (n >> 16) & 0xffffU; |
| 478 | } else { |
| 479 | if (netxen_rom_fast_read(adapter, 0, &n) != 0 || |
| 480 | !(n & 0x80000000)) { |
| 481 | printk(KERN_ERR "%s: ERROR Reading crb_init area: " |
| 482 | "n: %08x\n", netxen_nic_driver_name, n); |
| 483 | return -EIO; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 484 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 485 | offset = 1; |
| 486 | n &= ~0x80000000; |
| 487 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 488 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 489 | if (n < 1024) { |
| 490 | if (verbose) |
| 491 | printk(KERN_DEBUG "%s: %d CRB init values found" |
| 492 | " in ROM.\n", netxen_nic_driver_name, n); |
| 493 | } else { |
| 494 | printk(KERN_ERR "%s:n=0x%x Error! NetXen card flash not" |
| 495 | " initialized.\n", __func__, n); |
| 496 | return -EIO; |
| 497 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 498 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 499 | buf = kcalloc(n, sizeof(struct crb_addr_pair), GFP_KERNEL); |
| 500 | if (buf == NULL) { |
| 501 | printk("%s: netxen_pinit_from_rom: Unable to calloc memory.\n", |
| 502 | netxen_nic_driver_name); |
| 503 | return -ENOMEM; |
| 504 | } |
| 505 | for (i = 0; i < n; i++) { |
| 506 | if (netxen_rom_fast_read(adapter, 8*i + 4*offset, &val) != 0 || |
Daniel Marjamäki | 584dbe9 | 2009-01-29 08:55:56 +0000 | [diff] [blame] | 507 | netxen_rom_fast_read(adapter, 8*i + 4*offset + 4, &addr) != 0) { |
| 508 | kfree(buf); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 509 | return -EIO; |
Daniel Marjamäki | 584dbe9 | 2009-01-29 08:55:56 +0000 | [diff] [blame] | 510 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 511 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 512 | buf[i].addr = addr; |
| 513 | buf[i].data = val; |
| 514 | |
| 515 | if (verbose) |
| 516 | printk(KERN_DEBUG "%s: PCI: 0x%08x == 0x%08x\n", |
| 517 | netxen_nic_driver_name, |
| 518 | (u32)netxen_decode_crb_addr(addr), val); |
| 519 | } |
| 520 | for (i = 0; i < n; i++) { |
| 521 | |
| 522 | off = netxen_decode_crb_addr(buf[i].addr); |
| 523 | if (off == NETXEN_ADDR_ERROR) { |
| 524 | printk(KERN_ERR"CRB init value out of range %x\n", |
Amit S. Kale | 1fcca1a | 2007-02-05 07:35:26 -0800 | [diff] [blame] | 525 | buf[i].addr); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 526 | continue; |
| 527 | } |
| 528 | off += NETXEN_PCI_CRBSPACE; |
| 529 | /* skipping cold reboot MAGIC */ |
| 530 | if (off == NETXEN_CAM_RAM(0x1fc)) |
| 531 | continue; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 532 | |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 533 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) { |
| 534 | /* do not reset PCI */ |
| 535 | if (off == (ROMUSB_GLB + 0xbc)) |
| 536 | continue; |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 537 | if (off == (ROMUSB_GLB + 0xa8)) |
| 538 | continue; |
| 539 | if (off == (ROMUSB_GLB + 0xc8)) /* core clock */ |
| 540 | continue; |
| 541 | if (off == (ROMUSB_GLB + 0x24)) /* MN clock */ |
| 542 | continue; |
| 543 | if (off == (ROMUSB_GLB + 0x1c)) /* MS clock */ |
| 544 | continue; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 545 | if (off == (NETXEN_CRB_PEG_NET_1 + 0x18)) |
| 546 | buf[i].data = 0x1020; |
| 547 | /* skip the function enable register */ |
| 548 | if (off == NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION)) |
| 549 | continue; |
| 550 | if (off == NETXEN_PCIE_REG(PCIE_SETUP_FUNCTION2)) |
| 551 | continue; |
| 552 | if ((off & 0x0ff00000) == NETXEN_CRB_SMB) |
| 553 | continue; |
| 554 | } |
| 555 | |
| 556 | if (off == NETXEN_ADDR_ERROR) { |
| 557 | printk(KERN_ERR "%s: Err: Unknown addr: 0x%08x\n", |
| 558 | netxen_nic_driver_name, buf[i].addr); |
| 559 | continue; |
| 560 | } |
| 561 | |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 562 | init_delay = 1; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 563 | /* After writing this register, HW needs time for CRB */ |
| 564 | /* to quiet down (else crb_window returns 0xffffffff) */ |
| 565 | if (off == NETXEN_ROMUSB_GLB_SW_RESET) { |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 566 | init_delay = 1000; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 567 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 568 | /* hold xdma in reset also */ |
Amit S. Kale | cb8011a | 2006-11-29 09:00:10 -0800 | [diff] [blame] | 569 | buf[i].data = NETXEN_NIC_XDMA_RESET; |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 570 | buf[i].data = 0x8000ff; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 571 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 572 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 573 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 574 | NXWR32(adapter, off, buf[i].data); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 575 | |
Dhananjay Phadke | 27c915a | 2009-01-14 20:49:00 -0800 | [diff] [blame] | 576 | msleep(init_delay); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 577 | } |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 578 | kfree(buf); |
| 579 | |
| 580 | /* disable_peg_cache_all */ |
| 581 | |
| 582 | /* unreset_net_cache */ |
| 583 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 584 | val = NXRD32(adapter, NETXEN_ROMUSB_GLB_SW_RESET); |
| 585 | NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, (val & 0xffffff0f)); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /* p2dn replyCount */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 589 | NXWR32(adapter, NETXEN_CRB_PEG_NET_D + 0xec, 0x1e); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 590 | /* disable_peg_cache 0 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 591 | NXWR32(adapter, NETXEN_CRB_PEG_NET_D + 0x4c, 8); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 592 | /* disable_peg_cache 1 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 593 | NXWR32(adapter, NETXEN_CRB_PEG_NET_I + 0x4c, 8); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 594 | |
| 595 | /* peg_clr_all */ |
| 596 | |
| 597 | /* peg_clr 0 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 598 | NXWR32(adapter, NETXEN_CRB_PEG_NET_0 + 0x8, 0); |
| 599 | NXWR32(adapter, NETXEN_CRB_PEG_NET_0 + 0xc, 0); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 600 | /* peg_clr 1 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 601 | NXWR32(adapter, NETXEN_CRB_PEG_NET_1 + 0x8, 0); |
| 602 | NXWR32(adapter, NETXEN_CRB_PEG_NET_1 + 0xc, 0); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 603 | /* peg_clr 2 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 604 | NXWR32(adapter, NETXEN_CRB_PEG_NET_2 + 0x8, 0); |
| 605 | NXWR32(adapter, NETXEN_CRB_PEG_NET_2 + 0xc, 0); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 606 | /* peg_clr 3 */ |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 607 | NXWR32(adapter, NETXEN_CRB_PEG_NET_3 + 0x8, 0); |
| 608 | NXWR32(adapter, NETXEN_CRB_PEG_NET_3 + 0xc, 0); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 609 | return 0; |
| 610 | } |
| 611 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 612 | int |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 613 | netxen_need_fw_reset(struct netxen_adapter *adapter) |
| 614 | { |
| 615 | u32 count, old_count; |
| 616 | u32 val, version, major, minor, build; |
| 617 | int i, timeout; |
| 618 | u8 fw_type; |
| 619 | |
| 620 | /* NX2031 firmware doesn't support heartbit */ |
| 621 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 622 | return 1; |
| 623 | |
| 624 | /* last attempt had failed */ |
| 625 | if (NXRD32(adapter, CRB_CMDPEG_STATE) == PHAN_INITIALIZE_FAILED) |
| 626 | return 1; |
| 627 | |
| 628 | old_count = count = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER); |
| 629 | |
| 630 | for (i = 0; i < 10; i++) { |
| 631 | |
| 632 | timeout = msleep_interruptible(200); |
| 633 | if (timeout) { |
| 634 | NXWR32(adapter, CRB_CMDPEG_STATE, |
| 635 | PHAN_INITIALIZE_FAILED); |
| 636 | return -EINTR; |
| 637 | } |
| 638 | |
| 639 | count = NXRD32(adapter, NETXEN_PEG_ALIVE_COUNTER); |
| 640 | if (count != old_count) |
| 641 | break; |
| 642 | } |
| 643 | |
| 644 | /* firmware is dead */ |
| 645 | if (count == old_count) |
| 646 | return 1; |
| 647 | |
| 648 | /* check if we have got newer or different file firmware */ |
| 649 | if (adapter->fw) { |
| 650 | |
| 651 | const struct firmware *fw = adapter->fw; |
| 652 | |
| 653 | val = cpu_to_le32(*(u32 *)&fw->data[NX_FW_VERSION_OFFSET]); |
| 654 | version = NETXEN_DECODE_VERSION(val); |
| 655 | |
| 656 | major = NXRD32(adapter, NETXEN_FW_VERSION_MAJOR); |
| 657 | minor = NXRD32(adapter, NETXEN_FW_VERSION_MINOR); |
| 658 | build = NXRD32(adapter, NETXEN_FW_VERSION_SUB); |
| 659 | |
| 660 | if (version > NETXEN_VERSION_CODE(major, minor, build)) |
| 661 | return 1; |
| 662 | |
| 663 | if (version == NETXEN_VERSION_CODE(major, minor, build)) { |
| 664 | |
| 665 | val = NXRD32(adapter, NETXEN_MIU_MN_CONTROL); |
| 666 | fw_type = (val & 0x4) ? |
| 667 | NX_P3_CT_ROMIMAGE : NX_P3_MN_ROMIMAGE; |
| 668 | |
| 669 | if (adapter->fw_type != fw_type) |
| 670 | return 1; |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | return 0; |
| 675 | } |
| 676 | |
| 677 | static char *fw_name[] = { |
| 678 | "nxromimg.bin", "nx3fwct.bin", "nx3fwmn.bin", "flash", |
| 679 | }; |
| 680 | |
| 681 | int |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 682 | netxen_load_firmware(struct netxen_adapter *adapter) |
| 683 | { |
| 684 | u64 *ptr64; |
| 685 | u32 i, flashaddr, size; |
| 686 | const struct firmware *fw = adapter->fw; |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 687 | struct pci_dev *pdev = adapter->pdev; |
| 688 | |
| 689 | dev_info(&pdev->dev, "loading firmware from %s\n", |
| 690 | fw_name[adapter->fw_type]); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 691 | |
| 692 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 693 | NXWR32(adapter, NETXEN_ROMUSB_GLB_CAS_RST, 1); |
| 694 | |
| 695 | if (fw) { |
| 696 | __le64 data; |
| 697 | |
| 698 | size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START) / 8; |
| 699 | |
| 700 | ptr64 = (u64 *)&fw->data[NETXEN_BOOTLD_START]; |
| 701 | flashaddr = NETXEN_BOOTLD_START; |
| 702 | |
| 703 | for (i = 0; i < size; i++) { |
| 704 | data = cpu_to_le64(ptr64[i]); |
Amit Kumar Salecha | 1f5e055 | 2009-10-13 05:31:41 +0000 | [diff] [blame] | 705 | if (adapter->pci_mem_write(adapter, |
| 706 | flashaddr, data)) |
| 707 | return -EIO; |
| 708 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 709 | flashaddr += 8; |
| 710 | } |
| 711 | |
| 712 | size = *(u32 *)&fw->data[NX_FW_SIZE_OFFSET]; |
| 713 | size = (__force u32)cpu_to_le32(size) / 8; |
| 714 | |
| 715 | ptr64 = (u64 *)&fw->data[NETXEN_IMAGE_START]; |
| 716 | flashaddr = NETXEN_IMAGE_START; |
| 717 | |
| 718 | for (i = 0; i < size; i++) { |
| 719 | data = cpu_to_le64(ptr64[i]); |
| 720 | |
| 721 | if (adapter->pci_mem_write(adapter, |
Amit Kumar Salecha | 1f5e055 | 2009-10-13 05:31:41 +0000 | [diff] [blame] | 722 | flashaddr, data)) |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 723 | return -EIO; |
| 724 | |
| 725 | flashaddr += 8; |
| 726 | } |
| 727 | } else { |
Amit Kumar Salecha | f78c085 | 2009-09-11 11:28:11 +0000 | [diff] [blame] | 728 | u64 data; |
| 729 | u32 hi, lo; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 730 | |
Amit Kumar Salecha | f78c085 | 2009-09-11 11:28:11 +0000 | [diff] [blame] | 731 | size = (NETXEN_IMAGE_START - NETXEN_BOOTLD_START) / 8; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 732 | flashaddr = NETXEN_BOOTLD_START; |
| 733 | |
| 734 | for (i = 0; i < size; i++) { |
| 735 | if (netxen_rom_fast_read(adapter, |
Amit Kumar Salecha | 1f5e055 | 2009-10-13 05:31:41 +0000 | [diff] [blame] | 736 | flashaddr, (int *)&lo) != 0) |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 737 | return -EIO; |
Amit Kumar Salecha | f78c085 | 2009-09-11 11:28:11 +0000 | [diff] [blame] | 738 | if (netxen_rom_fast_read(adapter, |
Amit Kumar Salecha | 1f5e055 | 2009-10-13 05:31:41 +0000 | [diff] [blame] | 739 | flashaddr + 4, (int *)&hi) != 0) |
Amit Kumar Salecha | f78c085 | 2009-09-11 11:28:11 +0000 | [diff] [blame] | 740 | return -EIO; |
| 741 | |
| 742 | /* hi, lo are already in host endian byteorder */ |
| 743 | data = (((u64)hi << 32) | lo); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 744 | |
| 745 | if (adapter->pci_mem_write(adapter, |
Amit Kumar Salecha | 1f5e055 | 2009-10-13 05:31:41 +0000 | [diff] [blame] | 746 | flashaddr, data)) |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 747 | return -EIO; |
| 748 | |
Amit Kumar Salecha | f78c085 | 2009-09-11 11:28:11 +0000 | [diff] [blame] | 749 | flashaddr += 8; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | msleep(1); |
| 753 | |
| 754 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 755 | NXWR32(adapter, NETXEN_ROMUSB_GLB_SW_RESET, 0x80001d); |
| 756 | else { |
| 757 | NXWR32(adapter, NETXEN_ROMUSB_GLB_CHIP_CLK_CTRL, 0x3fff); |
| 758 | NXWR32(adapter, NETXEN_ROMUSB_GLB_CAS_RST, 0); |
| 759 | } |
| 760 | |
| 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | static int |
| 765 | netxen_validate_firmware(struct netxen_adapter *adapter, const char *fwname) |
| 766 | { |
| 767 | __le32 val; |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 768 | u32 ver, min_ver, bios; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 769 | struct pci_dev *pdev = adapter->pdev; |
| 770 | const struct firmware *fw = adapter->fw; |
| 771 | |
| 772 | if (fw->size < NX_FW_MIN_SIZE) |
| 773 | return -EINVAL; |
| 774 | |
| 775 | val = cpu_to_le32(*(u32 *)&fw->data[NX_FW_MAGIC_OFFSET]); |
| 776 | if ((__force u32)val != NETXEN_BDINFO_MAGIC) |
| 777 | return -EINVAL; |
| 778 | |
| 779 | val = cpu_to_le32(*(u32 *)&fw->data[NX_FW_VERSION_OFFSET]); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 780 | |
| 781 | if (NX_IS_REVISION_P3(adapter->ahw.revision_id)) |
| 782 | min_ver = NETXEN_VERSION_CODE(4, 0, 216); |
| 783 | else |
| 784 | min_ver = NETXEN_VERSION_CODE(3, 4, 216); |
| 785 | |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 786 | ver = NETXEN_DECODE_VERSION(val); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 787 | |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 788 | if ((_major(ver) > _NETXEN_NIC_LINUX_MAJOR) || (ver < min_ver)) { |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 789 | dev_err(&pdev->dev, |
| 790 | "%s: firmware version %d.%d.%d unsupported\n", |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 791 | fwname, _major(ver), _minor(ver), _build(ver)); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 792 | return -EINVAL; |
| 793 | } |
| 794 | |
| 795 | val = cpu_to_le32(*(u32 *)&fw->data[NX_BIOS_VERSION_OFFSET]); |
| 796 | netxen_rom_fast_read(adapter, NX_BIOS_VERSION_OFFSET, (int *)&bios); |
| 797 | if ((__force u32)val != bios) { |
| 798 | dev_err(&pdev->dev, "%s: firmware bios is incompatible\n", |
| 799 | fwname); |
| 800 | return -EINVAL; |
| 801 | } |
| 802 | |
| 803 | /* check if flashed firmware is newer */ |
| 804 | if (netxen_rom_fast_read(adapter, |
| 805 | NX_FW_VERSION_OFFSET, (int *)&val)) |
| 806 | return -EIO; |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 807 | val = NETXEN_DECODE_VERSION(val); |
| 808 | if (val > ver) { |
| 809 | dev_info(&pdev->dev, "%s: firmware is older than flash\n", |
| 810 | fwname); |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 811 | return -EINVAL; |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 812 | } |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 813 | |
| 814 | NXWR32(adapter, NETXEN_CAM_RAM(0x1fc), NETXEN_BDINFO_MAGIC); |
| 815 | return 0; |
| 816 | } |
| 817 | |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 818 | static int |
| 819 | netxen_p3_has_mn(struct netxen_adapter *adapter) |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 820 | { |
| 821 | u32 capability, flashed_ver; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 822 | capability = 0; |
| 823 | |
| 824 | netxen_rom_fast_read(adapter, |
| 825 | NX_FW_VERSION_OFFSET, (int *)&flashed_ver); |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 826 | flashed_ver = NETXEN_DECODE_VERSION(flashed_ver); |
| 827 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 828 | if (flashed_ver >= NETXEN_VERSION_CODE(4, 0, 220)) { |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 829 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 830 | capability = NXRD32(adapter, NX_PEG_TUNE_CAPABILITY); |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 831 | if (capability & NX_PEG_TUNE_MN_PRESENT) |
| 832 | return 1; |
| 833 | } |
| 834 | return 0; |
| 835 | } |
| 836 | |
| 837 | void netxen_request_firmware(struct netxen_adapter *adapter) |
| 838 | { |
| 839 | u8 fw_type; |
| 840 | struct pci_dev *pdev = adapter->pdev; |
| 841 | int rc = 0; |
| 842 | |
| 843 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
| 844 | fw_type = NX_P2_MN_ROMIMAGE; |
| 845 | goto request_fw; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 846 | } |
| 847 | |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 848 | fw_type = netxen_p3_has_mn(adapter) ? |
| 849 | NX_P3_MN_ROMIMAGE : NX_P3_CT_ROMIMAGE; |
Dhananjay Phadke | 98e31bb | 2009-07-01 11:41:42 +0000 | [diff] [blame] | 850 | |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 851 | request_fw: |
| 852 | rc = request_firmware(&adapter->fw, fw_name[fw_type], &pdev->dev); |
| 853 | if (rc != 0) { |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 854 | if (fw_type == NX_P3_MN_ROMIMAGE) { |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 855 | msleep(1); |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 856 | fw_type = NX_P3_CT_ROMIMAGE; |
| 857 | goto request_fw; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 858 | } |
| 859 | |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 860 | fw_type = NX_FLASH_ROMIMAGE; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 861 | adapter->fw = NULL; |
| 862 | goto done; |
| 863 | } |
| 864 | |
| 865 | rc = netxen_validate_firmware(adapter, fw_name[fw_type]); |
| 866 | if (rc != 0) { |
| 867 | release_firmware(adapter->fw); |
| 868 | |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 869 | if (fw_type == NX_P3_MN_ROMIMAGE) { |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 870 | msleep(1); |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 871 | fw_type = NX_P3_CT_ROMIMAGE; |
| 872 | goto request_fw; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 875 | fw_type = NX_FLASH_ROMIMAGE; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 876 | adapter->fw = NULL; |
| 877 | goto done; |
| 878 | } |
| 879 | |
| 880 | done: |
Dhananjay Phadke | 67c38fc | 2009-07-01 11:41:43 +0000 | [diff] [blame] | 881 | adapter->fw_type = fw_type; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | |
| 885 | void |
| 886 | netxen_release_firmware(struct netxen_adapter *adapter) |
| 887 | { |
| 888 | if (adapter->fw) |
| 889 | release_firmware(adapter->fw); |
Dhananjay Phadke | db4cfd8 | 2009-09-05 17:43:07 +0000 | [diff] [blame] | 890 | adapter->fw = NULL; |
Dhananjay Phadke | f7185c7 | 2009-04-28 15:29:11 +0000 | [diff] [blame] | 891 | } |
| 892 | |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 893 | int netxen_init_dummy_dma(struct netxen_adapter *adapter) |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 894 | { |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 895 | u64 addr; |
| 896 | u32 hi, lo; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 897 | |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 898 | if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 899 | return 0; |
| 900 | |
| 901 | adapter->dummy_dma.addr = pci_alloc_consistent(adapter->pdev, |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 902 | NETXEN_HOST_DUMMY_DMA_SIZE, |
| 903 | &adapter->dummy_dma.phys_addr); |
| 904 | if (adapter->dummy_dma.addr == NULL) { |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 905 | dev_err(&adapter->pdev->dev, |
| 906 | "ERROR: Could not allocate dummy DMA memory\n"); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 907 | return -ENOMEM; |
| 908 | } |
| 909 | |
| 910 | addr = (uint64_t) adapter->dummy_dma.phys_addr; |
| 911 | hi = (addr >> 32) & 0xffffffff; |
| 912 | lo = addr & 0xffffffff; |
| 913 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 914 | NXWR32(adapter, CRB_HOST_DUMMY_BUF_ADDR_HI, hi); |
| 915 | NXWR32(adapter, CRB_HOST_DUMMY_BUF_ADDR_LO, lo); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 916 | |
| 917 | return 0; |
| 918 | } |
| 919 | |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 920 | /* |
| 921 | * NetXen DMA watchdog control: |
| 922 | * |
| 923 | * Bit 0 : enabled => R/O: 1 watchdog active, 0 inactive |
| 924 | * Bit 1 : disable_request => 1 req disable dma watchdog |
| 925 | * Bit 2 : enable_request => 1 req enable dma watchdog |
| 926 | * Bit 3-31 : unused |
| 927 | */ |
| 928 | void netxen_free_dummy_dma(struct netxen_adapter *adapter) |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 929 | { |
Dhananjay Phadke | 15eef1e | 2008-08-08 00:08:42 -0700 | [diff] [blame] | 930 | int i = 100; |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 931 | u32 ctrl; |
| 932 | |
| 933 | if (!NX_IS_REVISION_P2(adapter->ahw.revision_id)) |
| 934 | return; |
Dhananjay Phadke | 439b454 | 2008-06-15 22:59:46 -0700 | [diff] [blame] | 935 | |
Dhananjay Phadke | 15eef1e | 2008-08-08 00:08:42 -0700 | [diff] [blame] | 936 | if (!adapter->dummy_dma.addr) |
| 937 | return; |
| 938 | |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 939 | ctrl = NXRD32(adapter, NETXEN_DMA_WATCHDOG_CTRL); |
| 940 | if ((ctrl & 0x1) != 0) { |
| 941 | NXWR32(adapter, NETXEN_DMA_WATCHDOG_CTRL, (ctrl | 0x2)); |
| 942 | |
| 943 | while ((ctrl & 0x1) != 0) { |
| 944 | |
Dhananjay Phadke | 439b454 | 2008-06-15 22:59:46 -0700 | [diff] [blame] | 945 | msleep(50); |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 946 | |
| 947 | ctrl = NXRD32(adapter, NETXEN_DMA_WATCHDOG_CTRL); |
| 948 | |
| 949 | if (--i == 0) |
Dhananjay Phadke | 439b454 | 2008-06-15 22:59:46 -0700 | [diff] [blame] | 950 | break; |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 951 | }; |
Dhananjay Phadke | 15eef1e | 2008-08-08 00:08:42 -0700 | [diff] [blame] | 952 | } |
Dhananjay Phadke | 439b454 | 2008-06-15 22:59:46 -0700 | [diff] [blame] | 953 | |
Dhananjay Phadke | 15eef1e | 2008-08-08 00:08:42 -0700 | [diff] [blame] | 954 | if (i) { |
| 955 | pci_free_consistent(adapter->pdev, |
| 956 | NETXEN_HOST_DUMMY_DMA_SIZE, |
| 957 | adapter->dummy_dma.addr, |
| 958 | adapter->dummy_dma.phys_addr); |
| 959 | adapter->dummy_dma.addr = NULL; |
Dhananjay Phadke | 83ac51f | 2009-07-26 20:07:39 +0000 | [diff] [blame] | 960 | } else |
| 961 | dev_err(&adapter->pdev->dev, "dma_watchdog_shutdown failed\n"); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 962 | } |
| 963 | |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 964 | int netxen_phantom_init(struct netxen_adapter *adapter, int pegtune_val) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 965 | { |
| 966 | u32 val = 0; |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 967 | int retries = 60; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 968 | |
Dhananjay Phadke | 96f2ebd | 2009-06-22 20:26:21 +0000 | [diff] [blame] | 969 | if (pegtune_val) |
| 970 | return 0; |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 971 | |
Dhananjay Phadke | 96f2ebd | 2009-06-22 20:26:21 +0000 | [diff] [blame] | 972 | do { |
| 973 | val = NXRD32(adapter, CRB_CMDPEG_STATE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 974 | |
Dhananjay Phadke | 96f2ebd | 2009-06-22 20:26:21 +0000 | [diff] [blame] | 975 | switch (val) { |
| 976 | case PHAN_INITIALIZE_COMPLETE: |
| 977 | case PHAN_INITIALIZE_ACK: |
| 978 | return 0; |
| 979 | case PHAN_INITIALIZE_FAILED: |
| 980 | goto out_err; |
| 981 | default: |
| 982 | break; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 983 | } |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 984 | |
Dhananjay Phadke | 96f2ebd | 2009-06-22 20:26:21 +0000 | [diff] [blame] | 985 | msleep(500); |
| 986 | |
| 987 | } while (--retries); |
| 988 | |
| 989 | NXWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_FAILED); |
| 990 | |
| 991 | out_err: |
| 992 | dev_warn(&adapter->pdev->dev, "firmware init failed\n"); |
| 993 | return -EIO; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 994 | } |
| 995 | |
Dhananjay Phadke | 56a0078 | 2009-04-07 22:50:41 +0000 | [diff] [blame] | 996 | static int |
| 997 | netxen_receive_peg_ready(struct netxen_adapter *adapter) |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 998 | { |
| 999 | u32 val = 0; |
| 1000 | int retries = 2000; |
| 1001 | |
| 1002 | do { |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1003 | val = NXRD32(adapter, CRB_RCVPEG_STATE); |
Dhananjay Phadke | 2956640 | 2008-07-21 19:44:04 -0700 | [diff] [blame] | 1004 | |
| 1005 | if (val == PHAN_PEG_RCV_INITIALIZED) |
| 1006 | return 0; |
| 1007 | |
| 1008 | msleep(10); |
| 1009 | |
| 1010 | } while (--retries); |
| 1011 | |
| 1012 | if (!retries) { |
| 1013 | printk(KERN_ERR "Receive Peg initialization not " |
| 1014 | "complete, state: 0x%x.\n", val); |
| 1015 | return -EIO; |
| 1016 | } |
| 1017 | |
| 1018 | return 0; |
| 1019 | } |
| 1020 | |
Dhananjay Phadke | 56a0078 | 2009-04-07 22:50:41 +0000 | [diff] [blame] | 1021 | int netxen_init_firmware(struct netxen_adapter *adapter) |
| 1022 | { |
| 1023 | int err; |
| 1024 | |
| 1025 | err = netxen_receive_peg_ready(adapter); |
| 1026 | if (err) |
| 1027 | return err; |
| 1028 | |
Dhananjay Phadke | f98a9f6 | 2009-04-07 22:50:45 +0000 | [diff] [blame] | 1029 | NXWR32(adapter, CRB_NIC_CAPABILITIES_HOST, INTR_SCHEME_PERPORT); |
| 1030 | NXWR32(adapter, CRB_NIC_MSI_MODE_HOST, MSI_MODE_MULTIFUNC); |
| 1031 | NXWR32(adapter, CRB_MPORT_MODE, MPORT_MULTI_FUNCTION_MODE); |
| 1032 | NXWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_ACK); |
Dhananjay Phadke | 56a0078 | 2009-04-07 22:50:41 +0000 | [diff] [blame] | 1033 | |
| 1034 | return err; |
| 1035 | } |
| 1036 | |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1037 | static void |
| 1038 | netxen_handle_linkevent(struct netxen_adapter *adapter, nx_fw_msg_t *msg) |
| 1039 | { |
| 1040 | u32 cable_OUI; |
| 1041 | u16 cable_len; |
| 1042 | u16 link_speed; |
| 1043 | u8 link_status, module, duplex, autoneg; |
| 1044 | struct net_device *netdev = adapter->netdev; |
| 1045 | |
| 1046 | adapter->has_link_events = 1; |
| 1047 | |
| 1048 | cable_OUI = msg->body[1] & 0xffffffff; |
| 1049 | cable_len = (msg->body[1] >> 32) & 0xffff; |
| 1050 | link_speed = (msg->body[1] >> 48) & 0xffff; |
| 1051 | |
| 1052 | link_status = msg->body[2] & 0xff; |
| 1053 | duplex = (msg->body[2] >> 16) & 0xff; |
| 1054 | autoneg = (msg->body[2] >> 24) & 0xff; |
| 1055 | |
| 1056 | module = (msg->body[2] >> 8) & 0xff; |
| 1057 | if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLE) { |
| 1058 | printk(KERN_INFO "%s: unsupported cable: OUI 0x%x, length %d\n", |
| 1059 | netdev->name, cable_OUI, cable_len); |
| 1060 | } else if (module == LINKEVENT_MODULE_TWINAX_UNSUPPORTED_CABLELEN) { |
| 1061 | printk(KERN_INFO "%s: unsupported cable length %d\n", |
| 1062 | netdev->name, cable_len); |
| 1063 | } |
| 1064 | |
| 1065 | netxen_advert_link_change(adapter, link_status); |
| 1066 | |
| 1067 | /* update link parameters */ |
| 1068 | if (duplex == LINKEVENT_FULL_DUPLEX) |
| 1069 | adapter->link_duplex = DUPLEX_FULL; |
| 1070 | else |
| 1071 | adapter->link_duplex = DUPLEX_HALF; |
| 1072 | adapter->module_type = module; |
| 1073 | adapter->link_autoneg = autoneg; |
| 1074 | adapter->link_speed = link_speed; |
| 1075 | } |
| 1076 | |
| 1077 | static void |
| 1078 | netxen_handle_fw_message(int desc_cnt, int index, |
| 1079 | struct nx_host_sds_ring *sds_ring) |
| 1080 | { |
| 1081 | nx_fw_msg_t msg; |
| 1082 | struct status_desc *desc; |
| 1083 | int i = 0, opcode; |
| 1084 | |
| 1085 | while (desc_cnt > 0 && i < 8) { |
| 1086 | desc = &sds_ring->desc_head[index]; |
| 1087 | msg.words[i++] = le64_to_cpu(desc->status_desc_data[0]); |
| 1088 | msg.words[i++] = le64_to_cpu(desc->status_desc_data[1]); |
| 1089 | |
| 1090 | index = get_next_index(index, sds_ring->num_desc); |
| 1091 | desc_cnt--; |
| 1092 | } |
| 1093 | |
| 1094 | opcode = netxen_get_nic_msg_opcode(msg.body[0]); |
| 1095 | switch (opcode) { |
| 1096 | case NX_NIC_C2H_OPCODE_GET_LINKEVENT_RESPONSE: |
| 1097 | netxen_handle_linkevent(sds_ring->adapter, &msg); |
| 1098 | break; |
| 1099 | default: |
| 1100 | break; |
| 1101 | } |
| 1102 | } |
| 1103 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1104 | static int |
| 1105 | netxen_alloc_rx_skb(struct netxen_adapter *adapter, |
| 1106 | struct nx_host_rds_ring *rds_ring, |
| 1107 | struct netxen_rx_buffer *buffer) |
| 1108 | { |
| 1109 | struct sk_buff *skb; |
| 1110 | dma_addr_t dma; |
| 1111 | struct pci_dev *pdev = adapter->pdev; |
| 1112 | |
| 1113 | buffer->skb = dev_alloc_skb(rds_ring->skb_size); |
| 1114 | if (!buffer->skb) |
| 1115 | return 1; |
| 1116 | |
| 1117 | skb = buffer->skb; |
| 1118 | |
| 1119 | if (!adapter->ahw.cut_through) |
| 1120 | skb_reserve(skb, 2); |
| 1121 | |
| 1122 | dma = pci_map_single(pdev, skb->data, |
| 1123 | rds_ring->dma_size, PCI_DMA_FROMDEVICE); |
| 1124 | |
| 1125 | if (pci_dma_mapping_error(pdev, dma)) { |
| 1126 | dev_kfree_skb_any(skb); |
| 1127 | buffer->skb = NULL; |
| 1128 | return 1; |
| 1129 | } |
| 1130 | |
| 1131 | buffer->skb = skb; |
| 1132 | buffer->dma = dma; |
| 1133 | buffer->state = NETXEN_BUFFER_BUSY; |
| 1134 | |
| 1135 | return 0; |
| 1136 | } |
| 1137 | |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1138 | static struct sk_buff *netxen_process_rxbuf(struct netxen_adapter *adapter, |
| 1139 | struct nx_host_rds_ring *rds_ring, u16 index, u16 cksum) |
| 1140 | { |
| 1141 | struct netxen_rx_buffer *buffer; |
| 1142 | struct sk_buff *skb; |
| 1143 | |
| 1144 | buffer = &rds_ring->rx_buf_arr[index]; |
| 1145 | |
| 1146 | pci_unmap_single(adapter->pdev, buffer->dma, rds_ring->dma_size, |
| 1147 | PCI_DMA_FROMDEVICE); |
| 1148 | |
| 1149 | skb = buffer->skb; |
| 1150 | if (!skb) |
| 1151 | goto no_skb; |
| 1152 | |
| 1153 | if (likely(adapter->rx_csum && cksum == STATUS_CKSUM_OK)) { |
| 1154 | adapter->stats.csummed++; |
| 1155 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1156 | } else |
| 1157 | skb->ip_summed = CHECKSUM_NONE; |
| 1158 | |
| 1159 | skb->dev = adapter->netdev; |
| 1160 | |
| 1161 | buffer->skb = NULL; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1162 | no_skb: |
| 1163 | buffer->state = NETXEN_BUFFER_FREE; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1164 | return skb; |
| 1165 | } |
| 1166 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1167 | static struct netxen_rx_buffer * |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1168 | netxen_process_rcv(struct netxen_adapter *adapter, |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1169 | struct nx_host_sds_ring *sds_ring, |
| 1170 | int ring, u64 sts_data0) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1171 | { |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1172 | struct net_device *netdev = adapter->netdev; |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 1173 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1174 | struct netxen_rx_buffer *buffer; |
| 1175 | struct sk_buff *skb; |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1176 | struct nx_host_rds_ring *rds_ring; |
| 1177 | int index, length, cksum, pkt_offset; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1178 | |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1179 | if (unlikely(ring >= adapter->max_rds_rings)) |
| 1180 | return NULL; |
| 1181 | |
| 1182 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 1183 | |
| 1184 | index = netxen_get_sts_refhandle(sts_data0); |
| 1185 | if (unlikely(index >= rds_ring->num_desc)) |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1186 | return NULL; |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1187 | |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1188 | buffer = &rds_ring->rx_buf_arr[index]; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1189 | |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1190 | length = netxen_get_sts_totallength(sts_data0); |
| 1191 | cksum = netxen_get_sts_status(sts_data0); |
| 1192 | pkt_offset = netxen_get_sts_pkt_offset(sts_data0); |
| 1193 | |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1194 | skb = netxen_process_rxbuf(adapter, rds_ring, index, cksum); |
| 1195 | if (!skb) |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1196 | return buffer; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1197 | |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1198 | if (length > rds_ring->skb_size) |
| 1199 | skb_put(skb, rds_ring->skb_size); |
| 1200 | else |
| 1201 | skb_put(skb, length); |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1202 | |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1203 | |
| 1204 | if (pkt_offset) |
| 1205 | skb_pull(skb, pkt_offset); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1206 | |
Dhananjay Phadke | bc75e5b | 2009-09-03 13:10:53 +0000 | [diff] [blame] | 1207 | skb->truesize = skb->len + sizeof(struct sk_buff); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1208 | skb->protocol = eth_type_trans(skb, netdev); |
| 1209 | |
Amit Kumar Salecha | a92e9e6 | 2009-04-07 22:50:47 +0000 | [diff] [blame] | 1210 | napi_gro_receive(&sds_ring->napi, skb); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1211 | |
Narender Kumar | 1bb482f | 2009-08-23 08:35:09 +0000 | [diff] [blame] | 1212 | adapter->stats.rx_pkts++; |
Dhananjay Phadke | 0ddc110 | 2009-03-09 08:50:52 +0000 | [diff] [blame] | 1213 | adapter->stats.rxbytes += length; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1214 | |
| 1215 | return buffer; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1216 | } |
| 1217 | |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1218 | #define TCP_HDR_SIZE 20 |
| 1219 | #define TCP_TS_OPTION_SIZE 12 |
| 1220 | #define TCP_TS_HDR_SIZE (TCP_HDR_SIZE + TCP_TS_OPTION_SIZE) |
| 1221 | |
| 1222 | static struct netxen_rx_buffer * |
| 1223 | netxen_process_lro(struct netxen_adapter *adapter, |
| 1224 | struct nx_host_sds_ring *sds_ring, |
| 1225 | int ring, u64 sts_data0, u64 sts_data1) |
| 1226 | { |
| 1227 | struct net_device *netdev = adapter->netdev; |
| 1228 | struct netxen_recv_context *recv_ctx = &adapter->recv_ctx; |
| 1229 | struct netxen_rx_buffer *buffer; |
| 1230 | struct sk_buff *skb; |
| 1231 | struct nx_host_rds_ring *rds_ring; |
| 1232 | struct iphdr *iph; |
| 1233 | struct tcphdr *th; |
| 1234 | bool push, timestamp; |
| 1235 | int l2_hdr_offset, l4_hdr_offset; |
| 1236 | int index; |
| 1237 | u16 lro_length, length, data_offset; |
| 1238 | u32 seq_number; |
| 1239 | |
| 1240 | if (unlikely(ring > adapter->max_rds_rings)) |
| 1241 | return NULL; |
| 1242 | |
| 1243 | rds_ring = &recv_ctx->rds_rings[ring]; |
| 1244 | |
| 1245 | index = netxen_get_lro_sts_refhandle(sts_data0); |
| 1246 | if (unlikely(index > rds_ring->num_desc)) |
| 1247 | return NULL; |
| 1248 | |
| 1249 | buffer = &rds_ring->rx_buf_arr[index]; |
| 1250 | |
| 1251 | timestamp = netxen_get_lro_sts_timestamp(sts_data0); |
| 1252 | lro_length = netxen_get_lro_sts_length(sts_data0); |
| 1253 | l2_hdr_offset = netxen_get_lro_sts_l2_hdr_offset(sts_data0); |
| 1254 | l4_hdr_offset = netxen_get_lro_sts_l4_hdr_offset(sts_data0); |
| 1255 | push = netxen_get_lro_sts_push_flag(sts_data0); |
| 1256 | seq_number = netxen_get_lro_sts_seq_number(sts_data1); |
| 1257 | |
| 1258 | skb = netxen_process_rxbuf(adapter, rds_ring, index, STATUS_CKSUM_OK); |
| 1259 | if (!skb) |
| 1260 | return buffer; |
| 1261 | |
| 1262 | if (timestamp) |
| 1263 | data_offset = l4_hdr_offset + TCP_TS_HDR_SIZE; |
| 1264 | else |
| 1265 | data_offset = l4_hdr_offset + TCP_HDR_SIZE; |
| 1266 | |
| 1267 | skb_put(skb, lro_length + data_offset); |
| 1268 | |
Dhananjay Phadke | bc75e5b | 2009-09-03 13:10:53 +0000 | [diff] [blame] | 1269 | skb->truesize = skb->len + sizeof(struct sk_buff) + skb_headroom(skb); |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1270 | |
| 1271 | skb_pull(skb, l2_hdr_offset); |
| 1272 | skb->protocol = eth_type_trans(skb, netdev); |
| 1273 | |
| 1274 | iph = (struct iphdr *)skb->data; |
| 1275 | th = (struct tcphdr *)(skb->data + (iph->ihl << 2)); |
| 1276 | |
| 1277 | length = (iph->ihl << 2) + (th->doff << 2) + lro_length; |
| 1278 | iph->tot_len = htons(length); |
| 1279 | iph->check = 0; |
| 1280 | iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl); |
| 1281 | th->psh = push; |
| 1282 | th->seq = htonl(seq_number); |
| 1283 | |
Narender Kumar | 1bb482f | 2009-08-23 08:35:09 +0000 | [diff] [blame] | 1284 | length = skb->len; |
| 1285 | |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1286 | netif_receive_skb(skb); |
| 1287 | |
Narender Kumar | 1bb482f | 2009-08-23 08:35:09 +0000 | [diff] [blame] | 1288 | adapter->stats.lro_pkts++; |
| 1289 | adapter->stats.rxbytes += length; |
| 1290 | |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1291 | return buffer; |
| 1292 | } |
| 1293 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1294 | #define netxen_merge_rx_buffers(list, head) \ |
| 1295 | do { list_splice_tail_init(list, head); } while (0); |
| 1296 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 1297 | int |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1298 | netxen_process_rcv_ring(struct nx_host_sds_ring *sds_ring, int max) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1299 | { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1300 | struct netxen_adapter *adapter = sds_ring->adapter; |
| 1301 | |
| 1302 | struct list_head *cur; |
| 1303 | |
Dhananjay Phadke | 0ddc110 | 2009-03-09 08:50:52 +0000 | [diff] [blame] | 1304 | struct status_desc *desc; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1305 | struct netxen_rx_buffer *rxbuf; |
| 1306 | |
| 1307 | u32 consumer = sds_ring->consumer; |
| 1308 | |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1309 | int count = 0; |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1310 | u64 sts_data0, sts_data1; |
| 1311 | int opcode, ring = 0, desc_cnt; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1312 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1313 | while (count < max) { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1314 | desc = &sds_ring->desc_head[consumer]; |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1315 | sts_data0 = le64_to_cpu(desc->status_desc_data[0]); |
Dhananjay Phadke | 0ddc110 | 2009-03-09 08:50:52 +0000 | [diff] [blame] | 1316 | |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1317 | if (!(sts_data0 & STATUS_OWNER_HOST)) |
Dhananjay Phadke | 0ddc110 | 2009-03-09 08:50:52 +0000 | [diff] [blame] | 1318 | break; |
| 1319 | |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1320 | desc_cnt = netxen_get_sts_desc_cnt(sts_data0); |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1321 | |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1322 | opcode = netxen_get_sts_opcode(sts_data0); |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1323 | |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1324 | switch (opcode) { |
| 1325 | case NETXEN_NIC_RXPKT_DESC: |
| 1326 | case NETXEN_OLD_RXPKT_DESC: |
Dhananjay Phadke | 6598b16 | 2009-07-26 20:07:37 +0000 | [diff] [blame] | 1327 | case NETXEN_NIC_SYN_OFFLOAD: |
Dhananjay Phadke | c1c00ab | 2009-08-05 07:34:09 +0000 | [diff] [blame] | 1328 | ring = netxen_get_sts_type(sts_data0); |
| 1329 | rxbuf = netxen_process_rcv(adapter, sds_ring, |
| 1330 | ring, sts_data0); |
| 1331 | break; |
| 1332 | case NETXEN_NIC_LRO_DESC: |
| 1333 | ring = netxen_get_lro_sts_type(sts_data0); |
| 1334 | sts_data1 = le64_to_cpu(desc->status_desc_data[1]); |
| 1335 | rxbuf = netxen_process_lro(adapter, sds_ring, |
| 1336 | ring, sts_data0, sts_data1); |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1337 | break; |
| 1338 | case NETXEN_NIC_RESPONSE_DESC: |
| 1339 | netxen_handle_fw_message(desc_cnt, consumer, sds_ring); |
| 1340 | default: |
| 1341 | goto skip; |
| 1342 | } |
| 1343 | |
| 1344 | WARN_ON(desc_cnt > 1); |
| 1345 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1346 | if (rxbuf) |
| 1347 | list_add_tail(&rxbuf->list, &sds_ring->free_list[ring]); |
| 1348 | |
Dhananjay Phadke | 3bf26ce | 2009-04-07 22:50:42 +0000 | [diff] [blame] | 1349 | skip: |
| 1350 | for (; desc_cnt > 0; desc_cnt--) { |
| 1351 | desc = &sds_ring->desc_head[consumer]; |
| 1352 | desc->status_desc_data[0] = |
| 1353 | cpu_to_le64(STATUS_OWNER_PHANTOM); |
| 1354 | consumer = get_next_index(consumer, sds_ring->num_desc); |
| 1355 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1356 | count++; |
| 1357 | } |
Dhananjay Phadke | 0ddc110 | 2009-03-09 08:50:52 +0000 | [diff] [blame] | 1358 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1359 | for (ring = 0; ring < adapter->max_rds_rings; ring++) { |
| 1360 | struct nx_host_rds_ring *rds_ring = |
| 1361 | &adapter->recv_ctx.rds_rings[ring]; |
| 1362 | |
| 1363 | if (!list_empty(&sds_ring->free_list[ring])) { |
| 1364 | list_for_each(cur, &sds_ring->free_list[ring]) { |
| 1365 | rxbuf = list_entry(cur, |
| 1366 | struct netxen_rx_buffer, list); |
| 1367 | netxen_alloc_rx_skb(adapter, rds_ring, rxbuf); |
| 1368 | } |
| 1369 | spin_lock(&rds_ring->lock); |
| 1370 | netxen_merge_rx_buffers(&sds_ring->free_list[ring], |
| 1371 | &rds_ring->free_list); |
| 1372 | spin_unlock(&rds_ring->lock); |
| 1373 | } |
| 1374 | |
| 1375 | netxen_post_rx_buffers_nodb(adapter, rds_ring); |
| 1376 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1377 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1378 | if (count) { |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1379 | sds_ring->consumer = consumer; |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 1380 | NXWRIO(adapter, sds_ring->crb_sts_consumer, consumer); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | return count; |
| 1384 | } |
| 1385 | |
| 1386 | /* Process Command status ring */ |
Dhananjay Phadke | 05aaa02 | 2008-03-17 19:59:49 -0700 | [diff] [blame] | 1387 | int netxen_process_cmd_ring(struct netxen_adapter *adapter) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1388 | { |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1389 | u32 sw_consumer, hw_consumer; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1390 | int count = 0, i; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1391 | struct netxen_cmd_buffer *buffer; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1392 | struct pci_dev *pdev = adapter->pdev; |
| 1393 | struct net_device *netdev = adapter->netdev; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1394 | struct netxen_skb_frag *frag; |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1395 | int done = 0; |
Dhananjay Phadke | 4ea528a | 2009-04-28 15:29:10 +0000 | [diff] [blame] | 1396 | struct nx_host_tx_ring *tx_ring = adapter->tx_ring; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1397 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1398 | if (!spin_trylock(&adapter->tx_clean_lock)) |
| 1399 | return 1; |
| 1400 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1401 | sw_consumer = tx_ring->sw_consumer; |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1402 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1403 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1404 | while (sw_consumer != hw_consumer) { |
| 1405 | buffer = &tx_ring->cmd_buf_arr[sw_consumer]; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1406 | if (buffer->skb) { |
| 1407 | frag = &buffer->frag_array[0]; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1408 | pci_unmap_single(pdev, frag->dma, frag->length, |
| 1409 | PCI_DMA_TODEVICE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1410 | frag->dma = 0ULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1411 | for (i = 1; i < buffer->frag_count; i++) { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1412 | frag++; /* Get the next frag */ |
| 1413 | pci_unmap_page(pdev, frag->dma, frag->length, |
| 1414 | PCI_DMA_TODEVICE); |
Dhananjay Phadke | 96acb6e | 2007-07-02 09:37:57 +0530 | [diff] [blame] | 1415 | frag->dma = 0ULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1416 | } |
| 1417 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1418 | adapter->stats.xmitfinished++; |
dhananjay@netxen.com | 53a01e0 | 2007-12-26 10:23:58 -0800 | [diff] [blame] | 1419 | dev_kfree_skb_any(buffer->skb); |
| 1420 | buffer->skb = NULL; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1421 | } |
| 1422 | |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1423 | sw_consumer = get_next_index(sw_consumer, tx_ring->num_desc); |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1424 | if (++count >= MAX_STATUS_HANDLE) |
| 1425 | break; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1426 | } |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1427 | |
Dhananjay Phadke | 2252786 | 2009-05-05 19:05:06 +0000 | [diff] [blame] | 1428 | if (count && netif_running(netdev)) { |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1429 | tx_ring->sw_consumer = sw_consumer; |
| 1430 | |
Dhananjay Phadke | ba53e6b | 2008-03-17 19:59:50 -0700 | [diff] [blame] | 1431 | smp_mb(); |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1432 | |
Dhananjay Phadke | 2252786 | 2009-05-05 19:05:06 +0000 | [diff] [blame] | 1433 | if (netif_queue_stopped(netdev) && netif_carrier_ok(netdev)) { |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 1434 | __netif_tx_lock(tx_ring->txq, smp_processor_id()); |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 1435 | if (netxen_tx_avail(tx_ring) > TX_STOP_THRESH) { |
Dhananjay Phadke | cb2107b | 2009-06-17 17:27:25 +0000 | [diff] [blame] | 1436 | netif_wake_queue(netdev); |
Amit Kumar Salecha | 74c520d | 2009-09-11 11:28:14 +0000 | [diff] [blame] | 1437 | adapter->tx_timeo_cnt = 0; |
| 1438 | } |
Dhananjay Phadke | b2af9cb | 2009-07-17 15:27:07 +0000 | [diff] [blame] | 1439 | __netif_tx_unlock(tx_ring->txq); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1440 | } |
| 1441 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1442 | /* |
| 1443 | * If everything is freed up to consumer then check if the ring is full |
| 1444 | * If the ring is full then check if more needs to be freed and |
| 1445 | * schedule the call back again. |
| 1446 | * |
| 1447 | * This happens when there are 2 CPUs. One could be freeing and the |
| 1448 | * other filling it. If the ring is full when we get out of here and |
| 1449 | * the card has already interrupted the host then the host can miss the |
| 1450 | * interrupt. |
| 1451 | * |
| 1452 | * There is still a possible race condition and the host could miss an |
| 1453 | * interrupt. The card has to take care of this. |
| 1454 | */ |
Dhananjay Phadke | d877f1e | 2009-04-07 22:50:40 +0000 | [diff] [blame] | 1455 | hw_consumer = le32_to_cpu(*(tx_ring->hw_consumer)); |
| 1456 | done = (sw_consumer == hw_consumer); |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1457 | spin_unlock(&adapter->tx_clean_lock); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1458 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1459 | return (done); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1460 | } |
| 1461 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 1462 | void |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1463 | netxen_post_rx_buffers(struct netxen_adapter *adapter, u32 ringid, |
| 1464 | struct nx_host_rds_ring *rds_ring) |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1465 | { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1466 | struct rcv_desc *pdesc; |
| 1467 | struct netxen_rx_buffer *buffer; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1468 | int producer, count = 0; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1469 | netxen_ctx_msg msg = 0; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1470 | struct list_head *head; |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1471 | |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1472 | producer = rds_ring->producer; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1473 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1474 | spin_lock(&rds_ring->lock); |
| 1475 | head = &rds_ring->free_list; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1476 | while (!list_empty(head)) { |
| 1477 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1478 | buffer = list_entry(head->next, struct netxen_rx_buffer, list); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1479 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1480 | if (!buffer->skb) { |
| 1481 | if (netxen_alloc_rx_skb(adapter, rds_ring, buffer)) |
| 1482 | break; |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | count++; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1486 | list_del(&buffer->list); |
| 1487 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1488 | /* make a rcv descriptor */ |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1489 | pdesc = &rds_ring->desc_head[producer]; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1490 | pdesc->addr_buffer = cpu_to_le64(buffer->dma); |
Amit S. Kale | ed33ebe | 2006-12-18 05:53:59 -0800 | [diff] [blame] | 1491 | pdesc->reference_handle = cpu_to_le16(buffer->ref_handle); |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1492 | pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size); |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1493 | |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1494 | producer = get_next_index(producer, rds_ring->num_desc); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1495 | } |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1496 | spin_unlock(&rds_ring->lock); |
Dhananjay Phadke | 9b3ef55 | 2009-03-13 14:52:04 +0000 | [diff] [blame] | 1497 | |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1498 | if (count) { |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1499 | rds_ring->producer = producer; |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 1500 | NXWRIO(adapter, rds_ring->crb_rcv_producer, |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1501 | (producer-1) & (rds_ring->num_desc-1)); |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1502 | |
Dhananjay Phadke | 4f96b98 | 2009-07-26 20:07:42 +0000 | [diff] [blame] | 1503 | if (NX_IS_REVISION_P2(adapter->ahw.revision_id)) { |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1504 | /* |
| 1505 | * Write a doorbell msg to tell phanmon of change in |
| 1506 | * receive ring producer |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1507 | * Only for firmware version < 4.0.0 |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1508 | */ |
| 1509 | netxen_set_msg_peg_id(msg, NETXEN_RCV_PEG_DB_ID); |
| 1510 | netxen_set_msg_privid(msg); |
| 1511 | netxen_set_msg_count(msg, |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1512 | ((producer - 1) & |
| 1513 | (rds_ring->num_desc - 1))); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1514 | netxen_set_msg_ctxid(msg, adapter->portnum); |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1515 | netxen_set_msg_opcode(msg, NETXEN_RCV_PRODUCER(ringid)); |
Dhananjay Phadke | f03b0eb | 2009-10-13 05:31:44 +0000 | [diff] [blame^] | 1516 | NXWRIO(adapter, DB_NORMALIZE(adapter, |
| 1517 | NETXEN_RCV_PRODUCER_OFFSET), msg); |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1518 | } |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1519 | } |
| 1520 | } |
| 1521 | |
Dhananjay Phadke | becf46a | 2009-03-09 08:50:55 +0000 | [diff] [blame] | 1522 | static void |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1523 | netxen_post_rx_buffers_nodb(struct netxen_adapter *adapter, |
| 1524 | struct nx_host_rds_ring *rds_ring) |
Amit S. Kale | ed25ffa | 2006-12-04 09:23:25 -0800 | [diff] [blame] | 1525 | { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1526 | struct rcv_desc *pdesc; |
| 1527 | struct netxen_rx_buffer *buffer; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1528 | int producer, count = 0; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1529 | struct list_head *head; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1530 | |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1531 | producer = rds_ring->producer; |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1532 | if (!spin_trylock(&rds_ring->lock)) |
| 1533 | return; |
| 1534 | |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1535 | head = &rds_ring->free_list; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1536 | while (!list_empty(head)) { |
| 1537 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1538 | buffer = list_entry(head->next, struct netxen_rx_buffer, list); |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1539 | |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1540 | if (!buffer->skb) { |
| 1541 | if (netxen_alloc_rx_skb(adapter, rds_ring, buffer)) |
| 1542 | break; |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | count++; |
Dhananjay Phadke | d9e651b | 2008-07-21 19:44:08 -0700 | [diff] [blame] | 1546 | list_del(&buffer->list); |
| 1547 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1548 | /* make a rcv descriptor */ |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1549 | pdesc = &rds_ring->desc_head[producer]; |
Amit S. Kale | ed33ebe | 2006-12-18 05:53:59 -0800 | [diff] [blame] | 1550 | pdesc->reference_handle = cpu_to_le16(buffer->ref_handle); |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1551 | pdesc->buffer_length = cpu_to_le32(rds_ring->dma_size); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1552 | pdesc->addr_buffer = cpu_to_le64(buffer->dma); |
Dhananjay Phadke | 6f70340 | 2009-01-14 20:50:00 -0800 | [diff] [blame] | 1553 | |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1554 | producer = get_next_index(producer, rds_ring->num_desc); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1555 | } |
| 1556 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1557 | if (count) { |
Dhananjay Phadke | 48bfd1e | 2008-07-21 19:44:06 -0700 | [diff] [blame] | 1558 | rds_ring->producer = producer; |
Amit Kumar Salecha | 195c5f9 | 2009-09-05 17:43:10 +0000 | [diff] [blame] | 1559 | NXWRIO(adapter, rds_ring->crb_rcv_producer, |
Dhananjay Phadke | 438627c | 2009-03-13 14:52:03 +0000 | [diff] [blame] | 1560 | (producer - 1) & (rds_ring->num_desc - 1)); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1561 | } |
Dhananjay Phadke | d8b100c | 2009-03-13 14:52:05 +0000 | [diff] [blame] | 1562 | spin_unlock(&rds_ring->lock); |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1563 | } |
| 1564 | |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1565 | void netxen_nic_clear_stats(struct netxen_adapter *adapter) |
| 1566 | { |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1567 | memset(&adapter->stats, 0, sizeof(adapter->stats)); |
Mithlesh Thukral | 3176ff3 | 2007-04-20 07:52:37 -0700 | [diff] [blame] | 1568 | return; |
Amit S. Kale | 3d396eb | 2006-10-21 15:33:03 -0400 | [diff] [blame] | 1569 | } |
| 1570 | |