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