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