blob: 9c8654d9c5080a580eec1989055e2f90c753ad7d [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
2 * Copyright (C) 2005 - 2009 ServerEngines
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
9 *
10 * Contact Information:
11 * linux-drivers@serverengines.com
12 *
13 * ServerEngines
14 * 209 N. Fair Oaks Ave
15 * Sunnyvale, CA 94085
16 */
17
18#include "be.h"
Sathya Perla8788fdc2009-07-27 22:52:03 +000019#include "be_cmds.h"
Stephen Hemminger65f71b82009-03-27 00:25:24 -070020#include <asm/div64.h>
Sathya Perla6b7c5b92009-03-11 23:32:03 -070021
22MODULE_VERSION(DRV_VER);
23MODULE_DEVICE_TABLE(pci, be_dev_ids);
24MODULE_DESCRIPTION(DRV_DESC " " DRV_VER);
25MODULE_AUTHOR("ServerEngines Corporation");
26MODULE_LICENSE("GPL");
27
28static unsigned int rx_frag_size = 2048;
29module_param(rx_frag_size, uint, S_IRUGO);
30MODULE_PARM_DESC(rx_frag_size, "Size of a fragment that holds rcvd data.");
31
Sathya Perla6b7c5b92009-03-11 23:32:03 -070032static DEFINE_PCI_DEVICE_TABLE(be_dev_ids) = {
Ajit Khapardec4ca2372009-05-18 15:38:55 -070033 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
34 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
35 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
Sathya Perla6b7c5b92009-03-11 23:32:03 -070036 { 0 }
37};
38MODULE_DEVICE_TABLE(pci, be_dev_ids);
39
40static void be_queue_free(struct be_adapter *adapter, struct be_queue_info *q)
41{
42 struct be_dma_mem *mem = &q->dma_mem;
43 if (mem->va)
44 pci_free_consistent(adapter->pdev, mem->size,
45 mem->va, mem->dma);
46}
47
48static int be_queue_alloc(struct be_adapter *adapter, struct be_queue_info *q,
49 u16 len, u16 entry_size)
50{
51 struct be_dma_mem *mem = &q->dma_mem;
52
53 memset(q, 0, sizeof(*q));
54 q->len = len;
55 q->entry_size = entry_size;
56 mem->size = len * entry_size;
57 mem->va = pci_alloc_consistent(adapter->pdev, mem->size, &mem->dma);
58 if (!mem->va)
59 return -1;
60 memset(mem->va, 0, mem->size);
61 return 0;
62}
63
Sathya Perla8788fdc2009-07-27 22:52:03 +000064static void be_intr_set(struct be_adapter *adapter, bool enable)
Sathya Perla6b7c5b92009-03-11 23:32:03 -070065{
Sathya Perla8788fdc2009-07-27 22:52:03 +000066 u8 __iomem *addr = adapter->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
Sathya Perla6b7c5b92009-03-11 23:32:03 -070067 u32 reg = ioread32(addr);
68 u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
69 if (!enabled && enable) {
70 reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
71 } else if (enabled && !enable) {
72 reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
73 } else {
74 printk(KERN_WARNING DRV_NAME
75 ": bad value in membar_int_ctrl reg=0x%x\n", reg);
76 return;
77 }
78 iowrite32(reg, addr);
79}
80
Sathya Perla8788fdc2009-07-27 22:52:03 +000081static void be_rxq_notify(struct be_adapter *adapter, u16 qid, u16 posted)
Sathya Perla6b7c5b92009-03-11 23:32:03 -070082{
83 u32 val = 0;
84 val |= qid & DB_RQ_RING_ID_MASK;
85 val |= posted << DB_RQ_NUM_POSTED_SHIFT;
Sathya Perla8788fdc2009-07-27 22:52:03 +000086 iowrite32(val, adapter->db + DB_RQ_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -070087}
88
Sathya Perla8788fdc2009-07-27 22:52:03 +000089static void be_txq_notify(struct be_adapter *adapter, u16 qid, u16 posted)
Sathya Perla6b7c5b92009-03-11 23:32:03 -070090{
91 u32 val = 0;
92 val |= qid & DB_TXULP_RING_ID_MASK;
93 val |= (posted & DB_TXULP_NUM_POSTED_MASK) << DB_TXULP_NUM_POSTED_SHIFT;
Sathya Perla8788fdc2009-07-27 22:52:03 +000094 iowrite32(val, adapter->db + DB_TXULP1_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -070095}
96
Sathya Perla8788fdc2009-07-27 22:52:03 +000097static void be_eq_notify(struct be_adapter *adapter, u16 qid,
Sathya Perla6b7c5b92009-03-11 23:32:03 -070098 bool arm, bool clear_int, u16 num_popped)
99{
100 u32 val = 0;
101 val |= qid & DB_EQ_RING_ID_MASK;
102 if (arm)
103 val |= 1 << DB_EQ_REARM_SHIFT;
104 if (clear_int)
105 val |= 1 << DB_EQ_CLR_SHIFT;
106 val |= 1 << DB_EQ_EVNT_SHIFT;
107 val |= num_popped << DB_EQ_NUM_POPPED_SHIFT;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000108 iowrite32(val, adapter->db + DB_EQ_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700109}
110
Sathya Perla8788fdc2009-07-27 22:52:03 +0000111void be_cq_notify(struct be_adapter *adapter, u16 qid, bool arm, u16 num_popped)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700112{
113 u32 val = 0;
114 val |= qid & DB_CQ_RING_ID_MASK;
115 if (arm)
116 val |= 1 << DB_CQ_REARM_SHIFT;
117 val |= num_popped << DB_CQ_NUM_POPPED_SHIFT;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000118 iowrite32(val, adapter->db + DB_CQ_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700119}
120
121
122static int be_mac_addr_set(struct net_device *netdev, void *p)
123{
124 struct be_adapter *adapter = netdev_priv(netdev);
125 struct sockaddr *addr = p;
126 int status = 0;
127
128 if (netif_running(netdev)) {
Sathya Perla8788fdc2009-07-27 22:52:03 +0000129 status = be_cmd_pmac_del(adapter, adapter->if_handle,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700130 adapter->pmac_id);
131 if (status)
132 return status;
133
Sathya Perla8788fdc2009-07-27 22:52:03 +0000134 status = be_cmd_pmac_add(adapter, (u8 *)addr->sa_data,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700135 adapter->if_handle, &adapter->pmac_id);
136 }
137
138 if (!status)
139 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
140
141 return status;
142}
143
144static void netdev_stats_update(struct be_adapter *adapter)
145{
146 struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats.cmd.va);
147 struct be_rxf_stats *rxf_stats = &hw_stats->rxf;
148 struct be_port_rxf_stats *port_stats =
149 &rxf_stats->port[adapter->port_num];
150 struct net_device_stats *dev_stats = &adapter->stats.net_stats;
Sathya Perla68110862009-06-10 02:21:16 +0000151 struct be_erx_stats *erx_stats = &hw_stats->erx;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700152
153 dev_stats->rx_packets = port_stats->rx_total_frames;
154 dev_stats->tx_packets = port_stats->tx_unicastframes +
155 port_stats->tx_multicastframes + port_stats->tx_broadcastframes;
156 dev_stats->rx_bytes = (u64) port_stats->rx_bytes_msd << 32 |
157 (u64) port_stats->rx_bytes_lsd;
158 dev_stats->tx_bytes = (u64) port_stats->tx_bytes_msd << 32 |
159 (u64) port_stats->tx_bytes_lsd;
160
161 /* bad pkts received */
162 dev_stats->rx_errors = port_stats->rx_crc_errors +
163 port_stats->rx_alignment_symbol_errors +
164 port_stats->rx_in_range_errors +
Sathya Perla68110862009-06-10 02:21:16 +0000165 port_stats->rx_out_range_errors +
166 port_stats->rx_frame_too_long +
167 port_stats->rx_dropped_too_small +
168 port_stats->rx_dropped_too_short +
169 port_stats->rx_dropped_header_too_small +
170 port_stats->rx_dropped_tcp_length +
171 port_stats->rx_dropped_runt +
172 port_stats->rx_tcp_checksum_errs +
173 port_stats->rx_ip_checksum_errs +
174 port_stats->rx_udp_checksum_errs;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700175
Sathya Perla68110862009-06-10 02:21:16 +0000176 /* no space in linux buffers: best possible approximation */
177 dev_stats->rx_dropped = erx_stats->rx_drops_no_fragments[0];
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700178
179 /* detailed rx errors */
180 dev_stats->rx_length_errors = port_stats->rx_in_range_errors +
Sathya Perla68110862009-06-10 02:21:16 +0000181 port_stats->rx_out_range_errors +
182 port_stats->rx_frame_too_long;
183
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700184 /* receive ring buffer overflow */
185 dev_stats->rx_over_errors = 0;
Sathya Perla68110862009-06-10 02:21:16 +0000186
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700187 dev_stats->rx_crc_errors = port_stats->rx_crc_errors;
188
189 /* frame alignment errors */
190 dev_stats->rx_frame_errors = port_stats->rx_alignment_symbol_errors;
Sathya Perla68110862009-06-10 02:21:16 +0000191
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700192 /* receiver fifo overrun */
193 /* drops_no_pbuf is no per i/f, it's per BE card */
194 dev_stats->rx_fifo_errors = port_stats->rx_fifo_overflow +
195 port_stats->rx_input_fifo_overflow +
196 rxf_stats->rx_drops_no_pbuf;
197 /* receiver missed packetd */
198 dev_stats->rx_missed_errors = 0;
Sathya Perla68110862009-06-10 02:21:16 +0000199
200 /* packet transmit problems */
201 dev_stats->tx_errors = 0;
202
203 /* no space available in linux */
204 dev_stats->tx_dropped = 0;
205
206 dev_stats->multicast = port_stats->tx_multicastframes;
207 dev_stats->collisions = 0;
208
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700209 /* detailed tx_errors */
210 dev_stats->tx_aborted_errors = 0;
211 dev_stats->tx_carrier_errors = 0;
212 dev_stats->tx_fifo_errors = 0;
213 dev_stats->tx_heartbeat_errors = 0;
214 dev_stats->tx_window_errors = 0;
215}
216
Sathya Perla8788fdc2009-07-27 22:52:03 +0000217void be_link_status_update(struct be_adapter *adapter, bool link_up)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700218{
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700219 struct net_device *netdev = adapter->netdev;
220
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700221 /* If link came up or went down */
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000222 if (adapter->link_up != link_up) {
223 if (link_up) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700224 netif_start_queue(netdev);
225 netif_carrier_on(netdev);
226 printk(KERN_INFO "%s: Link up\n", netdev->name);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000227 } else {
228 netif_stop_queue(netdev);
229 netif_carrier_off(netdev);
230 printk(KERN_INFO "%s: Link down\n", netdev->name);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700231 }
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000232 adapter->link_up = link_up;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700233 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700234}
235
236/* Update the EQ delay n BE based on the RX frags consumed / sec */
237static void be_rx_eqd_update(struct be_adapter *adapter)
238{
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700239 struct be_eq_obj *rx_eq = &adapter->rx_eq;
240 struct be_drvr_stats *stats = &adapter->stats.drvr_stats;
Sathya Perla4097f662009-03-24 16:40:13 -0700241 ulong now = jiffies;
242 u32 eqd;
243
244 if (!rx_eq->enable_aic)
245 return;
246
247 /* Wrapped around */
248 if (time_before(now, stats->rx_fps_jiffies)) {
249 stats->rx_fps_jiffies = now;
250 return;
251 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700252
253 /* Update once a second */
Sathya Perla4097f662009-03-24 16:40:13 -0700254 if ((now - stats->rx_fps_jiffies) < HZ)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700255 return;
256
257 stats->be_rx_fps = (stats->be_rx_frags - stats->be_prev_rx_frags) /
Sathya Perla4097f662009-03-24 16:40:13 -0700258 ((now - stats->rx_fps_jiffies) / HZ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700259
Sathya Perla4097f662009-03-24 16:40:13 -0700260 stats->rx_fps_jiffies = now;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700261 stats->be_prev_rx_frags = stats->be_rx_frags;
262 eqd = stats->be_rx_fps / 110000;
263 eqd = eqd << 3;
264 if (eqd > rx_eq->max_eqd)
265 eqd = rx_eq->max_eqd;
266 if (eqd < rx_eq->min_eqd)
267 eqd = rx_eq->min_eqd;
268 if (eqd < 10)
269 eqd = 0;
270 if (eqd != rx_eq->cur_eqd)
Sathya Perla8788fdc2009-07-27 22:52:03 +0000271 be_cmd_modify_eqd(adapter, rx_eq->q.id, eqd);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700272
273 rx_eq->cur_eqd = eqd;
274}
275
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700276static struct net_device_stats *be_get_stats(struct net_device *dev)
277{
278 struct be_adapter *adapter = netdev_priv(dev);
279
280 return &adapter->stats.net_stats;
281}
282
Stephen Hemminger65f71b82009-03-27 00:25:24 -0700283static u32 be_calc_rate(u64 bytes, unsigned long ticks)
284{
285 u64 rate = bytes;
286
287 do_div(rate, ticks / HZ);
288 rate <<= 3; /* bytes/sec -> bits/sec */
289 do_div(rate, 1000000ul); /* MB/Sec */
290
291 return rate;
292}
293
Sathya Perla4097f662009-03-24 16:40:13 -0700294static void be_tx_rate_update(struct be_adapter *adapter)
295{
296 struct be_drvr_stats *stats = drvr_stats(adapter);
297 ulong now = jiffies;
298
299 /* Wrapped around? */
300 if (time_before(now, stats->be_tx_jiffies)) {
301 stats->be_tx_jiffies = now;
302 return;
303 }
304
305 /* Update tx rate once in two seconds */
306 if ((now - stats->be_tx_jiffies) > 2 * HZ) {
Stephen Hemminger65f71b82009-03-27 00:25:24 -0700307 stats->be_tx_rate = be_calc_rate(stats->be_tx_bytes
308 - stats->be_tx_bytes_prev,
309 now - stats->be_tx_jiffies);
Sathya Perla4097f662009-03-24 16:40:13 -0700310 stats->be_tx_jiffies = now;
311 stats->be_tx_bytes_prev = stats->be_tx_bytes;
312 }
313}
314
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700315static void be_tx_stats_update(struct be_adapter *adapter,
316 u32 wrb_cnt, u32 copied, bool stopped)
317{
Sathya Perla4097f662009-03-24 16:40:13 -0700318 struct be_drvr_stats *stats = drvr_stats(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700319 stats->be_tx_reqs++;
320 stats->be_tx_wrbs += wrb_cnt;
321 stats->be_tx_bytes += copied;
322 if (stopped)
323 stats->be_tx_stops++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700324}
325
326/* Determine number of WRB entries needed to xmit data in an skb */
327static u32 wrb_cnt_for_skb(struct sk_buff *skb, bool *dummy)
328{
David S. Millerebc8d2a2009-06-09 01:01:31 -0700329 int cnt = (skb->len > skb->data_len);
330
331 cnt += skb_shinfo(skb)->nr_frags;
332
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700333 /* to account for hdr wrb */
334 cnt++;
335 if (cnt & 1) {
336 /* add a dummy to make it an even num */
337 cnt++;
338 *dummy = true;
339 } else
340 *dummy = false;
341 BUG_ON(cnt > BE_MAX_TX_FRAG_COUNT);
342 return cnt;
343}
344
345static inline void wrb_fill(struct be_eth_wrb *wrb, u64 addr, int len)
346{
347 wrb->frag_pa_hi = upper_32_bits(addr);
348 wrb->frag_pa_lo = addr & 0xFFFFFFFF;
349 wrb->frag_len = len & ETH_WRB_FRAG_LEN_MASK;
350}
351
352static void wrb_fill_hdr(struct be_eth_hdr_wrb *hdr, struct sk_buff *skb,
353 bool vlan, u32 wrb_cnt, u32 len)
354{
355 memset(hdr, 0, sizeof(*hdr));
356
357 AMAP_SET_BITS(struct amap_eth_hdr_wrb, crc, hdr, 1);
358
359 if (skb_shinfo(skb)->gso_segs > 1 && skb_shinfo(skb)->gso_size) {
360 AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso, hdr, 1);
361 AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso_mss,
362 hdr, skb_shinfo(skb)->gso_size);
363 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
364 if (is_tcp_pkt(skb))
365 AMAP_SET_BITS(struct amap_eth_hdr_wrb, tcpcs, hdr, 1);
366 else if (is_udp_pkt(skb))
367 AMAP_SET_BITS(struct amap_eth_hdr_wrb, udpcs, hdr, 1);
368 }
369
370 if (vlan && vlan_tx_tag_present(skb)) {
371 AMAP_SET_BITS(struct amap_eth_hdr_wrb, vlan, hdr, 1);
372 AMAP_SET_BITS(struct amap_eth_hdr_wrb, vlan_tag,
373 hdr, vlan_tx_tag_get(skb));
374 }
375
376 AMAP_SET_BITS(struct amap_eth_hdr_wrb, event, hdr, 1);
377 AMAP_SET_BITS(struct amap_eth_hdr_wrb, complete, hdr, 1);
378 AMAP_SET_BITS(struct amap_eth_hdr_wrb, num_wrb, hdr, wrb_cnt);
379 AMAP_SET_BITS(struct amap_eth_hdr_wrb, len, hdr, len);
380}
381
382
383static int make_tx_wrbs(struct be_adapter *adapter,
384 struct sk_buff *skb, u32 wrb_cnt, bool dummy_wrb)
385{
386 u64 busaddr;
387 u32 i, copied = 0;
388 struct pci_dev *pdev = adapter->pdev;
389 struct sk_buff *first_skb = skb;
390 struct be_queue_info *txq = &adapter->tx_obj.q;
391 struct be_eth_wrb *wrb;
392 struct be_eth_hdr_wrb *hdr;
393
394 atomic_add(wrb_cnt, &txq->used);
395 hdr = queue_head_node(txq);
396 queue_head_inc(txq);
397
David S. Millerebc8d2a2009-06-09 01:01:31 -0700398 if (skb->len > skb->data_len) {
399 int len = skb->len - skb->data_len;
400 busaddr = pci_map_single(pdev, skb->data, len,
401 PCI_DMA_TODEVICE);
402 wrb = queue_head_node(txq);
403 wrb_fill(wrb, busaddr, len);
404 be_dws_cpu_to_le(wrb, sizeof(*wrb));
405 queue_head_inc(txq);
406 copied += len;
407 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700408
David S. Millerebc8d2a2009-06-09 01:01:31 -0700409 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
410 struct skb_frag_struct *frag =
411 &skb_shinfo(skb)->frags[i];
412 busaddr = pci_map_page(pdev, frag->page,
Sathya Perla8788fdc2009-07-27 22:52:03 +0000413 frag->page_offset,
414 frag->size, PCI_DMA_TODEVICE);
David S. Millerebc8d2a2009-06-09 01:01:31 -0700415 wrb = queue_head_node(txq);
416 wrb_fill(wrb, busaddr, frag->size);
417 be_dws_cpu_to_le(wrb, sizeof(*wrb));
418 queue_head_inc(txq);
419 copied += frag->size;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700420 }
421
422 if (dummy_wrb) {
423 wrb = queue_head_node(txq);
424 wrb_fill(wrb, 0, 0);
425 be_dws_cpu_to_le(wrb, sizeof(*wrb));
426 queue_head_inc(txq);
427 }
428
429 wrb_fill_hdr(hdr, first_skb, adapter->vlan_grp ? true : false,
430 wrb_cnt, copied);
431 be_dws_cpu_to_le(hdr, sizeof(*hdr));
432
433 return copied;
434}
435
436static int be_xmit(struct sk_buff *skb, struct net_device *netdev)
437{
438 struct be_adapter *adapter = netdev_priv(netdev);
439 struct be_tx_obj *tx_obj = &adapter->tx_obj;
440 struct be_queue_info *txq = &tx_obj->q;
441 u32 wrb_cnt = 0, copied = 0;
442 u32 start = txq->head;
443 bool dummy_wrb, stopped = false;
444
445 wrb_cnt = wrb_cnt_for_skb(skb, &dummy_wrb);
446
447 copied = make_tx_wrbs(adapter, skb, wrb_cnt, dummy_wrb);
448
449 /* record the sent skb in the sent_skb table */
450 BUG_ON(tx_obj->sent_skb_list[start]);
451 tx_obj->sent_skb_list[start] = skb;
452
453 /* Ensure that txq has space for the next skb; Else stop the queue
454 * *BEFORE* ringing the tx doorbell, so that we serialze the
455 * tx compls of the current transmit which'll wake up the queue
456 */
457 if ((BE_MAX_TX_FRAG_COUNT + atomic_read(&txq->used)) >= txq->len) {
458 netif_stop_queue(netdev);
459 stopped = true;
460 }
461
Sathya Perla8788fdc2009-07-27 22:52:03 +0000462 be_txq_notify(adapter, txq->id, wrb_cnt);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700463
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700464 be_tx_stats_update(adapter, wrb_cnt, copied, stopped);
465 return NETDEV_TX_OK;
466}
467
468static int be_change_mtu(struct net_device *netdev, int new_mtu)
469{
470 struct be_adapter *adapter = netdev_priv(netdev);
471 if (new_mtu < BE_MIN_MTU ||
472 new_mtu > BE_MAX_JUMBO_FRAME_SIZE) {
473 dev_info(&adapter->pdev->dev,
474 "MTU must be between %d and %d bytes\n",
475 BE_MIN_MTU, BE_MAX_JUMBO_FRAME_SIZE);
476 return -EINVAL;
477 }
478 dev_info(&adapter->pdev->dev, "MTU changed from %d to %d bytes\n",
479 netdev->mtu, new_mtu);
480 netdev->mtu = new_mtu;
481 return 0;
482}
483
484/*
485 * if there are BE_NUM_VLANS_SUPPORTED or lesser number of VLANS configured,
486 * program them in BE. If more than BE_NUM_VLANS_SUPPORTED are configured,
487 * set the BE in promiscuous VLAN mode.
488 */
Sathya Perla1ab1ab72009-03-19 23:56:46 -0700489static void be_vid_config(struct net_device *netdev)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700490{
491 struct be_adapter *adapter = netdev_priv(netdev);
492 u16 vtag[BE_NUM_VLANS_SUPPORTED];
493 u16 ntags = 0, i;
494
495 if (adapter->num_vlans <= BE_NUM_VLANS_SUPPORTED) {
496 /* Construct VLAN Table to give to HW */
497 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
498 if (adapter->vlan_tag[i]) {
499 vtag[ntags] = cpu_to_le16(i);
500 ntags++;
501 }
502 }
Sathya Perla8788fdc2009-07-27 22:52:03 +0000503 be_cmd_vlan_config(adapter, adapter->if_handle,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700504 vtag, ntags, 1, 0);
505 } else {
Sathya Perla8788fdc2009-07-27 22:52:03 +0000506 be_cmd_vlan_config(adapter, adapter->if_handle,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700507 NULL, 0, 1, 1);
508 }
509}
510
511static void be_vlan_register(struct net_device *netdev, struct vlan_group *grp)
512{
513 struct be_adapter *adapter = netdev_priv(netdev);
514 struct be_eq_obj *rx_eq = &adapter->rx_eq;
515 struct be_eq_obj *tx_eq = &adapter->tx_eq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700516
Sathya Perla8788fdc2009-07-27 22:52:03 +0000517 be_eq_notify(adapter, rx_eq->q.id, false, false, 0);
518 be_eq_notify(adapter, tx_eq->q.id, false, false, 0);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700519 adapter->vlan_grp = grp;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000520 be_eq_notify(adapter, rx_eq->q.id, true, false, 0);
521 be_eq_notify(adapter, tx_eq->q.id, true, false, 0);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700522}
523
524static void be_vlan_add_vid(struct net_device *netdev, u16 vid)
525{
526 struct be_adapter *adapter = netdev_priv(netdev);
527
528 adapter->num_vlans++;
529 adapter->vlan_tag[vid] = 1;
530
Sathya Perla1ab1ab72009-03-19 23:56:46 -0700531 be_vid_config(netdev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700532}
533
534static void be_vlan_rem_vid(struct net_device *netdev, u16 vid)
535{
536 struct be_adapter *adapter = netdev_priv(netdev);
537
538 adapter->num_vlans--;
539 adapter->vlan_tag[vid] = 0;
540
541 vlan_group_set_device(adapter->vlan_grp, vid, NULL);
Sathya Perla1ab1ab72009-03-19 23:56:46 -0700542 be_vid_config(netdev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700543}
544
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700545static void be_set_multicast_list(struct net_device *netdev)
546{
547 struct be_adapter *adapter = netdev_priv(netdev);
548
549 if (netdev->flags & IFF_PROMISC) {
Sathya Perla8788fdc2009-07-27 22:52:03 +0000550 be_cmd_promiscuous_config(adapter, adapter->port_num, 1);
Sathya Perla24307ee2009-06-18 00:09:25 +0000551 adapter->promiscuous = true;
552 goto done;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700553 }
Sathya Perla24307ee2009-06-18 00:09:25 +0000554
555 /* BE was previously in promiscous mode; disable it */
556 if (adapter->promiscuous) {
557 adapter->promiscuous = false;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000558 be_cmd_promiscuous_config(adapter, adapter->port_num, 0);
Sathya Perla24307ee2009-06-18 00:09:25 +0000559 }
560
561 if (netdev->flags & IFF_ALLMULTI) {
Sathya Perla8788fdc2009-07-27 22:52:03 +0000562 be_cmd_multicast_set(adapter, adapter->if_handle, NULL, 0);
Sathya Perla24307ee2009-06-18 00:09:25 +0000563 goto done;
564 }
565
Sathya Perla8788fdc2009-07-27 22:52:03 +0000566 be_cmd_multicast_set(adapter, adapter->if_handle, netdev->mc_list,
Sathya Perla24307ee2009-06-18 00:09:25 +0000567 netdev->mc_count);
568done:
569 return;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700570}
571
Sathya Perla4097f662009-03-24 16:40:13 -0700572static void be_rx_rate_update(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700573{
Sathya Perla4097f662009-03-24 16:40:13 -0700574 struct be_drvr_stats *stats = drvr_stats(adapter);
575 ulong now = jiffies;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700576
Sathya Perla4097f662009-03-24 16:40:13 -0700577 /* Wrapped around */
578 if (time_before(now, stats->be_rx_jiffies)) {
579 stats->be_rx_jiffies = now;
580 return;
581 }
582
583 /* Update the rate once in two seconds */
584 if ((now - stats->be_rx_jiffies) < 2 * HZ)
585 return;
586
Stephen Hemminger65f71b82009-03-27 00:25:24 -0700587 stats->be_rx_rate = be_calc_rate(stats->be_rx_bytes
588 - stats->be_rx_bytes_prev,
589 now - stats->be_rx_jiffies);
Sathya Perla4097f662009-03-24 16:40:13 -0700590 stats->be_rx_jiffies = now;
591 stats->be_rx_bytes_prev = stats->be_rx_bytes;
592}
593
594static void be_rx_stats_update(struct be_adapter *adapter,
595 u32 pktsize, u16 numfrags)
596{
597 struct be_drvr_stats *stats = drvr_stats(adapter);
598
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700599 stats->be_rx_compl++;
600 stats->be_rx_frags += numfrags;
601 stats->be_rx_bytes += pktsize;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700602}
603
Ajit Khaparde728a9972009-04-13 15:41:22 -0700604static inline bool do_pkt_csum(struct be_eth_rx_compl *rxcp, bool cso)
605{
606 u8 l4_cksm, ip_version, ipcksm, tcpf = 0, udpf = 0, ipv6_chk;
607
608 l4_cksm = AMAP_GET_BITS(struct amap_eth_rx_compl, l4_cksm, rxcp);
609 ipcksm = AMAP_GET_BITS(struct amap_eth_rx_compl, ipcksm, rxcp);
610 ip_version = AMAP_GET_BITS(struct amap_eth_rx_compl, ip_version, rxcp);
611 if (ip_version) {
612 tcpf = AMAP_GET_BITS(struct amap_eth_rx_compl, tcpf, rxcp);
613 udpf = AMAP_GET_BITS(struct amap_eth_rx_compl, udpf, rxcp);
614 }
615 ipv6_chk = (ip_version && (tcpf || udpf));
616
617 return ((l4_cksm && ipv6_chk && ipcksm) && cso) ? false : true;
618}
619
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700620static struct be_rx_page_info *
621get_rx_page_info(struct be_adapter *adapter, u16 frag_idx)
622{
623 struct be_rx_page_info *rx_page_info;
624 struct be_queue_info *rxq = &adapter->rx_obj.q;
625
626 rx_page_info = &adapter->rx_obj.page_info_tbl[frag_idx];
627 BUG_ON(!rx_page_info->page);
628
629 if (rx_page_info->last_page_user)
630 pci_unmap_page(adapter->pdev, pci_unmap_addr(rx_page_info, bus),
631 adapter->big_page_size, PCI_DMA_FROMDEVICE);
632
633 atomic_dec(&rxq->used);
634 return rx_page_info;
635}
636
637/* Throwaway the data in the Rx completion */
638static void be_rx_compl_discard(struct be_adapter *adapter,
639 struct be_eth_rx_compl *rxcp)
640{
641 struct be_queue_info *rxq = &adapter->rx_obj.q;
642 struct be_rx_page_info *page_info;
643 u16 rxq_idx, i, num_rcvd;
644
645 rxq_idx = AMAP_GET_BITS(struct amap_eth_rx_compl, fragndx, rxcp);
646 num_rcvd = AMAP_GET_BITS(struct amap_eth_rx_compl, numfrags, rxcp);
647
648 for (i = 0; i < num_rcvd; i++) {
649 page_info = get_rx_page_info(adapter, rxq_idx);
650 put_page(page_info->page);
651 memset(page_info, 0, sizeof(*page_info));
652 index_inc(&rxq_idx, rxq->len);
653 }
654}
655
656/*
657 * skb_fill_rx_data forms a complete skb for an ether frame
658 * indicated by rxcp.
659 */
660static void skb_fill_rx_data(struct be_adapter *adapter,
661 struct sk_buff *skb, struct be_eth_rx_compl *rxcp)
662{
663 struct be_queue_info *rxq = &adapter->rx_obj.q;
664 struct be_rx_page_info *page_info;
Ajit Khapardebd46cb62009-06-26 02:51:07 +0000665 u16 rxq_idx, i, num_rcvd, j;
Ajit Khapardefa774062009-07-22 09:28:55 -0700666 u32 pktsize, hdr_len, curr_frag_len, size;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700667 u8 *start;
668
669 rxq_idx = AMAP_GET_BITS(struct amap_eth_rx_compl, fragndx, rxcp);
670 pktsize = AMAP_GET_BITS(struct amap_eth_rx_compl, pktsize, rxcp);
671 num_rcvd = AMAP_GET_BITS(struct amap_eth_rx_compl, numfrags, rxcp);
672
673 page_info = get_rx_page_info(adapter, rxq_idx);
674
675 start = page_address(page_info->page) + page_info->page_offset;
676 prefetch(start);
677
678 /* Copy data in the first descriptor of this completion */
679 curr_frag_len = min(pktsize, rx_frag_size);
680
681 /* Copy the header portion into skb_data */
682 hdr_len = min((u32)BE_HDR_LEN, curr_frag_len);
683 memcpy(skb->data, start, hdr_len);
684 skb->len = curr_frag_len;
685 if (curr_frag_len <= BE_HDR_LEN) { /* tiny packet */
686 /* Complete packet has now been moved to data */
687 put_page(page_info->page);
688 skb->data_len = 0;
689 skb->tail += curr_frag_len;
690 } else {
691 skb_shinfo(skb)->nr_frags = 1;
692 skb_shinfo(skb)->frags[0].page = page_info->page;
693 skb_shinfo(skb)->frags[0].page_offset =
694 page_info->page_offset + hdr_len;
695 skb_shinfo(skb)->frags[0].size = curr_frag_len - hdr_len;
696 skb->data_len = curr_frag_len - hdr_len;
697 skb->tail += hdr_len;
698 }
699 memset(page_info, 0, sizeof(*page_info));
700
701 if (pktsize <= rx_frag_size) {
702 BUG_ON(num_rcvd != 1);
Sathya Perla76fbb422009-06-10 02:21:56 +0000703 goto done;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700704 }
705
706 /* More frags present for this completion */
Ajit Khapardefa774062009-07-22 09:28:55 -0700707 size = pktsize;
Ajit Khapardebd46cb62009-06-26 02:51:07 +0000708 for (i = 1, j = 0; i < num_rcvd; i++) {
Ajit Khapardefa774062009-07-22 09:28:55 -0700709 size -= curr_frag_len;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700710 index_inc(&rxq_idx, rxq->len);
711 page_info = get_rx_page_info(adapter, rxq_idx);
712
Ajit Khapardefa774062009-07-22 09:28:55 -0700713 curr_frag_len = min(size, rx_frag_size);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700714
Ajit Khapardebd46cb62009-06-26 02:51:07 +0000715 /* Coalesce all frags from the same physical page in one slot */
716 if (page_info->page_offset == 0) {
717 /* Fresh page */
718 j++;
719 skb_shinfo(skb)->frags[j].page = page_info->page;
720 skb_shinfo(skb)->frags[j].page_offset =
721 page_info->page_offset;
722 skb_shinfo(skb)->frags[j].size = 0;
723 skb_shinfo(skb)->nr_frags++;
724 } else {
725 put_page(page_info->page);
726 }
727
728 skb_shinfo(skb)->frags[j].size += curr_frag_len;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700729 skb->len += curr_frag_len;
730 skb->data_len += curr_frag_len;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700731
732 memset(page_info, 0, sizeof(*page_info));
733 }
Ajit Khapardebd46cb62009-06-26 02:51:07 +0000734 BUG_ON(j > MAX_SKB_FRAGS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700735
Sathya Perla76fbb422009-06-10 02:21:56 +0000736done:
Sathya Perla4097f662009-03-24 16:40:13 -0700737 be_rx_stats_update(adapter, pktsize, num_rcvd);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700738 return;
739}
740
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700741/* Process the RX completion indicated by rxcp when GRO is disabled */
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700742static void be_rx_compl_process(struct be_adapter *adapter,
743 struct be_eth_rx_compl *rxcp)
744{
745 struct sk_buff *skb;
746 u32 vtp, vid;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700747
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700748 vtp = AMAP_GET_BITS(struct amap_eth_rx_compl, vtp, rxcp);
749
750 skb = netdev_alloc_skb(adapter->netdev, BE_HDR_LEN + NET_IP_ALIGN);
751 if (!skb) {
752 if (net_ratelimit())
753 dev_warn(&adapter->pdev->dev, "skb alloc failed\n");
754 be_rx_compl_discard(adapter, rxcp);
755 return;
756 }
757
758 skb_reserve(skb, NET_IP_ALIGN);
759
760 skb_fill_rx_data(adapter, skb, rxcp);
761
Ajit Khaparde728a9972009-04-13 15:41:22 -0700762 if (do_pkt_csum(rxcp, adapter->rx_csum))
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700763 skb->ip_summed = CHECKSUM_NONE;
Ajit Khaparde728a9972009-04-13 15:41:22 -0700764 else
765 skb->ip_summed = CHECKSUM_UNNECESSARY;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700766
767 skb->truesize = skb->len + sizeof(struct sk_buff);
768 skb->protocol = eth_type_trans(skb, adapter->netdev);
769 skb->dev = adapter->netdev;
770
771 if (vtp) {
772 if (!adapter->vlan_grp || adapter->num_vlans == 0) {
773 kfree_skb(skb);
774 return;
775 }
776 vid = AMAP_GET_BITS(struct amap_eth_rx_compl, vlan_tag, rxcp);
777 vid = be16_to_cpu(vid);
778 vlan_hwaccel_receive_skb(skb, adapter->vlan_grp, vid);
779 } else {
780 netif_receive_skb(skb);
781 }
782
783 adapter->netdev->last_rx = jiffies;
784
785 return;
786}
787
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700788/* Process the RX completion indicated by rxcp when GRO is enabled */
789static void be_rx_compl_process_gro(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700790 struct be_eth_rx_compl *rxcp)
791{
792 struct be_rx_page_info *page_info;
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700793 struct sk_buff *skb = NULL;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700794 struct be_queue_info *rxq = &adapter->rx_obj.q;
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700795 struct be_eq_obj *eq_obj = &adapter->rx_eq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700796 u32 num_rcvd, pkt_size, remaining, vlanf, curr_frag_len;
Ajit Khapardebd46cb62009-06-26 02:51:07 +0000797 u16 i, rxq_idx = 0, vid, j;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700798
799 num_rcvd = AMAP_GET_BITS(struct amap_eth_rx_compl, numfrags, rxcp);
800 pkt_size = AMAP_GET_BITS(struct amap_eth_rx_compl, pktsize, rxcp);
801 vlanf = AMAP_GET_BITS(struct amap_eth_rx_compl, vtp, rxcp);
802 rxq_idx = AMAP_GET_BITS(struct amap_eth_rx_compl, fragndx, rxcp);
803
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700804 skb = napi_get_frags(&eq_obj->napi);
805 if (!skb) {
806 be_rx_compl_discard(adapter, rxcp);
807 return;
808 }
809
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700810 remaining = pkt_size;
Ajit Khapardebd46cb62009-06-26 02:51:07 +0000811 for (i = 0, j = -1; i < num_rcvd; i++) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700812 page_info = get_rx_page_info(adapter, rxq_idx);
813
814 curr_frag_len = min(remaining, rx_frag_size);
815
Ajit Khapardebd46cb62009-06-26 02:51:07 +0000816 /* Coalesce all frags from the same physical page in one slot */
817 if (i == 0 || page_info->page_offset == 0) {
818 /* First frag or Fresh page */
819 j++;
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700820 skb_shinfo(skb)->frags[j].page = page_info->page;
821 skb_shinfo(skb)->frags[j].page_offset =
822 page_info->page_offset;
823 skb_shinfo(skb)->frags[j].size = 0;
Ajit Khapardebd46cb62009-06-26 02:51:07 +0000824 } else {
825 put_page(page_info->page);
826 }
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700827 skb_shinfo(skb)->frags[j].size += curr_frag_len;
Ajit Khapardebd46cb62009-06-26 02:51:07 +0000828
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700829 remaining -= curr_frag_len;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700830 index_inc(&rxq_idx, rxq->len);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700831 memset(page_info, 0, sizeof(*page_info));
832 }
Ajit Khapardebd46cb62009-06-26 02:51:07 +0000833 BUG_ON(j > MAX_SKB_FRAGS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700834
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700835 skb_shinfo(skb)->nr_frags = j + 1;
836 skb->len = pkt_size;
837 skb->data_len = pkt_size;
838 skb->truesize += pkt_size;
839 skb->ip_summed = CHECKSUM_UNNECESSARY;
840
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700841 if (likely(!vlanf)) {
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700842 napi_gro_frags(&eq_obj->napi);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700843 } else {
844 vid = AMAP_GET_BITS(struct amap_eth_rx_compl, vlan_tag, rxcp);
845 vid = be16_to_cpu(vid);
846
847 if (!adapter->vlan_grp || adapter->num_vlans == 0)
848 return;
849
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700850 vlan_gro_frags(&eq_obj->napi, adapter->vlan_grp, vid);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700851 }
852
Sathya Perla4097f662009-03-24 16:40:13 -0700853 be_rx_stats_update(adapter, pkt_size, num_rcvd);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700854 return;
855}
856
857static struct be_eth_rx_compl *be_rx_compl_get(struct be_adapter *adapter)
858{
859 struct be_eth_rx_compl *rxcp = queue_tail_node(&adapter->rx_obj.cq);
860
861 if (rxcp->dw[offsetof(struct amap_eth_rx_compl, valid) / 32] == 0)
862 return NULL;
863
864 be_dws_le_to_cpu(rxcp, sizeof(*rxcp));
865
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700866 queue_tail_inc(&adapter->rx_obj.cq);
867 return rxcp;
868}
869
Sathya Perlaa7a0ef32009-06-10 02:23:28 +0000870/* To reset the valid bit, we need to reset the whole word as
871 * when walking the queue the valid entries are little-endian
872 * and invalid entries are host endian
873 */
874static inline void be_rx_compl_reset(struct be_eth_rx_compl *rxcp)
875{
876 rxcp->dw[offsetof(struct amap_eth_rx_compl, valid) / 32] = 0;
877}
878
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700879static inline struct page *be_alloc_pages(u32 size)
880{
881 gfp_t alloc_flags = GFP_ATOMIC;
882 u32 order = get_order(size);
883 if (order > 0)
884 alloc_flags |= __GFP_COMP;
885 return alloc_pages(alloc_flags, order);
886}
887
888/*
889 * Allocate a page, split it to fragments of size rx_frag_size and post as
890 * receive buffers to BE
891 */
892static void be_post_rx_frags(struct be_adapter *adapter)
893{
894 struct be_rx_page_info *page_info_tbl = adapter->rx_obj.page_info_tbl;
895 struct be_rx_page_info *page_info = NULL;
896 struct be_queue_info *rxq = &adapter->rx_obj.q;
897 struct page *pagep = NULL;
898 struct be_eth_rx_d *rxd;
899 u64 page_dmaaddr = 0, frag_dmaaddr;
900 u32 posted, page_offset = 0;
901
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700902 page_info = &page_info_tbl[rxq->head];
903 for (posted = 0; posted < MAX_RX_POST && !page_info->page; posted++) {
904 if (!pagep) {
905 pagep = be_alloc_pages(adapter->big_page_size);
906 if (unlikely(!pagep)) {
907 drvr_stats(adapter)->be_ethrx_post_fail++;
908 break;
909 }
910 page_dmaaddr = pci_map_page(adapter->pdev, pagep, 0,
911 adapter->big_page_size,
912 PCI_DMA_FROMDEVICE);
913 page_info->page_offset = 0;
914 } else {
915 get_page(pagep);
916 page_info->page_offset = page_offset + rx_frag_size;
917 }
918 page_offset = page_info->page_offset;
919 page_info->page = pagep;
920 pci_unmap_addr_set(page_info, bus, page_dmaaddr);
921 frag_dmaaddr = page_dmaaddr + page_info->page_offset;
922
923 rxd = queue_head_node(rxq);
924 rxd->fragpa_lo = cpu_to_le32(frag_dmaaddr & 0xFFFFFFFF);
925 rxd->fragpa_hi = cpu_to_le32(upper_32_bits(frag_dmaaddr));
926 queue_head_inc(rxq);
927
928 /* Any space left in the current big page for another frag? */
929 if ((page_offset + rx_frag_size + rx_frag_size) >
930 adapter->big_page_size) {
931 pagep = NULL;
932 page_info->last_page_user = true;
933 }
934 page_info = &page_info_tbl[rxq->head];
935 }
936 if (pagep)
937 page_info->last_page_user = true;
938
939 if (posted) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700940 atomic_add(posted, &rxq->used);
Sathya Perla8788fdc2009-07-27 22:52:03 +0000941 be_rxq_notify(adapter, rxq->id, posted);
Sathya Perlaea1dae12009-03-19 23:56:20 -0700942 } else if (atomic_read(&rxq->used) == 0) {
943 /* Let be_worker replenish when memory is available */
944 adapter->rx_post_starved = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700945 }
946
947 return;
948}
949
Sathya Perla5fb379e2009-06-18 00:02:59 +0000950static struct be_eth_tx_compl *be_tx_compl_get(struct be_queue_info *tx_cq)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700951{
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700952 struct be_eth_tx_compl *txcp = queue_tail_node(tx_cq);
953
954 if (txcp->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] == 0)
955 return NULL;
956
957 be_dws_le_to_cpu(txcp, sizeof(*txcp));
958
959 txcp->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] = 0;
960
961 queue_tail_inc(tx_cq);
962 return txcp;
963}
964
965static void be_tx_compl_process(struct be_adapter *adapter, u16 last_index)
966{
967 struct be_queue_info *txq = &adapter->tx_obj.q;
968 struct be_eth_wrb *wrb;
969 struct sk_buff **sent_skbs = adapter->tx_obj.sent_skb_list;
970 struct sk_buff *sent_skb;
971 u64 busaddr;
972 u16 cur_index, num_wrbs = 0;
973
974 cur_index = txq->tail;
975 sent_skb = sent_skbs[cur_index];
976 BUG_ON(!sent_skb);
977 sent_skbs[cur_index] = NULL;
978
979 do {
980 cur_index = txq->tail;
981 wrb = queue_tail_node(txq);
982 be_dws_le_to_cpu(wrb, sizeof(*wrb));
983 busaddr = ((u64)wrb->frag_pa_hi << 32) | (u64)wrb->frag_pa_lo;
984 if (busaddr != 0) {
985 pci_unmap_single(adapter->pdev, busaddr,
986 wrb->frag_len, PCI_DMA_TODEVICE);
987 }
988 num_wrbs++;
989 queue_tail_inc(txq);
990 } while (cur_index != last_index);
991
992 atomic_sub(num_wrbs, &txq->used);
993
994 kfree_skb(sent_skb);
995}
996
997static void be_rx_q_clean(struct be_adapter *adapter)
998{
999 struct be_rx_page_info *page_info;
1000 struct be_queue_info *rxq = &adapter->rx_obj.q;
1001 struct be_queue_info *rx_cq = &adapter->rx_obj.cq;
1002 struct be_eth_rx_compl *rxcp;
1003 u16 tail;
1004
1005 /* First cleanup pending rx completions */
1006 while ((rxcp = be_rx_compl_get(adapter)) != NULL) {
1007 be_rx_compl_discard(adapter, rxcp);
Sathya Perlaa7a0ef32009-06-10 02:23:28 +00001008 be_rx_compl_reset(rxcp);
Sathya Perla8788fdc2009-07-27 22:52:03 +00001009 be_cq_notify(adapter, rx_cq->id, true, 1);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001010 }
1011
1012 /* Then free posted rx buffer that were not used */
1013 tail = (rxq->head + rxq->len - atomic_read(&rxq->used)) % rxq->len;
1014 for (; tail != rxq->head; index_inc(&tail, rxq->len)) {
1015 page_info = get_rx_page_info(adapter, tail);
1016 put_page(page_info->page);
1017 memset(page_info, 0, sizeof(*page_info));
1018 }
1019 BUG_ON(atomic_read(&rxq->used));
1020}
1021
1022static void be_tx_q_clean(struct be_adapter *adapter)
1023{
1024 struct sk_buff **sent_skbs = adapter->tx_obj.sent_skb_list;
1025 struct sk_buff *sent_skb;
1026 struct be_queue_info *txq = &adapter->tx_obj.q;
1027 u16 last_index;
1028 bool dummy_wrb;
1029
1030 while (atomic_read(&txq->used)) {
1031 sent_skb = sent_skbs[txq->tail];
1032 last_index = txq->tail;
1033 index_adv(&last_index,
1034 wrb_cnt_for_skb(sent_skb, &dummy_wrb) - 1, txq->len);
1035 be_tx_compl_process(adapter, last_index);
1036 }
1037}
1038
Sathya Perla5fb379e2009-06-18 00:02:59 +00001039static void be_mcc_queues_destroy(struct be_adapter *adapter)
1040{
1041 struct be_queue_info *q;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001042
Sathya Perla8788fdc2009-07-27 22:52:03 +00001043 q = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001044 if (q->created)
Sathya Perla8788fdc2009-07-27 22:52:03 +00001045 be_cmd_q_destroy(adapter, q, QTYPE_MCCQ);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001046 be_queue_free(adapter, q);
1047
Sathya Perla8788fdc2009-07-27 22:52:03 +00001048 q = &adapter->mcc_obj.cq;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001049 if (q->created)
Sathya Perla8788fdc2009-07-27 22:52:03 +00001050 be_cmd_q_destroy(adapter, q, QTYPE_CQ);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001051 be_queue_free(adapter, q);
1052}
1053
1054/* Must be called only after TX qs are created as MCC shares TX EQ */
1055static int be_mcc_queues_create(struct be_adapter *adapter)
1056{
1057 struct be_queue_info *q, *cq;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001058
1059 /* Alloc MCC compl queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001060 cq = &adapter->mcc_obj.cq;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001061 if (be_queue_alloc(adapter, cq, MCC_CQ_LEN,
1062 sizeof(struct be_mcc_cq_entry)))
1063 goto err;
1064
1065 /* Ask BE to create MCC compl queue; share TX's eq */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001066 if (be_cmd_cq_create(adapter, cq, &adapter->tx_eq.q, false, true, 0))
Sathya Perla5fb379e2009-06-18 00:02:59 +00001067 goto mcc_cq_free;
1068
1069 /* Alloc MCC queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001070 q = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001071 if (be_queue_alloc(adapter, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
1072 goto mcc_cq_destroy;
1073
1074 /* Ask BE to create MCC queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001075 if (be_cmd_mccq_create(adapter, q, cq))
Sathya Perla5fb379e2009-06-18 00:02:59 +00001076 goto mcc_q_free;
1077
1078 return 0;
1079
1080mcc_q_free:
1081 be_queue_free(adapter, q);
1082mcc_cq_destroy:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001083 be_cmd_q_destroy(adapter, cq, QTYPE_CQ);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001084mcc_cq_free:
1085 be_queue_free(adapter, cq);
1086err:
1087 return -1;
1088}
1089
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001090static void be_tx_queues_destroy(struct be_adapter *adapter)
1091{
1092 struct be_queue_info *q;
1093
1094 q = &adapter->tx_obj.q;
Sathya Perla934037b2009-06-10 02:23:50 +00001095 if (q->created) {
Sathya Perla8788fdc2009-07-27 22:52:03 +00001096 be_cmd_q_destroy(adapter, q, QTYPE_TXQ);
Sathya Perla934037b2009-06-10 02:23:50 +00001097
1098 /* No more tx completions can be rcvd now; clean up if there
1099 * are any pending completions or pending tx requests */
1100 be_tx_q_clean(adapter);
1101 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001102 be_queue_free(adapter, q);
1103
1104 q = &adapter->tx_obj.cq;
1105 if (q->created)
Sathya Perla8788fdc2009-07-27 22:52:03 +00001106 be_cmd_q_destroy(adapter, q, QTYPE_CQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001107 be_queue_free(adapter, q);
1108
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001109 q = &adapter->tx_eq.q;
1110 if (q->created)
Sathya Perla8788fdc2009-07-27 22:52:03 +00001111 be_cmd_q_destroy(adapter, q, QTYPE_EQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001112 be_queue_free(adapter, q);
1113}
1114
1115static int be_tx_queues_create(struct be_adapter *adapter)
1116{
1117 struct be_queue_info *eq, *q, *cq;
1118
1119 adapter->tx_eq.max_eqd = 0;
1120 adapter->tx_eq.min_eqd = 0;
1121 adapter->tx_eq.cur_eqd = 96;
1122 adapter->tx_eq.enable_aic = false;
1123 /* Alloc Tx Event queue */
1124 eq = &adapter->tx_eq.q;
1125 if (be_queue_alloc(adapter, eq, EVNT_Q_LEN, sizeof(struct be_eq_entry)))
1126 return -1;
1127
1128 /* Ask BE to create Tx Event queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001129 if (be_cmd_eq_create(adapter, eq, adapter->tx_eq.cur_eqd))
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001130 goto tx_eq_free;
1131 /* Alloc TX eth compl queue */
1132 cq = &adapter->tx_obj.cq;
1133 if (be_queue_alloc(adapter, cq, TX_CQ_LEN,
1134 sizeof(struct be_eth_tx_compl)))
1135 goto tx_eq_destroy;
1136
1137 /* Ask BE to create Tx eth compl queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001138 if (be_cmd_cq_create(adapter, cq, eq, false, false, 3))
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001139 goto tx_cq_free;
1140
1141 /* Alloc TX eth queue */
1142 q = &adapter->tx_obj.q;
1143 if (be_queue_alloc(adapter, q, TX_Q_LEN, sizeof(struct be_eth_wrb)))
1144 goto tx_cq_destroy;
1145
1146 /* Ask BE to create Tx eth queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001147 if (be_cmd_txq_create(adapter, q, cq))
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001148 goto tx_q_free;
1149 return 0;
1150
1151tx_q_free:
1152 be_queue_free(adapter, q);
1153tx_cq_destroy:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001154 be_cmd_q_destroy(adapter, cq, QTYPE_CQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001155tx_cq_free:
1156 be_queue_free(adapter, cq);
1157tx_eq_destroy:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001158 be_cmd_q_destroy(adapter, eq, QTYPE_EQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001159tx_eq_free:
1160 be_queue_free(adapter, eq);
1161 return -1;
1162}
1163
1164static void be_rx_queues_destroy(struct be_adapter *adapter)
1165{
1166 struct be_queue_info *q;
1167
1168 q = &adapter->rx_obj.q;
1169 if (q->created) {
Sathya Perla8788fdc2009-07-27 22:52:03 +00001170 be_cmd_q_destroy(adapter, q, QTYPE_RXQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001171 be_rx_q_clean(adapter);
1172 }
1173 be_queue_free(adapter, q);
1174
1175 q = &adapter->rx_obj.cq;
1176 if (q->created)
Sathya Perla8788fdc2009-07-27 22:52:03 +00001177 be_cmd_q_destroy(adapter, q, QTYPE_CQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001178 be_queue_free(adapter, q);
1179
1180 q = &adapter->rx_eq.q;
1181 if (q->created)
Sathya Perla8788fdc2009-07-27 22:52:03 +00001182 be_cmd_q_destroy(adapter, q, QTYPE_EQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001183 be_queue_free(adapter, q);
1184}
1185
1186static int be_rx_queues_create(struct be_adapter *adapter)
1187{
1188 struct be_queue_info *eq, *q, *cq;
1189 int rc;
1190
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001191 adapter->big_page_size = (1 << get_order(rx_frag_size)) * PAGE_SIZE;
1192 adapter->rx_eq.max_eqd = BE_MAX_EQD;
1193 adapter->rx_eq.min_eqd = 0;
1194 adapter->rx_eq.cur_eqd = 0;
1195 adapter->rx_eq.enable_aic = true;
1196
1197 /* Alloc Rx Event queue */
1198 eq = &adapter->rx_eq.q;
1199 rc = be_queue_alloc(adapter, eq, EVNT_Q_LEN,
1200 sizeof(struct be_eq_entry));
1201 if (rc)
1202 return rc;
1203
1204 /* Ask BE to create Rx Event queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001205 rc = be_cmd_eq_create(adapter, eq, adapter->rx_eq.cur_eqd);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001206 if (rc)
1207 goto rx_eq_free;
1208
1209 /* Alloc RX eth compl queue */
1210 cq = &adapter->rx_obj.cq;
1211 rc = be_queue_alloc(adapter, cq, RX_CQ_LEN,
1212 sizeof(struct be_eth_rx_compl));
1213 if (rc)
1214 goto rx_eq_destroy;
1215
1216 /* Ask BE to create Rx eth compl queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001217 rc = be_cmd_cq_create(adapter, cq, eq, false, false, 3);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001218 if (rc)
1219 goto rx_cq_free;
1220
1221 /* Alloc RX eth queue */
1222 q = &adapter->rx_obj.q;
1223 rc = be_queue_alloc(adapter, q, RX_Q_LEN, sizeof(struct be_eth_rx_d));
1224 if (rc)
1225 goto rx_cq_destroy;
1226
1227 /* Ask BE to create Rx eth queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001228 rc = be_cmd_rxq_create(adapter, q, cq->id, rx_frag_size,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001229 BE_MAX_JUMBO_FRAME_SIZE, adapter->if_handle, false);
1230 if (rc)
1231 goto rx_q_free;
1232
1233 return 0;
1234rx_q_free:
1235 be_queue_free(adapter, q);
1236rx_cq_destroy:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001237 be_cmd_q_destroy(adapter, cq, QTYPE_CQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001238rx_cq_free:
1239 be_queue_free(adapter, cq);
1240rx_eq_destroy:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001241 be_cmd_q_destroy(adapter, eq, QTYPE_EQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001242rx_eq_free:
1243 be_queue_free(adapter, eq);
1244 return rc;
1245}
1246static bool event_get(struct be_eq_obj *eq_obj, u16 *rid)
1247{
1248 struct be_eq_entry *entry = queue_tail_node(&eq_obj->q);
1249 u32 evt = entry->evt;
1250
1251 if (!evt)
1252 return false;
1253
1254 evt = le32_to_cpu(evt);
1255 *rid = (evt >> EQ_ENTRY_RES_ID_SHIFT) & EQ_ENTRY_RES_ID_MASK;
1256 entry->evt = 0;
1257 queue_tail_inc(&eq_obj->q);
1258 return true;
1259}
1260
Sathya Perla8788fdc2009-07-27 22:52:03 +00001261static int event_handle(struct be_adapter *adapter, struct be_eq_obj *eq_obj)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001262{
1263 u16 rid = 0, num = 0;
1264
1265 while (event_get(eq_obj, &rid))
1266 num++;
1267
1268 /* We can see an interrupt and no event */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001269 be_eq_notify(adapter, eq_obj->q.id, true, true, num);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001270 if (num)
1271 napi_schedule(&eq_obj->napi);
1272
1273 return num;
1274}
1275
1276static irqreturn_t be_intx(int irq, void *dev)
1277{
1278 struct be_adapter *adapter = dev;
Sathya Perla8788fdc2009-07-27 22:52:03 +00001279 int isr;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001280
Sathya Perla8788fdc2009-07-27 22:52:03 +00001281 isr = ioread32(adapter->csr + CEV_ISR0_OFFSET +
Sathya Perlaeec368f2009-07-27 22:52:23 +00001282 be_pci_func(adapter) * CEV_ISR_SIZE);
Sathya Perlac001c212009-07-01 01:06:07 +00001283 if (!isr)
Sathya Perla8788fdc2009-07-27 22:52:03 +00001284 return IRQ_NONE;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001285
Sathya Perla8788fdc2009-07-27 22:52:03 +00001286 event_handle(adapter, &adapter->tx_eq);
1287 event_handle(adapter, &adapter->rx_eq);
Sathya Perlac001c212009-07-01 01:06:07 +00001288
Sathya Perla8788fdc2009-07-27 22:52:03 +00001289 return IRQ_HANDLED;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001290}
1291
1292static irqreturn_t be_msix_rx(int irq, void *dev)
1293{
1294 struct be_adapter *adapter = dev;
1295
Sathya Perla8788fdc2009-07-27 22:52:03 +00001296 event_handle(adapter, &adapter->rx_eq);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001297
1298 return IRQ_HANDLED;
1299}
1300
Sathya Perla5fb379e2009-06-18 00:02:59 +00001301static irqreturn_t be_msix_tx_mcc(int irq, void *dev)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001302{
1303 struct be_adapter *adapter = dev;
1304
Sathya Perla8788fdc2009-07-27 22:52:03 +00001305 event_handle(adapter, &adapter->tx_eq);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001306
1307 return IRQ_HANDLED;
1308}
1309
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001310static inline bool do_gro(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001311 struct be_eth_rx_compl *rxcp)
1312{
1313 int err = AMAP_GET_BITS(struct amap_eth_rx_compl, err, rxcp);
1314 int tcp_frame = AMAP_GET_BITS(struct amap_eth_rx_compl, tcpf, rxcp);
1315
1316 if (err)
1317 drvr_stats(adapter)->be_rxcp_err++;
1318
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001319 return (tcp_frame && !err) ? true : false;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001320}
1321
1322int be_poll_rx(struct napi_struct *napi, int budget)
1323{
1324 struct be_eq_obj *rx_eq = container_of(napi, struct be_eq_obj, napi);
1325 struct be_adapter *adapter =
1326 container_of(rx_eq, struct be_adapter, rx_eq);
1327 struct be_queue_info *rx_cq = &adapter->rx_obj.cq;
1328 struct be_eth_rx_compl *rxcp;
1329 u32 work_done;
1330
1331 for (work_done = 0; work_done < budget; work_done++) {
1332 rxcp = be_rx_compl_get(adapter);
1333 if (!rxcp)
1334 break;
1335
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001336 if (do_gro(adapter, rxcp))
1337 be_rx_compl_process_gro(adapter, rxcp);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001338 else
1339 be_rx_compl_process(adapter, rxcp);
Sathya Perlaa7a0ef32009-06-10 02:23:28 +00001340
1341 be_rx_compl_reset(rxcp);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001342 }
1343
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001344 /* Refill the queue */
1345 if (atomic_read(&adapter->rx_obj.q.used) < RX_FRAGS_REFILL_WM)
1346 be_post_rx_frags(adapter);
1347
1348 /* All consumed */
1349 if (work_done < budget) {
1350 napi_complete(napi);
Sathya Perla8788fdc2009-07-27 22:52:03 +00001351 be_cq_notify(adapter, rx_cq->id, true, work_done);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001352 } else {
1353 /* More to be consumed; continue with interrupts disabled */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001354 be_cq_notify(adapter, rx_cq->id, false, work_done);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001355 }
1356 return work_done;
1357}
1358
Sathya Perla5fb379e2009-06-18 00:02:59 +00001359void be_process_tx(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001360{
Sathya Perla5fb379e2009-06-18 00:02:59 +00001361 struct be_queue_info *txq = &adapter->tx_obj.q;
1362 struct be_queue_info *tx_cq = &adapter->tx_obj.cq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001363 struct be_eth_tx_compl *txcp;
1364 u32 num_cmpl = 0;
1365 u16 end_idx;
1366
Sathya Perla5fb379e2009-06-18 00:02:59 +00001367 while ((txcp = be_tx_compl_get(tx_cq))) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001368 end_idx = AMAP_GET_BITS(struct amap_eth_tx_compl,
1369 wrb_index, txcp);
1370 be_tx_compl_process(adapter, end_idx);
1371 num_cmpl++;
1372 }
1373
Sathya Perla5fb379e2009-06-18 00:02:59 +00001374 if (num_cmpl) {
Sathya Perla8788fdc2009-07-27 22:52:03 +00001375 be_cq_notify(adapter, tx_cq->id, true, num_cmpl);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001376
1377 /* As Tx wrbs have been freed up, wake up netdev queue if
1378 * it was stopped due to lack of tx wrbs.
1379 */
1380 if (netif_queue_stopped(adapter->netdev) &&
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001381 atomic_read(&txq->used) < txq->len / 2) {
Sathya Perla5fb379e2009-06-18 00:02:59 +00001382 netif_wake_queue(adapter->netdev);
1383 }
1384
1385 drvr_stats(adapter)->be_tx_events++;
1386 drvr_stats(adapter)->be_tx_compl += num_cmpl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001387 }
Sathya Perla5fb379e2009-06-18 00:02:59 +00001388}
1389
1390/* As TX and MCC share the same EQ check for both TX and MCC completions.
1391 * For TX/MCC we don't honour budget; consume everything
1392 */
1393static int be_poll_tx_mcc(struct napi_struct *napi, int budget)
1394{
1395 struct be_eq_obj *tx_eq = container_of(napi, struct be_eq_obj, napi);
1396 struct be_adapter *adapter =
1397 container_of(tx_eq, struct be_adapter, tx_eq);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001398
1399 napi_complete(napi);
1400
Sathya Perla5fb379e2009-06-18 00:02:59 +00001401 be_process_tx(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001402
Sathya Perla8788fdc2009-07-27 22:52:03 +00001403 be_process_mcc(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001404
1405 return 1;
1406}
1407
Sathya Perlaea1dae12009-03-19 23:56:20 -07001408static void be_worker(struct work_struct *work)
1409{
1410 struct be_adapter *adapter =
1411 container_of(work, struct be_adapter, work.work);
1412 int status;
1413
Sathya Perlaea1dae12009-03-19 23:56:20 -07001414 /* Get Stats */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001415 status = be_cmd_get_stats(adapter, &adapter->stats.cmd);
Sathya Perlaea1dae12009-03-19 23:56:20 -07001416 if (!status)
1417 netdev_stats_update(adapter);
1418
1419 /* Set EQ delay */
1420 be_rx_eqd_update(adapter);
1421
Sathya Perla4097f662009-03-24 16:40:13 -07001422 be_tx_rate_update(adapter);
1423 be_rx_rate_update(adapter);
1424
Sathya Perlaea1dae12009-03-19 23:56:20 -07001425 if (adapter->rx_post_starved) {
1426 adapter->rx_post_starved = false;
1427 be_post_rx_frags(adapter);
1428 }
1429
1430 schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000));
1431}
1432
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001433static void be_msix_enable(struct be_adapter *adapter)
1434{
1435 int i, status;
1436
1437 for (i = 0; i < BE_NUM_MSIX_VECTORS; i++)
1438 adapter->msix_entries[i].entry = i;
1439
1440 status = pci_enable_msix(adapter->pdev, adapter->msix_entries,
1441 BE_NUM_MSIX_VECTORS);
1442 if (status == 0)
1443 adapter->msix_enabled = true;
1444 return;
1445}
1446
1447static inline int be_msix_vec_get(struct be_adapter *adapter, u32 eq_id)
1448{
Sathya Perlaeec368f2009-07-27 22:52:23 +00001449 return adapter->msix_entries[eq_id - 8 * be_pci_func(adapter)].vector;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001450}
1451
1452static int be_msix_register(struct be_adapter *adapter)
1453{
1454 struct net_device *netdev = adapter->netdev;
1455 struct be_eq_obj *tx_eq = &adapter->tx_eq;
1456 struct be_eq_obj *rx_eq = &adapter->rx_eq;
1457 int status, vec;
1458
1459 sprintf(tx_eq->desc, "%s-tx", netdev->name);
1460 vec = be_msix_vec_get(adapter, tx_eq->q.id);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001461 status = request_irq(vec, be_msix_tx_mcc, 0, tx_eq->desc, adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001462 if (status)
1463 goto err;
1464
1465 sprintf(rx_eq->desc, "%s-rx", netdev->name);
1466 vec = be_msix_vec_get(adapter, rx_eq->q.id);
1467 status = request_irq(vec, be_msix_rx, 0, rx_eq->desc, adapter);
1468 if (status) { /* Free TX IRQ */
1469 vec = be_msix_vec_get(adapter, tx_eq->q.id);
1470 free_irq(vec, adapter);
1471 goto err;
1472 }
1473 return 0;
1474err:
1475 dev_warn(&adapter->pdev->dev,
1476 "MSIX Request IRQ failed - err %d\n", status);
1477 pci_disable_msix(adapter->pdev);
1478 adapter->msix_enabled = false;
1479 return status;
1480}
1481
1482static int be_irq_register(struct be_adapter *adapter)
1483{
1484 struct net_device *netdev = adapter->netdev;
1485 int status;
1486
1487 if (adapter->msix_enabled) {
1488 status = be_msix_register(adapter);
1489 if (status == 0)
1490 goto done;
1491 }
1492
1493 /* INTx */
1494 netdev->irq = adapter->pdev->irq;
1495 status = request_irq(netdev->irq, be_intx, IRQF_SHARED, netdev->name,
1496 adapter);
1497 if (status) {
1498 dev_err(&adapter->pdev->dev,
1499 "INTx request IRQ failed - err %d\n", status);
1500 return status;
1501 }
1502done:
1503 adapter->isr_registered = true;
1504 return 0;
1505}
1506
1507static void be_irq_unregister(struct be_adapter *adapter)
1508{
1509 struct net_device *netdev = adapter->netdev;
1510 int vec;
1511
1512 if (!adapter->isr_registered)
1513 return;
1514
1515 /* INTx */
1516 if (!adapter->msix_enabled) {
1517 free_irq(netdev->irq, adapter);
1518 goto done;
1519 }
1520
1521 /* MSIx */
1522 vec = be_msix_vec_get(adapter, adapter->tx_eq.q.id);
1523 free_irq(vec, adapter);
1524 vec = be_msix_vec_get(adapter, adapter->rx_eq.q.id);
1525 free_irq(vec, adapter);
1526done:
1527 adapter->isr_registered = false;
1528 return;
1529}
1530
1531static int be_open(struct net_device *netdev)
1532{
1533 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001534 struct be_eq_obj *rx_eq = &adapter->rx_eq;
1535 struct be_eq_obj *tx_eq = &adapter->tx_eq;
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001536 bool link_up;
1537 int status;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001538
1539 /* First time posting */
1540 be_post_rx_frags(adapter);
1541
1542 napi_enable(&rx_eq->napi);
1543 napi_enable(&tx_eq->napi);
1544
1545 be_irq_register(adapter);
1546
Sathya Perla8788fdc2009-07-27 22:52:03 +00001547 be_intr_set(adapter, true);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001548
1549 /* The evt queues are created in unarmed state; arm them */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001550 be_eq_notify(adapter, rx_eq->q.id, true, false, 0);
1551 be_eq_notify(adapter, tx_eq->q.id, true, false, 0);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001552
1553 /* Rx compl queue may be in unarmed state; rearm it */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001554 be_cq_notify(adapter, adapter->rx_obj.cq.id, true, 0);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001555
Sathya Perla8788fdc2009-07-27 22:52:03 +00001556 status = be_cmd_link_status_query(adapter, &link_up);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001557 if (status)
1558 return status;
1559 be_link_status_update(adapter, link_up);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001560
1561 schedule_delayed_work(&adapter->work, msecs_to_jiffies(100));
1562 return 0;
1563}
1564
1565static int be_setup(struct be_adapter *adapter)
1566{
Sathya Perla5fb379e2009-06-18 00:02:59 +00001567 struct net_device *netdev = adapter->netdev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001568 u32 if_flags;
1569 int status;
1570
1571 if_flags = BE_IF_FLAGS_BROADCAST | BE_IF_FLAGS_PROMISCUOUS |
1572 BE_IF_FLAGS_MCAST_PROMISCUOUS | BE_IF_FLAGS_UNTAGGED |
1573 BE_IF_FLAGS_PASS_L3L4_ERRORS;
Sathya Perla8788fdc2009-07-27 22:52:03 +00001574 status = be_cmd_if_create(adapter, if_flags, netdev->dev_addr,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001575 false/* pmac_invalid */, &adapter->if_handle,
1576 &adapter->pmac_id);
1577 if (status != 0)
1578 goto do_none;
1579
Sathya Perla1ab1ab72009-03-19 23:56:46 -07001580 be_vid_config(netdev);
1581
Sathya Perla8788fdc2009-07-27 22:52:03 +00001582 status = be_cmd_set_flow_control(adapter, true, true);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001583 if (status != 0)
1584 goto if_destroy;
1585
1586 status = be_tx_queues_create(adapter);
1587 if (status != 0)
1588 goto if_destroy;
1589
1590 status = be_rx_queues_create(adapter);
1591 if (status != 0)
1592 goto tx_qs_destroy;
1593
Sathya Perla5fb379e2009-06-18 00:02:59 +00001594 status = be_mcc_queues_create(adapter);
1595 if (status != 0)
1596 goto rx_qs_destroy;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001597
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001598 return 0;
1599
Sathya Perla5fb379e2009-06-18 00:02:59 +00001600rx_qs_destroy:
1601 be_rx_queues_destroy(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001602tx_qs_destroy:
1603 be_tx_queues_destroy(adapter);
1604if_destroy:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001605 be_cmd_if_destroy(adapter, adapter->if_handle);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001606do_none:
1607 return status;
1608}
1609
Sathya Perla5fb379e2009-06-18 00:02:59 +00001610static int be_clear(struct be_adapter *adapter)
1611{
Sathya Perla5fb379e2009-06-18 00:02:59 +00001612 be_rx_queues_destroy(adapter);
1613 be_tx_queues_destroy(adapter);
1614
Sathya Perla8788fdc2009-07-27 22:52:03 +00001615 be_cmd_if_destroy(adapter, adapter->if_handle);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001616
1617 be_mcc_queues_destroy(adapter);
1618 return 0;
1619}
1620
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001621static int be_close(struct net_device *netdev)
1622{
1623 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001624 struct be_eq_obj *rx_eq = &adapter->rx_eq;
1625 struct be_eq_obj *tx_eq = &adapter->tx_eq;
1626 int vec;
1627
Sathya Perlab305be72009-06-10 02:18:35 +00001628 cancel_delayed_work_sync(&adapter->work);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001629
1630 netif_stop_queue(netdev);
1631 netif_carrier_off(netdev);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001632 adapter->link_up = false;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001633
Sathya Perla8788fdc2009-07-27 22:52:03 +00001634 be_intr_set(adapter, false);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001635
1636 if (adapter->msix_enabled) {
1637 vec = be_msix_vec_get(adapter, tx_eq->q.id);
1638 synchronize_irq(vec);
1639 vec = be_msix_vec_get(adapter, rx_eq->q.id);
1640 synchronize_irq(vec);
1641 } else {
1642 synchronize_irq(netdev->irq);
1643 }
1644 be_irq_unregister(adapter);
1645
1646 napi_disable(&rx_eq->napi);
1647 napi_disable(&tx_eq->napi);
1648
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001649 return 0;
1650}
1651
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001652static struct net_device_ops be_netdev_ops = {
1653 .ndo_open = be_open,
1654 .ndo_stop = be_close,
1655 .ndo_start_xmit = be_xmit,
1656 .ndo_get_stats = be_get_stats,
1657 .ndo_set_rx_mode = be_set_multicast_list,
1658 .ndo_set_mac_address = be_mac_addr_set,
1659 .ndo_change_mtu = be_change_mtu,
1660 .ndo_validate_addr = eth_validate_addr,
1661 .ndo_vlan_rx_register = be_vlan_register,
1662 .ndo_vlan_rx_add_vid = be_vlan_add_vid,
1663 .ndo_vlan_rx_kill_vid = be_vlan_rem_vid,
1664};
1665
1666static void be_netdev_init(struct net_device *netdev)
1667{
1668 struct be_adapter *adapter = netdev_priv(netdev);
1669
1670 netdev->features |= NETIF_F_SG | NETIF_F_HW_VLAN_RX | NETIF_F_TSO |
1671 NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_FILTER | NETIF_F_IP_CSUM |
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001672 NETIF_F_IPV6_CSUM | NETIF_F_GRO;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001673
1674 netdev->flags |= IFF_MULTICAST;
1675
Ajit Khaparde728a9972009-04-13 15:41:22 -07001676 adapter->rx_csum = true;
1677
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001678 BE_SET_NETDEV_OPS(netdev, &be_netdev_ops);
1679
1680 SET_ETHTOOL_OPS(netdev, &be_ethtool_ops);
1681
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001682 netif_napi_add(netdev, &adapter->rx_eq.napi, be_poll_rx,
1683 BE_NAPI_WEIGHT);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001684 netif_napi_add(netdev, &adapter->tx_eq.napi, be_poll_tx_mcc,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001685 BE_NAPI_WEIGHT);
1686
1687 netif_carrier_off(netdev);
1688 netif_stop_queue(netdev);
1689}
1690
1691static void be_unmap_pci_bars(struct be_adapter *adapter)
1692{
Sathya Perla8788fdc2009-07-27 22:52:03 +00001693 if (adapter->csr)
1694 iounmap(adapter->csr);
1695 if (adapter->db)
1696 iounmap(adapter->db);
1697 if (adapter->pcicfg)
1698 iounmap(adapter->pcicfg);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001699}
1700
1701static int be_map_pci_bars(struct be_adapter *adapter)
1702{
1703 u8 __iomem *addr;
1704
1705 addr = ioremap_nocache(pci_resource_start(adapter->pdev, 2),
1706 pci_resource_len(adapter->pdev, 2));
1707 if (addr == NULL)
1708 return -ENOMEM;
Sathya Perla8788fdc2009-07-27 22:52:03 +00001709 adapter->csr = addr;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001710
1711 addr = ioremap_nocache(pci_resource_start(adapter->pdev, 4),
1712 128 * 1024);
1713 if (addr == NULL)
1714 goto pci_map_err;
Sathya Perla8788fdc2009-07-27 22:52:03 +00001715 adapter->db = addr;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001716
1717 addr = ioremap_nocache(pci_resource_start(adapter->pdev, 1),
1718 pci_resource_len(adapter->pdev, 1));
1719 if (addr == NULL)
1720 goto pci_map_err;
Sathya Perla8788fdc2009-07-27 22:52:03 +00001721 adapter->pcicfg = addr;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001722
1723 return 0;
1724pci_map_err:
1725 be_unmap_pci_bars(adapter);
1726 return -ENOMEM;
1727}
1728
1729
1730static void be_ctrl_cleanup(struct be_adapter *adapter)
1731{
Sathya Perla8788fdc2009-07-27 22:52:03 +00001732 struct be_dma_mem *mem = &adapter->mbox_mem_alloced;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001733
1734 be_unmap_pci_bars(adapter);
1735
1736 if (mem->va)
1737 pci_free_consistent(adapter->pdev, mem->size,
1738 mem->va, mem->dma);
1739}
1740
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001741static int be_ctrl_init(struct be_adapter *adapter)
1742{
Sathya Perla8788fdc2009-07-27 22:52:03 +00001743 struct be_dma_mem *mbox_mem_alloc = &adapter->mbox_mem_alloced;
1744 struct be_dma_mem *mbox_mem_align = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001745 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001746
1747 status = be_map_pci_bars(adapter);
1748 if (status)
1749 return status;
1750
1751 mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
1752 mbox_mem_alloc->va = pci_alloc_consistent(adapter->pdev,
1753 mbox_mem_alloc->size, &mbox_mem_alloc->dma);
1754 if (!mbox_mem_alloc->va) {
1755 be_unmap_pci_bars(adapter);
1756 return -1;
1757 }
1758 mbox_mem_align->size = sizeof(struct be_mcc_mailbox);
1759 mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16);
1760 mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16);
1761 memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox));
Sathya Perla8788fdc2009-07-27 22:52:03 +00001762 spin_lock_init(&adapter->mbox_lock);
1763 spin_lock_init(&adapter->mcc_lock);
1764 spin_lock_init(&adapter->mcc_cq_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001765
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001766 return 0;
1767}
1768
1769static void be_stats_cleanup(struct be_adapter *adapter)
1770{
1771 struct be_stats_obj *stats = &adapter->stats;
1772 struct be_dma_mem *cmd = &stats->cmd;
1773
1774 if (cmd->va)
1775 pci_free_consistent(adapter->pdev, cmd->size,
1776 cmd->va, cmd->dma);
1777}
1778
1779static int be_stats_init(struct be_adapter *adapter)
1780{
1781 struct be_stats_obj *stats = &adapter->stats;
1782 struct be_dma_mem *cmd = &stats->cmd;
1783
1784 cmd->size = sizeof(struct be_cmd_req_get_stats);
1785 cmd->va = pci_alloc_consistent(adapter->pdev, cmd->size, &cmd->dma);
1786 if (cmd->va == NULL)
1787 return -1;
1788 return 0;
1789}
1790
1791static void __devexit be_remove(struct pci_dev *pdev)
1792{
1793 struct be_adapter *adapter = pci_get_drvdata(pdev);
1794 if (!adapter)
1795 return;
1796
1797 unregister_netdev(adapter->netdev);
1798
Sathya Perla5fb379e2009-06-18 00:02:59 +00001799 be_clear(adapter);
1800
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001801 be_stats_cleanup(adapter);
1802
1803 be_ctrl_cleanup(adapter);
1804
1805 if (adapter->msix_enabled) {
1806 pci_disable_msix(adapter->pdev);
1807 adapter->msix_enabled = false;
1808 }
1809
1810 pci_set_drvdata(pdev, NULL);
1811 pci_release_regions(pdev);
1812 pci_disable_device(pdev);
1813
1814 free_netdev(adapter->netdev);
1815}
1816
1817static int be_hw_up(struct be_adapter *adapter)
1818{
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001819 int status;
1820
Sathya Perla8788fdc2009-07-27 22:52:03 +00001821 status = be_cmd_POST(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001822 if (status)
1823 return status;
1824
Sathya Perla8788fdc2009-07-27 22:52:03 +00001825 status = be_cmd_get_fw_ver(adapter, adapter->fw_ver);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001826 if (status)
1827 return status;
1828
Sathya Perla8788fdc2009-07-27 22:52:03 +00001829 status = be_cmd_query_fw_cfg(adapter, &adapter->port_num);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001830 return status;
1831}
1832
1833static int __devinit be_probe(struct pci_dev *pdev,
1834 const struct pci_device_id *pdev_id)
1835{
1836 int status = 0;
1837 struct be_adapter *adapter;
1838 struct net_device *netdev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001839 u8 mac[ETH_ALEN];
1840
1841 status = pci_enable_device(pdev);
1842 if (status)
1843 goto do_none;
1844
1845 status = pci_request_regions(pdev, DRV_NAME);
1846 if (status)
1847 goto disable_dev;
1848 pci_set_master(pdev);
1849
1850 netdev = alloc_etherdev(sizeof(struct be_adapter));
1851 if (netdev == NULL) {
1852 status = -ENOMEM;
1853 goto rel_reg;
1854 }
1855 adapter = netdev_priv(netdev);
1856 adapter->pdev = pdev;
1857 pci_set_drvdata(pdev, adapter);
1858 adapter->netdev = netdev;
1859
1860 be_msix_enable(adapter);
1861
Yang Hongyange9304382009-04-13 14:40:14 -07001862 status = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001863 if (!status) {
1864 netdev->features |= NETIF_F_HIGHDMA;
1865 } else {
Yang Hongyange9304382009-04-13 14:40:14 -07001866 status = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001867 if (status) {
1868 dev_err(&pdev->dev, "Could not set PCI DMA Mask\n");
1869 goto free_netdev;
1870 }
1871 }
1872
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001873 status = be_ctrl_init(adapter);
1874 if (status)
1875 goto free_netdev;
1876
1877 status = be_stats_init(adapter);
1878 if (status)
1879 goto ctrl_clean;
1880
1881 status = be_hw_up(adapter);
1882 if (status)
1883 goto stats_clean;
1884
Sathya Perla8788fdc2009-07-27 22:52:03 +00001885 status = be_cmd_mac_addr_query(adapter, mac, MAC_ADDRESS_TYPE_NETWORK,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001886 true /* permanent */, 0);
1887 if (status)
1888 goto stats_clean;
1889 memcpy(netdev->dev_addr, mac, ETH_ALEN);
1890
1891 INIT_DELAYED_WORK(&adapter->work, be_worker);
1892 be_netdev_init(netdev);
1893 SET_NETDEV_DEV(netdev, &adapter->pdev->dev);
1894
Sathya Perla5fb379e2009-06-18 00:02:59 +00001895 status = be_setup(adapter);
1896 if (status)
1897 goto stats_clean;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001898 status = register_netdev(netdev);
1899 if (status != 0)
Sathya Perla5fb379e2009-06-18 00:02:59 +00001900 goto unsetup;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001901
Ajit Khapardec4ca2372009-05-18 15:38:55 -07001902 dev_info(&pdev->dev, "%s port %d\n", nic_name(pdev), adapter->port_num);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001903 return 0;
1904
Sathya Perla5fb379e2009-06-18 00:02:59 +00001905unsetup:
1906 be_clear(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001907stats_clean:
1908 be_stats_cleanup(adapter);
1909ctrl_clean:
1910 be_ctrl_cleanup(adapter);
1911free_netdev:
1912 free_netdev(adapter->netdev);
1913rel_reg:
1914 pci_release_regions(pdev);
1915disable_dev:
1916 pci_disable_device(pdev);
1917do_none:
Ajit Khapardec4ca2372009-05-18 15:38:55 -07001918 dev_err(&pdev->dev, "%s initialization failed\n", nic_name(pdev));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001919 return status;
1920}
1921
1922static int be_suspend(struct pci_dev *pdev, pm_message_t state)
1923{
1924 struct be_adapter *adapter = pci_get_drvdata(pdev);
1925 struct net_device *netdev = adapter->netdev;
1926
1927 netif_device_detach(netdev);
1928 if (netif_running(netdev)) {
1929 rtnl_lock();
1930 be_close(netdev);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001931 be_clear(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001932 rtnl_unlock();
1933 }
1934
1935 pci_save_state(pdev);
1936 pci_disable_device(pdev);
1937 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1938 return 0;
1939}
1940
1941static int be_resume(struct pci_dev *pdev)
1942{
1943 int status = 0;
1944 struct be_adapter *adapter = pci_get_drvdata(pdev);
1945 struct net_device *netdev = adapter->netdev;
1946
1947 netif_device_detach(netdev);
1948
1949 status = pci_enable_device(pdev);
1950 if (status)
1951 return status;
1952
1953 pci_set_power_state(pdev, 0);
1954 pci_restore_state(pdev);
1955
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001956 if (netif_running(netdev)) {
1957 rtnl_lock();
Sathya Perla5fb379e2009-06-18 00:02:59 +00001958 be_setup(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001959 be_open(netdev);
1960 rtnl_unlock();
1961 }
1962 netif_device_attach(netdev);
1963 return 0;
1964}
1965
1966static struct pci_driver be_driver = {
1967 .name = DRV_NAME,
1968 .id_table = be_dev_ids,
1969 .probe = be_probe,
1970 .remove = be_remove,
1971 .suspend = be_suspend,
1972 .resume = be_resume
1973};
1974
1975static int __init be_init_module(void)
1976{
1977 if (rx_frag_size != 8192 && rx_frag_size != 4096
1978 && rx_frag_size != 2048) {
1979 printk(KERN_WARNING DRV_NAME
1980 " : Module param rx_frag_size must be 2048/4096/8192."
1981 " Using 2048\n");
1982 rx_frag_size = 2048;
1983 }
1984 /* Ensure rx_frag_size is aligned to chache line */
1985 if (SKB_DATA_ALIGN(rx_frag_size) != rx_frag_size) {
1986 printk(KERN_WARNING DRV_NAME
1987 " : Bad module param rx_frag_size. Using 2048\n");
1988 rx_frag_size = 2048;
1989 }
1990
1991 return pci_register_driver(&be_driver);
1992}
1993module_init(be_init_module);
1994
1995static void __exit be_exit_module(void)
1996{
1997 pci_unregister_driver(&be_driver);
1998}
1999module_exit(be_exit_module);