Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Linux network driver for Brocade Converged Network Adapter. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License (GPL) Version 2 as |
| 6 | * published by the Free Software Foundation |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * General Public License for more details. |
| 12 | */ |
| 13 | /* |
| 14 | * Copyright (c) 2005-2010 Brocade Communications Systems, Inc. |
| 15 | * All rights reserved |
| 16 | * www.brocade.com |
| 17 | */ |
Jiri Pirko | f859d7c | 2011-07-20 04:54:14 +0000 | [diff] [blame] | 18 | #include <linux/bitops.h> |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 19 | #include <linux/netdevice.h> |
| 20 | #include <linux/skbuff.h> |
| 21 | #include <linux/etherdevice.h> |
| 22 | #include <linux/in.h> |
| 23 | #include <linux/ethtool.h> |
| 24 | #include <linux/if_vlan.h> |
| 25 | #include <linux/if_ether.h> |
| 26 | #include <linux/ip.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 27 | #include <linux/prefetch.h> |
Paul Gortmaker | 9d9779e | 2011-07-03 15:21:01 -0400 | [diff] [blame^] | 28 | #include <linux/module.h> |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 29 | |
| 30 | #include "bnad.h" |
| 31 | #include "bna.h" |
| 32 | #include "cna.h" |
| 33 | |
Rasesh Mody | b7ee31c5 | 2010-10-05 15:46:05 +0000 | [diff] [blame] | 34 | static DEFINE_MUTEX(bnad_fwimg_mutex); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * Module params |
| 38 | */ |
| 39 | static uint bnad_msix_disable; |
| 40 | module_param(bnad_msix_disable, uint, 0444); |
| 41 | MODULE_PARM_DESC(bnad_msix_disable, "Disable MSIX mode"); |
| 42 | |
| 43 | static uint bnad_ioc_auto_recover = 1; |
| 44 | module_param(bnad_ioc_auto_recover, uint, 0444); |
| 45 | MODULE_PARM_DESC(bnad_ioc_auto_recover, "Enable / Disable auto recovery"); |
| 46 | |
| 47 | /* |
| 48 | * Global variables |
| 49 | */ |
| 50 | u32 bnad_rxqs_per_cq = 2; |
| 51 | |
Rasesh Mody | b7ee31c5 | 2010-10-05 15:46:05 +0000 | [diff] [blame] | 52 | static const u8 bnad_bcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * Local MACROS |
| 56 | */ |
| 57 | #define BNAD_TX_UNMAPQ_DEPTH (bnad->txq_depth * 2) |
| 58 | |
| 59 | #define BNAD_RX_UNMAPQ_DEPTH (bnad->rxq_depth) |
| 60 | |
| 61 | #define BNAD_GET_MBOX_IRQ(_bnad) \ |
| 62 | (((_bnad)->cfg_flags & BNAD_CF_MSIX) ? \ |
Rasesh Mody | 8811e26 | 2011-07-22 08:07:44 +0000 | [diff] [blame] | 63 | ((_bnad)->msix_table[BNAD_MAILBOX_MSIX_INDEX].vector) : \ |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 64 | ((_bnad)->pcidev->irq)) |
| 65 | |
| 66 | #define BNAD_FILL_UNMAPQ_MEM_REQ(_res_info, _num, _depth) \ |
| 67 | do { \ |
| 68 | (_res_info)->res_type = BNA_RES_T_MEM; \ |
| 69 | (_res_info)->res_u.mem_info.mem_type = BNA_MEM_T_KVA; \ |
| 70 | (_res_info)->res_u.mem_info.num = (_num); \ |
| 71 | (_res_info)->res_u.mem_info.len = \ |
| 72 | sizeof(struct bnad_unmap_q) + \ |
| 73 | (sizeof(struct bnad_skb_unmap) * ((_depth) - 1)); \ |
| 74 | } while (0) |
| 75 | |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 76 | #define BNAD_TXRX_SYNC_MDELAY 250 /* 250 msecs */ |
| 77 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 78 | /* |
| 79 | * Reinitialize completions in CQ, once Rx is taken down |
| 80 | */ |
| 81 | static void |
| 82 | bnad_cq_cmpl_init(struct bnad *bnad, struct bna_ccb *ccb) |
| 83 | { |
| 84 | struct bna_cq_entry *cmpl, *next_cmpl; |
| 85 | unsigned int wi_range, wis = 0, ccb_prod = 0; |
| 86 | int i; |
| 87 | |
| 88 | BNA_CQ_QPGE_PTR_GET(ccb_prod, ccb->sw_qpt, cmpl, |
| 89 | wi_range); |
| 90 | |
| 91 | for (i = 0; i < ccb->q_depth; i++) { |
| 92 | wis++; |
| 93 | if (likely(--wi_range)) |
| 94 | next_cmpl = cmpl + 1; |
| 95 | else { |
| 96 | BNA_QE_INDX_ADD(ccb_prod, wis, ccb->q_depth); |
| 97 | wis = 0; |
| 98 | BNA_CQ_QPGE_PTR_GET(ccb_prod, ccb->sw_qpt, |
| 99 | next_cmpl, wi_range); |
| 100 | } |
| 101 | cmpl->valid = 0; |
| 102 | cmpl = next_cmpl; |
| 103 | } |
| 104 | } |
| 105 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 106 | static u32 |
| 107 | bnad_pci_unmap_skb(struct device *pdev, struct bnad_skb_unmap *array, |
| 108 | u32 index, u32 depth, struct sk_buff *skb, u32 frag) |
| 109 | { |
| 110 | int j; |
| 111 | array[index].skb = NULL; |
| 112 | |
| 113 | dma_unmap_single(pdev, dma_unmap_addr(&array[index], dma_addr), |
| 114 | skb_headlen(skb), DMA_TO_DEVICE); |
| 115 | dma_unmap_addr_set(&array[index], dma_addr, 0); |
| 116 | BNA_QE_INDX_ADD(index, 1, depth); |
| 117 | |
| 118 | for (j = 0; j < frag; j++) { |
| 119 | dma_unmap_page(pdev, dma_unmap_addr(&array[index], dma_addr), |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 120 | skb_frag_size(&skb_shinfo(skb)->frags[j]), DMA_TO_DEVICE); |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 121 | dma_unmap_addr_set(&array[index], dma_addr, 0); |
| 122 | BNA_QE_INDX_ADD(index, 1, depth); |
| 123 | } |
| 124 | |
| 125 | return index; |
| 126 | } |
| 127 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 128 | /* |
| 129 | * Frees all pending Tx Bufs |
| 130 | * At this point no activity is expected on the Q, |
| 131 | * so DMA unmap & freeing is fine. |
| 132 | */ |
| 133 | static void |
| 134 | bnad_free_all_txbufs(struct bnad *bnad, |
| 135 | struct bna_tcb *tcb) |
| 136 | { |
Rasesh Mody | 0120b99 | 2011-07-22 08:07:41 +0000 | [diff] [blame] | 137 | u32 unmap_cons; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 138 | struct bnad_unmap_q *unmap_q = tcb->unmap_q; |
| 139 | struct bnad_skb_unmap *unmap_array; |
Rasesh Mody | 0120b99 | 2011-07-22 08:07:41 +0000 | [diff] [blame] | 140 | struct sk_buff *skb = NULL; |
Rasesh Mody | 938fa48 | 2011-08-30 15:27:47 +0000 | [diff] [blame] | 141 | int q; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 142 | |
| 143 | unmap_array = unmap_q->unmap_array; |
| 144 | |
Rasesh Mody | 938fa48 | 2011-08-30 15:27:47 +0000 | [diff] [blame] | 145 | for (q = 0; q < unmap_q->q_depth; q++) { |
| 146 | skb = unmap_array[q].skb; |
| 147 | if (!skb) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 148 | continue; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 149 | |
Rasesh Mody | 938fa48 | 2011-08-30 15:27:47 +0000 | [diff] [blame] | 150 | unmap_cons = q; |
| 151 | unmap_cons = bnad_pci_unmap_skb(&bnad->pcidev->dev, unmap_array, |
| 152 | unmap_cons, unmap_q->q_depth, skb, |
| 153 | skb_shinfo(skb)->nr_frags); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 154 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 155 | dev_kfree_skb_any(skb); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /* Data Path Handlers */ |
| 160 | |
| 161 | /* |
| 162 | * bnad_free_txbufs : Frees the Tx bufs on Tx completion |
| 163 | * Can be called in a) Interrupt context |
| 164 | * b) Sending context |
| 165 | * c) Tasklet context |
| 166 | */ |
| 167 | static u32 |
| 168 | bnad_free_txbufs(struct bnad *bnad, |
| 169 | struct bna_tcb *tcb) |
| 170 | { |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 171 | u32 unmap_cons, sent_packets = 0, sent_bytes = 0; |
| 172 | u16 wis, updated_hw_cons; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 173 | struct bnad_unmap_q *unmap_q = tcb->unmap_q; |
| 174 | struct bnad_skb_unmap *unmap_array; |
Rasesh Mody | 0120b99 | 2011-07-22 08:07:41 +0000 | [diff] [blame] | 175 | struct sk_buff *skb; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 176 | |
| 177 | /* |
| 178 | * Just return if TX is stopped. This check is useful |
| 179 | * when bnad_free_txbufs() runs out of a tasklet scheduled |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 180 | * before bnad_cb_tx_cleanup() cleared BNAD_TXQ_TX_STARTED bit |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 181 | * but this routine runs actually after the cleanup has been |
| 182 | * executed. |
| 183 | */ |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 184 | if (!test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags)) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 185 | return 0; |
| 186 | |
| 187 | updated_hw_cons = *(tcb->hw_consumer_index); |
| 188 | |
| 189 | wis = BNA_Q_INDEX_CHANGE(tcb->consumer_index, |
| 190 | updated_hw_cons, tcb->q_depth); |
| 191 | |
| 192 | BUG_ON(!(wis <= BNA_QE_IN_USE_CNT(tcb, tcb->q_depth))); |
| 193 | |
| 194 | unmap_array = unmap_q->unmap_array; |
| 195 | unmap_cons = unmap_q->consumer_index; |
| 196 | |
| 197 | prefetch(&unmap_array[unmap_cons + 1]); |
| 198 | while (wis) { |
| 199 | skb = unmap_array[unmap_cons].skb; |
| 200 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 201 | sent_packets++; |
| 202 | sent_bytes += skb->len; |
| 203 | wis -= BNA_TXQ_WI_NEEDED(1 + skb_shinfo(skb)->nr_frags); |
| 204 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 205 | unmap_cons = bnad_pci_unmap_skb(&bnad->pcidev->dev, unmap_array, |
| 206 | unmap_cons, unmap_q->q_depth, skb, |
| 207 | skb_shinfo(skb)->nr_frags); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 208 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 209 | dev_kfree_skb_any(skb); |
| 210 | } |
| 211 | |
| 212 | /* Update consumer pointers. */ |
| 213 | tcb->consumer_index = updated_hw_cons; |
| 214 | unmap_q->consumer_index = unmap_cons; |
| 215 | |
| 216 | tcb->txq->tx_packets += sent_packets; |
| 217 | tcb->txq->tx_bytes += sent_bytes; |
| 218 | |
| 219 | return sent_packets; |
| 220 | } |
| 221 | |
| 222 | /* Tx Free Tasklet function */ |
| 223 | /* Frees for all the tcb's in all the Tx's */ |
| 224 | /* |
| 225 | * Scheduled from sending context, so that |
| 226 | * the fat Tx lock is not held for too long |
| 227 | * in the sending context. |
| 228 | */ |
| 229 | static void |
| 230 | bnad_tx_free_tasklet(unsigned long bnad_ptr) |
| 231 | { |
| 232 | struct bnad *bnad = (struct bnad *)bnad_ptr; |
| 233 | struct bna_tcb *tcb; |
Rasesh Mody | 0120b99 | 2011-07-22 08:07:41 +0000 | [diff] [blame] | 234 | u32 acked = 0; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 235 | int i, j; |
| 236 | |
| 237 | for (i = 0; i < bnad->num_tx; i++) { |
| 238 | for (j = 0; j < bnad->num_txq_per_tx; j++) { |
| 239 | tcb = bnad->tx_info[i].tcb[j]; |
| 240 | if (!tcb) |
| 241 | continue; |
| 242 | if (((u16) (*tcb->hw_consumer_index) != |
| 243 | tcb->consumer_index) && |
| 244 | (!test_and_set_bit(BNAD_TXQ_FREE_SENT, |
| 245 | &tcb->flags))) { |
| 246 | acked = bnad_free_txbufs(bnad, tcb); |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 247 | if (likely(test_bit(BNAD_TXQ_TX_STARTED, |
| 248 | &tcb->flags))) |
| 249 | bna_ib_ack(tcb->i_dbell, acked); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 250 | smp_mb__before_clear_bit(); |
| 251 | clear_bit(BNAD_TXQ_FREE_SENT, &tcb->flags); |
| 252 | } |
Rasesh Mody | f7c0fa4 | 2010-12-23 21:45:05 +0000 | [diff] [blame] | 253 | if (unlikely(!test_bit(BNAD_TXQ_TX_STARTED, |
| 254 | &tcb->flags))) |
| 255 | continue; |
| 256 | if (netif_queue_stopped(bnad->netdev)) { |
| 257 | if (acked && netif_carrier_ok(bnad->netdev) && |
| 258 | BNA_QE_FREE_CNT(tcb, tcb->q_depth) >= |
| 259 | BNAD_NETIF_WAKE_THRESHOLD) { |
| 260 | netif_wake_queue(bnad->netdev); |
| 261 | /* TODO */ |
| 262 | /* Counters for individual TxQs? */ |
| 263 | BNAD_UPDATE_CTR(bnad, |
| 264 | netif_queue_wakeup); |
| 265 | } |
| 266 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | static u32 |
| 272 | bnad_tx(struct bnad *bnad, struct bna_tcb *tcb) |
| 273 | { |
| 274 | struct net_device *netdev = bnad->netdev; |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 275 | u32 sent = 0; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 276 | |
| 277 | if (test_and_set_bit(BNAD_TXQ_FREE_SENT, &tcb->flags)) |
| 278 | return 0; |
| 279 | |
| 280 | sent = bnad_free_txbufs(bnad, tcb); |
| 281 | if (sent) { |
| 282 | if (netif_queue_stopped(netdev) && |
| 283 | netif_carrier_ok(netdev) && |
| 284 | BNA_QE_FREE_CNT(tcb, tcb->q_depth) >= |
| 285 | BNAD_NETIF_WAKE_THRESHOLD) { |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 286 | if (test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags)) { |
| 287 | netif_wake_queue(netdev); |
| 288 | BNAD_UPDATE_CTR(bnad, netif_queue_wakeup); |
| 289 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 290 | } |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | if (likely(test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags))) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 294 | bna_ib_ack(tcb->i_dbell, sent); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 295 | |
| 296 | smp_mb__before_clear_bit(); |
| 297 | clear_bit(BNAD_TXQ_FREE_SENT, &tcb->flags); |
| 298 | |
| 299 | return sent; |
| 300 | } |
| 301 | |
| 302 | /* MSIX Tx Completion Handler */ |
| 303 | static irqreturn_t |
| 304 | bnad_msix_tx(int irq, void *data) |
| 305 | { |
| 306 | struct bna_tcb *tcb = (struct bna_tcb *)data; |
| 307 | struct bnad *bnad = tcb->bnad; |
| 308 | |
| 309 | bnad_tx(bnad, tcb); |
| 310 | |
| 311 | return IRQ_HANDLED; |
| 312 | } |
| 313 | |
| 314 | static void |
| 315 | bnad_reset_rcb(struct bnad *bnad, struct bna_rcb *rcb) |
| 316 | { |
| 317 | struct bnad_unmap_q *unmap_q = rcb->unmap_q; |
| 318 | |
| 319 | rcb->producer_index = 0; |
| 320 | rcb->consumer_index = 0; |
| 321 | |
| 322 | unmap_q->producer_index = 0; |
| 323 | unmap_q->consumer_index = 0; |
| 324 | } |
| 325 | |
| 326 | static void |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 327 | bnad_free_all_rxbufs(struct bnad *bnad, struct bna_rcb *rcb) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 328 | { |
| 329 | struct bnad_unmap_q *unmap_q; |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 330 | struct bnad_skb_unmap *unmap_array; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 331 | struct sk_buff *skb; |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 332 | int unmap_cons; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 333 | |
| 334 | unmap_q = rcb->unmap_q; |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 335 | unmap_array = unmap_q->unmap_array; |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 336 | for (unmap_cons = 0; unmap_cons < unmap_q->q_depth; unmap_cons++) { |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 337 | skb = unmap_array[unmap_cons].skb; |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 338 | if (!skb) |
| 339 | continue; |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 340 | unmap_array[unmap_cons].skb = NULL; |
| 341 | dma_unmap_single(&bnad->pcidev->dev, |
| 342 | dma_unmap_addr(&unmap_array[unmap_cons], |
| 343 | dma_addr), |
| 344 | rcb->rxq->buffer_size, |
| 345 | DMA_FROM_DEVICE); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 346 | dev_kfree_skb(skb); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 347 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 348 | bnad_reset_rcb(bnad, rcb); |
| 349 | } |
| 350 | |
| 351 | static void |
| 352 | bnad_alloc_n_post_rxbufs(struct bnad *bnad, struct bna_rcb *rcb) |
| 353 | { |
| 354 | u16 to_alloc, alloced, unmap_prod, wi_range; |
| 355 | struct bnad_unmap_q *unmap_q = rcb->unmap_q; |
| 356 | struct bnad_skb_unmap *unmap_array; |
| 357 | struct bna_rxq_entry *rxent; |
| 358 | struct sk_buff *skb; |
| 359 | dma_addr_t dma_addr; |
| 360 | |
| 361 | alloced = 0; |
| 362 | to_alloc = |
| 363 | BNA_QE_FREE_CNT(unmap_q, unmap_q->q_depth); |
| 364 | |
| 365 | unmap_array = unmap_q->unmap_array; |
| 366 | unmap_prod = unmap_q->producer_index; |
| 367 | |
| 368 | BNA_RXQ_QPGE_PTR_GET(unmap_prod, rcb->sw_qpt, rxent, wi_range); |
| 369 | |
| 370 | while (to_alloc--) { |
Rasesh Mody | 19dbff9 | 2011-08-30 15:27:41 +0000 | [diff] [blame] | 371 | if (!wi_range) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 372 | BNA_RXQ_QPGE_PTR_GET(unmap_prod, rcb->sw_qpt, rxent, |
| 373 | wi_range); |
Eric Dumazet | 0a0e234 | 2011-07-08 05:29:30 +0000 | [diff] [blame] | 374 | skb = netdev_alloc_skb_ip_align(bnad->netdev, |
| 375 | rcb->rxq->buffer_size); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 376 | if (unlikely(!skb)) { |
| 377 | BNAD_UPDATE_CTR(bnad, rxbuf_alloc_failed); |
Rasesh Mody | 3caa1e95 | 2011-08-30 15:27:42 +0000 | [diff] [blame] | 378 | rcb->rxq->rxbuf_alloc_failed++; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 379 | goto finishing; |
| 380 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 381 | unmap_array[unmap_prod].skb = skb; |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 382 | dma_addr = dma_map_single(&bnad->pcidev->dev, skb->data, |
| 383 | rcb->rxq->buffer_size, |
| 384 | DMA_FROM_DEVICE); |
| 385 | dma_unmap_addr_set(&unmap_array[unmap_prod], dma_addr, |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 386 | dma_addr); |
| 387 | BNA_SET_DMA_ADDR(dma_addr, &rxent->host_addr); |
| 388 | BNA_QE_INDX_ADD(unmap_prod, 1, unmap_q->q_depth); |
| 389 | |
| 390 | rxent++; |
| 391 | wi_range--; |
| 392 | alloced++; |
| 393 | } |
| 394 | |
| 395 | finishing: |
| 396 | if (likely(alloced)) { |
| 397 | unmap_q->producer_index = unmap_prod; |
| 398 | rcb->producer_index = unmap_prod; |
| 399 | smp_mb(); |
Rasesh Mody | 5bcf6ac | 2011-09-27 10:39:10 +0000 | [diff] [blame] | 400 | if (likely(test_bit(BNAD_RXQ_POST_OK, &rcb->flags))) |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 401 | bna_rxq_prod_indx_doorbell(rcb); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 405 | static inline void |
| 406 | bnad_refill_rxq(struct bnad *bnad, struct bna_rcb *rcb) |
| 407 | { |
| 408 | struct bnad_unmap_q *unmap_q = rcb->unmap_q; |
| 409 | |
| 410 | if (!test_and_set_bit(BNAD_RXQ_REFILL, &rcb->flags)) { |
| 411 | if (BNA_QE_FREE_CNT(unmap_q, unmap_q->q_depth) |
| 412 | >> BNAD_RXQ_REFILL_THRESHOLD_SHIFT) |
| 413 | bnad_alloc_n_post_rxbufs(bnad, rcb); |
| 414 | smp_mb__before_clear_bit(); |
| 415 | clear_bit(BNAD_RXQ_REFILL, &rcb->flags); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | static u32 |
| 420 | bnad_poll_cq(struct bnad *bnad, struct bna_ccb *ccb, int budget) |
| 421 | { |
| 422 | struct bna_cq_entry *cmpl, *next_cmpl; |
| 423 | struct bna_rcb *rcb = NULL; |
| 424 | unsigned int wi_range, packets = 0, wis = 0; |
| 425 | struct bnad_unmap_q *unmap_q; |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 426 | struct bnad_skb_unmap *unmap_array; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 427 | struct sk_buff *skb; |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 428 | u32 flags, unmap_cons; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 429 | struct bna_pkt_rate *pkt_rt = &ccb->pkt_rate; |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 430 | struct bnad_rx_ctrl *rx_ctrl = (struct bnad_rx_ctrl *)(ccb->ctrl); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 431 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 432 | set_bit(BNAD_FP_IN_RX_PATH, &rx_ctrl->flags); |
| 433 | |
| 434 | if (!test_bit(BNAD_RXQ_STARTED, &ccb->rcb[0]->flags)) { |
| 435 | clear_bit(BNAD_FP_IN_RX_PATH, &rx_ctrl->flags); |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 436 | return 0; |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 437 | } |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 438 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 439 | prefetch(bnad->netdev); |
| 440 | BNA_CQ_QPGE_PTR_GET(ccb->producer_index, ccb->sw_qpt, cmpl, |
| 441 | wi_range); |
| 442 | BUG_ON(!(wi_range <= ccb->q_depth)); |
| 443 | while (cmpl->valid && packets < budget) { |
| 444 | packets++; |
| 445 | BNA_UPDATE_PKT_CNT(pkt_rt, ntohs(cmpl->length)); |
| 446 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 447 | if (bna_is_small_rxq(cmpl->rxq_id)) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 448 | rcb = ccb->rcb[1]; |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 449 | else |
| 450 | rcb = ccb->rcb[0]; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 451 | |
| 452 | unmap_q = rcb->unmap_q; |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 453 | unmap_array = unmap_q->unmap_array; |
| 454 | unmap_cons = unmap_q->consumer_index; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 455 | |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 456 | skb = unmap_array[unmap_cons].skb; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 457 | BUG_ON(!(skb)); |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 458 | unmap_array[unmap_cons].skb = NULL; |
| 459 | dma_unmap_single(&bnad->pcidev->dev, |
| 460 | dma_unmap_addr(&unmap_array[unmap_cons], |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 461 | dma_addr), |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 462 | rcb->rxq->buffer_size, |
| 463 | DMA_FROM_DEVICE); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 464 | BNA_QE_INDX_ADD(unmap_q->consumer_index, 1, unmap_q->q_depth); |
| 465 | |
| 466 | /* Should be more efficient ? Performance ? */ |
| 467 | BNA_QE_INDX_ADD(rcb->consumer_index, 1, rcb->q_depth); |
| 468 | |
| 469 | wis++; |
| 470 | if (likely(--wi_range)) |
| 471 | next_cmpl = cmpl + 1; |
| 472 | else { |
| 473 | BNA_QE_INDX_ADD(ccb->producer_index, wis, ccb->q_depth); |
| 474 | wis = 0; |
| 475 | BNA_CQ_QPGE_PTR_GET(ccb->producer_index, ccb->sw_qpt, |
| 476 | next_cmpl, wi_range); |
| 477 | BUG_ON(!(wi_range <= ccb->q_depth)); |
| 478 | } |
| 479 | prefetch(next_cmpl); |
| 480 | |
| 481 | flags = ntohl(cmpl->flags); |
| 482 | if (unlikely |
| 483 | (flags & |
| 484 | (BNA_CQ_EF_MAC_ERROR | BNA_CQ_EF_FCS_ERROR | |
| 485 | BNA_CQ_EF_TOO_LONG))) { |
| 486 | dev_kfree_skb_any(skb); |
| 487 | rcb->rxq->rx_packets_with_error++; |
| 488 | goto next; |
| 489 | } |
| 490 | |
| 491 | skb_put(skb, ntohs(cmpl->length)); |
| 492 | if (likely |
Michał Mirosław | e5ee20e | 2011-04-12 09:38:23 +0000 | [diff] [blame] | 493 | ((bnad->netdev->features & NETIF_F_RXCSUM) && |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 494 | (((flags & BNA_CQ_EF_IPV4) && |
| 495 | (flags & BNA_CQ_EF_L3_CKSUM_OK)) || |
| 496 | (flags & BNA_CQ_EF_IPV6)) && |
| 497 | (flags & (BNA_CQ_EF_TCP | BNA_CQ_EF_UDP)) && |
| 498 | (flags & BNA_CQ_EF_L4_CKSUM_OK))) |
| 499 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 500 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 501 | skb_checksum_none_assert(skb); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 502 | |
| 503 | rcb->rxq->rx_packets++; |
| 504 | rcb->rxq->rx_bytes += skb->len; |
| 505 | skb->protocol = eth_type_trans(skb, bnad->netdev); |
| 506 | |
Jiri Pirko | f859d7c | 2011-07-20 04:54:14 +0000 | [diff] [blame] | 507 | if (flags & BNA_CQ_EF_VLAN) |
| 508 | __vlan_hwaccel_put_tag(skb, ntohs(cmpl->vlan_tag)); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 509 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 510 | if (skb->ip_summed == CHECKSUM_UNNECESSARY) |
Jiri Pirko | f859d7c | 2011-07-20 04:54:14 +0000 | [diff] [blame] | 511 | napi_gro_receive(&rx_ctrl->napi, skb); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 512 | else { |
Jiri Pirko | f859d7c | 2011-07-20 04:54:14 +0000 | [diff] [blame] | 513 | netif_receive_skb(skb); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | next: |
| 517 | cmpl->valid = 0; |
| 518 | cmpl = next_cmpl; |
| 519 | } |
| 520 | |
| 521 | BNA_QE_INDX_ADD(ccb->producer_index, wis, ccb->q_depth); |
| 522 | |
Rasesh Mody | 2be6714 | 2011-08-30 15:27:39 +0000 | [diff] [blame] | 523 | if (likely(test_bit(BNAD_RXQ_STARTED, &ccb->rcb[0]->flags))) |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 524 | bna_ib_ack_disable_irq(ccb->i_dbell, packets); |
| 525 | |
Rasesh Mody | 2be6714 | 2011-08-30 15:27:39 +0000 | [diff] [blame] | 526 | bnad_refill_rxq(bnad, ccb->rcb[0]); |
| 527 | if (ccb->rcb[1]) |
| 528 | bnad_refill_rxq(bnad, ccb->rcb[1]); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 529 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 530 | clear_bit(BNAD_FP_IN_RX_PATH, &rx_ctrl->flags); |
| 531 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 532 | return packets; |
| 533 | } |
| 534 | |
| 535 | static void |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 536 | bnad_netif_rx_schedule_poll(struct bnad *bnad, struct bna_ccb *ccb) |
| 537 | { |
| 538 | struct bnad_rx_ctrl *rx_ctrl = (struct bnad_rx_ctrl *)(ccb->ctrl); |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 539 | struct napi_struct *napi = &rx_ctrl->napi; |
| 540 | |
| 541 | if (likely(napi_schedule_prep(napi))) { |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 542 | __napi_schedule(napi); |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 543 | rx_ctrl->rx_schedule++; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 544 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | /* MSIX Rx Path Handler */ |
| 548 | static irqreturn_t |
| 549 | bnad_msix_rx(int irq, void *data) |
| 550 | { |
| 551 | struct bna_ccb *ccb = (struct bna_ccb *)data; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 552 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 553 | if (ccb) { |
| 554 | ((struct bnad_rx_ctrl *)(ccb->ctrl))->rx_intr_ctr++; |
Rasesh Mody | 2be6714 | 2011-08-30 15:27:39 +0000 | [diff] [blame] | 555 | bnad_netif_rx_schedule_poll(ccb->bnad, ccb); |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 556 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 557 | |
| 558 | return IRQ_HANDLED; |
| 559 | } |
| 560 | |
| 561 | /* Interrupt handlers */ |
| 562 | |
| 563 | /* Mbox Interrupt Handlers */ |
| 564 | static irqreturn_t |
| 565 | bnad_msix_mbox_handler(int irq, void *data) |
| 566 | { |
| 567 | u32 intr_status; |
Rasesh Mody | e2fa6f2 | 2010-10-05 15:46:04 +0000 | [diff] [blame] | 568 | unsigned long flags; |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 569 | struct bnad *bnad = (struct bnad *)data; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 570 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 571 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Rasesh Mody | dfee325 | 2011-08-30 15:27:45 +0000 | [diff] [blame] | 572 | if (unlikely(test_bit(BNAD_RF_MBOX_IRQ_DISABLED, &bnad->run_flags))) { |
| 573 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 574 | return IRQ_HANDLED; |
| 575 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 576 | |
| 577 | bna_intr_status_get(&bnad->bna, intr_status); |
| 578 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 579 | if (BNA_IS_MBOX_ERR_INTR(&bnad->bna, intr_status)) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 580 | bna_mbox_handler(&bnad->bna, intr_status); |
| 581 | |
| 582 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 583 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 584 | return IRQ_HANDLED; |
| 585 | } |
| 586 | |
| 587 | static irqreturn_t |
| 588 | bnad_isr(int irq, void *data) |
| 589 | { |
| 590 | int i, j; |
| 591 | u32 intr_status; |
| 592 | unsigned long flags; |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 593 | struct bnad *bnad = (struct bnad *)data; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 594 | struct bnad_rx_info *rx_info; |
| 595 | struct bnad_rx_ctrl *rx_ctrl; |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 596 | struct bna_tcb *tcb = NULL; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 597 | |
Rasesh Mody | dfee325 | 2011-08-30 15:27:45 +0000 | [diff] [blame] | 598 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 599 | if (unlikely(test_bit(BNAD_RF_MBOX_IRQ_DISABLED, &bnad->run_flags))) { |
| 600 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
Rasesh Mody | e2fa6f2 | 2010-10-05 15:46:04 +0000 | [diff] [blame] | 601 | return IRQ_NONE; |
Rasesh Mody | dfee325 | 2011-08-30 15:27:45 +0000 | [diff] [blame] | 602 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 603 | |
| 604 | bna_intr_status_get(&bnad->bna, intr_status); |
Rasesh Mody | e2fa6f2 | 2010-10-05 15:46:04 +0000 | [diff] [blame] | 605 | |
Rasesh Mody | dfee325 | 2011-08-30 15:27:45 +0000 | [diff] [blame] | 606 | if (unlikely(!intr_status)) { |
| 607 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 608 | return IRQ_NONE; |
Rasesh Mody | dfee325 | 2011-08-30 15:27:45 +0000 | [diff] [blame] | 609 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 610 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 611 | if (BNA_IS_MBOX_ERR_INTR(&bnad->bna, intr_status)) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 612 | bna_mbox_handler(&bnad->bna, intr_status); |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 613 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 614 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 615 | |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 616 | if (!BNA_IS_INTX_DATA_INTR(intr_status)) |
| 617 | return IRQ_HANDLED; |
| 618 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 619 | /* Process data interrupts */ |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 620 | /* Tx processing */ |
| 621 | for (i = 0; i < bnad->num_tx; i++) { |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 622 | for (j = 0; j < bnad->num_txq_per_tx; j++) { |
| 623 | tcb = bnad->tx_info[i].tcb[j]; |
| 624 | if (tcb && test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags)) |
| 625 | bnad_tx(bnad, bnad->tx_info[i].tcb[j]); |
| 626 | } |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 627 | } |
| 628 | /* Rx processing */ |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 629 | for (i = 0; i < bnad->num_rx; i++) { |
| 630 | rx_info = &bnad->rx_info[i]; |
| 631 | if (!rx_info->rx) |
| 632 | continue; |
| 633 | for (j = 0; j < bnad->num_rxp_per_rx; j++) { |
| 634 | rx_ctrl = &rx_info->rx_ctrl[j]; |
| 635 | if (rx_ctrl->ccb) |
| 636 | bnad_netif_rx_schedule_poll(bnad, |
| 637 | rx_ctrl->ccb); |
| 638 | } |
| 639 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 640 | return IRQ_HANDLED; |
| 641 | } |
| 642 | |
| 643 | /* |
| 644 | * Called in interrupt / callback context |
| 645 | * with bna_lock held, so cfg_flags access is OK |
| 646 | */ |
| 647 | static void |
| 648 | bnad_enable_mbox_irq(struct bnad *bnad) |
| 649 | { |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 650 | clear_bit(BNAD_RF_MBOX_IRQ_DISABLED, &bnad->run_flags); |
Rasesh Mody | e2fa6f2 | 2010-10-05 15:46:04 +0000 | [diff] [blame] | 651 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 652 | BNAD_UPDATE_CTR(bnad, mbox_intr_enabled); |
| 653 | } |
| 654 | |
| 655 | /* |
| 656 | * Called with bnad->bna_lock held b'cos of |
| 657 | * bnad->cfg_flags access. |
| 658 | */ |
Rasesh Mody | b7ee31c5 | 2010-10-05 15:46:05 +0000 | [diff] [blame] | 659 | static void |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 660 | bnad_disable_mbox_irq(struct bnad *bnad) |
| 661 | { |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 662 | set_bit(BNAD_RF_MBOX_IRQ_DISABLED, &bnad->run_flags); |
Rasesh Mody | e2fa6f2 | 2010-10-05 15:46:04 +0000 | [diff] [blame] | 663 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 664 | BNAD_UPDATE_CTR(bnad, mbox_intr_disabled); |
| 665 | } |
| 666 | |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 667 | static void |
| 668 | bnad_set_netdev_perm_addr(struct bnad *bnad) |
| 669 | { |
| 670 | struct net_device *netdev = bnad->netdev; |
| 671 | |
| 672 | memcpy(netdev->perm_addr, &bnad->perm_addr, netdev->addr_len); |
| 673 | if (is_zero_ether_addr(netdev->dev_addr)) |
| 674 | memcpy(netdev->dev_addr, &bnad->perm_addr, netdev->addr_len); |
| 675 | } |
| 676 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 677 | /* Control Path Handlers */ |
| 678 | |
| 679 | /* Callbacks */ |
| 680 | void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 681 | bnad_cb_mbox_intr_enable(struct bnad *bnad) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 682 | { |
| 683 | bnad_enable_mbox_irq(bnad); |
| 684 | } |
| 685 | |
| 686 | void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 687 | bnad_cb_mbox_intr_disable(struct bnad *bnad) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 688 | { |
| 689 | bnad_disable_mbox_irq(bnad); |
| 690 | } |
| 691 | |
| 692 | void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 693 | bnad_cb_ioceth_ready(struct bnad *bnad) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 694 | { |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 695 | bnad->bnad_completions.ioc_comp_status = BNA_CB_SUCCESS; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 696 | complete(&bnad->bnad_completions.ioc_comp); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 700 | bnad_cb_ioceth_failed(struct bnad *bnad) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 701 | { |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 702 | bnad->bnad_completions.ioc_comp_status = BNA_CB_FAIL; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 703 | complete(&bnad->bnad_completions.ioc_comp); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | void |
| 707 | bnad_cb_ioceth_disabled(struct bnad *bnad) |
| 708 | { |
| 709 | bnad->bnad_completions.ioc_comp_status = BNA_CB_SUCCESS; |
| 710 | complete(&bnad->bnad_completions.ioc_comp); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | static void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 714 | bnad_cb_enet_disabled(void *arg) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 715 | { |
| 716 | struct bnad *bnad = (struct bnad *)arg; |
| 717 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 718 | netif_carrier_off(bnad->netdev); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 719 | complete(&bnad->bnad_completions.enet_comp); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 723 | bnad_cb_ethport_link_status(struct bnad *bnad, |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 724 | enum bna_link_status link_status) |
| 725 | { |
| 726 | bool link_up = 0; |
| 727 | |
| 728 | link_up = (link_status == BNA_LINK_UP) || (link_status == BNA_CEE_UP); |
| 729 | |
| 730 | if (link_status == BNA_CEE_UP) { |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 731 | if (!test_bit(BNAD_RF_CEE_RUNNING, &bnad->run_flags)) |
| 732 | BNAD_UPDATE_CTR(bnad, cee_toggle); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 733 | set_bit(BNAD_RF_CEE_RUNNING, &bnad->run_flags); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 734 | } else { |
| 735 | if (test_bit(BNAD_RF_CEE_RUNNING, &bnad->run_flags)) |
| 736 | BNAD_UPDATE_CTR(bnad, cee_toggle); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 737 | clear_bit(BNAD_RF_CEE_RUNNING, &bnad->run_flags); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 738 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 739 | |
| 740 | if (link_up) { |
| 741 | if (!netif_carrier_ok(bnad->netdev)) { |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 742 | uint tx_id, tcb_id; |
| 743 | printk(KERN_WARNING "bna: %s link up\n", |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 744 | bnad->netdev->name); |
| 745 | netif_carrier_on(bnad->netdev); |
| 746 | BNAD_UPDATE_CTR(bnad, link_toggle); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 747 | for (tx_id = 0; tx_id < bnad->num_tx; tx_id++) { |
| 748 | for (tcb_id = 0; tcb_id < bnad->num_txq_per_tx; |
| 749 | tcb_id++) { |
| 750 | struct bna_tcb *tcb = |
| 751 | bnad->tx_info[tx_id].tcb[tcb_id]; |
| 752 | u32 txq_id; |
| 753 | if (!tcb) |
| 754 | continue; |
| 755 | |
| 756 | txq_id = tcb->id; |
| 757 | |
| 758 | if (test_bit(BNAD_TXQ_TX_STARTED, |
| 759 | &tcb->flags)) { |
| 760 | /* |
| 761 | * Force an immediate |
| 762 | * Transmit Schedule */ |
| 763 | printk(KERN_INFO "bna: %s %d " |
| 764 | "TXQ_STARTED\n", |
| 765 | bnad->netdev->name, |
| 766 | txq_id); |
| 767 | netif_wake_subqueue( |
| 768 | bnad->netdev, |
| 769 | txq_id); |
| 770 | BNAD_UPDATE_CTR(bnad, |
| 771 | netif_queue_wakeup); |
| 772 | } else { |
| 773 | netif_stop_subqueue( |
| 774 | bnad->netdev, |
| 775 | txq_id); |
| 776 | BNAD_UPDATE_CTR(bnad, |
| 777 | netif_queue_stop); |
| 778 | } |
| 779 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | } else { |
| 783 | if (netif_carrier_ok(bnad->netdev)) { |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 784 | printk(KERN_WARNING "bna: %s link down\n", |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 785 | bnad->netdev->name); |
| 786 | netif_carrier_off(bnad->netdev); |
| 787 | BNAD_UPDATE_CTR(bnad, link_toggle); |
| 788 | } |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | static void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 793 | bnad_cb_tx_disabled(void *arg, struct bna_tx *tx) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 794 | { |
| 795 | struct bnad *bnad = (struct bnad *)arg; |
| 796 | |
| 797 | complete(&bnad->bnad_completions.tx_comp); |
| 798 | } |
| 799 | |
| 800 | static void |
| 801 | bnad_cb_tcb_setup(struct bnad *bnad, struct bna_tcb *tcb) |
| 802 | { |
| 803 | struct bnad_tx_info *tx_info = |
| 804 | (struct bnad_tx_info *)tcb->txq->tx->priv; |
| 805 | struct bnad_unmap_q *unmap_q = tcb->unmap_q; |
| 806 | |
| 807 | tx_info->tcb[tcb->id] = tcb; |
| 808 | unmap_q->producer_index = 0; |
| 809 | unmap_q->consumer_index = 0; |
| 810 | unmap_q->q_depth = BNAD_TX_UNMAPQ_DEPTH; |
| 811 | } |
| 812 | |
| 813 | static void |
| 814 | bnad_cb_tcb_destroy(struct bnad *bnad, struct bna_tcb *tcb) |
| 815 | { |
| 816 | struct bnad_tx_info *tx_info = |
| 817 | (struct bnad_tx_info *)tcb->txq->tx->priv; |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 818 | struct bnad_unmap_q *unmap_q = tcb->unmap_q; |
| 819 | |
| 820 | while (test_and_set_bit(BNAD_TXQ_FREE_SENT, &tcb->flags)) |
| 821 | cpu_relax(); |
| 822 | |
| 823 | bnad_free_all_txbufs(bnad, tcb); |
| 824 | |
| 825 | unmap_q->producer_index = 0; |
| 826 | unmap_q->consumer_index = 0; |
| 827 | |
| 828 | smp_mb__before_clear_bit(); |
| 829 | clear_bit(BNAD_TXQ_FREE_SENT, &tcb->flags); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 830 | |
| 831 | tx_info->tcb[tcb->id] = NULL; |
| 832 | } |
| 833 | |
| 834 | static void |
| 835 | bnad_cb_rcb_setup(struct bnad *bnad, struct bna_rcb *rcb) |
| 836 | { |
| 837 | struct bnad_unmap_q *unmap_q = rcb->unmap_q; |
| 838 | |
| 839 | unmap_q->producer_index = 0; |
| 840 | unmap_q->consumer_index = 0; |
| 841 | unmap_q->q_depth = BNAD_RX_UNMAPQ_DEPTH; |
| 842 | } |
| 843 | |
| 844 | static void |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 845 | bnad_cb_rcb_destroy(struct bnad *bnad, struct bna_rcb *rcb) |
| 846 | { |
| 847 | bnad_free_all_rxbufs(bnad, rcb); |
| 848 | } |
| 849 | |
| 850 | static void |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 851 | bnad_cb_ccb_setup(struct bnad *bnad, struct bna_ccb *ccb) |
| 852 | { |
| 853 | struct bnad_rx_info *rx_info = |
| 854 | (struct bnad_rx_info *)ccb->cq->rx->priv; |
| 855 | |
| 856 | rx_info->rx_ctrl[ccb->id].ccb = ccb; |
| 857 | ccb->ctrl = &rx_info->rx_ctrl[ccb->id]; |
| 858 | } |
| 859 | |
| 860 | static void |
| 861 | bnad_cb_ccb_destroy(struct bnad *bnad, struct bna_ccb *ccb) |
| 862 | { |
| 863 | struct bnad_rx_info *rx_info = |
| 864 | (struct bnad_rx_info *)ccb->cq->rx->priv; |
| 865 | |
| 866 | rx_info->rx_ctrl[ccb->id].ccb = NULL; |
| 867 | } |
| 868 | |
| 869 | static void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 870 | bnad_cb_tx_stall(struct bnad *bnad, struct bna_tx *tx) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 871 | { |
| 872 | struct bnad_tx_info *tx_info = |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 873 | (struct bnad_tx_info *)tx->priv; |
| 874 | struct bna_tcb *tcb; |
| 875 | u32 txq_id; |
| 876 | int i; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 877 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 878 | for (i = 0; i < BNAD_MAX_TXQ_PER_TX; i++) { |
| 879 | tcb = tx_info->tcb[i]; |
| 880 | if (!tcb) |
| 881 | continue; |
| 882 | txq_id = tcb->id; |
| 883 | clear_bit(BNAD_TXQ_TX_STARTED, &tcb->flags); |
| 884 | netif_stop_subqueue(bnad->netdev, txq_id); |
| 885 | printk(KERN_INFO "bna: %s %d TXQ_STOPPED\n", |
| 886 | bnad->netdev->name, txq_id); |
| 887 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | static void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 891 | bnad_cb_tx_resume(struct bnad *bnad, struct bna_tx *tx) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 892 | { |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 893 | struct bnad_tx_info *tx_info = (struct bnad_tx_info *)tx->priv; |
| 894 | struct bna_tcb *tcb; |
| 895 | struct bnad_unmap_q *unmap_q; |
| 896 | u32 txq_id; |
| 897 | int i; |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 898 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 899 | for (i = 0; i < BNAD_MAX_TXQ_PER_TX; i++) { |
| 900 | tcb = tx_info->tcb[i]; |
| 901 | if (!tcb) |
| 902 | continue; |
| 903 | txq_id = tcb->id; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 904 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 905 | unmap_q = tcb->unmap_q; |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 906 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 907 | if (test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags)) |
| 908 | continue; |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 909 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 910 | while (test_and_set_bit(BNAD_TXQ_FREE_SENT, &tcb->flags)) |
| 911 | cpu_relax(); |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 912 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 913 | bnad_free_all_txbufs(bnad, tcb); |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 914 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 915 | unmap_q->producer_index = 0; |
| 916 | unmap_q->consumer_index = 0; |
| 917 | |
| 918 | smp_mb__before_clear_bit(); |
| 919 | clear_bit(BNAD_TXQ_FREE_SENT, &tcb->flags); |
| 920 | |
| 921 | set_bit(BNAD_TXQ_TX_STARTED, &tcb->flags); |
| 922 | |
| 923 | if (netif_carrier_ok(bnad->netdev)) { |
| 924 | printk(KERN_INFO "bna: %s %d TXQ_STARTED\n", |
| 925 | bnad->netdev->name, txq_id); |
| 926 | netif_wake_subqueue(bnad->netdev, txq_id); |
| 927 | BNAD_UPDATE_CTR(bnad, netif_queue_wakeup); |
| 928 | } |
| 929 | } |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 930 | |
| 931 | /* |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 932 | * Workaround for first ioceth enable failure & we |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 933 | * get a 0 MAC address. We try to get the MAC address |
| 934 | * again here. |
| 935 | */ |
| 936 | if (is_zero_ether_addr(&bnad->perm_addr.mac[0])) { |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 937 | bna_enet_perm_mac_get(&bnad->bna.enet, &bnad->perm_addr); |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 938 | bnad_set_netdev_perm_addr(bnad); |
| 939 | } |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 940 | } |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 941 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 942 | static void |
| 943 | bnad_cb_tx_cleanup(struct bnad *bnad, struct bna_tx *tx) |
| 944 | { |
| 945 | struct bnad_tx_info *tx_info = (struct bnad_tx_info *)tx->priv; |
| 946 | struct bna_tcb *tcb; |
| 947 | int i; |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 948 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 949 | for (i = 0; i < BNAD_MAX_TXQ_PER_TX; i++) { |
| 950 | tcb = tx_info->tcb[i]; |
| 951 | if (!tcb) |
| 952 | continue; |
| 953 | } |
| 954 | |
| 955 | mdelay(BNAD_TXRX_SYNC_MDELAY); |
| 956 | bna_tx_cleanup_complete(tx); |
| 957 | } |
| 958 | |
| 959 | static void |
Rasesh Mody | 5bcf6ac | 2011-09-27 10:39:10 +0000 | [diff] [blame] | 960 | bnad_cb_rx_stall(struct bnad *bnad, struct bna_rx *rx) |
| 961 | { |
| 962 | struct bnad_rx_info *rx_info = (struct bnad_rx_info *)rx->priv; |
| 963 | struct bna_ccb *ccb; |
| 964 | struct bnad_rx_ctrl *rx_ctrl; |
| 965 | int i; |
| 966 | |
| 967 | for (i = 0; i < BNAD_MAX_RXP_PER_RX; i++) { |
| 968 | rx_ctrl = &rx_info->rx_ctrl[i]; |
| 969 | ccb = rx_ctrl->ccb; |
| 970 | if (!ccb) |
| 971 | continue; |
| 972 | |
| 973 | clear_bit(BNAD_RXQ_POST_OK, &ccb->rcb[0]->flags); |
| 974 | |
| 975 | if (ccb->rcb[1]) |
| 976 | clear_bit(BNAD_RXQ_POST_OK, &ccb->rcb[1]->flags); |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | static void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 981 | bnad_cb_rx_cleanup(struct bnad *bnad, struct bna_rx *rx) |
| 982 | { |
| 983 | struct bnad_rx_info *rx_info = (struct bnad_rx_info *)rx->priv; |
| 984 | struct bna_ccb *ccb; |
| 985 | struct bnad_rx_ctrl *rx_ctrl; |
| 986 | int i; |
| 987 | |
| 988 | mdelay(BNAD_TXRX_SYNC_MDELAY); |
| 989 | |
Rasesh Mody | 772b523 | 2011-08-30 15:27:37 +0000 | [diff] [blame] | 990 | for (i = 0; i < BNAD_MAX_RXP_PER_RX; i++) { |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 991 | rx_ctrl = &rx_info->rx_ctrl[i]; |
| 992 | ccb = rx_ctrl->ccb; |
| 993 | if (!ccb) |
| 994 | continue; |
| 995 | |
| 996 | clear_bit(BNAD_RXQ_STARTED, &ccb->rcb[0]->flags); |
| 997 | |
| 998 | if (ccb->rcb[1]) |
| 999 | clear_bit(BNAD_RXQ_STARTED, &ccb->rcb[1]->flags); |
| 1000 | |
| 1001 | while (test_bit(BNAD_FP_IN_RX_PATH, &rx_ctrl->flags)) |
| 1002 | cpu_relax(); |
| 1003 | } |
| 1004 | |
| 1005 | bna_rx_cleanup_complete(rx); |
| 1006 | } |
| 1007 | |
| 1008 | static void |
| 1009 | bnad_cb_rx_post(struct bnad *bnad, struct bna_rx *rx) |
| 1010 | { |
| 1011 | struct bnad_rx_info *rx_info = (struct bnad_rx_info *)rx->priv; |
| 1012 | struct bna_ccb *ccb; |
| 1013 | struct bna_rcb *rcb; |
| 1014 | struct bnad_rx_ctrl *rx_ctrl; |
| 1015 | struct bnad_unmap_q *unmap_q; |
| 1016 | int i; |
| 1017 | int j; |
| 1018 | |
Rasesh Mody | 772b523 | 2011-08-30 15:27:37 +0000 | [diff] [blame] | 1019 | for (i = 0; i < BNAD_MAX_RXP_PER_RX; i++) { |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1020 | rx_ctrl = &rx_info->rx_ctrl[i]; |
| 1021 | ccb = rx_ctrl->ccb; |
| 1022 | if (!ccb) |
| 1023 | continue; |
| 1024 | |
| 1025 | bnad_cq_cmpl_init(bnad, ccb); |
| 1026 | |
| 1027 | for (j = 0; j < BNAD_MAX_RXQ_PER_RXP; j++) { |
| 1028 | rcb = ccb->rcb[j]; |
| 1029 | if (!rcb) |
| 1030 | continue; |
| 1031 | bnad_free_all_rxbufs(bnad, rcb); |
| 1032 | |
| 1033 | set_bit(BNAD_RXQ_STARTED, &rcb->flags); |
Rasesh Mody | 5bcf6ac | 2011-09-27 10:39:10 +0000 | [diff] [blame] | 1034 | set_bit(BNAD_RXQ_POST_OK, &rcb->flags); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1035 | unmap_q = rcb->unmap_q; |
| 1036 | |
| 1037 | /* Now allocate & post buffers for this RCB */ |
| 1038 | /* !!Allocation in callback context */ |
| 1039 | if (!test_and_set_bit(BNAD_RXQ_REFILL, &rcb->flags)) { |
| 1040 | if (BNA_QE_FREE_CNT(unmap_q, unmap_q->q_depth) |
| 1041 | >> BNAD_RXQ_REFILL_THRESHOLD_SHIFT) |
| 1042 | bnad_alloc_n_post_rxbufs(bnad, rcb); |
| 1043 | smp_mb__before_clear_bit(); |
| 1044 | clear_bit(BNAD_RXQ_REFILL, &rcb->flags); |
| 1045 | } |
| 1046 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1047 | } |
| 1048 | } |
| 1049 | |
| 1050 | static void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1051 | bnad_cb_rx_disabled(void *arg, struct bna_rx *rx) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1052 | { |
| 1053 | struct bnad *bnad = (struct bnad *)arg; |
| 1054 | |
| 1055 | complete(&bnad->bnad_completions.rx_comp); |
| 1056 | } |
| 1057 | |
| 1058 | static void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1059 | bnad_cb_rx_mcast_add(struct bnad *bnad, struct bna_rx *rx) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1060 | { |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1061 | bnad->bnad_completions.mcast_comp_status = BNA_CB_SUCCESS; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1062 | complete(&bnad->bnad_completions.mcast_comp); |
| 1063 | } |
| 1064 | |
| 1065 | void |
| 1066 | bnad_cb_stats_get(struct bnad *bnad, enum bna_cb_status status, |
| 1067 | struct bna_stats *stats) |
| 1068 | { |
| 1069 | if (status == BNA_CB_SUCCESS) |
| 1070 | BNAD_UPDATE_CTR(bnad, hw_stats_updates); |
| 1071 | |
| 1072 | if (!netif_running(bnad->netdev) || |
| 1073 | !test_bit(BNAD_RF_STATS_TIMER_RUNNING, &bnad->run_flags)) |
| 1074 | return; |
| 1075 | |
| 1076 | mod_timer(&bnad->stats_timer, |
| 1077 | jiffies + msecs_to_jiffies(BNAD_STATS_TIMER_FREQ)); |
| 1078 | } |
| 1079 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1080 | static void |
| 1081 | bnad_cb_enet_mtu_set(struct bnad *bnad) |
| 1082 | { |
| 1083 | bnad->bnad_completions.mtu_comp_status = BNA_CB_SUCCESS; |
| 1084 | complete(&bnad->bnad_completions.mtu_comp); |
| 1085 | } |
| 1086 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1087 | /* Resource allocation, free functions */ |
| 1088 | |
| 1089 | static void |
| 1090 | bnad_mem_free(struct bnad *bnad, |
| 1091 | struct bna_mem_info *mem_info) |
| 1092 | { |
| 1093 | int i; |
| 1094 | dma_addr_t dma_pa; |
| 1095 | |
| 1096 | if (mem_info->mdl == NULL) |
| 1097 | return; |
| 1098 | |
| 1099 | for (i = 0; i < mem_info->num; i++) { |
| 1100 | if (mem_info->mdl[i].kva != NULL) { |
| 1101 | if (mem_info->mem_type == BNA_MEM_T_DMA) { |
| 1102 | BNA_GET_DMA_ADDR(&(mem_info->mdl[i].dma), |
| 1103 | dma_pa); |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 1104 | dma_free_coherent(&bnad->pcidev->dev, |
| 1105 | mem_info->mdl[i].len, |
| 1106 | mem_info->mdl[i].kva, dma_pa); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1107 | } else |
| 1108 | kfree(mem_info->mdl[i].kva); |
| 1109 | } |
| 1110 | } |
| 1111 | kfree(mem_info->mdl); |
| 1112 | mem_info->mdl = NULL; |
| 1113 | } |
| 1114 | |
| 1115 | static int |
| 1116 | bnad_mem_alloc(struct bnad *bnad, |
| 1117 | struct bna_mem_info *mem_info) |
| 1118 | { |
| 1119 | int i; |
| 1120 | dma_addr_t dma_pa; |
| 1121 | |
| 1122 | if ((mem_info->num == 0) || (mem_info->len == 0)) { |
| 1123 | mem_info->mdl = NULL; |
| 1124 | return 0; |
| 1125 | } |
| 1126 | |
| 1127 | mem_info->mdl = kcalloc(mem_info->num, sizeof(struct bna_mem_descr), |
| 1128 | GFP_KERNEL); |
| 1129 | if (mem_info->mdl == NULL) |
| 1130 | return -ENOMEM; |
| 1131 | |
| 1132 | if (mem_info->mem_type == BNA_MEM_T_DMA) { |
| 1133 | for (i = 0; i < mem_info->num; i++) { |
| 1134 | mem_info->mdl[i].len = mem_info->len; |
| 1135 | mem_info->mdl[i].kva = |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 1136 | dma_alloc_coherent(&bnad->pcidev->dev, |
| 1137 | mem_info->len, &dma_pa, |
| 1138 | GFP_KERNEL); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1139 | |
| 1140 | if (mem_info->mdl[i].kva == NULL) |
| 1141 | goto err_return; |
| 1142 | |
| 1143 | BNA_SET_DMA_ADDR(dma_pa, |
| 1144 | &(mem_info->mdl[i].dma)); |
| 1145 | } |
| 1146 | } else { |
| 1147 | for (i = 0; i < mem_info->num; i++) { |
| 1148 | mem_info->mdl[i].len = mem_info->len; |
| 1149 | mem_info->mdl[i].kva = kzalloc(mem_info->len, |
| 1150 | GFP_KERNEL); |
| 1151 | if (mem_info->mdl[i].kva == NULL) |
| 1152 | goto err_return; |
| 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | return 0; |
| 1157 | |
| 1158 | err_return: |
| 1159 | bnad_mem_free(bnad, mem_info); |
| 1160 | return -ENOMEM; |
| 1161 | } |
| 1162 | |
| 1163 | /* Free IRQ for Mailbox */ |
| 1164 | static void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1165 | bnad_mbox_irq_free(struct bnad *bnad) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1166 | { |
| 1167 | int irq; |
| 1168 | unsigned long flags; |
| 1169 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1170 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1171 | bnad_disable_mbox_irq(bnad); |
Rasesh Mody | e2fa6f2 | 2010-10-05 15:46:04 +0000 | [diff] [blame] | 1172 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1173 | |
| 1174 | irq = BNAD_GET_MBOX_IRQ(bnad); |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 1175 | free_irq(irq, bnad); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | /* |
| 1179 | * Allocates IRQ for Mailbox, but keep it disabled |
| 1180 | * This will be enabled once we get the mbox enable callback |
| 1181 | * from bna |
| 1182 | */ |
| 1183 | static int |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1184 | bnad_mbox_irq_alloc(struct bnad *bnad) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1185 | { |
Rasesh Mody | 0120b99 | 2011-07-22 08:07:41 +0000 | [diff] [blame] | 1186 | int err = 0; |
| 1187 | unsigned long irq_flags, flags; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1188 | u32 irq; |
Rasesh Mody | 0120b99 | 2011-07-22 08:07:41 +0000 | [diff] [blame] | 1189 | irq_handler_t irq_handler; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1190 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1191 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 1192 | if (bnad->cfg_flags & BNAD_CF_MSIX) { |
| 1193 | irq_handler = (irq_handler_t)bnad_msix_mbox_handler; |
Rasesh Mody | 8811e26 | 2011-07-22 08:07:44 +0000 | [diff] [blame] | 1194 | irq = bnad->msix_table[BNAD_MAILBOX_MSIX_INDEX].vector; |
Shyam Iyer | 8279171 | 2011-07-14 15:00:32 +0000 | [diff] [blame] | 1195 | irq_flags = 0; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1196 | } else { |
| 1197 | irq_handler = (irq_handler_t)bnad_isr; |
| 1198 | irq = bnad->pcidev->irq; |
Shyam Iyer | 5f77898 | 2011-06-28 08:58:05 +0000 | [diff] [blame] | 1199 | irq_flags = IRQF_SHARED; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1200 | } |
Rasesh Mody | 8811e26 | 2011-07-22 08:07:44 +0000 | [diff] [blame] | 1201 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1202 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1203 | sprintf(bnad->mbox_irq_name, "%s", BNAD_NAME); |
| 1204 | |
Rasesh Mody | e2fa6f2 | 2010-10-05 15:46:04 +0000 | [diff] [blame] | 1205 | /* |
| 1206 | * Set the Mbox IRQ disable flag, so that the IRQ handler |
| 1207 | * called from request_irq() for SHARED IRQs do not execute |
| 1208 | */ |
| 1209 | set_bit(BNAD_RF_MBOX_IRQ_DISABLED, &bnad->run_flags); |
| 1210 | |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 1211 | BNAD_UPDATE_CTR(bnad, mbox_intr_disabled); |
| 1212 | |
Shyam Iyer | 8279171 | 2011-07-14 15:00:32 +0000 | [diff] [blame] | 1213 | err = request_irq(irq, irq_handler, irq_flags, |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 1214 | bnad->mbox_irq_name, bnad); |
Rasesh Mody | e2fa6f2 | 2010-10-05 15:46:04 +0000 | [diff] [blame] | 1215 | |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 1216 | return err; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | static void |
| 1220 | bnad_txrx_irq_free(struct bnad *bnad, struct bna_intr_info *intr_info) |
| 1221 | { |
| 1222 | kfree(intr_info->idl); |
| 1223 | intr_info->idl = NULL; |
| 1224 | } |
| 1225 | |
| 1226 | /* Allocates Interrupt Descriptor List for MSIX/INT-X vectors */ |
| 1227 | static int |
| 1228 | bnad_txrx_irq_alloc(struct bnad *bnad, enum bnad_intr_source src, |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1229 | u32 txrx_id, struct bna_intr_info *intr_info) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1230 | { |
| 1231 | int i, vector_start = 0; |
| 1232 | u32 cfg_flags; |
| 1233 | unsigned long flags; |
| 1234 | |
| 1235 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 1236 | cfg_flags = bnad->cfg_flags; |
| 1237 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 1238 | |
| 1239 | if (cfg_flags & BNAD_CF_MSIX) { |
| 1240 | intr_info->intr_type = BNA_INTR_T_MSIX; |
| 1241 | intr_info->idl = kcalloc(intr_info->num, |
| 1242 | sizeof(struct bna_intr_descr), |
| 1243 | GFP_KERNEL); |
| 1244 | if (!intr_info->idl) |
| 1245 | return -ENOMEM; |
| 1246 | |
| 1247 | switch (src) { |
| 1248 | case BNAD_INTR_TX: |
Rasesh Mody | 8811e26 | 2011-07-22 08:07:44 +0000 | [diff] [blame] | 1249 | vector_start = BNAD_MAILBOX_MSIX_VECTORS + txrx_id; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1250 | break; |
| 1251 | |
| 1252 | case BNAD_INTR_RX: |
Rasesh Mody | 8811e26 | 2011-07-22 08:07:44 +0000 | [diff] [blame] | 1253 | vector_start = BNAD_MAILBOX_MSIX_VECTORS + |
| 1254 | (bnad->num_tx * bnad->num_txq_per_tx) + |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1255 | txrx_id; |
| 1256 | break; |
| 1257 | |
| 1258 | default: |
| 1259 | BUG(); |
| 1260 | } |
| 1261 | |
| 1262 | for (i = 0; i < intr_info->num; i++) |
| 1263 | intr_info->idl[i].vector = vector_start + i; |
| 1264 | } else { |
| 1265 | intr_info->intr_type = BNA_INTR_T_INTX; |
| 1266 | intr_info->num = 1; |
| 1267 | intr_info->idl = kcalloc(intr_info->num, |
| 1268 | sizeof(struct bna_intr_descr), |
| 1269 | GFP_KERNEL); |
| 1270 | if (!intr_info->idl) |
| 1271 | return -ENOMEM; |
| 1272 | |
| 1273 | switch (src) { |
| 1274 | case BNAD_INTR_TX: |
Rasesh Mody | 8811e26 | 2011-07-22 08:07:44 +0000 | [diff] [blame] | 1275 | intr_info->idl[0].vector = BNAD_INTX_TX_IB_BITMASK; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1276 | break; |
| 1277 | |
| 1278 | case BNAD_INTR_RX: |
Rasesh Mody | 8811e26 | 2011-07-22 08:07:44 +0000 | [diff] [blame] | 1279 | intr_info->idl[0].vector = BNAD_INTX_RX_IB_BITMASK; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1280 | break; |
| 1281 | } |
| 1282 | } |
| 1283 | return 0; |
| 1284 | } |
| 1285 | |
| 1286 | /** |
| 1287 | * NOTE: Should be called for MSIX only |
| 1288 | * Unregisters Tx MSIX vector(s) from the kernel |
| 1289 | */ |
| 1290 | static void |
| 1291 | bnad_tx_msix_unregister(struct bnad *bnad, struct bnad_tx_info *tx_info, |
| 1292 | int num_txqs) |
| 1293 | { |
| 1294 | int i; |
| 1295 | int vector_num; |
| 1296 | |
| 1297 | for (i = 0; i < num_txqs; i++) { |
| 1298 | if (tx_info->tcb[i] == NULL) |
| 1299 | continue; |
| 1300 | |
| 1301 | vector_num = tx_info->tcb[i]->intr_vector; |
| 1302 | free_irq(bnad->msix_table[vector_num].vector, tx_info->tcb[i]); |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | /** |
| 1307 | * NOTE: Should be called for MSIX only |
| 1308 | * Registers Tx MSIX vector(s) and ISR(s), cookie with the kernel |
| 1309 | */ |
| 1310 | static int |
| 1311 | bnad_tx_msix_register(struct bnad *bnad, struct bnad_tx_info *tx_info, |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1312 | u32 tx_id, int num_txqs) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1313 | { |
| 1314 | int i; |
| 1315 | int err; |
| 1316 | int vector_num; |
| 1317 | |
| 1318 | for (i = 0; i < num_txqs; i++) { |
| 1319 | vector_num = tx_info->tcb[i]->intr_vector; |
| 1320 | sprintf(tx_info->tcb[i]->name, "%s TXQ %d", bnad->netdev->name, |
| 1321 | tx_id + tx_info->tcb[i]->id); |
| 1322 | err = request_irq(bnad->msix_table[vector_num].vector, |
| 1323 | (irq_handler_t)bnad_msix_tx, 0, |
| 1324 | tx_info->tcb[i]->name, |
| 1325 | tx_info->tcb[i]); |
| 1326 | if (err) |
| 1327 | goto err_return; |
| 1328 | } |
| 1329 | |
| 1330 | return 0; |
| 1331 | |
| 1332 | err_return: |
| 1333 | if (i > 0) |
| 1334 | bnad_tx_msix_unregister(bnad, tx_info, (i - 1)); |
| 1335 | return -1; |
| 1336 | } |
| 1337 | |
| 1338 | /** |
| 1339 | * NOTE: Should be called for MSIX only |
| 1340 | * Unregisters Rx MSIX vector(s) from the kernel |
| 1341 | */ |
| 1342 | static void |
| 1343 | bnad_rx_msix_unregister(struct bnad *bnad, struct bnad_rx_info *rx_info, |
| 1344 | int num_rxps) |
| 1345 | { |
| 1346 | int i; |
| 1347 | int vector_num; |
| 1348 | |
| 1349 | for (i = 0; i < num_rxps; i++) { |
| 1350 | if (rx_info->rx_ctrl[i].ccb == NULL) |
| 1351 | continue; |
| 1352 | |
| 1353 | vector_num = rx_info->rx_ctrl[i].ccb->intr_vector; |
| 1354 | free_irq(bnad->msix_table[vector_num].vector, |
| 1355 | rx_info->rx_ctrl[i].ccb); |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | /** |
| 1360 | * NOTE: Should be called for MSIX only |
| 1361 | * Registers Tx MSIX vector(s) and ISR(s), cookie with the kernel |
| 1362 | */ |
| 1363 | static int |
| 1364 | bnad_rx_msix_register(struct bnad *bnad, struct bnad_rx_info *rx_info, |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1365 | u32 rx_id, int num_rxps) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1366 | { |
| 1367 | int i; |
| 1368 | int err; |
| 1369 | int vector_num; |
| 1370 | |
| 1371 | for (i = 0; i < num_rxps; i++) { |
| 1372 | vector_num = rx_info->rx_ctrl[i].ccb->intr_vector; |
| 1373 | sprintf(rx_info->rx_ctrl[i].ccb->name, "%s CQ %d", |
| 1374 | bnad->netdev->name, |
| 1375 | rx_id + rx_info->rx_ctrl[i].ccb->id); |
| 1376 | err = request_irq(bnad->msix_table[vector_num].vector, |
| 1377 | (irq_handler_t)bnad_msix_rx, 0, |
| 1378 | rx_info->rx_ctrl[i].ccb->name, |
| 1379 | rx_info->rx_ctrl[i].ccb); |
| 1380 | if (err) |
| 1381 | goto err_return; |
| 1382 | } |
| 1383 | |
| 1384 | return 0; |
| 1385 | |
| 1386 | err_return: |
| 1387 | if (i > 0) |
| 1388 | bnad_rx_msix_unregister(bnad, rx_info, (i - 1)); |
| 1389 | return -1; |
| 1390 | } |
| 1391 | |
| 1392 | /* Free Tx object Resources */ |
| 1393 | static void |
| 1394 | bnad_tx_res_free(struct bnad *bnad, struct bna_res_info *res_info) |
| 1395 | { |
| 1396 | int i; |
| 1397 | |
| 1398 | for (i = 0; i < BNA_TX_RES_T_MAX; i++) { |
| 1399 | if (res_info[i].res_type == BNA_RES_T_MEM) |
| 1400 | bnad_mem_free(bnad, &res_info[i].res_u.mem_info); |
| 1401 | else if (res_info[i].res_type == BNA_RES_T_INTR) |
| 1402 | bnad_txrx_irq_free(bnad, &res_info[i].res_u.intr_info); |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | /* Allocates memory and interrupt resources for Tx object */ |
| 1407 | static int |
| 1408 | bnad_tx_res_alloc(struct bnad *bnad, struct bna_res_info *res_info, |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1409 | u32 tx_id) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1410 | { |
| 1411 | int i, err = 0; |
| 1412 | |
| 1413 | for (i = 0; i < BNA_TX_RES_T_MAX; i++) { |
| 1414 | if (res_info[i].res_type == BNA_RES_T_MEM) |
| 1415 | err = bnad_mem_alloc(bnad, |
| 1416 | &res_info[i].res_u.mem_info); |
| 1417 | else if (res_info[i].res_type == BNA_RES_T_INTR) |
| 1418 | err = bnad_txrx_irq_alloc(bnad, BNAD_INTR_TX, tx_id, |
| 1419 | &res_info[i].res_u.intr_info); |
| 1420 | if (err) |
| 1421 | goto err_return; |
| 1422 | } |
| 1423 | return 0; |
| 1424 | |
| 1425 | err_return: |
| 1426 | bnad_tx_res_free(bnad, res_info); |
| 1427 | return err; |
| 1428 | } |
| 1429 | |
| 1430 | /* Free Rx object Resources */ |
| 1431 | static void |
| 1432 | bnad_rx_res_free(struct bnad *bnad, struct bna_res_info *res_info) |
| 1433 | { |
| 1434 | int i; |
| 1435 | |
| 1436 | for (i = 0; i < BNA_RX_RES_T_MAX; i++) { |
| 1437 | if (res_info[i].res_type == BNA_RES_T_MEM) |
| 1438 | bnad_mem_free(bnad, &res_info[i].res_u.mem_info); |
| 1439 | else if (res_info[i].res_type == BNA_RES_T_INTR) |
| 1440 | bnad_txrx_irq_free(bnad, &res_info[i].res_u.intr_info); |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | /* Allocates memory and interrupt resources for Rx object */ |
| 1445 | static int |
| 1446 | bnad_rx_res_alloc(struct bnad *bnad, struct bna_res_info *res_info, |
| 1447 | uint rx_id) |
| 1448 | { |
| 1449 | int i, err = 0; |
| 1450 | |
| 1451 | /* All memory needs to be allocated before setup_ccbs */ |
| 1452 | for (i = 0; i < BNA_RX_RES_T_MAX; i++) { |
| 1453 | if (res_info[i].res_type == BNA_RES_T_MEM) |
| 1454 | err = bnad_mem_alloc(bnad, |
| 1455 | &res_info[i].res_u.mem_info); |
| 1456 | else if (res_info[i].res_type == BNA_RES_T_INTR) |
| 1457 | err = bnad_txrx_irq_alloc(bnad, BNAD_INTR_RX, rx_id, |
| 1458 | &res_info[i].res_u.intr_info); |
| 1459 | if (err) |
| 1460 | goto err_return; |
| 1461 | } |
| 1462 | return 0; |
| 1463 | |
| 1464 | err_return: |
| 1465 | bnad_rx_res_free(bnad, res_info); |
| 1466 | return err; |
| 1467 | } |
| 1468 | |
| 1469 | /* Timer callbacks */ |
| 1470 | /* a) IOC timer */ |
| 1471 | static void |
| 1472 | bnad_ioc_timeout(unsigned long data) |
| 1473 | { |
| 1474 | struct bnad *bnad = (struct bnad *)data; |
| 1475 | unsigned long flags; |
| 1476 | |
| 1477 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1478 | bfa_nw_ioc_timeout((void *) &bnad->bna.ioceth.ioc); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1479 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 1480 | } |
| 1481 | |
| 1482 | static void |
| 1483 | bnad_ioc_hb_check(unsigned long data) |
| 1484 | { |
| 1485 | struct bnad *bnad = (struct bnad *)data; |
| 1486 | unsigned long flags; |
| 1487 | |
| 1488 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1489 | bfa_nw_ioc_hb_check((void *) &bnad->bna.ioceth.ioc); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1490 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 1491 | } |
| 1492 | |
| 1493 | static void |
Rasesh Mody | 1d32f76 | 2010-12-23 21:45:09 +0000 | [diff] [blame] | 1494 | bnad_iocpf_timeout(unsigned long data) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1495 | { |
| 1496 | struct bnad *bnad = (struct bnad *)data; |
| 1497 | unsigned long flags; |
| 1498 | |
| 1499 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1500 | bfa_nw_iocpf_timeout((void *) &bnad->bna.ioceth.ioc); |
Rasesh Mody | 1d32f76 | 2010-12-23 21:45:09 +0000 | [diff] [blame] | 1501 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 1502 | } |
| 1503 | |
| 1504 | static void |
| 1505 | bnad_iocpf_sem_timeout(unsigned long data) |
| 1506 | { |
| 1507 | struct bnad *bnad = (struct bnad *)data; |
| 1508 | unsigned long flags; |
| 1509 | |
| 1510 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1511 | bfa_nw_iocpf_sem_timeout((void *) &bnad->bna.ioceth.ioc); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1512 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 1513 | } |
| 1514 | |
| 1515 | /* |
| 1516 | * All timer routines use bnad->bna_lock to protect against |
| 1517 | * the following race, which may occur in case of no locking: |
Rasesh Mody | 0120b99 | 2011-07-22 08:07:41 +0000 | [diff] [blame] | 1518 | * Time CPU m CPU n |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1519 | * 0 1 = test_bit |
| 1520 | * 1 clear_bit |
| 1521 | * 2 del_timer_sync |
| 1522 | * 3 mod_timer |
| 1523 | */ |
| 1524 | |
| 1525 | /* b) Dynamic Interrupt Moderation Timer */ |
| 1526 | static void |
| 1527 | bnad_dim_timeout(unsigned long data) |
| 1528 | { |
| 1529 | struct bnad *bnad = (struct bnad *)data; |
| 1530 | struct bnad_rx_info *rx_info; |
| 1531 | struct bnad_rx_ctrl *rx_ctrl; |
| 1532 | int i, j; |
| 1533 | unsigned long flags; |
| 1534 | |
| 1535 | if (!netif_carrier_ok(bnad->netdev)) |
| 1536 | return; |
| 1537 | |
| 1538 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 1539 | for (i = 0; i < bnad->num_rx; i++) { |
| 1540 | rx_info = &bnad->rx_info[i]; |
| 1541 | if (!rx_info->rx) |
| 1542 | continue; |
| 1543 | for (j = 0; j < bnad->num_rxp_per_rx; j++) { |
| 1544 | rx_ctrl = &rx_info->rx_ctrl[j]; |
| 1545 | if (!rx_ctrl->ccb) |
| 1546 | continue; |
| 1547 | bna_rx_dim_update(rx_ctrl->ccb); |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | /* Check for BNAD_CF_DIM_ENABLED, does not eleminate a race */ |
| 1552 | if (test_bit(BNAD_RF_DIM_TIMER_RUNNING, &bnad->run_flags)) |
| 1553 | mod_timer(&bnad->dim_timer, |
| 1554 | jiffies + msecs_to_jiffies(BNAD_DIM_TIMER_FREQ)); |
| 1555 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 1556 | } |
| 1557 | |
| 1558 | /* c) Statistics Timer */ |
| 1559 | static void |
| 1560 | bnad_stats_timeout(unsigned long data) |
| 1561 | { |
| 1562 | struct bnad *bnad = (struct bnad *)data; |
| 1563 | unsigned long flags; |
| 1564 | |
| 1565 | if (!netif_running(bnad->netdev) || |
| 1566 | !test_bit(BNAD_RF_STATS_TIMER_RUNNING, &bnad->run_flags)) |
| 1567 | return; |
| 1568 | |
| 1569 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1570 | bna_hw_stats_get(&bnad->bna); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1571 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 1572 | } |
| 1573 | |
| 1574 | /* |
| 1575 | * Set up timer for DIM |
| 1576 | * Called with bnad->bna_lock held |
| 1577 | */ |
| 1578 | void |
| 1579 | bnad_dim_timer_start(struct bnad *bnad) |
| 1580 | { |
| 1581 | if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED && |
| 1582 | !test_bit(BNAD_RF_DIM_TIMER_RUNNING, &bnad->run_flags)) { |
| 1583 | setup_timer(&bnad->dim_timer, bnad_dim_timeout, |
| 1584 | (unsigned long)bnad); |
| 1585 | set_bit(BNAD_RF_DIM_TIMER_RUNNING, &bnad->run_flags); |
| 1586 | mod_timer(&bnad->dim_timer, |
| 1587 | jiffies + msecs_to_jiffies(BNAD_DIM_TIMER_FREQ)); |
| 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | /* |
| 1592 | * Set up timer for statistics |
| 1593 | * Called with mutex_lock(&bnad->conf_mutex) held |
| 1594 | */ |
| 1595 | static void |
| 1596 | bnad_stats_timer_start(struct bnad *bnad) |
| 1597 | { |
| 1598 | unsigned long flags; |
| 1599 | |
| 1600 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 1601 | if (!test_and_set_bit(BNAD_RF_STATS_TIMER_RUNNING, &bnad->run_flags)) { |
| 1602 | setup_timer(&bnad->stats_timer, bnad_stats_timeout, |
| 1603 | (unsigned long)bnad); |
| 1604 | mod_timer(&bnad->stats_timer, |
| 1605 | jiffies + msecs_to_jiffies(BNAD_STATS_TIMER_FREQ)); |
| 1606 | } |
| 1607 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | /* |
| 1611 | * Stops the stats timer |
| 1612 | * Called with mutex_lock(&bnad->conf_mutex) held |
| 1613 | */ |
| 1614 | static void |
| 1615 | bnad_stats_timer_stop(struct bnad *bnad) |
| 1616 | { |
| 1617 | int to_del = 0; |
| 1618 | unsigned long flags; |
| 1619 | |
| 1620 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 1621 | if (test_and_clear_bit(BNAD_RF_STATS_TIMER_RUNNING, &bnad->run_flags)) |
| 1622 | to_del = 1; |
| 1623 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 1624 | if (to_del) |
| 1625 | del_timer_sync(&bnad->stats_timer); |
| 1626 | } |
| 1627 | |
| 1628 | /* Utilities */ |
| 1629 | |
| 1630 | static void |
| 1631 | bnad_netdev_mc_list_get(struct net_device *netdev, u8 *mc_list) |
| 1632 | { |
| 1633 | int i = 1; /* Index 0 has broadcast address */ |
| 1634 | struct netdev_hw_addr *mc_addr; |
| 1635 | |
| 1636 | netdev_for_each_mc_addr(mc_addr, netdev) { |
| 1637 | memcpy(&mc_list[i * ETH_ALEN], &mc_addr->addr[0], |
| 1638 | ETH_ALEN); |
| 1639 | i++; |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | static int |
| 1644 | bnad_napi_poll_rx(struct napi_struct *napi, int budget) |
| 1645 | { |
| 1646 | struct bnad_rx_ctrl *rx_ctrl = |
| 1647 | container_of(napi, struct bnad_rx_ctrl, napi); |
Rasesh Mody | 2be6714 | 2011-08-30 15:27:39 +0000 | [diff] [blame] | 1648 | struct bnad *bnad = rx_ctrl->bnad; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1649 | int rcvd = 0; |
| 1650 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 1651 | rx_ctrl->rx_poll_ctr++; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1652 | |
| 1653 | if (!netif_carrier_ok(bnad->netdev)) |
| 1654 | goto poll_exit; |
| 1655 | |
Rasesh Mody | 2be6714 | 2011-08-30 15:27:39 +0000 | [diff] [blame] | 1656 | rcvd = bnad_poll_cq(bnad, rx_ctrl->ccb, budget); |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 1657 | if (rcvd >= budget) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1658 | return rcvd; |
| 1659 | |
| 1660 | poll_exit: |
Rasesh Mody | 19dbff9 | 2011-08-30 15:27:41 +0000 | [diff] [blame] | 1661 | napi_complete(napi); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1662 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 1663 | rx_ctrl->rx_complete++; |
Rasesh Mody | 2be6714 | 2011-08-30 15:27:39 +0000 | [diff] [blame] | 1664 | |
| 1665 | if (rx_ctrl->ccb) |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 1666 | bnad_enable_rx_irq_unsafe(rx_ctrl->ccb); |
| 1667 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1668 | return rcvd; |
| 1669 | } |
| 1670 | |
Rasesh Mody | 2be6714 | 2011-08-30 15:27:39 +0000 | [diff] [blame] | 1671 | #define BNAD_NAPI_POLL_QUOTA 64 |
| 1672 | static void |
| 1673 | bnad_napi_init(struct bnad *bnad, u32 rx_id) |
| 1674 | { |
| 1675 | struct bnad_rx_ctrl *rx_ctrl; |
| 1676 | int i; |
| 1677 | |
| 1678 | /* Initialize & enable NAPI */ |
| 1679 | for (i = 0; i < bnad->num_rxp_per_rx; i++) { |
| 1680 | rx_ctrl = &bnad->rx_info[rx_id].rx_ctrl[i]; |
| 1681 | netif_napi_add(bnad->netdev, &rx_ctrl->napi, |
| 1682 | bnad_napi_poll_rx, BNAD_NAPI_POLL_QUOTA); |
| 1683 | } |
| 1684 | } |
| 1685 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1686 | static void |
| 1687 | bnad_napi_enable(struct bnad *bnad, u32 rx_id) |
| 1688 | { |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1689 | struct bnad_rx_ctrl *rx_ctrl; |
| 1690 | int i; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1691 | |
| 1692 | /* Initialize & enable NAPI */ |
| 1693 | for (i = 0; i < bnad->num_rxp_per_rx; i++) { |
| 1694 | rx_ctrl = &bnad->rx_info[rx_id].rx_ctrl[i]; |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 1695 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1696 | napi_enable(&rx_ctrl->napi); |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | static void |
| 1701 | bnad_napi_disable(struct bnad *bnad, u32 rx_id) |
| 1702 | { |
| 1703 | int i; |
| 1704 | |
| 1705 | /* First disable and then clean up */ |
| 1706 | for (i = 0; i < bnad->num_rxp_per_rx; i++) { |
| 1707 | napi_disable(&bnad->rx_info[rx_id].rx_ctrl[i].napi); |
| 1708 | netif_napi_del(&bnad->rx_info[rx_id].rx_ctrl[i].napi); |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | /* Should be held with conf_lock held */ |
| 1713 | void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1714 | bnad_cleanup_tx(struct bnad *bnad, u32 tx_id) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1715 | { |
| 1716 | struct bnad_tx_info *tx_info = &bnad->tx_info[tx_id]; |
| 1717 | struct bna_res_info *res_info = &bnad->tx_res_info[tx_id].res_info[0]; |
| 1718 | unsigned long flags; |
| 1719 | |
| 1720 | if (!tx_info->tx) |
| 1721 | return; |
| 1722 | |
| 1723 | init_completion(&bnad->bnad_completions.tx_comp); |
| 1724 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 1725 | bna_tx_disable(tx_info->tx, BNA_HARD_CLEANUP, bnad_cb_tx_disabled); |
| 1726 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 1727 | wait_for_completion(&bnad->bnad_completions.tx_comp); |
| 1728 | |
| 1729 | if (tx_info->tcb[0]->intr_type == BNA_INTR_T_MSIX) |
| 1730 | bnad_tx_msix_unregister(bnad, tx_info, |
| 1731 | bnad->num_txq_per_tx); |
| 1732 | |
Rasesh Mody | 2be6714 | 2011-08-30 15:27:39 +0000 | [diff] [blame] | 1733 | if (0 == tx_id) |
| 1734 | tasklet_kill(&bnad->tx_free_tasklet); |
| 1735 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1736 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 1737 | bna_tx_destroy(tx_info->tx); |
| 1738 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 1739 | |
| 1740 | tx_info->tx = NULL; |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1741 | tx_info->tx_id = 0; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1742 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1743 | bnad_tx_res_free(bnad, res_info); |
| 1744 | } |
| 1745 | |
| 1746 | /* Should be held with conf_lock held */ |
| 1747 | int |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1748 | bnad_setup_tx(struct bnad *bnad, u32 tx_id) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1749 | { |
| 1750 | int err; |
| 1751 | struct bnad_tx_info *tx_info = &bnad->tx_info[tx_id]; |
| 1752 | struct bna_res_info *res_info = &bnad->tx_res_info[tx_id].res_info[0]; |
| 1753 | struct bna_intr_info *intr_info = |
| 1754 | &res_info[BNA_TX_RES_INTR_T_TXCMPL].res_u.intr_info; |
| 1755 | struct bna_tx_config *tx_config = &bnad->tx_config[tx_id]; |
stephen hemminger | d91d25d | 2011-09-16 11:09:51 +0000 | [diff] [blame] | 1756 | static const struct bna_tx_event_cbfn tx_cbfn = { |
| 1757 | .tcb_setup_cbfn = bnad_cb_tcb_setup, |
| 1758 | .tcb_destroy_cbfn = bnad_cb_tcb_destroy, |
| 1759 | .tx_stall_cbfn = bnad_cb_tx_stall, |
| 1760 | .tx_resume_cbfn = bnad_cb_tx_resume, |
| 1761 | .tx_cleanup_cbfn = bnad_cb_tx_cleanup, |
| 1762 | }; |
| 1763 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1764 | struct bna_tx *tx; |
| 1765 | unsigned long flags; |
| 1766 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1767 | tx_info->tx_id = tx_id; |
| 1768 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1769 | /* Initialize the Tx object configuration */ |
| 1770 | tx_config->num_txq = bnad->num_txq_per_tx; |
| 1771 | tx_config->txq_depth = bnad->txq_depth; |
| 1772 | tx_config->tx_type = BNA_TX_T_REGULAR; |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1773 | tx_config->coalescing_timeo = bnad->tx_coalescing_timeo; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1774 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1775 | /* Get BNA's resource requirement for one tx object */ |
| 1776 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 1777 | bna_tx_res_req(bnad->num_txq_per_tx, |
| 1778 | bnad->txq_depth, res_info); |
| 1779 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 1780 | |
| 1781 | /* Fill Unmap Q memory requirements */ |
| 1782 | BNAD_FILL_UNMAPQ_MEM_REQ( |
| 1783 | &res_info[BNA_TX_RES_MEM_T_UNMAPQ], |
| 1784 | bnad->num_txq_per_tx, |
| 1785 | BNAD_TX_UNMAPQ_DEPTH); |
| 1786 | |
| 1787 | /* Allocate resources */ |
| 1788 | err = bnad_tx_res_alloc(bnad, res_info, tx_id); |
| 1789 | if (err) |
| 1790 | return err; |
| 1791 | |
| 1792 | /* Ask BNA to create one Tx object, supplying required resources */ |
| 1793 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 1794 | tx = bna_tx_create(&bnad->bna, bnad, tx_config, &tx_cbfn, res_info, |
| 1795 | tx_info); |
| 1796 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 1797 | if (!tx) |
| 1798 | goto err_return; |
| 1799 | tx_info->tx = tx; |
| 1800 | |
| 1801 | /* Register ISR for the Tx object */ |
| 1802 | if (intr_info->intr_type == BNA_INTR_T_MSIX) { |
| 1803 | err = bnad_tx_msix_register(bnad, tx_info, |
| 1804 | tx_id, bnad->num_txq_per_tx); |
| 1805 | if (err) |
| 1806 | goto err_return; |
| 1807 | } |
| 1808 | |
| 1809 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 1810 | bna_tx_enable(tx); |
| 1811 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 1812 | |
| 1813 | return 0; |
| 1814 | |
| 1815 | err_return: |
| 1816 | bnad_tx_res_free(bnad, res_info); |
| 1817 | return err; |
| 1818 | } |
| 1819 | |
| 1820 | /* Setup the rx config for bna_rx_create */ |
| 1821 | /* bnad decides the configuration */ |
| 1822 | static void |
| 1823 | bnad_init_rx_config(struct bnad *bnad, struct bna_rx_config *rx_config) |
| 1824 | { |
| 1825 | rx_config->rx_type = BNA_RX_T_REGULAR; |
| 1826 | rx_config->num_paths = bnad->num_rxp_per_rx; |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1827 | rx_config->coalescing_timeo = bnad->rx_coalescing_timeo; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1828 | |
| 1829 | if (bnad->num_rxp_per_rx > 1) { |
| 1830 | rx_config->rss_status = BNA_STATUS_T_ENABLED; |
| 1831 | rx_config->rss_config.hash_type = |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1832 | (BFI_ENET_RSS_IPV6 | |
| 1833 | BFI_ENET_RSS_IPV6_TCP | |
| 1834 | BFI_ENET_RSS_IPV4 | |
| 1835 | BFI_ENET_RSS_IPV4_TCP); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1836 | rx_config->rss_config.hash_mask = |
| 1837 | bnad->num_rxp_per_rx - 1; |
| 1838 | get_random_bytes(rx_config->rss_config.toeplitz_hash_key, |
| 1839 | sizeof(rx_config->rss_config.toeplitz_hash_key)); |
| 1840 | } else { |
| 1841 | rx_config->rss_status = BNA_STATUS_T_DISABLED; |
| 1842 | memset(&rx_config->rss_config, 0, |
| 1843 | sizeof(rx_config->rss_config)); |
| 1844 | } |
| 1845 | rx_config->rxp_type = BNA_RXP_SLR; |
| 1846 | rx_config->q_depth = bnad->rxq_depth; |
| 1847 | |
| 1848 | rx_config->small_buff_size = BFI_SMALL_RXBUF_SIZE; |
| 1849 | |
| 1850 | rx_config->vlan_strip_status = BNA_STATUS_T_ENABLED; |
| 1851 | } |
| 1852 | |
Rasesh Mody | 2be6714 | 2011-08-30 15:27:39 +0000 | [diff] [blame] | 1853 | static void |
| 1854 | bnad_rx_ctrl_init(struct bnad *bnad, u32 rx_id) |
| 1855 | { |
| 1856 | struct bnad_rx_info *rx_info = &bnad->rx_info[rx_id]; |
| 1857 | int i; |
| 1858 | |
| 1859 | for (i = 0; i < bnad->num_rxp_per_rx; i++) |
| 1860 | rx_info->rx_ctrl[i].bnad = bnad; |
| 1861 | } |
| 1862 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1863 | /* Called with mutex_lock(&bnad->conf_mutex) held */ |
| 1864 | void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1865 | bnad_cleanup_rx(struct bnad *bnad, u32 rx_id) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1866 | { |
| 1867 | struct bnad_rx_info *rx_info = &bnad->rx_info[rx_id]; |
| 1868 | struct bna_rx_config *rx_config = &bnad->rx_config[rx_id]; |
| 1869 | struct bna_res_info *res_info = &bnad->rx_res_info[rx_id].res_info[0]; |
| 1870 | unsigned long flags; |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 1871 | int to_del = 0; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1872 | |
| 1873 | if (!rx_info->rx) |
| 1874 | return; |
| 1875 | |
| 1876 | if (0 == rx_id) { |
| 1877 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 1878 | if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED && |
| 1879 | test_bit(BNAD_RF_DIM_TIMER_RUNNING, &bnad->run_flags)) { |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1880 | clear_bit(BNAD_RF_DIM_TIMER_RUNNING, &bnad->run_flags); |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 1881 | to_del = 1; |
| 1882 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1883 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 1884 | if (to_del) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1885 | del_timer_sync(&bnad->dim_timer); |
| 1886 | } |
| 1887 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1888 | init_completion(&bnad->bnad_completions.rx_comp); |
| 1889 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 1890 | bna_rx_disable(rx_info->rx, BNA_HARD_CLEANUP, bnad_cb_rx_disabled); |
| 1891 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 1892 | wait_for_completion(&bnad->bnad_completions.rx_comp); |
| 1893 | |
| 1894 | if (rx_info->rx_ctrl[0].ccb->intr_type == BNA_INTR_T_MSIX) |
| 1895 | bnad_rx_msix_unregister(bnad, rx_info, rx_config->num_paths); |
| 1896 | |
Rasesh Mody | 2be6714 | 2011-08-30 15:27:39 +0000 | [diff] [blame] | 1897 | bnad_napi_disable(bnad, rx_id); |
| 1898 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1899 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 1900 | bna_rx_destroy(rx_info->rx); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1901 | |
| 1902 | rx_info->rx = NULL; |
Rasesh Mody | 3caa1e95 | 2011-08-30 15:27:42 +0000 | [diff] [blame] | 1903 | rx_info->rx_id = 0; |
Rasesh Mody | b9fa1fb | 2011-09-16 15:06:48 +0000 | [diff] [blame] | 1904 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1905 | |
| 1906 | bnad_rx_res_free(bnad, res_info); |
| 1907 | } |
| 1908 | |
| 1909 | /* Called with mutex_lock(&bnad->conf_mutex) held */ |
| 1910 | int |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1911 | bnad_setup_rx(struct bnad *bnad, u32 rx_id) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1912 | { |
| 1913 | int err; |
| 1914 | struct bnad_rx_info *rx_info = &bnad->rx_info[rx_id]; |
| 1915 | struct bna_res_info *res_info = &bnad->rx_res_info[rx_id].res_info[0]; |
| 1916 | struct bna_intr_info *intr_info = |
| 1917 | &res_info[BNA_RX_RES_T_INTR].res_u.intr_info; |
| 1918 | struct bna_rx_config *rx_config = &bnad->rx_config[rx_id]; |
stephen hemminger | d91d25d | 2011-09-16 11:09:51 +0000 | [diff] [blame] | 1919 | static const struct bna_rx_event_cbfn rx_cbfn = { |
| 1920 | .rcb_setup_cbfn = bnad_cb_rcb_setup, |
| 1921 | .rcb_destroy_cbfn = bnad_cb_rcb_destroy, |
| 1922 | .ccb_setup_cbfn = bnad_cb_ccb_setup, |
| 1923 | .ccb_destroy_cbfn = bnad_cb_ccb_destroy, |
Rasesh Mody | 5bcf6ac | 2011-09-27 10:39:10 +0000 | [diff] [blame] | 1924 | .rx_stall_cbfn = bnad_cb_rx_stall, |
stephen hemminger | d91d25d | 2011-09-16 11:09:51 +0000 | [diff] [blame] | 1925 | .rx_cleanup_cbfn = bnad_cb_rx_cleanup, |
| 1926 | .rx_post_cbfn = bnad_cb_rx_post, |
| 1927 | }; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1928 | struct bna_rx *rx; |
| 1929 | unsigned long flags; |
| 1930 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 1931 | rx_info->rx_id = rx_id; |
| 1932 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1933 | /* Initialize the Rx object configuration */ |
| 1934 | bnad_init_rx_config(bnad, rx_config); |
| 1935 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1936 | /* Get BNA's resource requirement for one Rx object */ |
| 1937 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 1938 | bna_rx_res_req(rx_config, res_info); |
| 1939 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 1940 | |
| 1941 | /* Fill Unmap Q memory requirements */ |
| 1942 | BNAD_FILL_UNMAPQ_MEM_REQ( |
| 1943 | &res_info[BNA_RX_RES_MEM_T_UNMAPQ], |
| 1944 | rx_config->num_paths + |
| 1945 | ((rx_config->rxp_type == BNA_RXP_SINGLE) ? 0 : |
| 1946 | rx_config->num_paths), BNAD_RX_UNMAPQ_DEPTH); |
| 1947 | |
| 1948 | /* Allocate resource */ |
| 1949 | err = bnad_rx_res_alloc(bnad, res_info, rx_id); |
| 1950 | if (err) |
| 1951 | return err; |
| 1952 | |
Rasesh Mody | 2be6714 | 2011-08-30 15:27:39 +0000 | [diff] [blame] | 1953 | bnad_rx_ctrl_init(bnad, rx_id); |
| 1954 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1955 | /* Ask BNA to create one Rx object, supplying required resources */ |
| 1956 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 1957 | rx = bna_rx_create(&bnad->bna, bnad, rx_config, &rx_cbfn, res_info, |
| 1958 | rx_info); |
Rasesh Mody | 3caa1e95 | 2011-08-30 15:27:42 +0000 | [diff] [blame] | 1959 | if (!rx) { |
| 1960 | err = -ENOMEM; |
Rasesh Mody | b9fa1fb | 2011-09-16 15:06:48 +0000 | [diff] [blame] | 1961 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1962 | goto err_return; |
Rasesh Mody | 3caa1e95 | 2011-08-30 15:27:42 +0000 | [diff] [blame] | 1963 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1964 | rx_info->rx = rx; |
Rasesh Mody | b9fa1fb | 2011-09-16 15:06:48 +0000 | [diff] [blame] | 1965 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1966 | |
Rasesh Mody | 2be6714 | 2011-08-30 15:27:39 +0000 | [diff] [blame] | 1967 | /* |
| 1968 | * Init NAPI, so that state is set to NAPI_STATE_SCHED, |
| 1969 | * so that IRQ handler cannot schedule NAPI at this point. |
| 1970 | */ |
| 1971 | bnad_napi_init(bnad, rx_id); |
| 1972 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1973 | /* Register ISR for the Rx object */ |
| 1974 | if (intr_info->intr_type == BNA_INTR_T_MSIX) { |
| 1975 | err = bnad_rx_msix_register(bnad, rx_info, rx_id, |
| 1976 | rx_config->num_paths); |
| 1977 | if (err) |
| 1978 | goto err_return; |
| 1979 | } |
| 1980 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 1981 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 1982 | if (0 == rx_id) { |
| 1983 | /* Set up Dynamic Interrupt Moderation Vector */ |
| 1984 | if (bnad->cfg_flags & BNAD_CF_DIM_ENABLED) |
| 1985 | bna_rx_dim_reconfig(&bnad->bna, bna_napi_dim_vector); |
| 1986 | |
| 1987 | /* Enable VLAN filtering only on the default Rx */ |
| 1988 | bna_rx_vlanfilter_enable(rx); |
| 1989 | |
| 1990 | /* Start the DIM timer */ |
| 1991 | bnad_dim_timer_start(bnad); |
| 1992 | } |
| 1993 | |
| 1994 | bna_rx_enable(rx); |
| 1995 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 1996 | |
Rasesh Mody | 2be6714 | 2011-08-30 15:27:39 +0000 | [diff] [blame] | 1997 | /* Enable scheduling of NAPI */ |
| 1998 | bnad_napi_enable(bnad, rx_id); |
| 1999 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2000 | return 0; |
| 2001 | |
| 2002 | err_return: |
| 2003 | bnad_cleanup_rx(bnad, rx_id); |
| 2004 | return err; |
| 2005 | } |
| 2006 | |
| 2007 | /* Called with conf_lock & bnad->bna_lock held */ |
| 2008 | void |
| 2009 | bnad_tx_coalescing_timeo_set(struct bnad *bnad) |
| 2010 | { |
| 2011 | struct bnad_tx_info *tx_info; |
| 2012 | |
| 2013 | tx_info = &bnad->tx_info[0]; |
| 2014 | if (!tx_info->tx) |
| 2015 | return; |
| 2016 | |
| 2017 | bna_tx_coalescing_timeo_set(tx_info->tx, bnad->tx_coalescing_timeo); |
| 2018 | } |
| 2019 | |
| 2020 | /* Called with conf_lock & bnad->bna_lock held */ |
| 2021 | void |
| 2022 | bnad_rx_coalescing_timeo_set(struct bnad *bnad) |
| 2023 | { |
| 2024 | struct bnad_rx_info *rx_info; |
Rasesh Mody | 0120b99 | 2011-07-22 08:07:41 +0000 | [diff] [blame] | 2025 | int i; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2026 | |
| 2027 | for (i = 0; i < bnad->num_rx; i++) { |
| 2028 | rx_info = &bnad->rx_info[i]; |
| 2029 | if (!rx_info->rx) |
| 2030 | continue; |
| 2031 | bna_rx_coalescing_timeo_set(rx_info->rx, |
| 2032 | bnad->rx_coalescing_timeo); |
| 2033 | } |
| 2034 | } |
| 2035 | |
| 2036 | /* |
| 2037 | * Called with bnad->bna_lock held |
| 2038 | */ |
Rasesh Mody | a2122d9 | 2011-08-30 15:27:43 +0000 | [diff] [blame] | 2039 | int |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2040 | bnad_mac_addr_set_locked(struct bnad *bnad, u8 *mac_addr) |
| 2041 | { |
| 2042 | int ret; |
| 2043 | |
| 2044 | if (!is_valid_ether_addr(mac_addr)) |
| 2045 | return -EADDRNOTAVAIL; |
| 2046 | |
| 2047 | /* If datapath is down, pretend everything went through */ |
| 2048 | if (!bnad->rx_info[0].rx) |
| 2049 | return 0; |
| 2050 | |
| 2051 | ret = bna_rx_ucast_set(bnad->rx_info[0].rx, mac_addr, NULL); |
| 2052 | if (ret != BNA_CB_SUCCESS) |
| 2053 | return -EADDRNOTAVAIL; |
| 2054 | |
| 2055 | return 0; |
| 2056 | } |
| 2057 | |
| 2058 | /* Should be called with conf_lock held */ |
Rasesh Mody | a2122d9 | 2011-08-30 15:27:43 +0000 | [diff] [blame] | 2059 | int |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2060 | bnad_enable_default_bcast(struct bnad *bnad) |
| 2061 | { |
| 2062 | struct bnad_rx_info *rx_info = &bnad->rx_info[0]; |
| 2063 | int ret; |
| 2064 | unsigned long flags; |
| 2065 | |
| 2066 | init_completion(&bnad->bnad_completions.mcast_comp); |
| 2067 | |
| 2068 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 2069 | ret = bna_rx_mcast_add(rx_info->rx, (u8 *)bnad_bcast_addr, |
| 2070 | bnad_cb_rx_mcast_add); |
| 2071 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2072 | |
| 2073 | if (ret == BNA_CB_SUCCESS) |
| 2074 | wait_for_completion(&bnad->bnad_completions.mcast_comp); |
| 2075 | else |
| 2076 | return -ENODEV; |
| 2077 | |
| 2078 | if (bnad->bnad_completions.mcast_comp_status != BNA_CB_SUCCESS) |
| 2079 | return -ENODEV; |
| 2080 | |
| 2081 | return 0; |
| 2082 | } |
| 2083 | |
Rasesh Mody | 19dbff9 | 2011-08-30 15:27:41 +0000 | [diff] [blame] | 2084 | /* Called with mutex_lock(&bnad->conf_mutex) held */ |
Rasesh Mody | a2122d9 | 2011-08-30 15:27:43 +0000 | [diff] [blame] | 2085 | void |
Rasesh Mody | aad75b6 | 2010-12-23 21:45:08 +0000 | [diff] [blame] | 2086 | bnad_restore_vlans(struct bnad *bnad, u32 rx_id) |
| 2087 | { |
Jiri Pirko | f859d7c | 2011-07-20 04:54:14 +0000 | [diff] [blame] | 2088 | u16 vid; |
Rasesh Mody | aad75b6 | 2010-12-23 21:45:08 +0000 | [diff] [blame] | 2089 | unsigned long flags; |
| 2090 | |
Jiri Pirko | f859d7c | 2011-07-20 04:54:14 +0000 | [diff] [blame] | 2091 | for_each_set_bit(vid, bnad->active_vlans, VLAN_N_VID) { |
Rasesh Mody | aad75b6 | 2010-12-23 21:45:08 +0000 | [diff] [blame] | 2092 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Jiri Pirko | f859d7c | 2011-07-20 04:54:14 +0000 | [diff] [blame] | 2093 | bna_rx_vlan_add(bnad->rx_info[rx_id].rx, vid); |
Rasesh Mody | aad75b6 | 2010-12-23 21:45:08 +0000 | [diff] [blame] | 2094 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2095 | } |
| 2096 | } |
| 2097 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2098 | /* Statistics utilities */ |
| 2099 | void |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2100 | bnad_netdev_qstats_fill(struct bnad *bnad, struct rtnl_link_stats64 *stats) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2101 | { |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2102 | int i, j; |
| 2103 | |
| 2104 | for (i = 0; i < bnad->num_rx; i++) { |
| 2105 | for (j = 0; j < bnad->num_rxp_per_rx; j++) { |
| 2106 | if (bnad->rx_info[i].rx_ctrl[j].ccb) { |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2107 | stats->rx_packets += bnad->rx_info[i]. |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2108 | rx_ctrl[j].ccb->rcb[0]->rxq->rx_packets; |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2109 | stats->rx_bytes += bnad->rx_info[i]. |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2110 | rx_ctrl[j].ccb->rcb[0]->rxq->rx_bytes; |
| 2111 | if (bnad->rx_info[i].rx_ctrl[j].ccb->rcb[1] && |
| 2112 | bnad->rx_info[i].rx_ctrl[j].ccb-> |
| 2113 | rcb[1]->rxq) { |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2114 | stats->rx_packets += |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2115 | bnad->rx_info[i].rx_ctrl[j]. |
| 2116 | ccb->rcb[1]->rxq->rx_packets; |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2117 | stats->rx_bytes += |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2118 | bnad->rx_info[i].rx_ctrl[j]. |
| 2119 | ccb->rcb[1]->rxq->rx_bytes; |
| 2120 | } |
| 2121 | } |
| 2122 | } |
| 2123 | } |
| 2124 | for (i = 0; i < bnad->num_tx; i++) { |
| 2125 | for (j = 0; j < bnad->num_txq_per_tx; j++) { |
| 2126 | if (bnad->tx_info[i].tcb[j]) { |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2127 | stats->tx_packets += |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2128 | bnad->tx_info[i].tcb[j]->txq->tx_packets; |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2129 | stats->tx_bytes += |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2130 | bnad->tx_info[i].tcb[j]->txq->tx_bytes; |
| 2131 | } |
| 2132 | } |
| 2133 | } |
| 2134 | } |
| 2135 | |
| 2136 | /* |
| 2137 | * Must be called with the bna_lock held. |
| 2138 | */ |
| 2139 | void |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2140 | bnad_netdev_hwstats_fill(struct bnad *bnad, struct rtnl_link_stats64 *stats) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2141 | { |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2142 | struct bfi_enet_stats_mac *mac_stats; |
| 2143 | u32 bmap; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2144 | int i; |
| 2145 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2146 | mac_stats = &bnad->stats.bna_stats->hw_stats.mac_stats; |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2147 | stats->rx_errors = |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2148 | mac_stats->rx_fcs_error + mac_stats->rx_alignment_error + |
| 2149 | mac_stats->rx_frame_length_error + mac_stats->rx_code_error + |
| 2150 | mac_stats->rx_undersize; |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2151 | stats->tx_errors = mac_stats->tx_fcs_error + |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2152 | mac_stats->tx_undersize; |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2153 | stats->rx_dropped = mac_stats->rx_drop; |
| 2154 | stats->tx_dropped = mac_stats->tx_drop; |
| 2155 | stats->multicast = mac_stats->rx_multicast; |
| 2156 | stats->collisions = mac_stats->tx_total_collision; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2157 | |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2158 | stats->rx_length_errors = mac_stats->rx_frame_length_error; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2159 | |
| 2160 | /* receive ring buffer overflow ?? */ |
| 2161 | |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2162 | stats->rx_crc_errors = mac_stats->rx_fcs_error; |
| 2163 | stats->rx_frame_errors = mac_stats->rx_alignment_error; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2164 | /* recv'r fifo overrun */ |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2165 | bmap = bna_rx_rid_mask(&bnad->bna); |
| 2166 | for (i = 0; bmap; i++) { |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2167 | if (bmap & 1) { |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2168 | stats->rx_fifo_errors += |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2169 | bnad->stats.bna_stats-> |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2170 | hw_stats.rxf_stats[i].frame_drops; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2171 | break; |
| 2172 | } |
| 2173 | bmap >>= 1; |
| 2174 | } |
| 2175 | } |
| 2176 | |
| 2177 | static void |
| 2178 | bnad_mbox_irq_sync(struct bnad *bnad) |
| 2179 | { |
| 2180 | u32 irq; |
| 2181 | unsigned long flags; |
| 2182 | |
| 2183 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 2184 | if (bnad->cfg_flags & BNAD_CF_MSIX) |
Rasesh Mody | 8811e26 | 2011-07-22 08:07:44 +0000 | [diff] [blame] | 2185 | irq = bnad->msix_table[BNAD_MAILBOX_MSIX_INDEX].vector; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2186 | else |
| 2187 | irq = bnad->pcidev->irq; |
| 2188 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2189 | |
| 2190 | synchronize_irq(irq); |
| 2191 | } |
| 2192 | |
| 2193 | /* Utility used by bnad_start_xmit, for doing TSO */ |
| 2194 | static int |
| 2195 | bnad_tso_prepare(struct bnad *bnad, struct sk_buff *skb) |
| 2196 | { |
| 2197 | int err; |
| 2198 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2199 | if (skb_header_cloned(skb)) { |
| 2200 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 2201 | if (err) { |
| 2202 | BNAD_UPDATE_CTR(bnad, tso_err); |
| 2203 | return err; |
| 2204 | } |
| 2205 | } |
| 2206 | |
| 2207 | /* |
| 2208 | * For TSO, the TCP checksum field is seeded with pseudo-header sum |
| 2209 | * excluding the length field. |
| 2210 | */ |
| 2211 | if (skb->protocol == htons(ETH_P_IP)) { |
| 2212 | struct iphdr *iph = ip_hdr(skb); |
| 2213 | |
| 2214 | /* Do we really need these? */ |
| 2215 | iph->tot_len = 0; |
| 2216 | iph->check = 0; |
| 2217 | |
| 2218 | tcp_hdr(skb)->check = |
| 2219 | ~csum_tcpudp_magic(iph->saddr, iph->daddr, 0, |
| 2220 | IPPROTO_TCP, 0); |
| 2221 | BNAD_UPDATE_CTR(bnad, tso4); |
| 2222 | } else { |
| 2223 | struct ipv6hdr *ipv6h = ipv6_hdr(skb); |
| 2224 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2225 | ipv6h->payload_len = 0; |
| 2226 | tcp_hdr(skb)->check = |
| 2227 | ~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr, 0, |
| 2228 | IPPROTO_TCP, 0); |
| 2229 | BNAD_UPDATE_CTR(bnad, tso6); |
| 2230 | } |
| 2231 | |
| 2232 | return 0; |
| 2233 | } |
| 2234 | |
| 2235 | /* |
| 2236 | * Initialize Q numbers depending on Rx Paths |
| 2237 | * Called with bnad->bna_lock held, because of cfg_flags |
| 2238 | * access. |
| 2239 | */ |
| 2240 | static void |
| 2241 | bnad_q_num_init(struct bnad *bnad) |
| 2242 | { |
| 2243 | int rxps; |
| 2244 | |
| 2245 | rxps = min((uint)num_online_cpus(), |
Rasesh Mody | 772b523 | 2011-08-30 15:27:37 +0000 | [diff] [blame] | 2246 | (uint)(BNAD_MAX_RX * BNAD_MAX_RXP_PER_RX)); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2247 | |
| 2248 | if (!(bnad->cfg_flags & BNAD_CF_MSIX)) |
| 2249 | rxps = 1; /* INTx */ |
| 2250 | |
| 2251 | bnad->num_rx = 1; |
| 2252 | bnad->num_tx = 1; |
| 2253 | bnad->num_rxp_per_rx = rxps; |
| 2254 | bnad->num_txq_per_tx = BNAD_TXQ_NUM; |
| 2255 | } |
| 2256 | |
| 2257 | /* |
| 2258 | * Adjusts the Q numbers, given a number of msix vectors |
| 2259 | * Give preference to RSS as opposed to Tx priority Queues, |
| 2260 | * in such a case, just use 1 Tx Q |
| 2261 | * Called with bnad->bna_lock held b'cos of cfg_flags access |
| 2262 | */ |
| 2263 | static void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2264 | bnad_q_num_adjust(struct bnad *bnad, int msix_vectors, int temp) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2265 | { |
| 2266 | bnad->num_txq_per_tx = 1; |
| 2267 | if ((msix_vectors >= (bnad->num_tx * bnad->num_txq_per_tx) + |
| 2268 | bnad_rxqs_per_cq + BNAD_MAILBOX_MSIX_VECTORS) && |
| 2269 | (bnad->cfg_flags & BNAD_CF_MSIX)) { |
| 2270 | bnad->num_rxp_per_rx = msix_vectors - |
| 2271 | (bnad->num_tx * bnad->num_txq_per_tx) - |
| 2272 | BNAD_MAILBOX_MSIX_VECTORS; |
| 2273 | } else |
| 2274 | bnad->num_rxp_per_rx = 1; |
| 2275 | } |
| 2276 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2277 | /* Enable / disable ioceth */ |
| 2278 | static int |
| 2279 | bnad_ioceth_disable(struct bnad *bnad) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2280 | { |
| 2281 | unsigned long flags; |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2282 | int err = 0; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2283 | |
| 2284 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2285 | init_completion(&bnad->bnad_completions.ioc_comp); |
| 2286 | bna_ioceth_disable(&bnad->bna.ioceth, BNA_HARD_CLEANUP); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2287 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2288 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2289 | wait_for_completion_timeout(&bnad->bnad_completions.ioc_comp, |
| 2290 | msecs_to_jiffies(BNAD_IOCETH_TIMEOUT)); |
| 2291 | |
| 2292 | err = bnad->bnad_completions.ioc_comp_status; |
| 2293 | return err; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | static int |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2297 | bnad_ioceth_enable(struct bnad *bnad) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2298 | { |
| 2299 | int err = 0; |
| 2300 | unsigned long flags; |
| 2301 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2302 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2303 | init_completion(&bnad->bnad_completions.ioc_comp); |
| 2304 | bnad->bnad_completions.ioc_comp_status = BNA_CB_WAITING; |
| 2305 | bna_ioceth_enable(&bnad->bna.ioceth); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2306 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2307 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2308 | wait_for_completion_timeout(&bnad->bnad_completions.ioc_comp, |
| 2309 | msecs_to_jiffies(BNAD_IOCETH_TIMEOUT)); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2310 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2311 | err = bnad->bnad_completions.ioc_comp_status; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2312 | |
| 2313 | return err; |
| 2314 | } |
| 2315 | |
| 2316 | /* Free BNA resources */ |
| 2317 | static void |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2318 | bnad_res_free(struct bnad *bnad, struct bna_res_info *res_info, |
| 2319 | u32 res_val_max) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2320 | { |
| 2321 | int i; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2322 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2323 | for (i = 0; i < res_val_max; i++) |
| 2324 | bnad_mem_free(bnad, &res_info[i].res_u.mem_info); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2325 | } |
| 2326 | |
| 2327 | /* Allocates memory and interrupt resources for BNA */ |
| 2328 | static int |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2329 | bnad_res_alloc(struct bnad *bnad, struct bna_res_info *res_info, |
| 2330 | u32 res_val_max) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2331 | { |
| 2332 | int i, err; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2333 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2334 | for (i = 0; i < res_val_max; i++) { |
| 2335 | err = bnad_mem_alloc(bnad, &res_info[i].res_u.mem_info); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2336 | if (err) |
| 2337 | goto err_return; |
| 2338 | } |
| 2339 | return 0; |
| 2340 | |
| 2341 | err_return: |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2342 | bnad_res_free(bnad, res_info, res_val_max); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2343 | return err; |
| 2344 | } |
| 2345 | |
| 2346 | /* Interrupt enable / disable */ |
| 2347 | static void |
| 2348 | bnad_enable_msix(struct bnad *bnad) |
| 2349 | { |
| 2350 | int i, ret; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2351 | unsigned long flags; |
| 2352 | |
| 2353 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 2354 | if (!(bnad->cfg_flags & BNAD_CF_MSIX)) { |
| 2355 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2356 | return; |
| 2357 | } |
| 2358 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2359 | |
| 2360 | if (bnad->msix_table) |
| 2361 | return; |
| 2362 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2363 | bnad->msix_table = |
Rasesh Mody | b7ee31c5 | 2010-10-05 15:46:05 +0000 | [diff] [blame] | 2364 | kcalloc(bnad->msix_num, sizeof(struct msix_entry), GFP_KERNEL); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2365 | |
| 2366 | if (!bnad->msix_table) |
| 2367 | goto intx_mode; |
| 2368 | |
Rasesh Mody | b7ee31c5 | 2010-10-05 15:46:05 +0000 | [diff] [blame] | 2369 | for (i = 0; i < bnad->msix_num; i++) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2370 | bnad->msix_table[i].entry = i; |
| 2371 | |
Rasesh Mody | b7ee31c5 | 2010-10-05 15:46:05 +0000 | [diff] [blame] | 2372 | ret = pci_enable_msix(bnad->pcidev, bnad->msix_table, bnad->msix_num); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2373 | if (ret > 0) { |
| 2374 | /* Not enough MSI-X vectors. */ |
Rasesh Mody | 19dbff9 | 2011-08-30 15:27:41 +0000 | [diff] [blame] | 2375 | pr_warn("BNA: %d MSI-X vectors allocated < %d requested\n", |
| 2376 | ret, bnad->msix_num); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2377 | |
| 2378 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 2379 | /* ret = #of vectors that we got */ |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2380 | bnad_q_num_adjust(bnad, (ret - BNAD_MAILBOX_MSIX_VECTORS) / 2, |
| 2381 | (ret - BNAD_MAILBOX_MSIX_VECTORS) / 2); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2382 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2383 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2384 | bnad->msix_num = BNAD_NUM_TXQ + BNAD_NUM_RXP + |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2385 | BNAD_MAILBOX_MSIX_VECTORS; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2386 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2387 | if (bnad->msix_num > ret) |
| 2388 | goto intx_mode; |
| 2389 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2390 | /* Try once more with adjusted numbers */ |
| 2391 | /* If this fails, fall back to INTx */ |
| 2392 | ret = pci_enable_msix(bnad->pcidev, bnad->msix_table, |
Rasesh Mody | b7ee31c5 | 2010-10-05 15:46:05 +0000 | [diff] [blame] | 2393 | bnad->msix_num); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2394 | if (ret) |
| 2395 | goto intx_mode; |
| 2396 | |
| 2397 | } else if (ret < 0) |
| 2398 | goto intx_mode; |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2399 | |
| 2400 | pci_intx(bnad->pcidev, 0); |
| 2401 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2402 | return; |
| 2403 | |
| 2404 | intx_mode: |
Rasesh Mody | 19dbff9 | 2011-08-30 15:27:41 +0000 | [diff] [blame] | 2405 | pr_warn("BNA: MSI-X enable failed - operating in INTx mode\n"); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2406 | |
| 2407 | kfree(bnad->msix_table); |
| 2408 | bnad->msix_table = NULL; |
| 2409 | bnad->msix_num = 0; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2410 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 2411 | bnad->cfg_flags &= ~BNAD_CF_MSIX; |
| 2412 | bnad_q_num_init(bnad); |
| 2413 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2414 | } |
| 2415 | |
| 2416 | static void |
| 2417 | bnad_disable_msix(struct bnad *bnad) |
| 2418 | { |
| 2419 | u32 cfg_flags; |
| 2420 | unsigned long flags; |
| 2421 | |
| 2422 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 2423 | cfg_flags = bnad->cfg_flags; |
| 2424 | if (bnad->cfg_flags & BNAD_CF_MSIX) |
| 2425 | bnad->cfg_flags &= ~BNAD_CF_MSIX; |
| 2426 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2427 | |
| 2428 | if (cfg_flags & BNAD_CF_MSIX) { |
| 2429 | pci_disable_msix(bnad->pcidev); |
| 2430 | kfree(bnad->msix_table); |
| 2431 | bnad->msix_table = NULL; |
| 2432 | } |
| 2433 | } |
| 2434 | |
| 2435 | /* Netdev entry points */ |
| 2436 | static int |
| 2437 | bnad_open(struct net_device *netdev) |
| 2438 | { |
| 2439 | int err; |
| 2440 | struct bnad *bnad = netdev_priv(netdev); |
| 2441 | struct bna_pause_config pause_config; |
| 2442 | int mtu; |
| 2443 | unsigned long flags; |
| 2444 | |
| 2445 | mutex_lock(&bnad->conf_mutex); |
| 2446 | |
| 2447 | /* Tx */ |
| 2448 | err = bnad_setup_tx(bnad, 0); |
| 2449 | if (err) |
| 2450 | goto err_return; |
| 2451 | |
| 2452 | /* Rx */ |
| 2453 | err = bnad_setup_rx(bnad, 0); |
| 2454 | if (err) |
| 2455 | goto cleanup_tx; |
| 2456 | |
| 2457 | /* Port */ |
| 2458 | pause_config.tx_pause = 0; |
| 2459 | pause_config.rx_pause = 0; |
| 2460 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2461 | mtu = ETH_HLEN + VLAN_HLEN + bnad->netdev->mtu + ETH_FCS_LEN; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2462 | |
| 2463 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2464 | bna_enet_mtu_set(&bnad->bna.enet, mtu, NULL); |
| 2465 | bna_enet_pause_config(&bnad->bna.enet, &pause_config, NULL); |
| 2466 | bna_enet_enable(&bnad->bna.enet); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2467 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2468 | |
| 2469 | /* Enable broadcast */ |
| 2470 | bnad_enable_default_bcast(bnad); |
| 2471 | |
Rasesh Mody | aad75b6 | 2010-12-23 21:45:08 +0000 | [diff] [blame] | 2472 | /* Restore VLANs, if any */ |
| 2473 | bnad_restore_vlans(bnad, 0); |
| 2474 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2475 | /* Set the UCAST address */ |
| 2476 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 2477 | bnad_mac_addr_set_locked(bnad, netdev->dev_addr); |
| 2478 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2479 | |
| 2480 | /* Start the stats timer */ |
| 2481 | bnad_stats_timer_start(bnad); |
| 2482 | |
| 2483 | mutex_unlock(&bnad->conf_mutex); |
| 2484 | |
| 2485 | return 0; |
| 2486 | |
| 2487 | cleanup_tx: |
| 2488 | bnad_cleanup_tx(bnad, 0); |
| 2489 | |
| 2490 | err_return: |
| 2491 | mutex_unlock(&bnad->conf_mutex); |
| 2492 | return err; |
| 2493 | } |
| 2494 | |
| 2495 | static int |
| 2496 | bnad_stop(struct net_device *netdev) |
| 2497 | { |
| 2498 | struct bnad *bnad = netdev_priv(netdev); |
| 2499 | unsigned long flags; |
| 2500 | |
| 2501 | mutex_lock(&bnad->conf_mutex); |
| 2502 | |
| 2503 | /* Stop the stats timer */ |
| 2504 | bnad_stats_timer_stop(bnad); |
| 2505 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2506 | init_completion(&bnad->bnad_completions.enet_comp); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2507 | |
| 2508 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2509 | bna_enet_disable(&bnad->bna.enet, BNA_HARD_CLEANUP, |
| 2510 | bnad_cb_enet_disabled); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2511 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2512 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2513 | wait_for_completion(&bnad->bnad_completions.enet_comp); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2514 | |
| 2515 | bnad_cleanup_tx(bnad, 0); |
| 2516 | bnad_cleanup_rx(bnad, 0); |
| 2517 | |
| 2518 | /* Synchronize mailbox IRQ */ |
| 2519 | bnad_mbox_irq_sync(bnad); |
| 2520 | |
| 2521 | mutex_unlock(&bnad->conf_mutex); |
| 2522 | |
| 2523 | return 0; |
| 2524 | } |
| 2525 | |
| 2526 | /* TX */ |
| 2527 | /* |
| 2528 | * bnad_start_xmit : Netdev entry point for Transmit |
| 2529 | * Called under lock held by net_device |
| 2530 | */ |
| 2531 | static netdev_tx_t |
| 2532 | bnad_start_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 2533 | { |
| 2534 | struct bnad *bnad = netdev_priv(netdev); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2535 | u32 txq_id = 0; |
| 2536 | struct bna_tcb *tcb = bnad->tx_info[0].tcb[txq_id]; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2537 | |
Rasesh Mody | 0120b99 | 2011-07-22 08:07:41 +0000 | [diff] [blame] | 2538 | u16 txq_prod, vlan_tag = 0; |
| 2539 | u32 unmap_prod, wis, wis_used, wi_range; |
| 2540 | u32 vectors, vect_id, i, acked; |
Rasesh Mody | 0120b99 | 2011-07-22 08:07:41 +0000 | [diff] [blame] | 2541 | int err; |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2542 | unsigned int len; |
| 2543 | u32 gso_size; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2544 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2545 | struct bnad_unmap_q *unmap_q = tcb->unmap_q; |
Rasesh Mody | 0120b99 | 2011-07-22 08:07:41 +0000 | [diff] [blame] | 2546 | dma_addr_t dma_addr; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2547 | struct bna_txq_entry *txqent; |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2548 | u16 flags; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2549 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2550 | if (unlikely(skb->len <= ETH_HLEN)) { |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2551 | dev_kfree_skb(skb); |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2552 | BNAD_UPDATE_CTR(bnad, tx_skb_too_short); |
| 2553 | return NETDEV_TX_OK; |
| 2554 | } |
| 2555 | if (unlikely(skb_headlen(skb) > BFI_TX_MAX_DATA_PER_VECTOR)) { |
| 2556 | dev_kfree_skb(skb); |
| 2557 | BNAD_UPDATE_CTR(bnad, tx_skb_headlen_too_long); |
| 2558 | return NETDEV_TX_OK; |
| 2559 | } |
| 2560 | if (unlikely(skb_headlen(skb) == 0)) { |
| 2561 | dev_kfree_skb(skb); |
| 2562 | BNAD_UPDATE_CTR(bnad, tx_skb_headlen_zero); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2563 | return NETDEV_TX_OK; |
| 2564 | } |
| 2565 | |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 2566 | /* |
| 2567 | * Takes care of the Tx that is scheduled between clearing the flag |
Rasesh Mody | 19dbff9 | 2011-08-30 15:27:41 +0000 | [diff] [blame] | 2568 | * and the netif_tx_stop_all_queues() call. |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 2569 | */ |
| 2570 | if (unlikely(!test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags))) { |
| 2571 | dev_kfree_skb(skb); |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2572 | BNAD_UPDATE_CTR(bnad, tx_skb_stopping); |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 2573 | return NETDEV_TX_OK; |
| 2574 | } |
| 2575 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2576 | vectors = 1 + skb_shinfo(skb)->nr_frags; |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2577 | if (unlikely(vectors > BFI_TX_MAX_VECTORS_PER_PKT)) { |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2578 | dev_kfree_skb(skb); |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2579 | BNAD_UPDATE_CTR(bnad, tx_skb_max_vectors); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2580 | return NETDEV_TX_OK; |
| 2581 | } |
| 2582 | wis = BNA_TXQ_WI_NEEDED(vectors); /* 4 vectors per work item */ |
| 2583 | acked = 0; |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2584 | if (unlikely(wis > BNA_QE_FREE_CNT(tcb, tcb->q_depth) || |
| 2585 | vectors > BNA_QE_FREE_CNT(unmap_q, unmap_q->q_depth))) { |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2586 | if ((u16) (*tcb->hw_consumer_index) != |
| 2587 | tcb->consumer_index && |
| 2588 | !test_and_set_bit(BNAD_TXQ_FREE_SENT, &tcb->flags)) { |
| 2589 | acked = bnad_free_txbufs(bnad, tcb); |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 2590 | if (likely(test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags))) |
| 2591 | bna_ib_ack(tcb->i_dbell, acked); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2592 | smp_mb__before_clear_bit(); |
| 2593 | clear_bit(BNAD_TXQ_FREE_SENT, &tcb->flags); |
| 2594 | } else { |
| 2595 | netif_stop_queue(netdev); |
| 2596 | BNAD_UPDATE_CTR(bnad, netif_queue_stop); |
| 2597 | } |
| 2598 | |
| 2599 | smp_mb(); |
| 2600 | /* |
| 2601 | * Check again to deal with race condition between |
| 2602 | * netif_stop_queue here, and netif_wake_queue in |
| 2603 | * interrupt handler which is not inside netif tx lock. |
| 2604 | */ |
| 2605 | if (likely |
| 2606 | (wis > BNA_QE_FREE_CNT(tcb, tcb->q_depth) || |
| 2607 | vectors > BNA_QE_FREE_CNT(unmap_q, unmap_q->q_depth))) { |
| 2608 | BNAD_UPDATE_CTR(bnad, netif_queue_stop); |
| 2609 | return NETDEV_TX_BUSY; |
| 2610 | } else { |
| 2611 | netif_wake_queue(netdev); |
| 2612 | BNAD_UPDATE_CTR(bnad, netif_queue_wakeup); |
| 2613 | } |
| 2614 | } |
| 2615 | |
| 2616 | unmap_prod = unmap_q->producer_index; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2617 | flags = 0; |
| 2618 | |
| 2619 | txq_prod = tcb->producer_index; |
| 2620 | BNA_TXQ_QPGE_PTR_GET(txq_prod, tcb->sw_qpt, txqent, wi_range); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2621 | txqent->hdr.wi.reserved = 0; |
| 2622 | txqent->hdr.wi.num_vectors = vectors; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2623 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 2624 | if (vlan_tx_tag_present(skb)) { |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2625 | vlan_tag = (u16) vlan_tx_tag_get(skb); |
| 2626 | flags |= (BNA_TXQ_WI_CF_INS_PRIO | BNA_TXQ_WI_CF_INS_VLAN); |
| 2627 | } |
| 2628 | if (test_bit(BNAD_RF_CEE_RUNNING, &bnad->run_flags)) { |
| 2629 | vlan_tag = |
| 2630 | (tcb->priority & 0x7) << 13 | (vlan_tag & 0x1fff); |
| 2631 | flags |= (BNA_TXQ_WI_CF_INS_PRIO | BNA_TXQ_WI_CF_INS_VLAN); |
| 2632 | } |
| 2633 | |
| 2634 | txqent->hdr.wi.vlan_tag = htons(vlan_tag); |
| 2635 | |
| 2636 | if (skb_is_gso(skb)) { |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2637 | gso_size = skb_shinfo(skb)->gso_size; |
| 2638 | |
| 2639 | if (unlikely(gso_size > netdev->mtu)) { |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2640 | dev_kfree_skb(skb); |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2641 | BNAD_UPDATE_CTR(bnad, tx_skb_mss_too_long); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2642 | return NETDEV_TX_OK; |
| 2643 | } |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2644 | if (unlikely((gso_size + skb_transport_offset(skb) + |
| 2645 | tcp_hdrlen(skb)) >= skb->len)) { |
| 2646 | txqent->hdr.wi.opcode = |
| 2647 | __constant_htons(BNA_TXQ_WI_SEND); |
| 2648 | txqent->hdr.wi.lso_mss = 0; |
| 2649 | BNAD_UPDATE_CTR(bnad, tx_skb_tso_too_short); |
| 2650 | } else { |
| 2651 | txqent->hdr.wi.opcode = |
| 2652 | __constant_htons(BNA_TXQ_WI_SEND_LSO); |
| 2653 | txqent->hdr.wi.lso_mss = htons(gso_size); |
| 2654 | } |
| 2655 | |
| 2656 | err = bnad_tso_prepare(bnad, skb); |
| 2657 | if (unlikely(err)) { |
| 2658 | dev_kfree_skb(skb); |
| 2659 | BNAD_UPDATE_CTR(bnad, tx_skb_tso_prepare); |
| 2660 | return NETDEV_TX_OK; |
| 2661 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2662 | flags |= (BNA_TXQ_WI_CF_IP_CKSUM | BNA_TXQ_WI_CF_TCP_CKSUM); |
| 2663 | txqent->hdr.wi.l4_hdr_size_n_offset = |
| 2664 | htons(BNA_TXQ_WI_L4_HDR_N_OFFSET |
| 2665 | (tcp_hdrlen(skb) >> 2, |
| 2666 | skb_transport_offset(skb))); |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2667 | } else { |
| 2668 | txqent->hdr.wi.opcode = __constant_htons(BNA_TXQ_WI_SEND); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2669 | txqent->hdr.wi.lso_mss = 0; |
| 2670 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2671 | if (unlikely(skb->len > (netdev->mtu + ETH_HLEN))) { |
| 2672 | dev_kfree_skb(skb); |
| 2673 | BNAD_UPDATE_CTR(bnad, tx_skb_non_tso_too_long); |
| 2674 | return NETDEV_TX_OK; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2675 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2676 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2677 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 2678 | u8 proto = 0; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2679 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2680 | if (skb->protocol == __constant_htons(ETH_P_IP)) |
| 2681 | proto = ip_hdr(skb)->protocol; |
| 2682 | else if (skb->protocol == |
| 2683 | __constant_htons(ETH_P_IPV6)) { |
| 2684 | /* nexthdr may not be TCP immediately. */ |
| 2685 | proto = ipv6_hdr(skb)->nexthdr; |
| 2686 | } |
| 2687 | if (proto == IPPROTO_TCP) { |
| 2688 | flags |= BNA_TXQ_WI_CF_TCP_CKSUM; |
| 2689 | txqent->hdr.wi.l4_hdr_size_n_offset = |
| 2690 | htons(BNA_TXQ_WI_L4_HDR_N_OFFSET |
| 2691 | (0, skb_transport_offset(skb))); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2692 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2693 | BNAD_UPDATE_CTR(bnad, tcpcsum_offload); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2694 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2695 | if (unlikely(skb_headlen(skb) < |
| 2696 | skb_transport_offset(skb) + tcp_hdrlen(skb))) { |
| 2697 | dev_kfree_skb(skb); |
| 2698 | BNAD_UPDATE_CTR(bnad, tx_skb_tcp_hdr); |
| 2699 | return NETDEV_TX_OK; |
| 2700 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2701 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2702 | } else if (proto == IPPROTO_UDP) { |
| 2703 | flags |= BNA_TXQ_WI_CF_UDP_CKSUM; |
| 2704 | txqent->hdr.wi.l4_hdr_size_n_offset = |
| 2705 | htons(BNA_TXQ_WI_L4_HDR_N_OFFSET |
| 2706 | (0, skb_transport_offset(skb))); |
| 2707 | |
| 2708 | BNAD_UPDATE_CTR(bnad, udpcsum_offload); |
| 2709 | if (unlikely(skb_headlen(skb) < |
| 2710 | skb_transport_offset(skb) + |
| 2711 | sizeof(struct udphdr))) { |
| 2712 | dev_kfree_skb(skb); |
| 2713 | BNAD_UPDATE_CTR(bnad, tx_skb_udp_hdr); |
| 2714 | return NETDEV_TX_OK; |
| 2715 | } |
| 2716 | } else { |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2717 | dev_kfree_skb(skb); |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2718 | BNAD_UPDATE_CTR(bnad, tx_skb_csum_err); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2719 | return NETDEV_TX_OK; |
| 2720 | } |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2721 | } else { |
| 2722 | txqent->hdr.wi.l4_hdr_size_n_offset = 0; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2723 | } |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2724 | } |
| 2725 | |
| 2726 | txqent->hdr.wi.flags = htons(flags); |
| 2727 | |
| 2728 | txqent->hdr.wi.frame_length = htonl(skb->len); |
| 2729 | |
| 2730 | unmap_q->unmap_array[unmap_prod].skb = skb; |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2731 | len = skb_headlen(skb); |
| 2732 | txqent->vector[0].length = htons(len); |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 2733 | dma_addr = dma_map_single(&bnad->pcidev->dev, skb->data, |
| 2734 | skb_headlen(skb), DMA_TO_DEVICE); |
| 2735 | dma_unmap_addr_set(&unmap_q->unmap_array[unmap_prod], dma_addr, |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2736 | dma_addr); |
| 2737 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2738 | BNA_SET_DMA_ADDR(dma_addr, &txqent->vector[0].host_addr); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2739 | BNA_QE_INDX_ADD(unmap_prod, 1, unmap_q->q_depth); |
| 2740 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2741 | vect_id = 0; |
| 2742 | wis_used = 1; |
| 2743 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2744 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2745 | const struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i]; |
| 2746 | u16 size = skb_frag_size(frag); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2747 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2748 | if (unlikely(size == 0)) { |
| 2749 | unmap_prod = unmap_q->producer_index; |
| 2750 | |
| 2751 | unmap_prod = bnad_pci_unmap_skb(&bnad->pcidev->dev, |
| 2752 | unmap_q->unmap_array, |
| 2753 | unmap_prod, unmap_q->q_depth, skb, |
| 2754 | i); |
| 2755 | dev_kfree_skb(skb); |
| 2756 | BNAD_UPDATE_CTR(bnad, tx_skb_frag_zero); |
| 2757 | return NETDEV_TX_OK; |
| 2758 | } |
| 2759 | |
| 2760 | len += size; |
| 2761 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2762 | if (++vect_id == BFI_TX_MAX_VECTORS_PER_WI) { |
| 2763 | vect_id = 0; |
| 2764 | if (--wi_range) |
| 2765 | txqent++; |
| 2766 | else { |
| 2767 | BNA_QE_INDX_ADD(txq_prod, wis_used, |
| 2768 | tcb->q_depth); |
| 2769 | wis_used = 0; |
| 2770 | BNA_TXQ_QPGE_PTR_GET(txq_prod, tcb->sw_qpt, |
| 2771 | txqent, wi_range); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2772 | } |
| 2773 | wis_used++; |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2774 | txqent->hdr.wi_ext.opcode = |
| 2775 | __constant_htons(BNA_TXQ_WI_EXTENSION); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2776 | } |
| 2777 | |
| 2778 | BUG_ON(!(size <= BFI_TX_MAX_DATA_PER_VECTOR)); |
| 2779 | txqent->vector[vect_id].length = htons(size); |
Ian Campbell | 4d5b1a6 | 2011-08-29 23:18:24 +0000 | [diff] [blame] | 2780 | dma_addr = skb_frag_dma_map(&bnad->pcidev->dev, frag, |
| 2781 | 0, size, DMA_TO_DEVICE); |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 2782 | dma_unmap_addr_set(&unmap_q->unmap_array[unmap_prod], dma_addr, |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2783 | dma_addr); |
| 2784 | BNA_SET_DMA_ADDR(dma_addr, &txqent->vector[vect_id].host_addr); |
| 2785 | BNA_QE_INDX_ADD(unmap_prod, 1, unmap_q->q_depth); |
| 2786 | } |
| 2787 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2788 | if (unlikely(len != skb->len)) { |
| 2789 | unmap_prod = unmap_q->producer_index; |
| 2790 | |
| 2791 | unmap_prod = bnad_pci_unmap_skb(&bnad->pcidev->dev, |
| 2792 | unmap_q->unmap_array, unmap_prod, |
| 2793 | unmap_q->q_depth, skb, |
| 2794 | skb_shinfo(skb)->nr_frags); |
| 2795 | dev_kfree_skb(skb); |
| 2796 | BNAD_UPDATE_CTR(bnad, tx_skb_len_mismatch); |
| 2797 | return NETDEV_TX_OK; |
| 2798 | } |
| 2799 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2800 | unmap_q->producer_index = unmap_prod; |
| 2801 | BNA_QE_INDX_ADD(txq_prod, wis_used, tcb->q_depth); |
| 2802 | tcb->producer_index = txq_prod; |
| 2803 | |
| 2804 | smp_mb(); |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 2805 | |
| 2806 | if (unlikely(!test_bit(BNAD_TXQ_TX_STARTED, &tcb->flags))) |
| 2807 | return NETDEV_TX_OK; |
| 2808 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2809 | bna_txq_prod_indx_doorbell(tcb); |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2810 | smp_mb(); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2811 | |
| 2812 | if ((u16) (*tcb->hw_consumer_index) != tcb->consumer_index) |
| 2813 | tasklet_schedule(&bnad->tx_free_tasklet); |
| 2814 | |
| 2815 | return NETDEV_TX_OK; |
| 2816 | } |
| 2817 | |
| 2818 | /* |
| 2819 | * Used spin_lock to synchronize reading of stats structures, which |
| 2820 | * is written by BNA under the same lock. |
| 2821 | */ |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2822 | static struct rtnl_link_stats64 * |
| 2823 | bnad_get_stats64(struct net_device *netdev, struct rtnl_link_stats64 *stats) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2824 | { |
| 2825 | struct bnad *bnad = netdev_priv(netdev); |
| 2826 | unsigned long flags; |
| 2827 | |
| 2828 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 2829 | |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2830 | bnad_netdev_qstats_fill(bnad, stats); |
| 2831 | bnad_netdev_hwstats_fill(bnad, stats); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2832 | |
| 2833 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2834 | |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 2835 | return stats; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2836 | } |
| 2837 | |
Rasesh Mody | a2122d9 | 2011-08-30 15:27:43 +0000 | [diff] [blame] | 2838 | void |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2839 | bnad_set_rx_mode(struct net_device *netdev) |
| 2840 | { |
| 2841 | struct bnad *bnad = netdev_priv(netdev); |
| 2842 | u32 new_mask, valid_mask; |
| 2843 | unsigned long flags; |
| 2844 | |
| 2845 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 2846 | |
| 2847 | new_mask = valid_mask = 0; |
| 2848 | |
| 2849 | if (netdev->flags & IFF_PROMISC) { |
| 2850 | if (!(bnad->cfg_flags & BNAD_CF_PROMISC)) { |
| 2851 | new_mask = BNAD_RXMODE_PROMISC_DEFAULT; |
| 2852 | valid_mask = BNAD_RXMODE_PROMISC_DEFAULT; |
| 2853 | bnad->cfg_flags |= BNAD_CF_PROMISC; |
| 2854 | } |
| 2855 | } else { |
| 2856 | if (bnad->cfg_flags & BNAD_CF_PROMISC) { |
| 2857 | new_mask = ~BNAD_RXMODE_PROMISC_DEFAULT; |
| 2858 | valid_mask = BNAD_RXMODE_PROMISC_DEFAULT; |
| 2859 | bnad->cfg_flags &= ~BNAD_CF_PROMISC; |
| 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | if (netdev->flags & IFF_ALLMULTI) { |
| 2864 | if (!(bnad->cfg_flags & BNAD_CF_ALLMULTI)) { |
| 2865 | new_mask |= BNA_RXMODE_ALLMULTI; |
| 2866 | valid_mask |= BNA_RXMODE_ALLMULTI; |
| 2867 | bnad->cfg_flags |= BNAD_CF_ALLMULTI; |
| 2868 | } |
| 2869 | } else { |
| 2870 | if (bnad->cfg_flags & BNAD_CF_ALLMULTI) { |
| 2871 | new_mask &= ~BNA_RXMODE_ALLMULTI; |
| 2872 | valid_mask |= BNA_RXMODE_ALLMULTI; |
| 2873 | bnad->cfg_flags &= ~BNAD_CF_ALLMULTI; |
| 2874 | } |
| 2875 | } |
| 2876 | |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 2877 | if (bnad->rx_info[0].rx == NULL) |
| 2878 | goto unlock; |
| 2879 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2880 | bna_rx_mode_set(bnad->rx_info[0].rx, new_mask, valid_mask, NULL); |
| 2881 | |
| 2882 | if (!netdev_mc_empty(netdev)) { |
| 2883 | u8 *mcaddr_list; |
| 2884 | int mc_count = netdev_mc_count(netdev); |
| 2885 | |
| 2886 | /* Index 0 holds the broadcast address */ |
| 2887 | mcaddr_list = |
| 2888 | kzalloc((mc_count + 1) * ETH_ALEN, |
| 2889 | GFP_ATOMIC); |
| 2890 | if (!mcaddr_list) |
Jiri Slaby | ca1cef3 | 2010-09-04 02:08:41 +0000 | [diff] [blame] | 2891 | goto unlock; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2892 | |
| 2893 | memcpy(&mcaddr_list[0], &bnad_bcast_addr[0], ETH_ALEN); |
| 2894 | |
| 2895 | /* Copy rest of the MC addresses */ |
| 2896 | bnad_netdev_mc_list_get(netdev, mcaddr_list); |
| 2897 | |
| 2898 | bna_rx_mcast_listset(bnad->rx_info[0].rx, mc_count + 1, |
| 2899 | mcaddr_list, NULL); |
| 2900 | |
| 2901 | /* Should we enable BNAD_CF_ALLMULTI for err != 0 ? */ |
| 2902 | kfree(mcaddr_list); |
| 2903 | } |
Jiri Slaby | ca1cef3 | 2010-09-04 02:08:41 +0000 | [diff] [blame] | 2904 | unlock: |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2905 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2906 | } |
| 2907 | |
| 2908 | /* |
| 2909 | * bna_lock is used to sync writes to netdev->addr |
| 2910 | * conf_lock cannot be used since this call may be made |
| 2911 | * in a non-blocking context. |
| 2912 | */ |
| 2913 | static int |
| 2914 | bnad_set_mac_address(struct net_device *netdev, void *mac_addr) |
| 2915 | { |
| 2916 | int err; |
| 2917 | struct bnad *bnad = netdev_priv(netdev); |
| 2918 | struct sockaddr *sa = (struct sockaddr *)mac_addr; |
| 2919 | unsigned long flags; |
| 2920 | |
| 2921 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 2922 | |
| 2923 | err = bnad_mac_addr_set_locked(bnad, sa->sa_data); |
| 2924 | |
| 2925 | if (!err) |
| 2926 | memcpy(netdev->dev_addr, sa->sa_data, netdev->addr_len); |
| 2927 | |
| 2928 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2929 | |
| 2930 | return err; |
| 2931 | } |
| 2932 | |
| 2933 | static int |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2934 | bnad_mtu_set(struct bnad *bnad, int mtu) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2935 | { |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2936 | unsigned long flags; |
| 2937 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2938 | init_completion(&bnad->bnad_completions.mtu_comp); |
| 2939 | |
| 2940 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 2941 | bna_enet_mtu_set(&bnad->bna.enet, mtu, bnad_cb_enet_mtu_set); |
| 2942 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2943 | |
| 2944 | wait_for_completion(&bnad->bnad_completions.mtu_comp); |
| 2945 | |
| 2946 | return bnad->bnad_completions.mtu_comp_status; |
| 2947 | } |
| 2948 | |
| 2949 | static int |
| 2950 | bnad_change_mtu(struct net_device *netdev, int new_mtu) |
| 2951 | { |
| 2952 | int err, mtu = netdev->mtu; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2953 | struct bnad *bnad = netdev_priv(netdev); |
| 2954 | |
| 2955 | if (new_mtu + ETH_HLEN < ETH_ZLEN || new_mtu > BNAD_JUMBO_MTU) |
| 2956 | return -EINVAL; |
| 2957 | |
| 2958 | mutex_lock(&bnad->conf_mutex); |
| 2959 | |
| 2960 | netdev->mtu = new_mtu; |
| 2961 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 2962 | mtu = ETH_HLEN + VLAN_HLEN + new_mtu + ETH_FCS_LEN; |
| 2963 | err = bnad_mtu_set(bnad, mtu); |
| 2964 | if (err) |
| 2965 | err = -EBUSY; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2966 | |
| 2967 | mutex_unlock(&bnad->conf_mutex); |
| 2968 | return err; |
| 2969 | } |
| 2970 | |
| 2971 | static void |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2972 | bnad_vlan_rx_add_vid(struct net_device *netdev, |
| 2973 | unsigned short vid) |
| 2974 | { |
| 2975 | struct bnad *bnad = netdev_priv(netdev); |
| 2976 | unsigned long flags; |
| 2977 | |
| 2978 | if (!bnad->rx_info[0].rx) |
| 2979 | return; |
| 2980 | |
| 2981 | mutex_lock(&bnad->conf_mutex); |
| 2982 | |
| 2983 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 2984 | bna_rx_vlan_add(bnad->rx_info[0].rx, vid); |
Jiri Pirko | f859d7c | 2011-07-20 04:54:14 +0000 | [diff] [blame] | 2985 | set_bit(vid, bnad->active_vlans); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 2986 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 2987 | |
| 2988 | mutex_unlock(&bnad->conf_mutex); |
| 2989 | } |
| 2990 | |
| 2991 | static void |
| 2992 | bnad_vlan_rx_kill_vid(struct net_device *netdev, |
| 2993 | unsigned short vid) |
| 2994 | { |
| 2995 | struct bnad *bnad = netdev_priv(netdev); |
| 2996 | unsigned long flags; |
| 2997 | |
| 2998 | if (!bnad->rx_info[0].rx) |
| 2999 | return; |
| 3000 | |
| 3001 | mutex_lock(&bnad->conf_mutex); |
| 3002 | |
| 3003 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Jiri Pirko | f859d7c | 2011-07-20 04:54:14 +0000 | [diff] [blame] | 3004 | clear_bit(vid, bnad->active_vlans); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3005 | bna_rx_vlan_del(bnad->rx_info[0].rx, vid); |
| 3006 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 3007 | |
| 3008 | mutex_unlock(&bnad->conf_mutex); |
| 3009 | } |
| 3010 | |
| 3011 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3012 | static void |
| 3013 | bnad_netpoll(struct net_device *netdev) |
| 3014 | { |
| 3015 | struct bnad *bnad = netdev_priv(netdev); |
| 3016 | struct bnad_rx_info *rx_info; |
| 3017 | struct bnad_rx_ctrl *rx_ctrl; |
| 3018 | u32 curr_mask; |
| 3019 | int i, j; |
| 3020 | |
| 3021 | if (!(bnad->cfg_flags & BNAD_CF_MSIX)) { |
| 3022 | bna_intx_disable(&bnad->bna, curr_mask); |
| 3023 | bnad_isr(bnad->pcidev->irq, netdev); |
| 3024 | bna_intx_enable(&bnad->bna, curr_mask); |
| 3025 | } else { |
Rasesh Mody | 19dbff9 | 2011-08-30 15:27:41 +0000 | [diff] [blame] | 3026 | /* |
| 3027 | * Tx processing may happen in sending context, so no need |
| 3028 | * to explicitly process completions here |
| 3029 | */ |
| 3030 | |
| 3031 | /* Rx processing */ |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3032 | for (i = 0; i < bnad->num_rx; i++) { |
| 3033 | rx_info = &bnad->rx_info[i]; |
| 3034 | if (!rx_info->rx) |
| 3035 | continue; |
| 3036 | for (j = 0; j < bnad->num_rxp_per_rx; j++) { |
| 3037 | rx_ctrl = &rx_info->rx_ctrl[j]; |
Rasesh Mody | 271e8b7 | 2011-08-30 15:27:40 +0000 | [diff] [blame] | 3038 | if (rx_ctrl->ccb) |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3039 | bnad_netif_rx_schedule_poll(bnad, |
| 3040 | rx_ctrl->ccb); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3041 | } |
| 3042 | } |
| 3043 | } |
| 3044 | } |
| 3045 | #endif |
| 3046 | |
| 3047 | static const struct net_device_ops bnad_netdev_ops = { |
| 3048 | .ndo_open = bnad_open, |
| 3049 | .ndo_stop = bnad_stop, |
| 3050 | .ndo_start_xmit = bnad_start_xmit, |
Eric Dumazet | 250e061 | 2010-09-02 12:45:02 -0700 | [diff] [blame] | 3051 | .ndo_get_stats64 = bnad_get_stats64, |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3052 | .ndo_set_rx_mode = bnad_set_rx_mode, |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3053 | .ndo_validate_addr = eth_validate_addr, |
| 3054 | .ndo_set_mac_address = bnad_set_mac_address, |
| 3055 | .ndo_change_mtu = bnad_change_mtu, |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3056 | .ndo_vlan_rx_add_vid = bnad_vlan_rx_add_vid, |
| 3057 | .ndo_vlan_rx_kill_vid = bnad_vlan_rx_kill_vid, |
| 3058 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3059 | .ndo_poll_controller = bnad_netpoll |
| 3060 | #endif |
| 3061 | }; |
| 3062 | |
| 3063 | static void |
| 3064 | bnad_netdev_init(struct bnad *bnad, bool using_dac) |
| 3065 | { |
| 3066 | struct net_device *netdev = bnad->netdev; |
| 3067 | |
Michał Mirosław | e5ee20e | 2011-04-12 09:38:23 +0000 | [diff] [blame] | 3068 | netdev->hw_features = NETIF_F_SG | NETIF_F_RXCSUM | |
| 3069 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 3070 | NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_HW_VLAN_TX; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3071 | |
Michał Mirosław | e5ee20e | 2011-04-12 09:38:23 +0000 | [diff] [blame] | 3072 | netdev->vlan_features = NETIF_F_SG | NETIF_F_HIGHDMA | |
| 3073 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | |
| 3074 | NETIF_F_TSO | NETIF_F_TSO6; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3075 | |
Michał Mirosław | e5ee20e | 2011-04-12 09:38:23 +0000 | [diff] [blame] | 3076 | netdev->features |= netdev->hw_features | |
| 3077 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3078 | |
| 3079 | if (using_dac) |
| 3080 | netdev->features |= NETIF_F_HIGHDMA; |
| 3081 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3082 | netdev->mem_start = bnad->mmio_start; |
| 3083 | netdev->mem_end = bnad->mmio_start + bnad->mmio_len - 1; |
| 3084 | |
| 3085 | netdev->netdev_ops = &bnad_netdev_ops; |
| 3086 | bnad_set_ethtool_ops(netdev); |
| 3087 | } |
| 3088 | |
| 3089 | /* |
| 3090 | * 1. Initialize the bnad structure |
| 3091 | * 2. Setup netdev pointer in pci_dev |
| 3092 | * 3. Initialze Tx free tasklet |
| 3093 | * 4. Initialize no. of TxQ & CQs & MSIX vectors |
| 3094 | */ |
| 3095 | static int |
| 3096 | bnad_init(struct bnad *bnad, |
| 3097 | struct pci_dev *pdev, struct net_device *netdev) |
| 3098 | { |
| 3099 | unsigned long flags; |
| 3100 | |
| 3101 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 3102 | pci_set_drvdata(pdev, netdev); |
| 3103 | |
| 3104 | bnad->netdev = netdev; |
| 3105 | bnad->pcidev = pdev; |
| 3106 | bnad->mmio_start = pci_resource_start(pdev, 0); |
| 3107 | bnad->mmio_len = pci_resource_len(pdev, 0); |
| 3108 | bnad->bar0 = ioremap_nocache(bnad->mmio_start, bnad->mmio_len); |
| 3109 | if (!bnad->bar0) { |
| 3110 | dev_err(&pdev->dev, "ioremap for bar0 failed\n"); |
| 3111 | pci_set_drvdata(pdev, NULL); |
| 3112 | return -ENOMEM; |
| 3113 | } |
| 3114 | pr_info("bar0 mapped to %p, len %llu\n", bnad->bar0, |
| 3115 | (unsigned long long) bnad->mmio_len); |
| 3116 | |
| 3117 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 3118 | if (!bnad_msix_disable) |
| 3119 | bnad->cfg_flags = BNAD_CF_MSIX; |
| 3120 | |
| 3121 | bnad->cfg_flags |= BNAD_CF_DIM_ENABLED; |
| 3122 | |
| 3123 | bnad_q_num_init(bnad); |
| 3124 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 3125 | |
| 3126 | bnad->msix_num = (bnad->num_tx * bnad->num_txq_per_tx) + |
| 3127 | (bnad->num_rx * bnad->num_rxp_per_rx) + |
| 3128 | BNAD_MAILBOX_MSIX_VECTORS; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3129 | |
| 3130 | bnad->txq_depth = BNAD_TXQ_DEPTH; |
| 3131 | bnad->rxq_depth = BNAD_RXQ_DEPTH; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3132 | |
| 3133 | bnad->tx_coalescing_timeo = BFI_TX_COALESCING_TIMEO; |
| 3134 | bnad->rx_coalescing_timeo = BFI_RX_COALESCING_TIMEO; |
| 3135 | |
| 3136 | tasklet_init(&bnad->tx_free_tasklet, bnad_tx_free_tasklet, |
| 3137 | (unsigned long)bnad); |
| 3138 | |
| 3139 | return 0; |
| 3140 | } |
| 3141 | |
| 3142 | /* |
| 3143 | * Must be called after bnad_pci_uninit() |
| 3144 | * so that iounmap() and pci_set_drvdata(NULL) |
| 3145 | * happens only after PCI uninitialization. |
| 3146 | */ |
| 3147 | static void |
| 3148 | bnad_uninit(struct bnad *bnad) |
| 3149 | { |
| 3150 | if (bnad->bar0) |
| 3151 | iounmap(bnad->bar0); |
| 3152 | pci_set_drvdata(bnad->pcidev, NULL); |
| 3153 | } |
| 3154 | |
| 3155 | /* |
| 3156 | * Initialize locks |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3157 | a) Per ioceth mutes used for serializing configuration |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3158 | changes from OS interface |
| 3159 | b) spin lock used to protect bna state machine |
| 3160 | */ |
| 3161 | static void |
| 3162 | bnad_lock_init(struct bnad *bnad) |
| 3163 | { |
| 3164 | spin_lock_init(&bnad->bna_lock); |
| 3165 | mutex_init(&bnad->conf_mutex); |
| 3166 | } |
| 3167 | |
| 3168 | static void |
| 3169 | bnad_lock_uninit(struct bnad *bnad) |
| 3170 | { |
| 3171 | mutex_destroy(&bnad->conf_mutex); |
| 3172 | } |
| 3173 | |
| 3174 | /* PCI Initialization */ |
| 3175 | static int |
| 3176 | bnad_pci_init(struct bnad *bnad, |
| 3177 | struct pci_dev *pdev, bool *using_dac) |
| 3178 | { |
| 3179 | int err; |
| 3180 | |
| 3181 | err = pci_enable_device(pdev); |
| 3182 | if (err) |
| 3183 | return err; |
| 3184 | err = pci_request_regions(pdev, BNAD_NAME); |
| 3185 | if (err) |
| 3186 | goto disable_device; |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 3187 | if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && |
| 3188 | !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3189 | *using_dac = 1; |
| 3190 | } else { |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 3191 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3192 | if (err) { |
Ivan Vecera | 5ea7431 | 2011-02-02 04:37:02 +0000 | [diff] [blame] | 3193 | err = dma_set_coherent_mask(&pdev->dev, |
| 3194 | DMA_BIT_MASK(32)); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3195 | if (err) |
| 3196 | goto release_regions; |
| 3197 | } |
| 3198 | *using_dac = 0; |
| 3199 | } |
| 3200 | pci_set_master(pdev); |
| 3201 | return 0; |
| 3202 | |
| 3203 | release_regions: |
| 3204 | pci_release_regions(pdev); |
| 3205 | disable_device: |
| 3206 | pci_disable_device(pdev); |
| 3207 | |
| 3208 | return err; |
| 3209 | } |
| 3210 | |
| 3211 | static void |
| 3212 | bnad_pci_uninit(struct pci_dev *pdev) |
| 3213 | { |
| 3214 | pci_release_regions(pdev); |
| 3215 | pci_disable_device(pdev); |
| 3216 | } |
| 3217 | |
| 3218 | static int __devinit |
| 3219 | bnad_pci_probe(struct pci_dev *pdev, |
| 3220 | const struct pci_device_id *pcidev_id) |
| 3221 | { |
Rasesh Mody | 3caa1e95 | 2011-08-30 15:27:42 +0000 | [diff] [blame] | 3222 | bool using_dac; |
Rasesh Mody | 0120b99 | 2011-07-22 08:07:41 +0000 | [diff] [blame] | 3223 | int err; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3224 | struct bnad *bnad; |
| 3225 | struct bna *bna; |
| 3226 | struct net_device *netdev; |
| 3227 | struct bfa_pcidev pcidev_info; |
| 3228 | unsigned long flags; |
| 3229 | |
| 3230 | pr_info("bnad_pci_probe : (0x%p, 0x%p) PCI Func : (%d)\n", |
| 3231 | pdev, pcidev_id, PCI_FUNC(pdev->devfn)); |
| 3232 | |
| 3233 | mutex_lock(&bnad_fwimg_mutex); |
| 3234 | if (!cna_get_firmware_buf(pdev)) { |
| 3235 | mutex_unlock(&bnad_fwimg_mutex); |
| 3236 | pr_warn("Failed to load Firmware Image!\n"); |
| 3237 | return -ENODEV; |
| 3238 | } |
| 3239 | mutex_unlock(&bnad_fwimg_mutex); |
| 3240 | |
| 3241 | /* |
| 3242 | * Allocates sizeof(struct net_device + struct bnad) |
| 3243 | * bnad = netdev->priv |
| 3244 | */ |
| 3245 | netdev = alloc_etherdev(sizeof(struct bnad)); |
| 3246 | if (!netdev) { |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3247 | dev_err(&pdev->dev, "netdev allocation failed\n"); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3248 | err = -ENOMEM; |
| 3249 | return err; |
| 3250 | } |
| 3251 | bnad = netdev_priv(netdev); |
| 3252 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3253 | bnad_lock_init(bnad); |
| 3254 | |
| 3255 | mutex_lock(&bnad->conf_mutex); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3256 | /* |
| 3257 | * PCI initialization |
Rasesh Mody | 0120b99 | 2011-07-22 08:07:41 +0000 | [diff] [blame] | 3258 | * Output : using_dac = 1 for 64 bit DMA |
Rasesh Mody | be7fa32 | 2010-12-23 21:45:01 +0000 | [diff] [blame] | 3259 | * = 0 for 32 bit DMA |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3260 | */ |
| 3261 | err = bnad_pci_init(bnad, pdev, &using_dac); |
| 3262 | if (err) |
Dan Carpenter | 44861f4 | 2011-08-24 01:29:22 +0000 | [diff] [blame] | 3263 | goto unlock_mutex; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3264 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3265 | /* |
| 3266 | * Initialize bnad structure |
| 3267 | * Setup relation between pci_dev & netdev |
| 3268 | * Init Tx free tasklet |
| 3269 | */ |
| 3270 | err = bnad_init(bnad, pdev, netdev); |
| 3271 | if (err) |
| 3272 | goto pci_uninit; |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3273 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3274 | /* Initialize netdev structure, set up ethtool ops */ |
| 3275 | bnad_netdev_init(bnad, using_dac); |
| 3276 | |
Rasesh Mody | 815f41e | 2010-12-23 21:45:03 +0000 | [diff] [blame] | 3277 | /* Set link to down state */ |
| 3278 | netif_carrier_off(netdev); |
| 3279 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3280 | /* Get resource requirement form bna */ |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3281 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3282 | bna_res_req(&bnad->res_info[0]); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3283 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3284 | |
| 3285 | /* Allocate resources from bna */ |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3286 | err = bnad_res_alloc(bnad, &bnad->res_info[0], BNA_RES_T_MAX); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3287 | if (err) |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3288 | goto drv_uninit; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3289 | |
| 3290 | bna = &bnad->bna; |
| 3291 | |
| 3292 | /* Setup pcidev_info for bna_init() */ |
| 3293 | pcidev_info.pci_slot = PCI_SLOT(bnad->pcidev->devfn); |
| 3294 | pcidev_info.pci_func = PCI_FUNC(bnad->pcidev->devfn); |
| 3295 | pcidev_info.device_id = bnad->pcidev->device; |
| 3296 | pcidev_info.pci_bar_kva = bnad->bar0; |
| 3297 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3298 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 3299 | bna_init(bna, bnad, &pcidev_info, &bnad->res_info[0]); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3300 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 3301 | |
| 3302 | bnad->stats.bna_stats = &bna->stats; |
| 3303 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3304 | bnad_enable_msix(bnad); |
| 3305 | err = bnad_mbox_irq_alloc(bnad); |
| 3306 | if (err) |
| 3307 | goto res_free; |
| 3308 | |
| 3309 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3310 | /* Set up timers */ |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3311 | setup_timer(&bnad->bna.ioceth.ioc.ioc_timer, bnad_ioc_timeout, |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3312 | ((unsigned long)bnad)); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3313 | setup_timer(&bnad->bna.ioceth.ioc.hb_timer, bnad_ioc_hb_check, |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3314 | ((unsigned long)bnad)); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3315 | setup_timer(&bnad->bna.ioceth.ioc.iocpf_timer, bnad_iocpf_timeout, |
Rasesh Mody | 1d32f76 | 2010-12-23 21:45:09 +0000 | [diff] [blame] | 3316 | ((unsigned long)bnad)); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3317 | setup_timer(&bnad->bna.ioceth.ioc.sem_timer, bnad_iocpf_sem_timeout, |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3318 | ((unsigned long)bnad)); |
| 3319 | |
| 3320 | /* Now start the timer before calling IOC */ |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3321 | mod_timer(&bnad->bna.ioceth.ioc.iocpf_timer, |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3322 | jiffies + msecs_to_jiffies(BNA_IOC_TIMER_FREQ)); |
| 3323 | |
| 3324 | /* |
| 3325 | * Start the chip |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3326 | * If the call back comes with error, we bail out. |
| 3327 | * This is a catastrophic error. |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3328 | */ |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3329 | err = bnad_ioceth_enable(bnad); |
| 3330 | if (err) { |
| 3331 | pr_err("BNA: Initialization failed err=%d\n", |
| 3332 | err); |
| 3333 | goto probe_success; |
| 3334 | } |
| 3335 | |
| 3336 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 3337 | if (bna_num_txq_set(bna, BNAD_NUM_TXQ + 1) || |
| 3338 | bna_num_rxp_set(bna, BNAD_NUM_RXP + 1)) { |
| 3339 | bnad_q_num_adjust(bnad, bna_attr(bna)->num_txq - 1, |
| 3340 | bna_attr(bna)->num_rxp - 1); |
| 3341 | if (bna_num_txq_set(bna, BNAD_NUM_TXQ + 1) || |
| 3342 | bna_num_rxp_set(bna, BNAD_NUM_RXP + 1)) |
| 3343 | err = -EIO; |
| 3344 | } |
Rasesh Mody | 3caa1e95 | 2011-08-30 15:27:42 +0000 | [diff] [blame] | 3345 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 3346 | if (err) |
| 3347 | goto disable_ioceth; |
| 3348 | |
| 3349 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3350 | bna_mod_res_req(&bnad->bna, &bnad->mod_res_info[0]); |
| 3351 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 3352 | |
| 3353 | err = bnad_res_alloc(bnad, &bnad->mod_res_info[0], BNA_MOD_RES_T_MAX); |
Rasesh Mody | 0caa9aa | 2011-08-30 15:27:38 +0000 | [diff] [blame] | 3354 | if (err) { |
| 3355 | err = -EIO; |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3356 | goto disable_ioceth; |
Rasesh Mody | 0caa9aa | 2011-08-30 15:27:38 +0000 | [diff] [blame] | 3357 | } |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3358 | |
| 3359 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 3360 | bna_mod_init(&bnad->bna, &bnad->mod_res_info[0]); |
| 3361 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3362 | |
| 3363 | /* Get the burnt-in mac */ |
| 3364 | spin_lock_irqsave(&bnad->bna_lock, flags); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3365 | bna_enet_perm_mac_get(&bna->enet, &bnad->perm_addr); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3366 | bnad_set_netdev_perm_addr(bnad); |
| 3367 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
| 3368 | |
Rasesh Mody | 0caa9aa | 2011-08-30 15:27:38 +0000 | [diff] [blame] | 3369 | mutex_unlock(&bnad->conf_mutex); |
| 3370 | |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3371 | /* Finally, reguister with net_device layer */ |
| 3372 | err = register_netdev(netdev); |
| 3373 | if (err) { |
| 3374 | pr_err("BNA : Registering with netdev failed\n"); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3375 | goto probe_uninit; |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3376 | } |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3377 | set_bit(BNAD_RF_NETDEV_REGISTERED, &bnad->run_flags); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3378 | |
Rasesh Mody | 0caa9aa | 2011-08-30 15:27:38 +0000 | [diff] [blame] | 3379 | return 0; |
| 3380 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3381 | probe_success: |
| 3382 | mutex_unlock(&bnad->conf_mutex); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3383 | return 0; |
| 3384 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3385 | probe_uninit: |
Rasesh Mody | 3fc7237 | 2011-09-21 20:55:41 -0400 | [diff] [blame] | 3386 | mutex_lock(&bnad->conf_mutex); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3387 | bnad_res_free(bnad, &bnad->mod_res_info[0], BNA_MOD_RES_T_MAX); |
| 3388 | disable_ioceth: |
| 3389 | bnad_ioceth_disable(bnad); |
| 3390 | del_timer_sync(&bnad->bna.ioceth.ioc.ioc_timer); |
| 3391 | del_timer_sync(&bnad->bna.ioceth.ioc.sem_timer); |
| 3392 | del_timer_sync(&bnad->bna.ioceth.ioc.hb_timer); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3393 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 3394 | bna_uninit(bna); |
| 3395 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3396 | bnad_mbox_irq_free(bnad); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3397 | bnad_disable_msix(bnad); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3398 | res_free: |
| 3399 | bnad_res_free(bnad, &bnad->res_info[0], BNA_RES_T_MAX); |
| 3400 | drv_uninit: |
| 3401 | bnad_uninit(bnad); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3402 | pci_uninit: |
| 3403 | bnad_pci_uninit(pdev); |
Dan Carpenter | 44861f4 | 2011-08-24 01:29:22 +0000 | [diff] [blame] | 3404 | unlock_mutex: |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3405 | mutex_unlock(&bnad->conf_mutex); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3406 | bnad_lock_uninit(bnad); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3407 | free_netdev(netdev); |
| 3408 | return err; |
| 3409 | } |
| 3410 | |
| 3411 | static void __devexit |
| 3412 | bnad_pci_remove(struct pci_dev *pdev) |
| 3413 | { |
| 3414 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 3415 | struct bnad *bnad; |
| 3416 | struct bna *bna; |
| 3417 | unsigned long flags; |
| 3418 | |
| 3419 | if (!netdev) |
| 3420 | return; |
| 3421 | |
| 3422 | pr_info("%s bnad_pci_remove\n", netdev->name); |
| 3423 | bnad = netdev_priv(netdev); |
| 3424 | bna = &bnad->bna; |
| 3425 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3426 | if (test_and_clear_bit(BNAD_RF_NETDEV_REGISTERED, &bnad->run_flags)) |
| 3427 | unregister_netdev(netdev); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3428 | |
| 3429 | mutex_lock(&bnad->conf_mutex); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3430 | bnad_ioceth_disable(bnad); |
| 3431 | del_timer_sync(&bnad->bna.ioceth.ioc.ioc_timer); |
| 3432 | del_timer_sync(&bnad->bna.ioceth.ioc.sem_timer); |
| 3433 | del_timer_sync(&bnad->bna.ioceth.ioc.hb_timer); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3434 | spin_lock_irqsave(&bnad->bna_lock, flags); |
| 3435 | bna_uninit(bna); |
| 3436 | spin_unlock_irqrestore(&bnad->bna_lock, flags); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3437 | |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3438 | bnad_res_free(bnad, &bnad->mod_res_info[0], BNA_MOD_RES_T_MAX); |
| 3439 | bnad_res_free(bnad, &bnad->res_info[0], BNA_RES_T_MAX); |
| 3440 | bnad_mbox_irq_free(bnad); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3441 | bnad_disable_msix(bnad); |
| 3442 | bnad_pci_uninit(pdev); |
Rasesh Mody | 078086f | 2011-08-08 16:21:39 +0000 | [diff] [blame] | 3443 | mutex_unlock(&bnad->conf_mutex); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3444 | bnad_lock_uninit(bnad); |
| 3445 | bnad_uninit(bnad); |
| 3446 | free_netdev(netdev); |
| 3447 | } |
| 3448 | |
Rasesh Mody | 0120b99 | 2011-07-22 08:07:41 +0000 | [diff] [blame] | 3449 | static DEFINE_PCI_DEVICE_TABLE(bnad_pci_id_table) = { |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3450 | { |
| 3451 | PCI_DEVICE(PCI_VENDOR_ID_BROCADE, |
| 3452 | PCI_DEVICE_ID_BROCADE_CT), |
| 3453 | .class = PCI_CLASS_NETWORK_ETHERNET << 8, |
| 3454 | .class_mask = 0xffff00 |
Rasesh Mody | 586b2816 | 2011-09-27 10:39:08 +0000 | [diff] [blame] | 3455 | }, |
| 3456 | { |
| 3457 | PCI_DEVICE(PCI_VENDOR_ID_BROCADE, |
| 3458 | BFA_PCI_DEVICE_ID_CT2), |
| 3459 | .class = PCI_CLASS_NETWORK_ETHERNET << 8, |
| 3460 | .class_mask = 0xffff00 |
| 3461 | }, |
| 3462 | {0, }, |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3463 | }; |
| 3464 | |
| 3465 | MODULE_DEVICE_TABLE(pci, bnad_pci_id_table); |
| 3466 | |
| 3467 | static struct pci_driver bnad_pci_driver = { |
| 3468 | .name = BNAD_NAME, |
| 3469 | .id_table = bnad_pci_id_table, |
| 3470 | .probe = bnad_pci_probe, |
| 3471 | .remove = __devexit_p(bnad_pci_remove), |
| 3472 | }; |
| 3473 | |
| 3474 | static int __init |
| 3475 | bnad_module_init(void) |
| 3476 | { |
| 3477 | int err; |
| 3478 | |
Rasesh Mody | 5aad001 | 2011-07-22 08:07:40 +0000 | [diff] [blame] | 3479 | pr_info("Brocade 10G Ethernet driver - version: %s\n", |
| 3480 | BNAD_VERSION); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3481 | |
Rasesh Mody | 8a89142 | 2010-08-25 23:00:27 -0700 | [diff] [blame] | 3482 | bfa_nw_ioc_auto_recover(bnad_ioc_auto_recover); |
Rasesh Mody | 8b230ed | 2010-08-23 20:24:12 -0700 | [diff] [blame] | 3483 | |
| 3484 | err = pci_register_driver(&bnad_pci_driver); |
| 3485 | if (err < 0) { |
| 3486 | pr_err("bna : PCI registration failed in module init " |
| 3487 | "(%d)\n", err); |
| 3488 | return err; |
| 3489 | } |
| 3490 | |
| 3491 | return 0; |
| 3492 | } |
| 3493 | |
| 3494 | static void __exit |
| 3495 | bnad_module_exit(void) |
| 3496 | { |
| 3497 | pci_unregister_driver(&bnad_pci_driver); |
| 3498 | |
| 3499 | if (bfi_fw) |
| 3500 | release_firmware(bfi_fw); |
| 3501 | } |
| 3502 | |
| 3503 | module_init(bnad_module_init); |
| 3504 | module_exit(bnad_module_exit); |
| 3505 | |
| 3506 | MODULE_AUTHOR("Brocade"); |
| 3507 | MODULE_LICENSE("GPL"); |
| 3508 | MODULE_DESCRIPTION("Brocade 10G PCIe Ethernet driver"); |
| 3509 | MODULE_VERSION(BNAD_VERSION); |
| 3510 | MODULE_FIRMWARE(CNA_FW_FILE_CT); |
Rasesh Mody | 1bf9fd70 | 2011-09-27 10:39:07 +0000 | [diff] [blame] | 3511 | MODULE_FIRMWARE(CNA_FW_FILE_CT2); |