blob: 43a3a574e2e04509e51bd8e8f319affda5e7e70d [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Ajit Khaparde294aedc2010-02-19 13:54:58 +00002 * Copyright (C) 2005 - 2010 ServerEngines
Sathya Perla6b7c5b92009-03-11 23:32:03 -07003 * 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;
Sarveshwar Bandiba343c72010-03-31 02:56:12 +000029static unsigned int num_vfs;
Sathya Perla6b7c5b92009-03-11 23:32:03 -070030module_param(rx_frag_size, uint, S_IRUGO);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +000031module_param(num_vfs, uint, S_IRUGO);
Sathya Perla6b7c5b92009-03-11 23:32:03 -070032MODULE_PARM_DESC(rx_frag_size, "Size of a fragment that holds rcvd data.");
Sarveshwar Bandiba343c72010-03-31 02:56:12 +000033MODULE_PARM_DESC(num_vfs, "Number of PCI VFs to initialize");
Sathya Perla6b7c5b92009-03-11 23:32:03 -070034
Sathya Perla6b7c5b92009-03-11 23:32:03 -070035static DEFINE_PCI_DEVICE_TABLE(be_dev_ids) = {
Ajit Khapardec4ca2372009-05-18 15:38:55 -070036 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
Ajit Khaparde59fd5d82009-10-29 01:11:06 -070037 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
Ajit Khapardec4ca2372009-05-18 15:38:55 -070038 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
39 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
Sathya Perla6b7c5b92009-03-11 23:32:03 -070040 { 0 }
41};
42MODULE_DEVICE_TABLE(pci, be_dev_ids);
Ajit Khaparde7c185272010-07-29 06:16:33 +000043/* UE Status Low CSR */
44static char *ue_status_low_desc[] = {
45 "CEV",
46 "CTX",
47 "DBUF",
48 "ERX",
49 "Host",
50 "MPU",
51 "NDMA",
52 "PTC ",
53 "RDMA ",
54 "RXF ",
55 "RXIPS ",
56 "RXULP0 ",
57 "RXULP1 ",
58 "RXULP2 ",
59 "TIM ",
60 "TPOST ",
61 "TPRE ",
62 "TXIPS ",
63 "TXULP0 ",
64 "TXULP1 ",
65 "UC ",
66 "WDMA ",
67 "TXULP2 ",
68 "HOST1 ",
69 "P0_OB_LINK ",
70 "P1_OB_LINK ",
71 "HOST_GPIO ",
72 "MBOX ",
73 "AXGMAC0",
74 "AXGMAC1",
75 "JTAG",
76 "MPU_INTPEND"
77};
78/* UE Status High CSR */
79static char *ue_status_hi_desc[] = {
80 "LPCMEMHOST",
81 "MGMT_MAC",
82 "PCS0ONLINE",
83 "MPU_IRAM",
84 "PCS1ONLINE",
85 "PCTL0",
86 "PCTL1",
87 "PMEM",
88 "RR",
89 "TXPB",
90 "RXPP",
91 "XAUI",
92 "TXP",
93 "ARM",
94 "IPC",
95 "HOST2",
96 "HOST3",
97 "HOST4",
98 "HOST5",
99 "HOST6",
100 "HOST7",
101 "HOST8",
102 "HOST9",
103 "NETC"
104 "Unknown",
105 "Unknown",
106 "Unknown",
107 "Unknown",
108 "Unknown",
109 "Unknown",
110 "Unknown",
111 "Unknown"
112};
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700113
114static void be_queue_free(struct be_adapter *adapter, struct be_queue_info *q)
115{
116 struct be_dma_mem *mem = &q->dma_mem;
117 if (mem->va)
118 pci_free_consistent(adapter->pdev, mem->size,
119 mem->va, mem->dma);
120}
121
122static int be_queue_alloc(struct be_adapter *adapter, struct be_queue_info *q,
123 u16 len, u16 entry_size)
124{
125 struct be_dma_mem *mem = &q->dma_mem;
126
127 memset(q, 0, sizeof(*q));
128 q->len = len;
129 q->entry_size = entry_size;
130 mem->size = len * entry_size;
131 mem->va = pci_alloc_consistent(adapter->pdev, mem->size, &mem->dma);
132 if (!mem->va)
133 return -1;
134 memset(mem->va, 0, mem->size);
135 return 0;
136}
137
Sathya Perla8788fdc2009-07-27 22:52:03 +0000138static void be_intr_set(struct be_adapter *adapter, bool enable)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700139{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000140 u8 __iomem *addr = adapter->pcicfg + PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700141 u32 reg = ioread32(addr);
142 u32 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
Sathya Perla5f0b8492009-07-27 22:52:56 +0000143
Sathya Perlacf588472010-02-14 21:22:01 +0000144 if (adapter->eeh_err)
145 return;
146
Sathya Perla5f0b8492009-07-27 22:52:56 +0000147 if (!enabled && enable)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700148 reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
Sathya Perla5f0b8492009-07-27 22:52:56 +0000149 else if (enabled && !enable)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700150 reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
Sathya Perla5f0b8492009-07-27 22:52:56 +0000151 else
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700152 return;
Sathya Perla5f0b8492009-07-27 22:52:56 +0000153
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700154 iowrite32(reg, addr);
155}
156
Sathya Perla8788fdc2009-07-27 22:52:03 +0000157static void be_rxq_notify(struct be_adapter *adapter, u16 qid, u16 posted)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700158{
159 u32 val = 0;
160 val |= qid & DB_RQ_RING_ID_MASK;
161 val |= posted << DB_RQ_NUM_POSTED_SHIFT;
Sathya Perlaf3eb62d2010-06-29 00:11:17 +0000162
163 wmb();
Sathya Perla8788fdc2009-07-27 22:52:03 +0000164 iowrite32(val, adapter->db + DB_RQ_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700165}
166
Sathya Perla8788fdc2009-07-27 22:52:03 +0000167static void be_txq_notify(struct be_adapter *adapter, u16 qid, u16 posted)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700168{
169 u32 val = 0;
170 val |= qid & DB_TXULP_RING_ID_MASK;
171 val |= (posted & DB_TXULP_NUM_POSTED_MASK) << DB_TXULP_NUM_POSTED_SHIFT;
Sathya Perlaf3eb62d2010-06-29 00:11:17 +0000172
173 wmb();
Sathya Perla8788fdc2009-07-27 22:52:03 +0000174 iowrite32(val, adapter->db + DB_TXULP1_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700175}
176
Sathya Perla8788fdc2009-07-27 22:52:03 +0000177static void be_eq_notify(struct be_adapter *adapter, u16 qid,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700178 bool arm, bool clear_int, u16 num_popped)
179{
180 u32 val = 0;
181 val |= qid & DB_EQ_RING_ID_MASK;
Sathya Perlacf588472010-02-14 21:22:01 +0000182
183 if (adapter->eeh_err)
184 return;
185
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700186 if (arm)
187 val |= 1 << DB_EQ_REARM_SHIFT;
188 if (clear_int)
189 val |= 1 << DB_EQ_CLR_SHIFT;
190 val |= 1 << DB_EQ_EVNT_SHIFT;
191 val |= num_popped << DB_EQ_NUM_POPPED_SHIFT;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000192 iowrite32(val, adapter->db + DB_EQ_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700193}
194
Sathya Perla8788fdc2009-07-27 22:52:03 +0000195void be_cq_notify(struct be_adapter *adapter, u16 qid, bool arm, u16 num_popped)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700196{
197 u32 val = 0;
198 val |= qid & DB_CQ_RING_ID_MASK;
Sathya Perlacf588472010-02-14 21:22:01 +0000199
200 if (adapter->eeh_err)
201 return;
202
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700203 if (arm)
204 val |= 1 << DB_CQ_REARM_SHIFT;
205 val |= num_popped << DB_CQ_NUM_POPPED_SHIFT;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000206 iowrite32(val, adapter->db + DB_CQ_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700207}
208
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700209static int be_mac_addr_set(struct net_device *netdev, void *p)
210{
211 struct be_adapter *adapter = netdev_priv(netdev);
212 struct sockaddr *addr = p;
213 int status = 0;
214
Ajit Khapardeca9e4982009-11-29 17:56:26 +0000215 if (!is_valid_ether_addr(addr->sa_data))
216 return -EADDRNOTAVAIL;
217
Sarveshwar Bandiba343c72010-03-31 02:56:12 +0000218 /* MAC addr configuration will be done in hardware for VFs
219 * by their corresponding PFs. Just copy to netdev addr here
220 */
221 if (!be_physfn(adapter))
222 goto netdev_addr;
223
Sathya Perlaa65027e2009-08-17 00:58:04 +0000224 status = be_cmd_pmac_del(adapter, adapter->if_handle, adapter->pmac_id);
225 if (status)
226 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700227
Sathya Perlaa65027e2009-08-17 00:58:04 +0000228 status = be_cmd_pmac_add(adapter, (u8 *)addr->sa_data,
229 adapter->if_handle, &adapter->pmac_id);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +0000230netdev_addr:
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700231 if (!status)
232 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
233
234 return status;
235}
236
Sathya Perlab31c50a2009-09-17 10:30:13 -0700237void netdev_stats_update(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700238{
239 struct be_hw_stats *hw_stats = hw_stats_from_cmd(adapter->stats.cmd.va);
240 struct be_rxf_stats *rxf_stats = &hw_stats->rxf;
241 struct be_port_rxf_stats *port_stats =
242 &rxf_stats->port[adapter->port_num];
Ajit Khaparde78122a52009-10-07 03:11:20 -0700243 struct net_device_stats *dev_stats = &adapter->netdev->stats;
Sathya Perla68110862009-06-10 02:21:16 +0000244 struct be_erx_stats *erx_stats = &hw_stats->erx;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700245
Ajit Khaparde91992e42010-02-19 13:57:12 +0000246 dev_stats->rx_packets = drvr_stats(adapter)->be_rx_pkts;
247 dev_stats->tx_packets = drvr_stats(adapter)->be_tx_pkts;
248 dev_stats->rx_bytes = drvr_stats(adapter)->be_rx_bytes;
249 dev_stats->tx_bytes = drvr_stats(adapter)->be_tx_bytes;
Ajit Khaparde1ef78ab2010-09-03 06:17:10 +0000250 dev_stats->multicast = drvr_stats(adapter)->be_rx_mcast_pkt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700251
252 /* bad pkts received */
253 dev_stats->rx_errors = port_stats->rx_crc_errors +
254 port_stats->rx_alignment_symbol_errors +
255 port_stats->rx_in_range_errors +
Sathya Perla68110862009-06-10 02:21:16 +0000256 port_stats->rx_out_range_errors +
257 port_stats->rx_frame_too_long +
258 port_stats->rx_dropped_too_small +
259 port_stats->rx_dropped_too_short +
260 port_stats->rx_dropped_header_too_small +
261 port_stats->rx_dropped_tcp_length +
262 port_stats->rx_dropped_runt +
263 port_stats->rx_tcp_checksum_errs +
264 port_stats->rx_ip_checksum_errs +
265 port_stats->rx_udp_checksum_errs;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700266
Sathya Perla68110862009-06-10 02:21:16 +0000267 /* no space in linux buffers: best possible approximation */
Sathya Perla01ed30d2009-11-22 22:01:31 +0000268 dev_stats->rx_dropped =
269 erx_stats->rx_drops_no_fragments[adapter->rx_obj.q.id];
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700270
271 /* detailed rx errors */
272 dev_stats->rx_length_errors = port_stats->rx_in_range_errors +
Sathya Perla68110862009-06-10 02:21:16 +0000273 port_stats->rx_out_range_errors +
274 port_stats->rx_frame_too_long;
275
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700276 /* receive ring buffer overflow */
277 dev_stats->rx_over_errors = 0;
Sathya Perla68110862009-06-10 02:21:16 +0000278
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700279 dev_stats->rx_crc_errors = port_stats->rx_crc_errors;
280
281 /* frame alignment errors */
282 dev_stats->rx_frame_errors = port_stats->rx_alignment_symbol_errors;
Sathya Perla68110862009-06-10 02:21:16 +0000283
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700284 /* receiver fifo overrun */
285 /* drops_no_pbuf is no per i/f, it's per BE card */
286 dev_stats->rx_fifo_errors = port_stats->rx_fifo_overflow +
287 port_stats->rx_input_fifo_overflow +
288 rxf_stats->rx_drops_no_pbuf;
289 /* receiver missed packetd */
290 dev_stats->rx_missed_errors = 0;
Sathya Perla68110862009-06-10 02:21:16 +0000291
292 /* packet transmit problems */
293 dev_stats->tx_errors = 0;
294
295 /* no space available in linux */
296 dev_stats->tx_dropped = 0;
297
Sathya Perla68110862009-06-10 02:21:16 +0000298 dev_stats->collisions = 0;
299
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700300 /* detailed tx_errors */
301 dev_stats->tx_aborted_errors = 0;
302 dev_stats->tx_carrier_errors = 0;
303 dev_stats->tx_fifo_errors = 0;
304 dev_stats->tx_heartbeat_errors = 0;
305 dev_stats->tx_window_errors = 0;
306}
307
Sathya Perla8788fdc2009-07-27 22:52:03 +0000308void be_link_status_update(struct be_adapter *adapter, bool link_up)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700309{
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700310 struct net_device *netdev = adapter->netdev;
311
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700312 /* If link came up or went down */
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000313 if (adapter->link_up != link_up) {
Ajit Khaparde0dffc832009-11-29 17:57:46 +0000314 adapter->link_speed = -1;
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000315 if (link_up) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700316 netif_start_queue(netdev);
317 netif_carrier_on(netdev);
318 printk(KERN_INFO "%s: Link up\n", netdev->name);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000319 } else {
320 netif_stop_queue(netdev);
321 netif_carrier_off(netdev);
322 printk(KERN_INFO "%s: Link down\n", netdev->name);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700323 }
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000324 adapter->link_up = link_up;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700325 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700326}
327
328/* Update the EQ delay n BE based on the RX frags consumed / sec */
329static void be_rx_eqd_update(struct be_adapter *adapter)
330{
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700331 struct be_eq_obj *rx_eq = &adapter->rx_eq;
332 struct be_drvr_stats *stats = &adapter->stats.drvr_stats;
Sathya Perla4097f662009-03-24 16:40:13 -0700333 ulong now = jiffies;
334 u32 eqd;
335
336 if (!rx_eq->enable_aic)
337 return;
338
339 /* Wrapped around */
340 if (time_before(now, stats->rx_fps_jiffies)) {
341 stats->rx_fps_jiffies = now;
342 return;
343 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700344
345 /* Update once a second */
Sathya Perla4097f662009-03-24 16:40:13 -0700346 if ((now - stats->rx_fps_jiffies) < HZ)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700347 return;
348
349 stats->be_rx_fps = (stats->be_rx_frags - stats->be_prev_rx_frags) /
Sathya Perla4097f662009-03-24 16:40:13 -0700350 ((now - stats->rx_fps_jiffies) / HZ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700351
Sathya Perla4097f662009-03-24 16:40:13 -0700352 stats->rx_fps_jiffies = now;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700353 stats->be_prev_rx_frags = stats->be_rx_frags;
354 eqd = stats->be_rx_fps / 110000;
355 eqd = eqd << 3;
356 if (eqd > rx_eq->max_eqd)
357 eqd = rx_eq->max_eqd;
358 if (eqd < rx_eq->min_eqd)
359 eqd = rx_eq->min_eqd;
360 if (eqd < 10)
361 eqd = 0;
362 if (eqd != rx_eq->cur_eqd)
Sathya Perla8788fdc2009-07-27 22:52:03 +0000363 be_cmd_modify_eqd(adapter, rx_eq->q.id, eqd);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700364
365 rx_eq->cur_eqd = eqd;
366}
367
Stephen Hemminger65f71b82009-03-27 00:25:24 -0700368static u32 be_calc_rate(u64 bytes, unsigned long ticks)
369{
370 u64 rate = bytes;
371
372 do_div(rate, ticks / HZ);
373 rate <<= 3; /* bytes/sec -> bits/sec */
374 do_div(rate, 1000000ul); /* MB/Sec */
375
376 return rate;
377}
378
Sathya Perla4097f662009-03-24 16:40:13 -0700379static void be_tx_rate_update(struct be_adapter *adapter)
380{
381 struct be_drvr_stats *stats = drvr_stats(adapter);
382 ulong now = jiffies;
383
384 /* Wrapped around? */
385 if (time_before(now, stats->be_tx_jiffies)) {
386 stats->be_tx_jiffies = now;
387 return;
388 }
389
390 /* Update tx rate once in two seconds */
391 if ((now - stats->be_tx_jiffies) > 2 * HZ) {
Stephen Hemminger65f71b82009-03-27 00:25:24 -0700392 stats->be_tx_rate = be_calc_rate(stats->be_tx_bytes
393 - stats->be_tx_bytes_prev,
394 now - stats->be_tx_jiffies);
Sathya Perla4097f662009-03-24 16:40:13 -0700395 stats->be_tx_jiffies = now;
396 stats->be_tx_bytes_prev = stats->be_tx_bytes;
397 }
398}
399
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700400static void be_tx_stats_update(struct be_adapter *adapter,
Ajit Khaparde91992e42010-02-19 13:57:12 +0000401 u32 wrb_cnt, u32 copied, u32 gso_segs, bool stopped)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700402{
Sathya Perla4097f662009-03-24 16:40:13 -0700403 struct be_drvr_stats *stats = drvr_stats(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700404 stats->be_tx_reqs++;
405 stats->be_tx_wrbs += wrb_cnt;
406 stats->be_tx_bytes += copied;
Ajit Khaparde91992e42010-02-19 13:57:12 +0000407 stats->be_tx_pkts += (gso_segs ? gso_segs : 1);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700408 if (stopped)
409 stats->be_tx_stops++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700410}
411
412/* Determine number of WRB entries needed to xmit data in an skb */
413static u32 wrb_cnt_for_skb(struct sk_buff *skb, bool *dummy)
414{
David S. Millerebc8d2a2009-06-09 01:01:31 -0700415 int cnt = (skb->len > skb->data_len);
416
417 cnt += skb_shinfo(skb)->nr_frags;
418
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700419 /* to account for hdr wrb */
420 cnt++;
421 if (cnt & 1) {
422 /* add a dummy to make it an even num */
423 cnt++;
424 *dummy = true;
425 } else
426 *dummy = false;
427 BUG_ON(cnt > BE_MAX_TX_FRAG_COUNT);
428 return cnt;
429}
430
431static inline void wrb_fill(struct be_eth_wrb *wrb, u64 addr, int len)
432{
433 wrb->frag_pa_hi = upper_32_bits(addr);
434 wrb->frag_pa_lo = addr & 0xFFFFFFFF;
435 wrb->frag_len = len & ETH_WRB_FRAG_LEN_MASK;
436}
437
438static void wrb_fill_hdr(struct be_eth_hdr_wrb *hdr, struct sk_buff *skb,
439 bool vlan, u32 wrb_cnt, u32 len)
440{
441 memset(hdr, 0, sizeof(*hdr));
442
443 AMAP_SET_BITS(struct amap_eth_hdr_wrb, crc, hdr, 1);
444
Ajit Khaparde49e4b8472010-06-14 04:56:07 +0000445 if (skb_is_gso(skb)) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700446 AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso, hdr, 1);
447 AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso_mss,
448 hdr, skb_shinfo(skb)->gso_size);
Ajit Khaparde49e4b8472010-06-14 04:56:07 +0000449 if (skb_is_gso_v6(skb))
450 AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso6, hdr, 1);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700451 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
452 if (is_tcp_pkt(skb))
453 AMAP_SET_BITS(struct amap_eth_hdr_wrb, tcpcs, hdr, 1);
454 else if (is_udp_pkt(skb))
455 AMAP_SET_BITS(struct amap_eth_hdr_wrb, udpcs, hdr, 1);
456 }
457
458 if (vlan && vlan_tx_tag_present(skb)) {
459 AMAP_SET_BITS(struct amap_eth_hdr_wrb, vlan, hdr, 1);
460 AMAP_SET_BITS(struct amap_eth_hdr_wrb, vlan_tag,
461 hdr, vlan_tx_tag_get(skb));
462 }
463
464 AMAP_SET_BITS(struct amap_eth_hdr_wrb, event, hdr, 1);
465 AMAP_SET_BITS(struct amap_eth_hdr_wrb, complete, hdr, 1);
466 AMAP_SET_BITS(struct amap_eth_hdr_wrb, num_wrb, hdr, wrb_cnt);
467 AMAP_SET_BITS(struct amap_eth_hdr_wrb, len, hdr, len);
468}
469
Sathya Perla7101e112010-03-22 20:41:12 +0000470static void unmap_tx_frag(struct pci_dev *pdev, struct be_eth_wrb *wrb,
471 bool unmap_single)
472{
473 dma_addr_t dma;
474
475 be_dws_le_to_cpu(wrb, sizeof(*wrb));
476
477 dma = (u64)wrb->frag_pa_hi << 32 | (u64)wrb->frag_pa_lo;
FUJITA Tomonorib681ee72010-04-04 21:40:18 +0000478 if (wrb->frag_len) {
Sathya Perla7101e112010-03-22 20:41:12 +0000479 if (unmap_single)
480 pci_unmap_single(pdev, dma, wrb->frag_len,
481 PCI_DMA_TODEVICE);
482 else
483 pci_unmap_page(pdev, dma, wrb->frag_len,
484 PCI_DMA_TODEVICE);
485 }
486}
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700487
488static int make_tx_wrbs(struct be_adapter *adapter,
489 struct sk_buff *skb, u32 wrb_cnt, bool dummy_wrb)
490{
Sathya Perla7101e112010-03-22 20:41:12 +0000491 dma_addr_t busaddr;
492 int i, copied = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700493 struct pci_dev *pdev = adapter->pdev;
494 struct sk_buff *first_skb = skb;
495 struct be_queue_info *txq = &adapter->tx_obj.q;
496 struct be_eth_wrb *wrb;
497 struct be_eth_hdr_wrb *hdr;
Sathya Perla7101e112010-03-22 20:41:12 +0000498 bool map_single = false;
499 u16 map_head;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700500
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700501 hdr = queue_head_node(txq);
502 queue_head_inc(txq);
Sathya Perla7101e112010-03-22 20:41:12 +0000503 map_head = txq->head;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700504
David S. Millerebc8d2a2009-06-09 01:01:31 -0700505 if (skb->len > skb->data_len) {
Eric Dumazete743d312010-04-14 15:59:40 -0700506 int len = skb_headlen(skb);
Alexander Duycka73b7962009-12-02 16:48:18 +0000507 busaddr = pci_map_single(pdev, skb->data, len,
508 PCI_DMA_TODEVICE);
Sathya Perla7101e112010-03-22 20:41:12 +0000509 if (pci_dma_mapping_error(pdev, busaddr))
510 goto dma_err;
511 map_single = true;
David S. Millerebc8d2a2009-06-09 01:01:31 -0700512 wrb = queue_head_node(txq);
513 wrb_fill(wrb, busaddr, len);
514 be_dws_cpu_to_le(wrb, sizeof(*wrb));
515 queue_head_inc(txq);
516 copied += len;
517 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700518
David S. Millerebc8d2a2009-06-09 01:01:31 -0700519 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
520 struct skb_frag_struct *frag =
521 &skb_shinfo(skb)->frags[i];
Alexander Duycka73b7962009-12-02 16:48:18 +0000522 busaddr = pci_map_page(pdev, frag->page,
523 frag->page_offset,
524 frag->size, PCI_DMA_TODEVICE);
Sathya Perla7101e112010-03-22 20:41:12 +0000525 if (pci_dma_mapping_error(pdev, busaddr))
526 goto dma_err;
David S. Millerebc8d2a2009-06-09 01:01:31 -0700527 wrb = queue_head_node(txq);
528 wrb_fill(wrb, busaddr, frag->size);
529 be_dws_cpu_to_le(wrb, sizeof(*wrb));
530 queue_head_inc(txq);
531 copied += frag->size;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700532 }
533
534 if (dummy_wrb) {
535 wrb = queue_head_node(txq);
536 wrb_fill(wrb, 0, 0);
537 be_dws_cpu_to_le(wrb, sizeof(*wrb));
538 queue_head_inc(txq);
539 }
540
541 wrb_fill_hdr(hdr, first_skb, adapter->vlan_grp ? true : false,
542 wrb_cnt, copied);
543 be_dws_cpu_to_le(hdr, sizeof(*hdr));
544
545 return copied;
Sathya Perla7101e112010-03-22 20:41:12 +0000546dma_err:
547 txq->head = map_head;
548 while (copied) {
549 wrb = queue_head_node(txq);
550 unmap_tx_frag(pdev, wrb, map_single);
551 map_single = false;
552 copied -= wrb->frag_len;
553 queue_head_inc(txq);
554 }
555 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700556}
557
Stephen Hemminger613573252009-08-31 19:50:58 +0000558static netdev_tx_t be_xmit(struct sk_buff *skb,
Sathya Perlab31c50a2009-09-17 10:30:13 -0700559 struct net_device *netdev)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700560{
561 struct be_adapter *adapter = netdev_priv(netdev);
562 struct be_tx_obj *tx_obj = &adapter->tx_obj;
563 struct be_queue_info *txq = &tx_obj->q;
564 u32 wrb_cnt = 0, copied = 0;
565 u32 start = txq->head;
566 bool dummy_wrb, stopped = false;
567
568 wrb_cnt = wrb_cnt_for_skb(skb, &dummy_wrb);
569
570 copied = make_tx_wrbs(adapter, skb, wrb_cnt, dummy_wrb);
Ajit Khapardec190e3c2009-09-04 03:12:29 +0000571 if (copied) {
572 /* record the sent skb in the sent_skb table */
573 BUG_ON(tx_obj->sent_skb_list[start]);
574 tx_obj->sent_skb_list[start] = skb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700575
Ajit Khapardec190e3c2009-09-04 03:12:29 +0000576 /* Ensure txq has space for the next skb; Else stop the queue
577 * *BEFORE* ringing the tx doorbell, so that we serialze the
578 * tx compls of the current transmit which'll wake up the queue
579 */
Sathya Perla7101e112010-03-22 20:41:12 +0000580 atomic_add(wrb_cnt, &txq->used);
Ajit Khapardec190e3c2009-09-04 03:12:29 +0000581 if ((BE_MAX_TX_FRAG_COUNT + atomic_read(&txq->used)) >=
582 txq->len) {
583 netif_stop_queue(netdev);
584 stopped = true;
585 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700586
Ajit Khapardec190e3c2009-09-04 03:12:29 +0000587 be_txq_notify(adapter, txq->id, wrb_cnt);
588
Ajit Khaparde91992e42010-02-19 13:57:12 +0000589 be_tx_stats_update(adapter, wrb_cnt, copied,
590 skb_shinfo(skb)->gso_segs, stopped);
Ajit Khapardec190e3c2009-09-04 03:12:29 +0000591 } else {
592 txq->head = start;
593 dev_kfree_skb_any(skb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700594 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700595 return NETDEV_TX_OK;
596}
597
598static int be_change_mtu(struct net_device *netdev, int new_mtu)
599{
600 struct be_adapter *adapter = netdev_priv(netdev);
601 if (new_mtu < BE_MIN_MTU ||
Ajit Khaparde34a89b82010-02-09 01:32:43 +0000602 new_mtu > (BE_MAX_JUMBO_FRAME_SIZE -
603 (ETH_HLEN + ETH_FCS_LEN))) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700604 dev_info(&adapter->pdev->dev,
605 "MTU must be between %d and %d bytes\n",
Ajit Khaparde34a89b82010-02-09 01:32:43 +0000606 BE_MIN_MTU,
607 (BE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN)));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700608 return -EINVAL;
609 }
610 dev_info(&adapter->pdev->dev, "MTU changed from %d to %d bytes\n",
611 netdev->mtu, new_mtu);
612 netdev->mtu = new_mtu;
613 return 0;
614}
615
616/*
Ajit Khaparde82903e42010-02-09 01:34:57 +0000617 * A max of 64 (BE_NUM_VLANS_SUPPORTED) vlans can be configured in BE.
618 * If the user configures more, place BE in vlan promiscuous mode.
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700619 */
Ajit Khaparde1da87b72010-07-23 01:51:22 +0000620static int be_vid_config(struct be_adapter *adapter, bool vf, u32 vf_num)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700621{
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700622 u16 vtag[BE_NUM_VLANS_SUPPORTED];
623 u16 ntags = 0, i;
Ajit Khaparde82903e42010-02-09 01:34:57 +0000624 int status = 0;
Ajit Khaparde1da87b72010-07-23 01:51:22 +0000625 u32 if_handle;
626
627 if (vf) {
628 if_handle = adapter->vf_cfg[vf_num].vf_if_handle;
629 vtag[0] = cpu_to_le16(adapter->vf_cfg[vf_num].vf_vlan_tag);
630 status = be_cmd_vlan_config(adapter, if_handle, vtag, 1, 1, 0);
631 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700632
Ajit Khaparde82903e42010-02-09 01:34:57 +0000633 if (adapter->vlans_added <= adapter->max_vlans) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700634 /* Construct VLAN Table to give to HW */
635 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
636 if (adapter->vlan_tag[i]) {
637 vtag[ntags] = cpu_to_le16(i);
638 ntags++;
639 }
640 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700641 status = be_cmd_vlan_config(adapter, adapter->if_handle,
642 vtag, ntags, 1, 0);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700643 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700644 status = be_cmd_vlan_config(adapter, adapter->if_handle,
645 NULL, 0, 1, 1);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700646 }
Ajit Khaparde1da87b72010-07-23 01:51:22 +0000647
Sathya Perlab31c50a2009-09-17 10:30:13 -0700648 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700649}
650
651static void be_vlan_register(struct net_device *netdev, struct vlan_group *grp)
652{
653 struct be_adapter *adapter = netdev_priv(netdev);
654 struct be_eq_obj *rx_eq = &adapter->rx_eq;
655 struct be_eq_obj *tx_eq = &adapter->tx_eq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700656
Sathya Perla8788fdc2009-07-27 22:52:03 +0000657 be_eq_notify(adapter, rx_eq->q.id, false, false, 0);
658 be_eq_notify(adapter, tx_eq->q.id, false, false, 0);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700659 adapter->vlan_grp = grp;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000660 be_eq_notify(adapter, rx_eq->q.id, true, false, 0);
661 be_eq_notify(adapter, tx_eq->q.id, true, false, 0);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700662}
663
664static void be_vlan_add_vid(struct net_device *netdev, u16 vid)
665{
666 struct be_adapter *adapter = netdev_priv(netdev);
667
Ajit Khaparde1da87b72010-07-23 01:51:22 +0000668 adapter->vlans_added++;
Sarveshwar Bandiba343c72010-03-31 02:56:12 +0000669 if (!be_physfn(adapter))
670 return;
671
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700672 adapter->vlan_tag[vid] = 1;
Ajit Khaparde82903e42010-02-09 01:34:57 +0000673 if (adapter->vlans_added <= (adapter->max_vlans + 1))
Ajit Khaparde1da87b72010-07-23 01:51:22 +0000674 be_vid_config(adapter, false, 0);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700675}
676
677static void be_vlan_rem_vid(struct net_device *netdev, u16 vid)
678{
679 struct be_adapter *adapter = netdev_priv(netdev);
680
Ajit Khaparde1da87b72010-07-23 01:51:22 +0000681 adapter->vlans_added--;
682 vlan_group_set_device(adapter->vlan_grp, vid, NULL);
683
Sarveshwar Bandiba343c72010-03-31 02:56:12 +0000684 if (!be_physfn(adapter))
685 return;
686
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700687 adapter->vlan_tag[vid] = 0;
Ajit Khaparde82903e42010-02-09 01:34:57 +0000688 if (adapter->vlans_added <= adapter->max_vlans)
Ajit Khaparde1da87b72010-07-23 01:51:22 +0000689 be_vid_config(adapter, false, 0);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700690}
691
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700692static void be_set_multicast_list(struct net_device *netdev)
693{
694 struct be_adapter *adapter = netdev_priv(netdev);
695
696 if (netdev->flags & IFF_PROMISC) {
Sathya Perla8788fdc2009-07-27 22:52:03 +0000697 be_cmd_promiscuous_config(adapter, adapter->port_num, 1);
Sathya Perla24307ee2009-06-18 00:09:25 +0000698 adapter->promiscuous = true;
699 goto done;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700700 }
Sathya Perla24307ee2009-06-18 00:09:25 +0000701
702 /* BE was previously in promiscous mode; disable it */
703 if (adapter->promiscuous) {
704 adapter->promiscuous = false;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000705 be_cmd_promiscuous_config(adapter, adapter->port_num, 0);
Sathya Perla24307ee2009-06-18 00:09:25 +0000706 }
707
Sathya Perlae7b909a2009-11-22 22:01:10 +0000708 /* Enable multicast promisc if num configured exceeds what we support */
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000709 if (netdev->flags & IFF_ALLMULTI ||
710 netdev_mc_count(netdev) > BE_MAX_MC) {
Jiri Pirko0ddf4772010-02-20 00:13:58 +0000711 be_cmd_multicast_set(adapter, adapter->if_handle, NULL,
Sathya Perlae7b909a2009-11-22 22:01:10 +0000712 &adapter->mc_cmd_mem);
Sathya Perla24307ee2009-06-18 00:09:25 +0000713 goto done;
714 }
715
Jiri Pirko0ddf4772010-02-20 00:13:58 +0000716 be_cmd_multicast_set(adapter, adapter->if_handle, netdev,
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800717 &adapter->mc_cmd_mem);
Sathya Perla24307ee2009-06-18 00:09:25 +0000718done:
719 return;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700720}
721
Sarveshwar Bandiba343c72010-03-31 02:56:12 +0000722static int be_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
723{
724 struct be_adapter *adapter = netdev_priv(netdev);
725 int status;
726
727 if (!adapter->sriov_enabled)
728 return -EPERM;
729
730 if (!is_valid_ether_addr(mac) || (vf >= num_vfs))
731 return -EINVAL;
732
Ajit Khaparde64600ea2010-07-23 01:50:34 +0000733 if (adapter->vf_cfg[vf].vf_pmac_id != BE_INVALID_PMAC_ID)
734 status = be_cmd_pmac_del(adapter,
735 adapter->vf_cfg[vf].vf_if_handle,
736 adapter->vf_cfg[vf].vf_pmac_id);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +0000737
Ajit Khaparde64600ea2010-07-23 01:50:34 +0000738 status = be_cmd_pmac_add(adapter, mac,
739 adapter->vf_cfg[vf].vf_if_handle,
740 &adapter->vf_cfg[vf].vf_pmac_id);
741
742 if (status)
Sarveshwar Bandiba343c72010-03-31 02:56:12 +0000743 dev_err(&adapter->pdev->dev, "MAC %pM set on VF %d Failed\n",
744 mac, vf);
Ajit Khaparde64600ea2010-07-23 01:50:34 +0000745 else
746 memcpy(adapter->vf_cfg[vf].vf_mac_addr, mac, ETH_ALEN);
747
Sarveshwar Bandiba343c72010-03-31 02:56:12 +0000748 return status;
749}
750
Ajit Khaparde64600ea2010-07-23 01:50:34 +0000751static int be_get_vf_config(struct net_device *netdev, int vf,
752 struct ifla_vf_info *vi)
753{
754 struct be_adapter *adapter = netdev_priv(netdev);
755
756 if (!adapter->sriov_enabled)
757 return -EPERM;
758
759 if (vf >= num_vfs)
760 return -EINVAL;
761
762 vi->vf = vf;
Ajit Khapardee1d18732010-07-23 01:52:13 +0000763 vi->tx_rate = adapter->vf_cfg[vf].vf_tx_rate;
Ajit Khaparde1da87b72010-07-23 01:51:22 +0000764 vi->vlan = adapter->vf_cfg[vf].vf_vlan_tag;
Ajit Khaparde64600ea2010-07-23 01:50:34 +0000765 vi->qos = 0;
766 memcpy(&vi->mac, adapter->vf_cfg[vf].vf_mac_addr, ETH_ALEN);
767
768 return 0;
769}
770
Ajit Khaparde1da87b72010-07-23 01:51:22 +0000771static int be_set_vf_vlan(struct net_device *netdev,
772 int vf, u16 vlan, u8 qos)
773{
774 struct be_adapter *adapter = netdev_priv(netdev);
775 int status = 0;
776
777 if (!adapter->sriov_enabled)
778 return -EPERM;
779
780 if ((vf >= num_vfs) || (vlan > 4095))
781 return -EINVAL;
782
783 if (vlan) {
784 adapter->vf_cfg[vf].vf_vlan_tag = vlan;
785 adapter->vlans_added++;
786 } else {
787 adapter->vf_cfg[vf].vf_vlan_tag = 0;
788 adapter->vlans_added--;
789 }
790
791 status = be_vid_config(adapter, true, vf);
792
793 if (status)
794 dev_info(&adapter->pdev->dev,
795 "VLAN %d config on VF %d failed\n", vlan, vf);
796 return status;
797}
798
Ajit Khapardee1d18732010-07-23 01:52:13 +0000799static int be_set_vf_tx_rate(struct net_device *netdev,
800 int vf, int rate)
801{
802 struct be_adapter *adapter = netdev_priv(netdev);
803 int status = 0;
804
805 if (!adapter->sriov_enabled)
806 return -EPERM;
807
808 if ((vf >= num_vfs) || (rate < 0))
809 return -EINVAL;
810
811 if (rate > 10000)
812 rate = 10000;
813
814 adapter->vf_cfg[vf].vf_tx_rate = rate;
815 status = be_cmd_set_qos(adapter, rate / 10, vf);
816
817 if (status)
818 dev_info(&adapter->pdev->dev,
819 "tx rate %d on VF %d failed\n", rate, vf);
820 return status;
821}
822
Sathya Perla4097f662009-03-24 16:40:13 -0700823static void be_rx_rate_update(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700824{
Sathya Perla4097f662009-03-24 16:40:13 -0700825 struct be_drvr_stats *stats = drvr_stats(adapter);
826 ulong now = jiffies;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700827
Sathya Perla4097f662009-03-24 16:40:13 -0700828 /* Wrapped around */
829 if (time_before(now, stats->be_rx_jiffies)) {
830 stats->be_rx_jiffies = now;
831 return;
832 }
833
834 /* Update the rate once in two seconds */
835 if ((now - stats->be_rx_jiffies) < 2 * HZ)
836 return;
837
Stephen Hemminger65f71b82009-03-27 00:25:24 -0700838 stats->be_rx_rate = be_calc_rate(stats->be_rx_bytes
839 - stats->be_rx_bytes_prev,
840 now - stats->be_rx_jiffies);
Sathya Perla4097f662009-03-24 16:40:13 -0700841 stats->be_rx_jiffies = now;
842 stats->be_rx_bytes_prev = stats->be_rx_bytes;
843}
844
845static void be_rx_stats_update(struct be_adapter *adapter,
Ajit Khaparde1ef78ab2010-09-03 06:17:10 +0000846 u32 pktsize, u16 numfrags, u8 pkt_type)
Sathya Perla4097f662009-03-24 16:40:13 -0700847{
848 struct be_drvr_stats *stats = drvr_stats(adapter);
849
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700850 stats->be_rx_compl++;
851 stats->be_rx_frags += numfrags;
852 stats->be_rx_bytes += pktsize;
Ajit Khaparde91992e42010-02-19 13:57:12 +0000853 stats->be_rx_pkts++;
Ajit Khaparde1ef78ab2010-09-03 06:17:10 +0000854
855 if (pkt_type == BE_MULTICAST_PACKET)
856 stats->be_rx_mcast_pkt++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700857}
858
Ajit Khaparde728a9972009-04-13 15:41:22 -0700859static inline bool do_pkt_csum(struct be_eth_rx_compl *rxcp, bool cso)
860{
861 u8 l4_cksm, ip_version, ipcksm, tcpf = 0, udpf = 0, ipv6_chk;
862
863 l4_cksm = AMAP_GET_BITS(struct amap_eth_rx_compl, l4_cksm, rxcp);
864 ipcksm = AMAP_GET_BITS(struct amap_eth_rx_compl, ipcksm, rxcp);
865 ip_version = AMAP_GET_BITS(struct amap_eth_rx_compl, ip_version, rxcp);
866 if (ip_version) {
867 tcpf = AMAP_GET_BITS(struct amap_eth_rx_compl, tcpf, rxcp);
868 udpf = AMAP_GET_BITS(struct amap_eth_rx_compl, udpf, rxcp);
869 }
870 ipv6_chk = (ip_version && (tcpf || udpf));
871
872 return ((l4_cksm && ipv6_chk && ipcksm) && cso) ? false : true;
873}
874
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700875static struct be_rx_page_info *
876get_rx_page_info(struct be_adapter *adapter, u16 frag_idx)
877{
878 struct be_rx_page_info *rx_page_info;
879 struct be_queue_info *rxq = &adapter->rx_obj.q;
880
881 rx_page_info = &adapter->rx_obj.page_info_tbl[frag_idx];
882 BUG_ON(!rx_page_info->page);
883
Ajit Khaparde205859a2010-02-09 01:34:21 +0000884 if (rx_page_info->last_page_user) {
FUJITA Tomonorifac6da52010-04-01 16:53:22 +0000885 pci_unmap_page(adapter->pdev, dma_unmap_addr(rx_page_info, bus),
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700886 adapter->big_page_size, PCI_DMA_FROMDEVICE);
Ajit Khaparde205859a2010-02-09 01:34:21 +0000887 rx_page_info->last_page_user = false;
888 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700889
890 atomic_dec(&rxq->used);
891 return rx_page_info;
892}
893
894/* Throwaway the data in the Rx completion */
895static void be_rx_compl_discard(struct be_adapter *adapter,
896 struct be_eth_rx_compl *rxcp)
897{
898 struct be_queue_info *rxq = &adapter->rx_obj.q;
899 struct be_rx_page_info *page_info;
900 u16 rxq_idx, i, num_rcvd;
901
902 rxq_idx = AMAP_GET_BITS(struct amap_eth_rx_compl, fragndx, rxcp);
903 num_rcvd = AMAP_GET_BITS(struct amap_eth_rx_compl, numfrags, rxcp);
904
905 for (i = 0; i < num_rcvd; i++) {
906 page_info = get_rx_page_info(adapter, rxq_idx);
907 put_page(page_info->page);
908 memset(page_info, 0, sizeof(*page_info));
909 index_inc(&rxq_idx, rxq->len);
910 }
911}
912
913/*
914 * skb_fill_rx_data forms a complete skb for an ether frame
915 * indicated by rxcp.
916 */
917static void skb_fill_rx_data(struct be_adapter *adapter,
Sathya Perla89420422010-02-17 01:35:26 +0000918 struct sk_buff *skb, struct be_eth_rx_compl *rxcp,
919 u16 num_rcvd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700920{
921 struct be_queue_info *rxq = &adapter->rx_obj.q;
922 struct be_rx_page_info *page_info;
Sathya Perla89420422010-02-17 01:35:26 +0000923 u16 rxq_idx, i, j;
Ajit Khapardefa774062009-07-22 09:28:55 -0700924 u32 pktsize, hdr_len, curr_frag_len, size;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700925 u8 *start;
Ajit Khaparde1ef78ab2010-09-03 06:17:10 +0000926 u8 pkt_type;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700927
928 rxq_idx = AMAP_GET_BITS(struct amap_eth_rx_compl, fragndx, rxcp);
929 pktsize = AMAP_GET_BITS(struct amap_eth_rx_compl, pktsize, rxcp);
Ajit Khaparde1ef78ab2010-09-03 06:17:10 +0000930 pkt_type = AMAP_GET_BITS(struct amap_eth_rx_compl, cast_enc, rxcp);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700931
932 page_info = get_rx_page_info(adapter, rxq_idx);
933
934 start = page_address(page_info->page) + page_info->page_offset;
935 prefetch(start);
936
937 /* Copy data in the first descriptor of this completion */
938 curr_frag_len = min(pktsize, rx_frag_size);
939
940 /* Copy the header portion into skb_data */
941 hdr_len = min((u32)BE_HDR_LEN, curr_frag_len);
942 memcpy(skb->data, start, hdr_len);
943 skb->len = curr_frag_len;
944 if (curr_frag_len <= BE_HDR_LEN) { /* tiny packet */
945 /* Complete packet has now been moved to data */
946 put_page(page_info->page);
947 skb->data_len = 0;
948 skb->tail += curr_frag_len;
949 } else {
950 skb_shinfo(skb)->nr_frags = 1;
951 skb_shinfo(skb)->frags[0].page = page_info->page;
952 skb_shinfo(skb)->frags[0].page_offset =
953 page_info->page_offset + hdr_len;
954 skb_shinfo(skb)->frags[0].size = curr_frag_len - hdr_len;
955 skb->data_len = curr_frag_len - hdr_len;
956 skb->tail += hdr_len;
957 }
Ajit Khaparde205859a2010-02-09 01:34:21 +0000958 page_info->page = NULL;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700959
960 if (pktsize <= rx_frag_size) {
961 BUG_ON(num_rcvd != 1);
Sathya Perla76fbb422009-06-10 02:21:56 +0000962 goto done;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700963 }
964
965 /* More frags present for this completion */
Ajit Khapardefa774062009-07-22 09:28:55 -0700966 size = pktsize;
Ajit Khapardebd46cb62009-06-26 02:51:07 +0000967 for (i = 1, j = 0; i < num_rcvd; i++) {
Ajit Khapardefa774062009-07-22 09:28:55 -0700968 size -= curr_frag_len;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700969 index_inc(&rxq_idx, rxq->len);
970 page_info = get_rx_page_info(adapter, rxq_idx);
971
Ajit Khapardefa774062009-07-22 09:28:55 -0700972 curr_frag_len = min(size, rx_frag_size);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700973
Ajit Khapardebd46cb62009-06-26 02:51:07 +0000974 /* Coalesce all frags from the same physical page in one slot */
975 if (page_info->page_offset == 0) {
976 /* Fresh page */
977 j++;
978 skb_shinfo(skb)->frags[j].page = page_info->page;
979 skb_shinfo(skb)->frags[j].page_offset =
980 page_info->page_offset;
981 skb_shinfo(skb)->frags[j].size = 0;
982 skb_shinfo(skb)->nr_frags++;
983 } else {
984 put_page(page_info->page);
985 }
986
987 skb_shinfo(skb)->frags[j].size += curr_frag_len;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700988 skb->len += curr_frag_len;
989 skb->data_len += curr_frag_len;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700990
Ajit Khaparde205859a2010-02-09 01:34:21 +0000991 page_info->page = NULL;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700992 }
Ajit Khapardebd46cb62009-06-26 02:51:07 +0000993 BUG_ON(j > MAX_SKB_FRAGS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700994
Sathya Perla76fbb422009-06-10 02:21:56 +0000995done:
Ajit Khaparde1ef78ab2010-09-03 06:17:10 +0000996 be_rx_stats_update(adapter, pktsize, num_rcvd, pkt_type);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700997}
998
Ajit Khaparde5be93b92009-07-21 12:36:19 -0700999/* Process the RX completion indicated by rxcp when GRO is disabled */
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001000static void be_rx_compl_process(struct be_adapter *adapter,
1001 struct be_eth_rx_compl *rxcp)
1002{
1003 struct sk_buff *skb;
Ajit Khapardedcb9b562009-09-30 21:58:22 -07001004 u32 vlanf, vid;
Sathya Perla89420422010-02-17 01:35:26 +00001005 u16 num_rcvd;
Ajit Khapardedcb9b562009-09-30 21:58:22 -07001006 u8 vtm;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001007
Sathya Perla89420422010-02-17 01:35:26 +00001008 num_rcvd = AMAP_GET_BITS(struct amap_eth_rx_compl, numfrags, rxcp);
1009 /* Is it a flush compl that has no data */
1010 if (unlikely(num_rcvd == 0))
1011 return;
1012
Eric Dumazet89d71a62009-10-13 05:34:20 +00001013 skb = netdev_alloc_skb_ip_align(adapter->netdev, BE_HDR_LEN);
Sathya Perlaa058a632010-02-17 01:34:22 +00001014 if (unlikely(!skb)) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001015 if (net_ratelimit())
1016 dev_warn(&adapter->pdev->dev, "skb alloc failed\n");
1017 be_rx_compl_discard(adapter, rxcp);
1018 return;
1019 }
1020
Sathya Perla89420422010-02-17 01:35:26 +00001021 skb_fill_rx_data(adapter, skb, rxcp, num_rcvd);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001022
Ajit Khaparde728a9972009-04-13 15:41:22 -07001023 if (do_pkt_csum(rxcp, adapter->rx_csum))
Eric Dumazetbc8acf22010-09-02 13:07:41 -07001024 skb_checksum_none_assert(skb);
Ajit Khaparde728a9972009-04-13 15:41:22 -07001025 else
1026 skb->ip_summed = CHECKSUM_UNNECESSARY;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001027
1028 skb->truesize = skb->len + sizeof(struct sk_buff);
1029 skb->protocol = eth_type_trans(skb, adapter->netdev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001030
Sathya Perlaa058a632010-02-17 01:34:22 +00001031 vlanf = AMAP_GET_BITS(struct amap_eth_rx_compl, vtp, rxcp);
1032 vtm = AMAP_GET_BITS(struct amap_eth_rx_compl, vtm, rxcp);
1033
1034 /* vlanf could be wrongly set in some cards.
1035 * ignore if vtm is not set */
Ajit Khaparde3486be22010-07-23 02:04:54 +00001036 if ((adapter->function_mode & 0x400) && !vtm)
Sathya Perlaa058a632010-02-17 01:34:22 +00001037 vlanf = 0;
1038
1039 if (unlikely(vlanf)) {
Ajit Khaparde82903e42010-02-09 01:34:57 +00001040 if (!adapter->vlan_grp || adapter->vlans_added == 0) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001041 kfree_skb(skb);
1042 return;
1043 }
1044 vid = AMAP_GET_BITS(struct amap_eth_rx_compl, vlan_tag, rxcp);
Ajit Khaparde9cae9e42010-03-31 02:00:32 +00001045 vid = swab16(vid);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001046 vlan_hwaccel_receive_skb(skb, adapter->vlan_grp, vid);
1047 } else {
1048 netif_receive_skb(skb);
1049 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001050}
1051
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001052/* Process the RX completion indicated by rxcp when GRO is enabled */
1053static void be_rx_compl_process_gro(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001054 struct be_eth_rx_compl *rxcp)
1055{
1056 struct be_rx_page_info *page_info;
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001057 struct sk_buff *skb = NULL;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001058 struct be_queue_info *rxq = &adapter->rx_obj.q;
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001059 struct be_eq_obj *eq_obj = &adapter->rx_eq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001060 u32 num_rcvd, pkt_size, remaining, vlanf, curr_frag_len;
Ajit Khapardebd46cb62009-06-26 02:51:07 +00001061 u16 i, rxq_idx = 0, vid, j;
Ajit Khapardedcb9b562009-09-30 21:58:22 -07001062 u8 vtm;
Ajit Khaparde1ef78ab2010-09-03 06:17:10 +00001063 u8 pkt_type;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001064
1065 num_rcvd = AMAP_GET_BITS(struct amap_eth_rx_compl, numfrags, rxcp);
Sathya Perla89420422010-02-17 01:35:26 +00001066 /* Is it a flush compl that has no data */
1067 if (unlikely(num_rcvd == 0))
1068 return;
1069
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001070 pkt_size = AMAP_GET_BITS(struct amap_eth_rx_compl, pktsize, rxcp);
1071 vlanf = AMAP_GET_BITS(struct amap_eth_rx_compl, vtp, rxcp);
1072 rxq_idx = AMAP_GET_BITS(struct amap_eth_rx_compl, fragndx, rxcp);
Ajit Khapardedcb9b562009-09-30 21:58:22 -07001073 vtm = AMAP_GET_BITS(struct amap_eth_rx_compl, vtm, rxcp);
Ajit Khaparde1ef78ab2010-09-03 06:17:10 +00001074 pkt_type = AMAP_GET_BITS(struct amap_eth_rx_compl, cast_enc, rxcp);
Ajit Khapardedcb9b562009-09-30 21:58:22 -07001075
1076 /* vlanf could be wrongly set in some cards.
1077 * ignore if vtm is not set */
Ajit Khaparde3486be22010-07-23 02:04:54 +00001078 if ((adapter->function_mode & 0x400) && !vtm)
Ajit Khapardedcb9b562009-09-30 21:58:22 -07001079 vlanf = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001080
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001081 skb = napi_get_frags(&eq_obj->napi);
1082 if (!skb) {
1083 be_rx_compl_discard(adapter, rxcp);
1084 return;
1085 }
1086
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001087 remaining = pkt_size;
Ajit Khapardebd46cb62009-06-26 02:51:07 +00001088 for (i = 0, j = -1; i < num_rcvd; i++) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001089 page_info = get_rx_page_info(adapter, rxq_idx);
1090
1091 curr_frag_len = min(remaining, rx_frag_size);
1092
Ajit Khapardebd46cb62009-06-26 02:51:07 +00001093 /* Coalesce all frags from the same physical page in one slot */
1094 if (i == 0 || page_info->page_offset == 0) {
1095 /* First frag or Fresh page */
1096 j++;
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001097 skb_shinfo(skb)->frags[j].page = page_info->page;
1098 skb_shinfo(skb)->frags[j].page_offset =
1099 page_info->page_offset;
1100 skb_shinfo(skb)->frags[j].size = 0;
Ajit Khapardebd46cb62009-06-26 02:51:07 +00001101 } else {
1102 put_page(page_info->page);
1103 }
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001104 skb_shinfo(skb)->frags[j].size += curr_frag_len;
Ajit Khapardebd46cb62009-06-26 02:51:07 +00001105
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001106 remaining -= curr_frag_len;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001107 index_inc(&rxq_idx, rxq->len);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001108 memset(page_info, 0, sizeof(*page_info));
1109 }
Ajit Khapardebd46cb62009-06-26 02:51:07 +00001110 BUG_ON(j > MAX_SKB_FRAGS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001111
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001112 skb_shinfo(skb)->nr_frags = j + 1;
1113 skb->len = pkt_size;
1114 skb->data_len = pkt_size;
1115 skb->truesize += pkt_size;
1116 skb->ip_summed = CHECKSUM_UNNECESSARY;
1117
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001118 if (likely(!vlanf)) {
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001119 napi_gro_frags(&eq_obj->napi);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001120 } else {
1121 vid = AMAP_GET_BITS(struct amap_eth_rx_compl, vlan_tag, rxcp);
Ajit Khaparde9cae9e42010-03-31 02:00:32 +00001122 vid = swab16(vid);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001123
Ajit Khaparde82903e42010-02-09 01:34:57 +00001124 if (!adapter->vlan_grp || adapter->vlans_added == 0)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001125 return;
1126
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001127 vlan_gro_frags(&eq_obj->napi, adapter->vlan_grp, vid);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001128 }
1129
Ajit Khaparde1ef78ab2010-09-03 06:17:10 +00001130 be_rx_stats_update(adapter, pkt_size, num_rcvd, pkt_type);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001131}
1132
1133static struct be_eth_rx_compl *be_rx_compl_get(struct be_adapter *adapter)
1134{
1135 struct be_eth_rx_compl *rxcp = queue_tail_node(&adapter->rx_obj.cq);
1136
1137 if (rxcp->dw[offsetof(struct amap_eth_rx_compl, valid) / 32] == 0)
1138 return NULL;
1139
Sathya Perlaf3eb62d2010-06-29 00:11:17 +00001140 rmb();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001141 be_dws_le_to_cpu(rxcp, sizeof(*rxcp));
1142
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001143 queue_tail_inc(&adapter->rx_obj.cq);
1144 return rxcp;
1145}
1146
Sathya Perlaa7a0ef32009-06-10 02:23:28 +00001147/* To reset the valid bit, we need to reset the whole word as
1148 * when walking the queue the valid entries are little-endian
1149 * and invalid entries are host endian
1150 */
1151static inline void be_rx_compl_reset(struct be_eth_rx_compl *rxcp)
1152{
1153 rxcp->dw[offsetof(struct amap_eth_rx_compl, valid) / 32] = 0;
1154}
1155
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001156static inline struct page *be_alloc_pages(u32 size)
1157{
1158 gfp_t alloc_flags = GFP_ATOMIC;
1159 u32 order = get_order(size);
1160 if (order > 0)
1161 alloc_flags |= __GFP_COMP;
1162 return alloc_pages(alloc_flags, order);
1163}
1164
1165/*
1166 * Allocate a page, split it to fragments of size rx_frag_size and post as
1167 * receive buffers to BE
1168 */
1169static void be_post_rx_frags(struct be_adapter *adapter)
1170{
1171 struct be_rx_page_info *page_info_tbl = adapter->rx_obj.page_info_tbl;
Sathya Perla26d92f92010-01-21 22:52:08 -08001172 struct be_rx_page_info *page_info = NULL, *prev_page_info = NULL;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001173 struct be_queue_info *rxq = &adapter->rx_obj.q;
1174 struct page *pagep = NULL;
1175 struct be_eth_rx_d *rxd;
1176 u64 page_dmaaddr = 0, frag_dmaaddr;
1177 u32 posted, page_offset = 0;
1178
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001179 page_info = &page_info_tbl[rxq->head];
1180 for (posted = 0; posted < MAX_RX_POST && !page_info->page; posted++) {
1181 if (!pagep) {
1182 pagep = be_alloc_pages(adapter->big_page_size);
1183 if (unlikely(!pagep)) {
1184 drvr_stats(adapter)->be_ethrx_post_fail++;
1185 break;
1186 }
1187 page_dmaaddr = pci_map_page(adapter->pdev, pagep, 0,
1188 adapter->big_page_size,
1189 PCI_DMA_FROMDEVICE);
1190 page_info->page_offset = 0;
1191 } else {
1192 get_page(pagep);
1193 page_info->page_offset = page_offset + rx_frag_size;
1194 }
1195 page_offset = page_info->page_offset;
1196 page_info->page = pagep;
FUJITA Tomonorifac6da52010-04-01 16:53:22 +00001197 dma_unmap_addr_set(page_info, bus, page_dmaaddr);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001198 frag_dmaaddr = page_dmaaddr + page_info->page_offset;
1199
1200 rxd = queue_head_node(rxq);
1201 rxd->fragpa_lo = cpu_to_le32(frag_dmaaddr & 0xFFFFFFFF);
1202 rxd->fragpa_hi = cpu_to_le32(upper_32_bits(frag_dmaaddr));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001203
1204 /* Any space left in the current big page for another frag? */
1205 if ((page_offset + rx_frag_size + rx_frag_size) >
1206 adapter->big_page_size) {
1207 pagep = NULL;
1208 page_info->last_page_user = true;
1209 }
Sathya Perla26d92f92010-01-21 22:52:08 -08001210
1211 prev_page_info = page_info;
1212 queue_head_inc(rxq);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001213 page_info = &page_info_tbl[rxq->head];
1214 }
1215 if (pagep)
Sathya Perla26d92f92010-01-21 22:52:08 -08001216 prev_page_info->last_page_user = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001217
1218 if (posted) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001219 atomic_add(posted, &rxq->used);
Sathya Perla8788fdc2009-07-27 22:52:03 +00001220 be_rxq_notify(adapter, rxq->id, posted);
Sathya Perlaea1dae12009-03-19 23:56:20 -07001221 } else if (atomic_read(&rxq->used) == 0) {
1222 /* Let be_worker replenish when memory is available */
1223 adapter->rx_post_starved = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001224 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001225}
1226
Sathya Perla5fb379e2009-06-18 00:02:59 +00001227static struct be_eth_tx_compl *be_tx_compl_get(struct be_queue_info *tx_cq)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001228{
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001229 struct be_eth_tx_compl *txcp = queue_tail_node(tx_cq);
1230
1231 if (txcp->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] == 0)
1232 return NULL;
1233
Sathya Perlaf3eb62d2010-06-29 00:11:17 +00001234 rmb();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001235 be_dws_le_to_cpu(txcp, sizeof(*txcp));
1236
1237 txcp->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] = 0;
1238
1239 queue_tail_inc(tx_cq);
1240 return txcp;
1241}
1242
1243static void be_tx_compl_process(struct be_adapter *adapter, u16 last_index)
1244{
1245 struct be_queue_info *txq = &adapter->tx_obj.q;
Alexander Duycka73b7962009-12-02 16:48:18 +00001246 struct be_eth_wrb *wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001247 struct sk_buff **sent_skbs = adapter->tx_obj.sent_skb_list;
1248 struct sk_buff *sent_skb;
Sathya Perlaec43b1a2010-03-22 20:41:34 +00001249 u16 cur_index, num_wrbs = 1; /* account for hdr wrb */
1250 bool unmap_skb_hdr = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001251
Sathya Perlaec43b1a2010-03-22 20:41:34 +00001252 sent_skb = sent_skbs[txq->tail];
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001253 BUG_ON(!sent_skb);
Sathya Perlaec43b1a2010-03-22 20:41:34 +00001254 sent_skbs[txq->tail] = NULL;
1255
1256 /* skip header wrb */
Alexander Duycka73b7962009-12-02 16:48:18 +00001257 queue_tail_inc(txq);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001258
Sathya Perlaec43b1a2010-03-22 20:41:34 +00001259 do {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001260 cur_index = txq->tail;
Alexander Duycka73b7962009-12-02 16:48:18 +00001261 wrb = queue_tail_node(txq);
Sathya Perlaec43b1a2010-03-22 20:41:34 +00001262 unmap_tx_frag(adapter->pdev, wrb, (unmap_skb_hdr &&
Eric Dumazete743d312010-04-14 15:59:40 -07001263 skb_headlen(sent_skb)));
Sathya Perlaec43b1a2010-03-22 20:41:34 +00001264 unmap_skb_hdr = false;
1265
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001266 num_wrbs++;
1267 queue_tail_inc(txq);
Sathya Perlaec43b1a2010-03-22 20:41:34 +00001268 } while (cur_index != last_index);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001269
1270 atomic_sub(num_wrbs, &txq->used);
Alexander Duycka73b7962009-12-02 16:48:18 +00001271
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001272 kfree_skb(sent_skb);
1273}
1274
Sathya Perla859b1e42009-08-10 03:43:51 +00001275static inline struct be_eq_entry *event_get(struct be_eq_obj *eq_obj)
1276{
1277 struct be_eq_entry *eqe = queue_tail_node(&eq_obj->q);
1278
1279 if (!eqe->evt)
1280 return NULL;
1281
Sathya Perlaf3eb62d2010-06-29 00:11:17 +00001282 rmb();
Sathya Perla859b1e42009-08-10 03:43:51 +00001283 eqe->evt = le32_to_cpu(eqe->evt);
1284 queue_tail_inc(&eq_obj->q);
1285 return eqe;
1286}
1287
1288static int event_handle(struct be_adapter *adapter,
1289 struct be_eq_obj *eq_obj)
1290{
1291 struct be_eq_entry *eqe;
1292 u16 num = 0;
1293
1294 while ((eqe = event_get(eq_obj)) != NULL) {
1295 eqe->evt = 0;
1296 num++;
1297 }
1298
1299 /* Deal with any spurious interrupts that come
1300 * without events
1301 */
1302 be_eq_notify(adapter, eq_obj->q.id, true, true, num);
1303 if (num)
1304 napi_schedule(&eq_obj->napi);
1305
1306 return num;
1307}
1308
1309/* Just read and notify events without processing them.
1310 * Used at the time of destroying event queues */
1311static void be_eq_clean(struct be_adapter *adapter,
1312 struct be_eq_obj *eq_obj)
1313{
1314 struct be_eq_entry *eqe;
1315 u16 num = 0;
1316
1317 while ((eqe = event_get(eq_obj)) != NULL) {
1318 eqe->evt = 0;
1319 num++;
1320 }
1321
1322 if (num)
1323 be_eq_notify(adapter, eq_obj->q.id, false, true, num);
1324}
1325
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001326static void be_rx_q_clean(struct be_adapter *adapter)
1327{
1328 struct be_rx_page_info *page_info;
1329 struct be_queue_info *rxq = &adapter->rx_obj.q;
1330 struct be_queue_info *rx_cq = &adapter->rx_obj.cq;
1331 struct be_eth_rx_compl *rxcp;
1332 u16 tail;
1333
1334 /* First cleanup pending rx completions */
1335 while ((rxcp = be_rx_compl_get(adapter)) != NULL) {
1336 be_rx_compl_discard(adapter, rxcp);
Sathya Perlaa7a0ef32009-06-10 02:23:28 +00001337 be_rx_compl_reset(rxcp);
Sathya Perla8788fdc2009-07-27 22:52:03 +00001338 be_cq_notify(adapter, rx_cq->id, true, 1);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001339 }
1340
1341 /* Then free posted rx buffer that were not used */
1342 tail = (rxq->head + rxq->len - atomic_read(&rxq->used)) % rxq->len;
Sathya Perlacdab23b2009-08-10 03:43:23 +00001343 for (; atomic_read(&rxq->used) > 0; index_inc(&tail, rxq->len)) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001344 page_info = get_rx_page_info(adapter, tail);
1345 put_page(page_info->page);
1346 memset(page_info, 0, sizeof(*page_info));
1347 }
1348 BUG_ON(atomic_read(&rxq->used));
1349}
1350
Sathya Perlaa8e91792009-08-10 03:42:43 +00001351static void be_tx_compl_clean(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001352{
Sathya Perlaa8e91792009-08-10 03:42:43 +00001353 struct be_queue_info *tx_cq = &adapter->tx_obj.cq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001354 struct be_queue_info *txq = &adapter->tx_obj.q;
Sathya Perlaa8e91792009-08-10 03:42:43 +00001355 struct be_eth_tx_compl *txcp;
1356 u16 end_idx, cmpl = 0, timeo = 0;
Sathya Perlab03388d2010-02-18 00:37:17 +00001357 struct sk_buff **sent_skbs = adapter->tx_obj.sent_skb_list;
1358 struct sk_buff *sent_skb;
1359 bool dummy_wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001360
Sathya Perlaa8e91792009-08-10 03:42:43 +00001361 /* Wait for a max of 200ms for all the tx-completions to arrive. */
1362 do {
1363 while ((txcp = be_tx_compl_get(tx_cq))) {
1364 end_idx = AMAP_GET_BITS(struct amap_eth_tx_compl,
1365 wrb_index, txcp);
1366 be_tx_compl_process(adapter, end_idx);
1367 cmpl++;
1368 }
1369 if (cmpl) {
1370 be_cq_notify(adapter, tx_cq->id, false, cmpl);
1371 cmpl = 0;
1372 }
1373
1374 if (atomic_read(&txq->used) == 0 || ++timeo > 200)
1375 break;
1376
1377 mdelay(1);
1378 } while (true);
1379
1380 if (atomic_read(&txq->used))
1381 dev_err(&adapter->pdev->dev, "%d pending tx-completions\n",
1382 atomic_read(&txq->used));
Sathya Perlab03388d2010-02-18 00:37:17 +00001383
1384 /* free posted tx for which compls will never arrive */
1385 while (atomic_read(&txq->used)) {
1386 sent_skb = sent_skbs[txq->tail];
1387 end_idx = txq->tail;
1388 index_adv(&end_idx,
1389 wrb_cnt_for_skb(sent_skb, &dummy_wrb) - 1, txq->len);
1390 be_tx_compl_process(adapter, end_idx);
1391 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001392}
1393
Sathya Perla5fb379e2009-06-18 00:02:59 +00001394static void be_mcc_queues_destroy(struct be_adapter *adapter)
1395{
1396 struct be_queue_info *q;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001397
Sathya Perla8788fdc2009-07-27 22:52:03 +00001398 q = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001399 if (q->created)
Sathya Perla8788fdc2009-07-27 22:52:03 +00001400 be_cmd_q_destroy(adapter, q, QTYPE_MCCQ);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001401 be_queue_free(adapter, q);
1402
Sathya Perla8788fdc2009-07-27 22:52:03 +00001403 q = &adapter->mcc_obj.cq;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001404 if (q->created)
Sathya Perla8788fdc2009-07-27 22:52:03 +00001405 be_cmd_q_destroy(adapter, q, QTYPE_CQ);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001406 be_queue_free(adapter, q);
1407}
1408
1409/* Must be called only after TX qs are created as MCC shares TX EQ */
1410static int be_mcc_queues_create(struct be_adapter *adapter)
1411{
1412 struct be_queue_info *q, *cq;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001413
1414 /* Alloc MCC compl queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001415 cq = &adapter->mcc_obj.cq;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001416 if (be_queue_alloc(adapter, cq, MCC_CQ_LEN,
Sathya Perlaefd2e402009-07-27 22:53:10 +00001417 sizeof(struct be_mcc_compl)))
Sathya Perla5fb379e2009-06-18 00:02:59 +00001418 goto err;
1419
1420 /* Ask BE to create MCC compl queue; share TX's eq */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001421 if (be_cmd_cq_create(adapter, cq, &adapter->tx_eq.q, false, true, 0))
Sathya Perla5fb379e2009-06-18 00:02:59 +00001422 goto mcc_cq_free;
1423
1424 /* Alloc MCC queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001425 q = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001426 if (be_queue_alloc(adapter, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
1427 goto mcc_cq_destroy;
1428
1429 /* Ask BE to create MCC queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001430 if (be_cmd_mccq_create(adapter, q, cq))
Sathya Perla5fb379e2009-06-18 00:02:59 +00001431 goto mcc_q_free;
1432
1433 return 0;
1434
1435mcc_q_free:
1436 be_queue_free(adapter, q);
1437mcc_cq_destroy:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001438 be_cmd_q_destroy(adapter, cq, QTYPE_CQ);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001439mcc_cq_free:
1440 be_queue_free(adapter, cq);
1441err:
1442 return -1;
1443}
1444
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001445static void be_tx_queues_destroy(struct be_adapter *adapter)
1446{
1447 struct be_queue_info *q;
1448
1449 q = &adapter->tx_obj.q;
Sathya Perlaa8e91792009-08-10 03:42:43 +00001450 if (q->created)
Sathya Perla8788fdc2009-07-27 22:52:03 +00001451 be_cmd_q_destroy(adapter, q, QTYPE_TXQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001452 be_queue_free(adapter, q);
1453
1454 q = &adapter->tx_obj.cq;
1455 if (q->created)
Sathya Perla8788fdc2009-07-27 22:52:03 +00001456 be_cmd_q_destroy(adapter, q, QTYPE_CQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001457 be_queue_free(adapter, q);
1458
Sathya Perla859b1e42009-08-10 03:43:51 +00001459 /* Clear any residual events */
1460 be_eq_clean(adapter, &adapter->tx_eq);
1461
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001462 q = &adapter->tx_eq.q;
1463 if (q->created)
Sathya Perla8788fdc2009-07-27 22:52:03 +00001464 be_cmd_q_destroy(adapter, q, QTYPE_EQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001465 be_queue_free(adapter, q);
1466}
1467
1468static int be_tx_queues_create(struct be_adapter *adapter)
1469{
1470 struct be_queue_info *eq, *q, *cq;
1471
1472 adapter->tx_eq.max_eqd = 0;
1473 adapter->tx_eq.min_eqd = 0;
1474 adapter->tx_eq.cur_eqd = 96;
1475 adapter->tx_eq.enable_aic = false;
1476 /* Alloc Tx Event queue */
1477 eq = &adapter->tx_eq.q;
1478 if (be_queue_alloc(adapter, eq, EVNT_Q_LEN, sizeof(struct be_eq_entry)))
1479 return -1;
1480
1481 /* Ask BE to create Tx Event queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001482 if (be_cmd_eq_create(adapter, eq, adapter->tx_eq.cur_eqd))
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001483 goto tx_eq_free;
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001484 adapter->base_eq_id = adapter->tx_eq.q.id;
1485
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001486 /* Alloc TX eth compl queue */
1487 cq = &adapter->tx_obj.cq;
1488 if (be_queue_alloc(adapter, cq, TX_CQ_LEN,
1489 sizeof(struct be_eth_tx_compl)))
1490 goto tx_eq_destroy;
1491
1492 /* Ask BE to create Tx eth compl queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001493 if (be_cmd_cq_create(adapter, cq, eq, false, false, 3))
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001494 goto tx_cq_free;
1495
1496 /* Alloc TX eth queue */
1497 q = &adapter->tx_obj.q;
1498 if (be_queue_alloc(adapter, q, TX_Q_LEN, sizeof(struct be_eth_wrb)))
1499 goto tx_cq_destroy;
1500
1501 /* Ask BE to create Tx eth queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001502 if (be_cmd_txq_create(adapter, q, cq))
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001503 goto tx_q_free;
1504 return 0;
1505
1506tx_q_free:
1507 be_queue_free(adapter, q);
1508tx_cq_destroy:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001509 be_cmd_q_destroy(adapter, cq, QTYPE_CQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001510tx_cq_free:
1511 be_queue_free(adapter, cq);
1512tx_eq_destroy:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001513 be_cmd_q_destroy(adapter, eq, QTYPE_EQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001514tx_eq_free:
1515 be_queue_free(adapter, eq);
1516 return -1;
1517}
1518
1519static void be_rx_queues_destroy(struct be_adapter *adapter)
1520{
1521 struct be_queue_info *q;
1522
1523 q = &adapter->rx_obj.q;
1524 if (q->created) {
Sathya Perla8788fdc2009-07-27 22:52:03 +00001525 be_cmd_q_destroy(adapter, q, QTYPE_RXQ);
Sathya Perla89420422010-02-17 01:35:26 +00001526
1527 /* After the rxq is invalidated, wait for a grace time
1528 * of 1ms for all dma to end and the flush compl to arrive
1529 */
1530 mdelay(1);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001531 be_rx_q_clean(adapter);
1532 }
1533 be_queue_free(adapter, q);
1534
1535 q = &adapter->rx_obj.cq;
1536 if (q->created)
Sathya Perla8788fdc2009-07-27 22:52:03 +00001537 be_cmd_q_destroy(adapter, q, QTYPE_CQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001538 be_queue_free(adapter, q);
1539
Sathya Perla859b1e42009-08-10 03:43:51 +00001540 /* Clear any residual events */
1541 be_eq_clean(adapter, &adapter->rx_eq);
1542
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001543 q = &adapter->rx_eq.q;
1544 if (q->created)
Sathya Perla8788fdc2009-07-27 22:52:03 +00001545 be_cmd_q_destroy(adapter, q, QTYPE_EQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001546 be_queue_free(adapter, q);
1547}
1548
1549static int be_rx_queues_create(struct be_adapter *adapter)
1550{
1551 struct be_queue_info *eq, *q, *cq;
1552 int rc;
1553
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001554 adapter->big_page_size = (1 << get_order(rx_frag_size)) * PAGE_SIZE;
1555 adapter->rx_eq.max_eqd = BE_MAX_EQD;
1556 adapter->rx_eq.min_eqd = 0;
1557 adapter->rx_eq.cur_eqd = 0;
1558 adapter->rx_eq.enable_aic = true;
1559
1560 /* Alloc Rx Event queue */
1561 eq = &adapter->rx_eq.q;
1562 rc = be_queue_alloc(adapter, eq, EVNT_Q_LEN,
1563 sizeof(struct be_eq_entry));
1564 if (rc)
1565 return rc;
1566
1567 /* Ask BE to create Rx Event queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001568 rc = be_cmd_eq_create(adapter, eq, adapter->rx_eq.cur_eqd);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001569 if (rc)
1570 goto rx_eq_free;
1571
1572 /* Alloc RX eth compl queue */
1573 cq = &adapter->rx_obj.cq;
1574 rc = be_queue_alloc(adapter, cq, RX_CQ_LEN,
1575 sizeof(struct be_eth_rx_compl));
1576 if (rc)
1577 goto rx_eq_destroy;
1578
1579 /* Ask BE to create Rx eth compl queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001580 rc = be_cmd_cq_create(adapter, cq, eq, false, false, 3);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001581 if (rc)
1582 goto rx_cq_free;
1583
1584 /* Alloc RX eth queue */
1585 q = &adapter->rx_obj.q;
1586 rc = be_queue_alloc(adapter, q, RX_Q_LEN, sizeof(struct be_eth_rx_d));
1587 if (rc)
1588 goto rx_cq_destroy;
1589
1590 /* Ask BE to create Rx eth queue */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001591 rc = be_cmd_rxq_create(adapter, q, cq->id, rx_frag_size,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001592 BE_MAX_JUMBO_FRAME_SIZE, adapter->if_handle, false);
1593 if (rc)
1594 goto rx_q_free;
1595
1596 return 0;
1597rx_q_free:
1598 be_queue_free(adapter, q);
1599rx_cq_destroy:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001600 be_cmd_q_destroy(adapter, cq, QTYPE_CQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001601rx_cq_free:
1602 be_queue_free(adapter, cq);
1603rx_eq_destroy:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001604 be_cmd_q_destroy(adapter, eq, QTYPE_EQ);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001605rx_eq_free:
1606 be_queue_free(adapter, eq);
1607 return rc;
1608}
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001609
Sathya Perlab628bde2009-08-17 00:58:26 +00001610/* There are 8 evt ids per func. Retruns the evt id's bit number */
1611static inline int be_evt_bit_get(struct be_adapter *adapter, u32 eq_id)
1612{
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001613 return eq_id - adapter->base_eq_id;
Sathya Perlab628bde2009-08-17 00:58:26 +00001614}
1615
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001616static irqreturn_t be_intx(int irq, void *dev)
1617{
1618 struct be_adapter *adapter = dev;
Sathya Perla8788fdc2009-07-27 22:52:03 +00001619 int isr;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001620
Sathya Perla8788fdc2009-07-27 22:52:03 +00001621 isr = ioread32(adapter->csr + CEV_ISR0_OFFSET +
Sathya Perla55bdeed2010-02-02 07:48:40 -08001622 (adapter->tx_eq.q.id/ 8) * CEV_ISR_SIZE);
Sathya Perlac001c212009-07-01 01:06:07 +00001623 if (!isr)
Sathya Perla8788fdc2009-07-27 22:52:03 +00001624 return IRQ_NONE;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001625
Sathya Perla8788fdc2009-07-27 22:52:03 +00001626 event_handle(adapter, &adapter->tx_eq);
1627 event_handle(adapter, &adapter->rx_eq);
Sathya Perlac001c212009-07-01 01:06:07 +00001628
Sathya Perla8788fdc2009-07-27 22:52:03 +00001629 return IRQ_HANDLED;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001630}
1631
1632static irqreturn_t be_msix_rx(int irq, void *dev)
1633{
1634 struct be_adapter *adapter = dev;
1635
Sathya Perla8788fdc2009-07-27 22:52:03 +00001636 event_handle(adapter, &adapter->rx_eq);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001637
1638 return IRQ_HANDLED;
1639}
1640
Sathya Perla5fb379e2009-06-18 00:02:59 +00001641static irqreturn_t be_msix_tx_mcc(int irq, void *dev)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001642{
1643 struct be_adapter *adapter = dev;
1644
Sathya Perla8788fdc2009-07-27 22:52:03 +00001645 event_handle(adapter, &adapter->tx_eq);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001646
1647 return IRQ_HANDLED;
1648}
1649
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001650static inline bool do_gro(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001651 struct be_eth_rx_compl *rxcp)
1652{
1653 int err = AMAP_GET_BITS(struct amap_eth_rx_compl, err, rxcp);
1654 int tcp_frame = AMAP_GET_BITS(struct amap_eth_rx_compl, tcpf, rxcp);
1655
1656 if (err)
1657 drvr_stats(adapter)->be_rxcp_err++;
1658
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001659 return (tcp_frame && !err) ? true : false;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001660}
1661
1662int be_poll_rx(struct napi_struct *napi, int budget)
1663{
1664 struct be_eq_obj *rx_eq = container_of(napi, struct be_eq_obj, napi);
1665 struct be_adapter *adapter =
1666 container_of(rx_eq, struct be_adapter, rx_eq);
1667 struct be_queue_info *rx_cq = &adapter->rx_obj.cq;
1668 struct be_eth_rx_compl *rxcp;
1669 u32 work_done;
1670
Ajit Khapardeb7b83ac2009-11-29 17:57:22 +00001671 adapter->stats.drvr_stats.be_rx_polls++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001672 for (work_done = 0; work_done < budget; work_done++) {
1673 rxcp = be_rx_compl_get(adapter);
1674 if (!rxcp)
1675 break;
1676
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001677 if (do_gro(adapter, rxcp))
1678 be_rx_compl_process_gro(adapter, rxcp);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001679 else
1680 be_rx_compl_process(adapter, rxcp);
Sathya Perlaa7a0ef32009-06-10 02:23:28 +00001681
1682 be_rx_compl_reset(rxcp);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001683 }
1684
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001685 /* Refill the queue */
1686 if (atomic_read(&adapter->rx_obj.q.used) < RX_FRAGS_REFILL_WM)
1687 be_post_rx_frags(adapter);
1688
1689 /* All consumed */
1690 if (work_done < budget) {
1691 napi_complete(napi);
Sathya Perla8788fdc2009-07-27 22:52:03 +00001692 be_cq_notify(adapter, rx_cq->id, true, work_done);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001693 } else {
1694 /* More to be consumed; continue with interrupts disabled */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001695 be_cq_notify(adapter, rx_cq->id, false, work_done);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001696 }
1697 return work_done;
1698}
1699
Sathya Perlaf31e50a2010-03-02 03:56:39 -08001700/* As TX and MCC share the same EQ check for both TX and MCC completions.
1701 * For TX/MCC we don't honour budget; consume everything
1702 */
1703static int be_poll_tx_mcc(struct napi_struct *napi, int budget)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001704{
Sathya Perlaf31e50a2010-03-02 03:56:39 -08001705 struct be_eq_obj *tx_eq = container_of(napi, struct be_eq_obj, napi);
1706 struct be_adapter *adapter =
1707 container_of(tx_eq, struct be_adapter, tx_eq);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001708 struct be_queue_info *txq = &adapter->tx_obj.q;
1709 struct be_queue_info *tx_cq = &adapter->tx_obj.cq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001710 struct be_eth_tx_compl *txcp;
Sathya Perlaf31e50a2010-03-02 03:56:39 -08001711 int tx_compl = 0, mcc_compl, status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001712 u16 end_idx;
1713
Sathya Perla5fb379e2009-06-18 00:02:59 +00001714 while ((txcp = be_tx_compl_get(tx_cq))) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001715 end_idx = AMAP_GET_BITS(struct amap_eth_tx_compl,
Sathya Perlaf31e50a2010-03-02 03:56:39 -08001716 wrb_index, txcp);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001717 be_tx_compl_process(adapter, end_idx);
Sathya Perlaf31e50a2010-03-02 03:56:39 -08001718 tx_compl++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001719 }
1720
Sathya Perlaf31e50a2010-03-02 03:56:39 -08001721 mcc_compl = be_process_mcc(adapter, &status);
1722
1723 napi_complete(napi);
1724
1725 if (mcc_compl) {
1726 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
1727 be_cq_notify(adapter, mcc_obj->cq.id, true, mcc_compl);
1728 }
1729
1730 if (tx_compl) {
1731 be_cq_notify(adapter, adapter->tx_obj.cq.id, true, tx_compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001732
1733 /* As Tx wrbs have been freed up, wake up netdev queue if
1734 * it was stopped due to lack of tx wrbs.
1735 */
1736 if (netif_queue_stopped(adapter->netdev) &&
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001737 atomic_read(&txq->used) < txq->len / 2) {
Sathya Perla5fb379e2009-06-18 00:02:59 +00001738 netif_wake_queue(adapter->netdev);
1739 }
1740
1741 drvr_stats(adapter)->be_tx_events++;
Sathya Perlaf31e50a2010-03-02 03:56:39 -08001742 drvr_stats(adapter)->be_tx_compl += tx_compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001743 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001744
1745 return 1;
1746}
1747
Ajit Khaparded053de92010-09-03 06:23:30 +00001748void be_detect_dump_ue(struct be_adapter *adapter)
Ajit Khaparde7c185272010-07-29 06:16:33 +00001749{
1750 u32 ue_status_lo, ue_status_hi, ue_status_lo_mask, ue_status_hi_mask;
1751 u32 i;
1752
1753 pci_read_config_dword(adapter->pdev,
1754 PCICFG_UE_STATUS_LOW, &ue_status_lo);
1755 pci_read_config_dword(adapter->pdev,
1756 PCICFG_UE_STATUS_HIGH, &ue_status_hi);
1757 pci_read_config_dword(adapter->pdev,
1758 PCICFG_UE_STATUS_LOW_MASK, &ue_status_lo_mask);
1759 pci_read_config_dword(adapter->pdev,
1760 PCICFG_UE_STATUS_HI_MASK, &ue_status_hi_mask);
1761
1762 ue_status_lo = (ue_status_lo & (~ue_status_lo_mask));
1763 ue_status_hi = (ue_status_hi & (~ue_status_hi_mask));
1764
Ajit Khaparded053de92010-09-03 06:23:30 +00001765 if (ue_status_lo || ue_status_hi) {
1766 adapter->ue_detected = true;
1767 dev_err(&adapter->pdev->dev, "UE Detected!!\n");
1768 }
1769
Ajit Khaparde7c185272010-07-29 06:16:33 +00001770 if (ue_status_lo) {
1771 for (i = 0; ue_status_lo; ue_status_lo >>= 1, i++) {
1772 if (ue_status_lo & 1)
1773 dev_err(&adapter->pdev->dev,
1774 "UE: %s bit set\n", ue_status_low_desc[i]);
1775 }
1776 }
1777 if (ue_status_hi) {
1778 for (i = 0; ue_status_hi; ue_status_hi >>= 1, i++) {
1779 if (ue_status_hi & 1)
1780 dev_err(&adapter->pdev->dev,
1781 "UE: %s bit set\n", ue_status_hi_desc[i]);
1782 }
1783 }
1784
1785}
1786
Sathya Perlaea1dae12009-03-19 23:56:20 -07001787static void be_worker(struct work_struct *work)
1788{
1789 struct be_adapter *adapter =
1790 container_of(work, struct be_adapter, work.work);
Sathya Perlaea1dae12009-03-19 23:56:20 -07001791
Ajit Khaparde0fc48c32010-07-29 06:18:58 +00001792 if (!adapter->stats_ioctl_sent)
1793 be_cmd_get_stats(adapter, &adapter->stats.cmd);
Sathya Perlaea1dae12009-03-19 23:56:20 -07001794
1795 /* Set EQ delay */
1796 be_rx_eqd_update(adapter);
1797
Sathya Perla4097f662009-03-24 16:40:13 -07001798 be_tx_rate_update(adapter);
1799 be_rx_rate_update(adapter);
1800
Sathya Perlaea1dae12009-03-19 23:56:20 -07001801 if (adapter->rx_post_starved) {
1802 adapter->rx_post_starved = false;
1803 be_post_rx_frags(adapter);
1804 }
Ajit Khaparded053de92010-09-03 06:23:30 +00001805 if (!adapter->ue_detected)
1806 be_detect_dump_ue(adapter);
Sathya Perlaea1dae12009-03-19 23:56:20 -07001807
1808 schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000));
1809}
1810
Sathya Perla8d56ff12009-11-22 22:02:26 +00001811static void be_msix_disable(struct be_adapter *adapter)
1812{
1813 if (adapter->msix_enabled) {
1814 pci_disable_msix(adapter->pdev);
1815 adapter->msix_enabled = false;
1816 }
1817}
1818
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001819static void be_msix_enable(struct be_adapter *adapter)
1820{
1821 int i, status;
1822
1823 for (i = 0; i < BE_NUM_MSIX_VECTORS; i++)
1824 adapter->msix_entries[i].entry = i;
1825
1826 status = pci_enable_msix(adapter->pdev, adapter->msix_entries,
1827 BE_NUM_MSIX_VECTORS);
1828 if (status == 0)
1829 adapter->msix_enabled = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001830}
1831
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001832static void be_sriov_enable(struct be_adapter *adapter)
1833{
Sarveshwar Bandi344dbf12010-07-09 01:43:55 +00001834 be_check_sriov_fn_type(adapter);
Ajit Khaparde6dedec82010-07-29 06:15:32 +00001835#ifdef CONFIG_PCI_IOV
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001836 if (be_physfn(adapter) && num_vfs) {
Ajit Khaparde6dedec82010-07-29 06:15:32 +00001837 int status;
1838
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001839 status = pci_enable_sriov(adapter->pdev, num_vfs);
1840 adapter->sriov_enabled = status ? false : true;
1841 }
1842#endif
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001843}
1844
1845static void be_sriov_disable(struct be_adapter *adapter)
1846{
1847#ifdef CONFIG_PCI_IOV
1848 if (adapter->sriov_enabled) {
1849 pci_disable_sriov(adapter->pdev);
1850 adapter->sriov_enabled = false;
1851 }
1852#endif
1853}
1854
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001855static inline int be_msix_vec_get(struct be_adapter *adapter, u32 eq_id)
1856{
Sathya Perlab628bde2009-08-17 00:58:26 +00001857 return adapter->msix_entries[
1858 be_evt_bit_get(adapter, eq_id)].vector;
1859}
1860
1861static int be_request_irq(struct be_adapter *adapter,
1862 struct be_eq_obj *eq_obj,
1863 void *handler, char *desc)
1864{
1865 struct net_device *netdev = adapter->netdev;
1866 int vec;
1867
1868 sprintf(eq_obj->desc, "%s-%s", netdev->name, desc);
1869 vec = be_msix_vec_get(adapter, eq_obj->q.id);
1870 return request_irq(vec, handler, 0, eq_obj->desc, adapter);
1871}
1872
1873static void be_free_irq(struct be_adapter *adapter, struct be_eq_obj *eq_obj)
1874{
1875 int vec = be_msix_vec_get(adapter, eq_obj->q.id);
1876 free_irq(vec, adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001877}
1878
1879static int be_msix_register(struct be_adapter *adapter)
1880{
Sathya Perlab628bde2009-08-17 00:58:26 +00001881 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001882
Sathya Perlab628bde2009-08-17 00:58:26 +00001883 status = be_request_irq(adapter, &adapter->tx_eq, be_msix_tx_mcc, "tx");
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001884 if (status)
1885 goto err;
1886
Sathya Perlab628bde2009-08-17 00:58:26 +00001887 status = be_request_irq(adapter, &adapter->rx_eq, be_msix_rx, "rx");
1888 if (status)
1889 goto free_tx_irq;
1890
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001891 return 0;
Sathya Perlab628bde2009-08-17 00:58:26 +00001892
1893free_tx_irq:
1894 be_free_irq(adapter, &adapter->tx_eq);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001895err:
1896 dev_warn(&adapter->pdev->dev,
1897 "MSIX Request IRQ failed - err %d\n", status);
1898 pci_disable_msix(adapter->pdev);
1899 adapter->msix_enabled = false;
1900 return status;
1901}
1902
1903static int be_irq_register(struct be_adapter *adapter)
1904{
1905 struct net_device *netdev = adapter->netdev;
1906 int status;
1907
1908 if (adapter->msix_enabled) {
1909 status = be_msix_register(adapter);
1910 if (status == 0)
1911 goto done;
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001912 /* INTx is not supported for VF */
1913 if (!be_physfn(adapter))
1914 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001915 }
1916
1917 /* INTx */
1918 netdev->irq = adapter->pdev->irq;
1919 status = request_irq(netdev->irq, be_intx, IRQF_SHARED, netdev->name,
1920 adapter);
1921 if (status) {
1922 dev_err(&adapter->pdev->dev,
1923 "INTx request IRQ failed - err %d\n", status);
1924 return status;
1925 }
1926done:
1927 adapter->isr_registered = true;
1928 return 0;
1929}
1930
1931static void be_irq_unregister(struct be_adapter *adapter)
1932{
1933 struct net_device *netdev = adapter->netdev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001934
1935 if (!adapter->isr_registered)
1936 return;
1937
1938 /* INTx */
1939 if (!adapter->msix_enabled) {
1940 free_irq(netdev->irq, adapter);
1941 goto done;
1942 }
1943
1944 /* MSIx */
Sathya Perlab628bde2009-08-17 00:58:26 +00001945 be_free_irq(adapter, &adapter->tx_eq);
1946 be_free_irq(adapter, &adapter->rx_eq);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001947done:
1948 adapter->isr_registered = false;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001949}
1950
Sathya Perla889cd4b2010-05-30 23:33:45 +00001951static int be_close(struct net_device *netdev)
1952{
1953 struct be_adapter *adapter = netdev_priv(netdev);
1954 struct be_eq_obj *rx_eq = &adapter->rx_eq;
1955 struct be_eq_obj *tx_eq = &adapter->tx_eq;
1956 int vec;
1957
1958 cancel_delayed_work_sync(&adapter->work);
1959
1960 be_async_mcc_disable(adapter);
1961
1962 netif_stop_queue(netdev);
1963 netif_carrier_off(netdev);
1964 adapter->link_up = false;
1965
1966 be_intr_set(adapter, false);
1967
1968 if (adapter->msix_enabled) {
1969 vec = be_msix_vec_get(adapter, tx_eq->q.id);
1970 synchronize_irq(vec);
1971 vec = be_msix_vec_get(adapter, rx_eq->q.id);
1972 synchronize_irq(vec);
1973 } else {
1974 synchronize_irq(netdev->irq);
1975 }
1976 be_irq_unregister(adapter);
1977
1978 napi_disable(&rx_eq->napi);
1979 napi_disable(&tx_eq->napi);
1980
1981 /* Wait for all pending tx completions to arrive so that
1982 * all tx skbs are freed.
1983 */
1984 be_tx_compl_clean(adapter);
1985
1986 return 0;
1987}
1988
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001989static int be_open(struct net_device *netdev)
1990{
1991 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001992 struct be_eq_obj *rx_eq = &adapter->rx_eq;
1993 struct be_eq_obj *tx_eq = &adapter->tx_eq;
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001994 bool link_up;
1995 int status;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001996 u8 mac_speed;
1997 u16 link_speed;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001998
1999 /* First time posting */
2000 be_post_rx_frags(adapter);
2001
2002 napi_enable(&rx_eq->napi);
2003 napi_enable(&tx_eq->napi);
2004
2005 be_irq_register(adapter);
2006
Sathya Perla8788fdc2009-07-27 22:52:03 +00002007 be_intr_set(adapter, true);
Sathya Perla5fb379e2009-06-18 00:02:59 +00002008
2009 /* The evt queues are created in unarmed state; arm them */
Sathya Perla8788fdc2009-07-27 22:52:03 +00002010 be_eq_notify(adapter, rx_eq->q.id, true, false, 0);
2011 be_eq_notify(adapter, tx_eq->q.id, true, false, 0);
Sathya Perla5fb379e2009-06-18 00:02:59 +00002012
2013 /* Rx compl queue may be in unarmed state; rearm it */
Sathya Perla8788fdc2009-07-27 22:52:03 +00002014 be_cq_notify(adapter, adapter->rx_obj.cq.id, true, 0);
Sathya Perla5fb379e2009-06-18 00:02:59 +00002015
Sathya Perla7a1e9b22010-02-17 01:35:11 +00002016 /* Now that interrupts are on we can process async mcc */
2017 be_async_mcc_enable(adapter);
2018
Sathya Perla889cd4b2010-05-30 23:33:45 +00002019 schedule_delayed_work(&adapter->work, msecs_to_jiffies(100));
2020
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07002021 status = be_cmd_link_status_query(adapter, &link_up, &mac_speed,
2022 &link_speed);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00002023 if (status)
Sathya Perla889cd4b2010-05-30 23:33:45 +00002024 goto err;
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00002025 be_link_status_update(adapter, link_up);
Sathya Perla5fb379e2009-06-18 00:02:59 +00002026
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002027 if (be_physfn(adapter)) {
Ajit Khaparde1da87b72010-07-23 01:51:22 +00002028 status = be_vid_config(adapter, false, 0);
Sathya Perla889cd4b2010-05-30 23:33:45 +00002029 if (status)
2030 goto err;
2031
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002032 status = be_cmd_set_flow_control(adapter,
2033 adapter->tx_fc, adapter->rx_fc);
2034 if (status)
Sathya Perla889cd4b2010-05-30 23:33:45 +00002035 goto err;
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002036 }
Ajit Khaparde4f2aa892009-11-06 02:07:32 +00002037
Sathya Perla889cd4b2010-05-30 23:33:45 +00002038 return 0;
2039err:
2040 be_close(adapter->netdev);
2041 return -EIO;
Sathya Perla5fb379e2009-06-18 00:02:59 +00002042}
2043
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002044static int be_setup_wol(struct be_adapter *adapter, bool enable)
2045{
2046 struct be_dma_mem cmd;
2047 int status = 0;
2048 u8 mac[ETH_ALEN];
2049
2050 memset(mac, 0, ETH_ALEN);
2051
2052 cmd.size = sizeof(struct be_cmd_req_acpi_wol_magic_config);
2053 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
2054 if (cmd.va == NULL)
2055 return -1;
2056 memset(cmd.va, 0, cmd.size);
2057
2058 if (enable) {
2059 status = pci_write_config_dword(adapter->pdev,
2060 PCICFG_PM_CONTROL_OFFSET, PCICFG_PM_CONTROL_MASK);
2061 if (status) {
2062 dev_err(&adapter->pdev->dev,
Frans Pop2381a552010-03-24 07:57:36 +00002063 "Could not enable Wake-on-lan\n");
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002064 pci_free_consistent(adapter->pdev, cmd.size, cmd.va,
2065 cmd.dma);
2066 return status;
2067 }
2068 status = be_cmd_enable_magic_wol(adapter,
2069 adapter->netdev->dev_addr, &cmd);
2070 pci_enable_wake(adapter->pdev, PCI_D3hot, 1);
2071 pci_enable_wake(adapter->pdev, PCI_D3cold, 1);
2072 } else {
2073 status = be_cmd_enable_magic_wol(adapter, mac, &cmd);
2074 pci_enable_wake(adapter->pdev, PCI_D3hot, 0);
2075 pci_enable_wake(adapter->pdev, PCI_D3cold, 0);
2076 }
2077
2078 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
2079 return status;
2080}
2081
Ajit Khaparde6d87f5c2010-08-25 00:32:33 +00002082/*
2083 * Generate a seed MAC address from the PF MAC Address using jhash.
2084 * MAC Address for VFs are assigned incrementally starting from the seed.
2085 * These addresses are programmed in the ASIC by the PF and the VF driver
2086 * queries for the MAC address during its probe.
2087 */
2088static inline int be_vf_eth_addr_config(struct be_adapter *adapter)
2089{
2090 u32 vf = 0;
2091 int status;
2092 u8 mac[ETH_ALEN];
2093
2094 be_vf_eth_addr_generate(adapter, mac);
2095
2096 for (vf = 0; vf < num_vfs; vf++) {
2097 status = be_cmd_pmac_add(adapter, mac,
2098 adapter->vf_cfg[vf].vf_if_handle,
2099 &adapter->vf_cfg[vf].vf_pmac_id);
2100 if (status)
2101 dev_err(&adapter->pdev->dev,
2102 "Mac address add failed for VF %d\n", vf);
2103 else
2104 memcpy(adapter->vf_cfg[vf].vf_mac_addr, mac, ETH_ALEN);
2105
2106 mac[5] += 1;
2107 }
2108 return status;
2109}
2110
2111static inline void be_vf_eth_addr_rem(struct be_adapter *adapter)
2112{
2113 u32 vf;
2114
2115 for (vf = 0; vf < num_vfs; vf++) {
2116 if (adapter->vf_cfg[vf].vf_pmac_id != BE_INVALID_PMAC_ID)
2117 be_cmd_pmac_del(adapter,
2118 adapter->vf_cfg[vf].vf_if_handle,
2119 adapter->vf_cfg[vf].vf_pmac_id);
2120 }
2121}
2122
Sathya Perla5fb379e2009-06-18 00:02:59 +00002123static int be_setup(struct be_adapter *adapter)
2124{
Sathya Perla5fb379e2009-06-18 00:02:59 +00002125 struct net_device *netdev = adapter->netdev;
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002126 u32 cap_flags, en_flags, vf = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002127 int status;
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002128 u8 mac[ETH_ALEN];
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002129
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002130 cap_flags = en_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST;
2131
2132 if (be_physfn(adapter)) {
2133 cap_flags |= BE_IF_FLAGS_MCAST_PROMISCUOUS |
2134 BE_IF_FLAGS_PROMISCUOUS |
2135 BE_IF_FLAGS_PASS_L3L4_ERRORS;
2136 en_flags |= BE_IF_FLAGS_PASS_L3L4_ERRORS;
2137 }
Sathya Perla73d540f2009-10-14 20:20:42 +00002138
2139 status = be_cmd_if_create(adapter, cap_flags, en_flags,
2140 netdev->dev_addr, false/* pmac_invalid */,
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002141 &adapter->if_handle, &adapter->pmac_id, 0);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002142 if (status != 0)
2143 goto do_none;
2144
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002145 if (be_physfn(adapter)) {
2146 while (vf < num_vfs) {
2147 cap_flags = en_flags = BE_IF_FLAGS_UNTAGGED
2148 | BE_IF_FLAGS_BROADCAST;
2149 status = be_cmd_if_create(adapter, cap_flags, en_flags,
Ajit Khaparde64600ea2010-07-23 01:50:34 +00002150 mac, true,
2151 &adapter->vf_cfg[vf].vf_if_handle,
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002152 NULL, vf+1);
2153 if (status) {
2154 dev_err(&adapter->pdev->dev,
2155 "Interface Create failed for VF %d\n", vf);
2156 goto if_destroy;
2157 }
Ajit Khaparde64600ea2010-07-23 01:50:34 +00002158 adapter->vf_cfg[vf].vf_pmac_id = BE_INVALID_PMAC_ID;
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002159 vf++;
Sarveshwar Bandi84e5b9f2010-05-27 16:28:15 -07002160 }
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002161 } else if (!be_physfn(adapter)) {
2162 status = be_cmd_mac_addr_query(adapter, mac,
2163 MAC_ADDRESS_TYPE_NETWORK, false, adapter->if_handle);
2164 if (!status) {
2165 memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN);
2166 memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN);
2167 }
2168 }
2169
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002170 status = be_tx_queues_create(adapter);
2171 if (status != 0)
2172 goto if_destroy;
2173
2174 status = be_rx_queues_create(adapter);
2175 if (status != 0)
2176 goto tx_qs_destroy;
2177
Sathya Perla5fb379e2009-06-18 00:02:59 +00002178 status = be_mcc_queues_create(adapter);
2179 if (status != 0)
2180 goto rx_qs_destroy;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002181
Ajit Khaparde6d87f5c2010-08-25 00:32:33 +00002182 if (be_physfn(adapter)) {
2183 status = be_vf_eth_addr_config(adapter);
2184 if (status)
2185 goto mcc_q_destroy;
2186 }
2187
Ajit Khaparde0dffc832009-11-29 17:57:46 +00002188 adapter->link_speed = -1;
2189
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002190 return 0;
2191
Ajit Khaparde6d87f5c2010-08-25 00:32:33 +00002192mcc_q_destroy:
2193 if (be_physfn(adapter))
2194 be_vf_eth_addr_rem(adapter);
2195 be_mcc_queues_destroy(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +00002196rx_qs_destroy:
2197 be_rx_queues_destroy(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002198tx_qs_destroy:
2199 be_tx_queues_destroy(adapter);
2200if_destroy:
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002201 for (vf = 0; vf < num_vfs; vf++)
Ajit Khaparde64600ea2010-07-23 01:50:34 +00002202 if (adapter->vf_cfg[vf].vf_if_handle)
2203 be_cmd_if_destroy(adapter,
2204 adapter->vf_cfg[vf].vf_if_handle);
Sathya Perla8788fdc2009-07-27 22:52:03 +00002205 be_cmd_if_destroy(adapter, adapter->if_handle);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002206do_none:
2207 return status;
2208}
2209
Sathya Perla5fb379e2009-06-18 00:02:59 +00002210static int be_clear(struct be_adapter *adapter)
2211{
Ajit Khaparde6d87f5c2010-08-25 00:32:33 +00002212 if (be_physfn(adapter))
2213 be_vf_eth_addr_rem(adapter);
2214
Sathya Perla1a8887d2009-08-17 00:58:41 +00002215 be_mcc_queues_destroy(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +00002216 be_rx_queues_destroy(adapter);
2217 be_tx_queues_destroy(adapter);
2218
Sathya Perla8788fdc2009-07-27 22:52:03 +00002219 be_cmd_if_destroy(adapter, adapter->if_handle);
Sathya Perla5fb379e2009-06-18 00:02:59 +00002220
Sathya Perla2243e2e2009-11-22 22:02:03 +00002221 /* tell fw we're done with firing cmds */
2222 be_cmd_fw_clean(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +00002223 return 0;
2224}
2225
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002226
Ajit Khaparde84517482009-09-04 03:12:16 +00002227#define FW_FILE_HDR_SIGN "ServerEngines Corp. "
2228char flash_cookie[2][16] = {"*** SE FLAS",
2229 "H DIRECTORY *** "};
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002230
2231static bool be_flash_redboot(struct be_adapter *adapter,
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002232 const u8 *p, u32 img_start, int image_size,
2233 int hdr_size)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002234{
2235 u32 crc_offset;
2236 u8 flashed_crc[4];
2237 int status;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002238
2239 crc_offset = hdr_size + img_start + image_size - 4;
2240
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002241 p += crc_offset;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002242
2243 status = be_cmd_get_flash_crc(adapter, flashed_crc,
Ajit Khapardef510fc62010-03-31 01:47:45 +00002244 (image_size - 4));
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002245 if (status) {
2246 dev_err(&adapter->pdev->dev,
2247 "could not get crc from flash, not flashing redboot\n");
2248 return false;
2249 }
2250
2251 /*update redboot only if crc does not match*/
2252 if (!memcmp(flashed_crc, p, 4))
2253 return false;
2254 else
2255 return true;
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002256}
2257
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002258static int be_flash_data(struct be_adapter *adapter,
Ajit Khaparde84517482009-09-04 03:12:16 +00002259 const struct firmware *fw,
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002260 struct be_dma_mem *flash_cmd, int num_of_images)
2261
Ajit Khaparde84517482009-09-04 03:12:16 +00002262{
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002263 int status = 0, i, filehdr_size = 0;
2264 u32 total_bytes = 0, flash_op;
Ajit Khaparde84517482009-09-04 03:12:16 +00002265 int num_bytes;
2266 const u8 *p = fw->data;
2267 struct be_cmd_write_flashrom *req = flash_cmd->va;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002268 struct flash_comp *pflashcomp;
Sarveshwar Bandi9fe96932010-03-02 22:37:28 +00002269 int num_comp;
Ajit Khaparde84517482009-09-04 03:12:16 +00002270
Sarveshwar Bandi9fe96932010-03-02 22:37:28 +00002271 struct flash_comp gen3_flash_types[9] = {
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002272 { FLASH_iSCSI_PRIMARY_IMAGE_START_g3, IMG_TYPE_ISCSI_ACTIVE,
2273 FLASH_IMAGE_MAX_SIZE_g3},
2274 { FLASH_REDBOOT_START_g3, IMG_TYPE_REDBOOT,
2275 FLASH_REDBOOT_IMAGE_MAX_SIZE_g3},
2276 { FLASH_iSCSI_BIOS_START_g3, IMG_TYPE_BIOS,
2277 FLASH_BIOS_IMAGE_MAX_SIZE_g3},
2278 { FLASH_PXE_BIOS_START_g3, IMG_TYPE_PXE_BIOS,
2279 FLASH_BIOS_IMAGE_MAX_SIZE_g3},
2280 { FLASH_FCoE_BIOS_START_g3, IMG_TYPE_FCOE_BIOS,
2281 FLASH_BIOS_IMAGE_MAX_SIZE_g3},
2282 { FLASH_iSCSI_BACKUP_IMAGE_START_g3, IMG_TYPE_ISCSI_BACKUP,
2283 FLASH_IMAGE_MAX_SIZE_g3},
2284 { FLASH_FCoE_PRIMARY_IMAGE_START_g3, IMG_TYPE_FCOE_FW_ACTIVE,
2285 FLASH_IMAGE_MAX_SIZE_g3},
2286 { FLASH_FCoE_BACKUP_IMAGE_START_g3, IMG_TYPE_FCOE_FW_BACKUP,
Sarveshwar Bandi9fe96932010-03-02 22:37:28 +00002287 FLASH_IMAGE_MAX_SIZE_g3},
2288 { FLASH_NCSI_START_g3, IMG_TYPE_NCSI_FW,
2289 FLASH_NCSI_IMAGE_MAX_SIZE_g3}
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002290 };
2291 struct flash_comp gen2_flash_types[8] = {
2292 { FLASH_iSCSI_PRIMARY_IMAGE_START_g2, IMG_TYPE_ISCSI_ACTIVE,
2293 FLASH_IMAGE_MAX_SIZE_g2},
2294 { FLASH_REDBOOT_START_g2, IMG_TYPE_REDBOOT,
2295 FLASH_REDBOOT_IMAGE_MAX_SIZE_g2},
2296 { FLASH_iSCSI_BIOS_START_g2, IMG_TYPE_BIOS,
2297 FLASH_BIOS_IMAGE_MAX_SIZE_g2},
2298 { FLASH_PXE_BIOS_START_g2, IMG_TYPE_PXE_BIOS,
2299 FLASH_BIOS_IMAGE_MAX_SIZE_g2},
2300 { FLASH_FCoE_BIOS_START_g2, IMG_TYPE_FCOE_BIOS,
2301 FLASH_BIOS_IMAGE_MAX_SIZE_g2},
2302 { FLASH_iSCSI_BACKUP_IMAGE_START_g2, IMG_TYPE_ISCSI_BACKUP,
2303 FLASH_IMAGE_MAX_SIZE_g2},
2304 { FLASH_FCoE_PRIMARY_IMAGE_START_g2, IMG_TYPE_FCOE_FW_ACTIVE,
2305 FLASH_IMAGE_MAX_SIZE_g2},
2306 { FLASH_FCoE_BACKUP_IMAGE_START_g2, IMG_TYPE_FCOE_FW_BACKUP,
2307 FLASH_IMAGE_MAX_SIZE_g2}
2308 };
2309
2310 if (adapter->generation == BE_GEN3) {
2311 pflashcomp = gen3_flash_types;
2312 filehdr_size = sizeof(struct flash_file_hdr_g3);
Sarveshwar Bandi9fe96932010-03-02 22:37:28 +00002313 num_comp = 9;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002314 } else {
2315 pflashcomp = gen2_flash_types;
2316 filehdr_size = sizeof(struct flash_file_hdr_g2);
Sarveshwar Bandi9fe96932010-03-02 22:37:28 +00002317 num_comp = 8;
Ajit Khaparde84517482009-09-04 03:12:16 +00002318 }
Sarveshwar Bandi9fe96932010-03-02 22:37:28 +00002319 for (i = 0; i < num_comp; i++) {
2320 if ((pflashcomp[i].optype == IMG_TYPE_NCSI_FW) &&
2321 memcmp(adapter->fw_ver, "3.102.148.0", 11) < 0)
2322 continue;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002323 if ((pflashcomp[i].optype == IMG_TYPE_REDBOOT) &&
2324 (!be_flash_redboot(adapter, fw->data,
2325 pflashcomp[i].offset, pflashcomp[i].size,
2326 filehdr_size)))
2327 continue;
2328 p = fw->data;
2329 p += filehdr_size + pflashcomp[i].offset
2330 + (num_of_images * sizeof(struct image_hdr));
2331 if (p + pflashcomp[i].size > fw->data + fw->size)
Ajit Khaparde84517482009-09-04 03:12:16 +00002332 return -1;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002333 total_bytes = pflashcomp[i].size;
2334 while (total_bytes) {
2335 if (total_bytes > 32*1024)
2336 num_bytes = 32*1024;
2337 else
2338 num_bytes = total_bytes;
2339 total_bytes -= num_bytes;
Ajit Khaparde84517482009-09-04 03:12:16 +00002340
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002341 if (!total_bytes)
2342 flash_op = FLASHROM_OPER_FLASH;
2343 else
2344 flash_op = FLASHROM_OPER_SAVE;
2345 memcpy(req->params.data_buf, p, num_bytes);
2346 p += num_bytes;
2347 status = be_cmd_write_flashrom(adapter, flash_cmd,
2348 pflashcomp[i].optype, flash_op, num_bytes);
2349 if (status) {
2350 dev_err(&adapter->pdev->dev,
2351 "cmd to write to flash rom failed.\n");
2352 return -1;
2353 }
2354 yield();
Ajit Khaparde84517482009-09-04 03:12:16 +00002355 }
Ajit Khaparde84517482009-09-04 03:12:16 +00002356 }
Ajit Khaparde84517482009-09-04 03:12:16 +00002357 return 0;
2358}
2359
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002360static int get_ufigen_type(struct flash_file_hdr_g2 *fhdr)
2361{
2362 if (fhdr == NULL)
2363 return 0;
2364 if (fhdr->build[0] == '3')
2365 return BE_GEN3;
2366 else if (fhdr->build[0] == '2')
2367 return BE_GEN2;
2368 else
2369 return 0;
2370}
2371
Ajit Khaparde84517482009-09-04 03:12:16 +00002372int be_load_fw(struct be_adapter *adapter, u8 *func)
2373{
2374 char fw_file[ETHTOOL_FLASH_MAX_FILENAME];
2375 const struct firmware *fw;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002376 struct flash_file_hdr_g2 *fhdr;
2377 struct flash_file_hdr_g3 *fhdr3;
2378 struct image_hdr *img_hdr_ptr = NULL;
Ajit Khaparde84517482009-09-04 03:12:16 +00002379 struct be_dma_mem flash_cmd;
Ajit Khaparde8b93b712010-03-31 01:57:10 +00002380 int status, i = 0, num_imgs = 0;
Ajit Khaparde84517482009-09-04 03:12:16 +00002381 const u8 *p;
Ajit Khaparde84517482009-09-04 03:12:16 +00002382
Ajit Khaparde84517482009-09-04 03:12:16 +00002383 strcpy(fw_file, func);
2384
2385 status = request_firmware(&fw, fw_file, &adapter->pdev->dev);
2386 if (status)
2387 goto fw_exit;
2388
2389 p = fw->data;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002390 fhdr = (struct flash_file_hdr_g2 *) p;
Ajit Khaparde84517482009-09-04 03:12:16 +00002391 dev_info(&adapter->pdev->dev, "Flashing firmware file %s\n", fw_file);
2392
Ajit Khaparde84517482009-09-04 03:12:16 +00002393 flash_cmd.size = sizeof(struct be_cmd_write_flashrom) + 32*1024;
2394 flash_cmd.va = pci_alloc_consistent(adapter->pdev, flash_cmd.size,
2395 &flash_cmd.dma);
2396 if (!flash_cmd.va) {
2397 status = -ENOMEM;
2398 dev_err(&adapter->pdev->dev,
2399 "Memory allocation failure while flashing\n");
2400 goto fw_exit;
2401 }
2402
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002403 if ((adapter->generation == BE_GEN3) &&
2404 (get_ufigen_type(fhdr) == BE_GEN3)) {
2405 fhdr3 = (struct flash_file_hdr_g3 *) fw->data;
Ajit Khaparde8b93b712010-03-31 01:57:10 +00002406 num_imgs = le32_to_cpu(fhdr3->num_imgs);
2407 for (i = 0; i < num_imgs; i++) {
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002408 img_hdr_ptr = (struct image_hdr *) (fw->data +
2409 (sizeof(struct flash_file_hdr_g3) +
Ajit Khaparde8b93b712010-03-31 01:57:10 +00002410 i * sizeof(struct image_hdr)));
2411 if (le32_to_cpu(img_hdr_ptr->imageid) == 1)
2412 status = be_flash_data(adapter, fw, &flash_cmd,
2413 num_imgs);
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002414 }
2415 } else if ((adapter->generation == BE_GEN2) &&
2416 (get_ufigen_type(fhdr) == BE_GEN2)) {
2417 status = be_flash_data(adapter, fw, &flash_cmd, 0);
2418 } else {
2419 dev_err(&adapter->pdev->dev,
2420 "UFI and Interface are not compatible for flashing\n");
2421 status = -1;
Ajit Khaparde84517482009-09-04 03:12:16 +00002422 }
2423
2424 pci_free_consistent(adapter->pdev, flash_cmd.size, flash_cmd.va,
2425 flash_cmd.dma);
2426 if (status) {
2427 dev_err(&adapter->pdev->dev, "Firmware load error\n");
2428 goto fw_exit;
2429 }
2430
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002431 dev_info(&adapter->pdev->dev, "Firmware flashed successfully\n");
Ajit Khaparde84517482009-09-04 03:12:16 +00002432
2433fw_exit:
2434 release_firmware(fw);
2435 return status;
2436}
2437
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002438static struct net_device_ops be_netdev_ops = {
2439 .ndo_open = be_open,
2440 .ndo_stop = be_close,
2441 .ndo_start_xmit = be_xmit,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002442 .ndo_set_rx_mode = be_set_multicast_list,
2443 .ndo_set_mac_address = be_mac_addr_set,
2444 .ndo_change_mtu = be_change_mtu,
2445 .ndo_validate_addr = eth_validate_addr,
2446 .ndo_vlan_rx_register = be_vlan_register,
2447 .ndo_vlan_rx_add_vid = be_vlan_add_vid,
2448 .ndo_vlan_rx_kill_vid = be_vlan_rem_vid,
Ajit Khaparde64600ea2010-07-23 01:50:34 +00002449 .ndo_set_vf_mac = be_set_vf_mac,
Ajit Khaparde1da87b72010-07-23 01:51:22 +00002450 .ndo_set_vf_vlan = be_set_vf_vlan,
Ajit Khapardee1d18732010-07-23 01:52:13 +00002451 .ndo_set_vf_tx_rate = be_set_vf_tx_rate,
Ajit Khaparde64600ea2010-07-23 01:50:34 +00002452 .ndo_get_vf_config = be_get_vf_config
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002453};
2454
2455static void be_netdev_init(struct net_device *netdev)
2456{
2457 struct be_adapter *adapter = netdev_priv(netdev);
2458
2459 netdev->features |= NETIF_F_SG | NETIF_F_HW_VLAN_RX | NETIF_F_TSO |
Ajit Khaparde583e3f32009-10-05 02:22:19 +00002460 NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_FILTER | NETIF_F_HW_CSUM |
Ajit Khaparde49e4b8472010-06-14 04:56:07 +00002461 NETIF_F_GRO | NETIF_F_TSO6;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002462
Ajit Khaparde51c59872009-11-29 17:54:54 +00002463 netdev->vlan_features |= NETIF_F_SG | NETIF_F_TSO | NETIF_F_HW_CSUM;
2464
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002465 netdev->flags |= IFF_MULTICAST;
2466
Ajit Khaparde728a9972009-04-13 15:41:22 -07002467 adapter->rx_csum = true;
2468
Ajit Khaparde9e90c962009-11-06 02:06:59 +00002469 /* Default settings for Rx and Tx flow control */
2470 adapter->rx_fc = true;
2471 adapter->tx_fc = true;
2472
Ajit Khapardec190e3c2009-09-04 03:12:29 +00002473 netif_set_gso_max_size(netdev, 65535);
2474
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002475 BE_SET_NETDEV_OPS(netdev, &be_netdev_ops);
2476
2477 SET_ETHTOOL_OPS(netdev, &be_ethtool_ops);
2478
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002479 netif_napi_add(netdev, &adapter->rx_eq.napi, be_poll_rx,
2480 BE_NAPI_WEIGHT);
Sathya Perla5fb379e2009-06-18 00:02:59 +00002481 netif_napi_add(netdev, &adapter->tx_eq.napi, be_poll_tx_mcc,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002482 BE_NAPI_WEIGHT);
2483
2484 netif_carrier_off(netdev);
2485 netif_stop_queue(netdev);
2486}
2487
2488static void be_unmap_pci_bars(struct be_adapter *adapter)
2489{
Sathya Perla8788fdc2009-07-27 22:52:03 +00002490 if (adapter->csr)
2491 iounmap(adapter->csr);
2492 if (adapter->db)
2493 iounmap(adapter->db);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002494 if (adapter->pcicfg && be_physfn(adapter))
Sathya Perla8788fdc2009-07-27 22:52:03 +00002495 iounmap(adapter->pcicfg);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002496}
2497
2498static int be_map_pci_bars(struct be_adapter *adapter)
2499{
2500 u8 __iomem *addr;
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002501 int pcicfg_reg, db_reg;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002502
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002503 if (be_physfn(adapter)) {
2504 addr = ioremap_nocache(pci_resource_start(adapter->pdev, 2),
2505 pci_resource_len(adapter->pdev, 2));
2506 if (addr == NULL)
2507 return -ENOMEM;
2508 adapter->csr = addr;
2509 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002510
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002511 if (adapter->generation == BE_GEN2) {
2512 pcicfg_reg = 1;
2513 db_reg = 4;
2514 } else {
2515 pcicfg_reg = 0;
2516 if (be_physfn(adapter))
2517 db_reg = 4;
2518 else
2519 db_reg = 0;
2520 }
2521 addr = ioremap_nocache(pci_resource_start(adapter->pdev, db_reg),
2522 pci_resource_len(adapter->pdev, db_reg));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002523 if (addr == NULL)
2524 goto pci_map_err;
Sathya Perla8788fdc2009-07-27 22:52:03 +00002525 adapter->db = addr;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002526
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002527 if (be_physfn(adapter)) {
2528 addr = ioremap_nocache(
2529 pci_resource_start(adapter->pdev, pcicfg_reg),
2530 pci_resource_len(adapter->pdev, pcicfg_reg));
2531 if (addr == NULL)
2532 goto pci_map_err;
2533 adapter->pcicfg = addr;
2534 } else
2535 adapter->pcicfg = adapter->db + SRIOV_VF_PCICFG_OFFSET;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002536
2537 return 0;
2538pci_map_err:
2539 be_unmap_pci_bars(adapter);
2540 return -ENOMEM;
2541}
2542
2543
2544static void be_ctrl_cleanup(struct be_adapter *adapter)
2545{
Sathya Perla8788fdc2009-07-27 22:52:03 +00002546 struct be_dma_mem *mem = &adapter->mbox_mem_alloced;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002547
2548 be_unmap_pci_bars(adapter);
2549
2550 if (mem->va)
2551 pci_free_consistent(adapter->pdev, mem->size,
2552 mem->va, mem->dma);
Sathya Perlae7b909a2009-11-22 22:01:10 +00002553
2554 mem = &adapter->mc_cmd_mem;
2555 if (mem->va)
2556 pci_free_consistent(adapter->pdev, mem->size,
2557 mem->va, mem->dma);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002558}
2559
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002560static int be_ctrl_init(struct be_adapter *adapter)
2561{
Sathya Perla8788fdc2009-07-27 22:52:03 +00002562 struct be_dma_mem *mbox_mem_alloc = &adapter->mbox_mem_alloced;
2563 struct be_dma_mem *mbox_mem_align = &adapter->mbox_mem;
Sathya Perlae7b909a2009-11-22 22:01:10 +00002564 struct be_dma_mem *mc_cmd_mem = &adapter->mc_cmd_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002565 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002566
2567 status = be_map_pci_bars(adapter);
2568 if (status)
Sathya Perlae7b909a2009-11-22 22:01:10 +00002569 goto done;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002570
2571 mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
2572 mbox_mem_alloc->va = pci_alloc_consistent(adapter->pdev,
2573 mbox_mem_alloc->size, &mbox_mem_alloc->dma);
2574 if (!mbox_mem_alloc->va) {
Sathya Perlae7b909a2009-11-22 22:01:10 +00002575 status = -ENOMEM;
2576 goto unmap_pci_bars;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002577 }
Sathya Perlae7b909a2009-11-22 22:01:10 +00002578
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002579 mbox_mem_align->size = sizeof(struct be_mcc_mailbox);
2580 mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16);
2581 mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16);
2582 memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox));
Sathya Perlae7b909a2009-11-22 22:01:10 +00002583
2584 mc_cmd_mem->size = sizeof(struct be_cmd_req_mcast_mac_config);
2585 mc_cmd_mem->va = pci_alloc_consistent(adapter->pdev, mc_cmd_mem->size,
2586 &mc_cmd_mem->dma);
2587 if (mc_cmd_mem->va == NULL) {
2588 status = -ENOMEM;
2589 goto free_mbox;
2590 }
2591 memset(mc_cmd_mem->va, 0, mc_cmd_mem->size);
2592
Sathya Perla8788fdc2009-07-27 22:52:03 +00002593 spin_lock_init(&adapter->mbox_lock);
2594 spin_lock_init(&adapter->mcc_lock);
2595 spin_lock_init(&adapter->mcc_cq_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002596
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002597 init_completion(&adapter->flash_compl);
Sathya Perlacf588472010-02-14 21:22:01 +00002598 pci_save_state(adapter->pdev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002599 return 0;
Sathya Perlae7b909a2009-11-22 22:01:10 +00002600
2601free_mbox:
2602 pci_free_consistent(adapter->pdev, mbox_mem_alloc->size,
2603 mbox_mem_alloc->va, mbox_mem_alloc->dma);
2604
2605unmap_pci_bars:
2606 be_unmap_pci_bars(adapter);
2607
2608done:
2609 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002610}
2611
2612static void be_stats_cleanup(struct be_adapter *adapter)
2613{
2614 struct be_stats_obj *stats = &adapter->stats;
2615 struct be_dma_mem *cmd = &stats->cmd;
2616
2617 if (cmd->va)
2618 pci_free_consistent(adapter->pdev, cmd->size,
2619 cmd->va, cmd->dma);
2620}
2621
2622static int be_stats_init(struct be_adapter *adapter)
2623{
2624 struct be_stats_obj *stats = &adapter->stats;
2625 struct be_dma_mem *cmd = &stats->cmd;
2626
2627 cmd->size = sizeof(struct be_cmd_req_get_stats);
2628 cmd->va = pci_alloc_consistent(adapter->pdev, cmd->size, &cmd->dma);
2629 if (cmd->va == NULL)
2630 return -1;
David S. Millerd291b9a2010-01-28 21:36:21 -08002631 memset(cmd->va, 0, cmd->size);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002632 return 0;
2633}
2634
2635static void __devexit be_remove(struct pci_dev *pdev)
2636{
2637 struct be_adapter *adapter = pci_get_drvdata(pdev);
Sathya Perla8d56ff12009-11-22 22:02:26 +00002638
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002639 if (!adapter)
2640 return;
2641
2642 unregister_netdev(adapter->netdev);
2643
Sathya Perla5fb379e2009-06-18 00:02:59 +00002644 be_clear(adapter);
2645
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002646 be_stats_cleanup(adapter);
2647
2648 be_ctrl_cleanup(adapter);
2649
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002650 be_sriov_disable(adapter);
2651
Sathya Perla8d56ff12009-11-22 22:02:26 +00002652 be_msix_disable(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002653
2654 pci_set_drvdata(pdev, NULL);
2655 pci_release_regions(pdev);
2656 pci_disable_device(pdev);
2657
2658 free_netdev(adapter->netdev);
2659}
2660
Sathya Perla2243e2e2009-11-22 22:02:03 +00002661static int be_get_config(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002662{
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002663 int status;
Sathya Perla2243e2e2009-11-22 22:02:03 +00002664 u8 mac[ETH_ALEN];
Sathya Perla43a04fdc2009-10-14 20:21:17 +00002665
Sathya Perla8788fdc2009-07-27 22:52:03 +00002666 status = be_cmd_get_fw_ver(adapter, adapter->fw_ver);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002667 if (status)
2668 return status;
2669
Ajit Khapardedcb9b562009-09-30 21:58:22 -07002670 status = be_cmd_query_fw_cfg(adapter,
Ajit Khaparde3486be22010-07-23 02:04:54 +00002671 &adapter->port_num, &adapter->function_mode);
Sathya Perla2243e2e2009-11-22 22:02:03 +00002672 if (status)
2673 return status;
2674
2675 memset(mac, 0, ETH_ALEN);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002676
2677 if (be_physfn(adapter)) {
2678 status = be_cmd_mac_addr_query(adapter, mac,
Sathya Perla2243e2e2009-11-22 22:02:03 +00002679 MAC_ADDRESS_TYPE_NETWORK, true /*permanent */, 0);
Ajit Khapardeca9e4982009-11-29 17:56:26 +00002680
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002681 if (status)
2682 return status;
Ajit Khapardeca9e4982009-11-29 17:56:26 +00002683
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002684 if (!is_valid_ether_addr(mac))
2685 return -EADDRNOTAVAIL;
2686
2687 memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN);
2688 memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN);
2689 }
Sathya Perla2243e2e2009-11-22 22:02:03 +00002690
Ajit Khaparde3486be22010-07-23 02:04:54 +00002691 if (adapter->function_mode & 0x400)
Ajit Khaparde82903e42010-02-09 01:34:57 +00002692 adapter->max_vlans = BE_NUM_VLANS_SUPPORTED/4;
2693 else
2694 adapter->max_vlans = BE_NUM_VLANS_SUPPORTED;
2695
Sathya Perla2243e2e2009-11-22 22:02:03 +00002696 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002697}
2698
2699static int __devinit be_probe(struct pci_dev *pdev,
2700 const struct pci_device_id *pdev_id)
2701{
2702 int status = 0;
2703 struct be_adapter *adapter;
2704 struct net_device *netdev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002705
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002706
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002707 status = pci_enable_device(pdev);
2708 if (status)
2709 goto do_none;
2710
2711 status = pci_request_regions(pdev, DRV_NAME);
2712 if (status)
2713 goto disable_dev;
2714 pci_set_master(pdev);
2715
2716 netdev = alloc_etherdev(sizeof(struct be_adapter));
2717 if (netdev == NULL) {
2718 status = -ENOMEM;
2719 goto rel_reg;
2720 }
2721 adapter = netdev_priv(netdev);
Ajit Khaparde7b139c82010-01-27 21:56:44 +00002722
2723 switch (pdev->device) {
2724 case BE_DEVICE_ID1:
2725 case OC_DEVICE_ID1:
2726 adapter->generation = BE_GEN2;
2727 break;
2728 case BE_DEVICE_ID2:
2729 case OC_DEVICE_ID2:
2730 adapter->generation = BE_GEN3;
2731 break;
2732 default:
2733 adapter->generation = 0;
2734 }
2735
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002736 adapter->pdev = pdev;
2737 pci_set_drvdata(pdev, adapter);
2738 adapter->netdev = netdev;
Sathya Perla2243e2e2009-11-22 22:02:03 +00002739 be_netdev_init(netdev);
2740 SET_NETDEV_DEV(netdev, &pdev->dev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002741
2742 be_msix_enable(adapter);
2743
Yang Hongyange9304382009-04-13 14:40:14 -07002744 status = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002745 if (!status) {
2746 netdev->features |= NETIF_F_HIGHDMA;
2747 } else {
Yang Hongyange9304382009-04-13 14:40:14 -07002748 status = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002749 if (status) {
2750 dev_err(&pdev->dev, "Could not set PCI DMA Mask\n");
2751 goto free_netdev;
2752 }
2753 }
2754
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002755 be_sriov_enable(adapter);
2756
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002757 status = be_ctrl_init(adapter);
2758 if (status)
2759 goto free_netdev;
2760
Sathya Perla2243e2e2009-11-22 22:02:03 +00002761 /* sync up with fw's ready state */
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002762 if (be_physfn(adapter)) {
2763 status = be_cmd_POST(adapter);
2764 if (status)
2765 goto ctrl_clean;
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002766 }
Sathya Perla2243e2e2009-11-22 22:02:03 +00002767
2768 /* tell fw we're ready to fire cmds */
2769 status = be_cmd_fw_init(adapter);
2770 if (status)
2771 goto ctrl_clean;
2772
Sarveshwar Bandi556ae192010-05-24 18:38:25 -07002773 if (be_physfn(adapter)) {
2774 status = be_cmd_reset_function(adapter);
2775 if (status)
2776 goto ctrl_clean;
2777 }
2778
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002779 status = be_stats_init(adapter);
2780 if (status)
2781 goto ctrl_clean;
2782
Sathya Perla2243e2e2009-11-22 22:02:03 +00002783 status = be_get_config(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002784 if (status)
2785 goto stats_clean;
2786
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002787 INIT_DELAYED_WORK(&adapter->work, be_worker);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002788
Sathya Perla5fb379e2009-06-18 00:02:59 +00002789 status = be_setup(adapter);
2790 if (status)
2791 goto stats_clean;
Sathya Perla2243e2e2009-11-22 22:02:03 +00002792
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002793 status = register_netdev(netdev);
2794 if (status != 0)
Sathya Perla5fb379e2009-06-18 00:02:59 +00002795 goto unsetup;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002796
Ajit Khapardec4ca2372009-05-18 15:38:55 -07002797 dev_info(&pdev->dev, "%s port %d\n", nic_name(pdev), adapter->port_num);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002798 return 0;
2799
Sathya Perla5fb379e2009-06-18 00:02:59 +00002800unsetup:
2801 be_clear(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002802stats_clean:
2803 be_stats_cleanup(adapter);
2804ctrl_clean:
2805 be_ctrl_cleanup(adapter);
2806free_netdev:
Sathya Perla8d56ff12009-11-22 22:02:26 +00002807 be_msix_disable(adapter);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002808 be_sriov_disable(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002809 free_netdev(adapter->netdev);
Sathya Perla8d56ff12009-11-22 22:02:26 +00002810 pci_set_drvdata(pdev, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002811rel_reg:
2812 pci_release_regions(pdev);
2813disable_dev:
2814 pci_disable_device(pdev);
2815do_none:
Ajit Khapardec4ca2372009-05-18 15:38:55 -07002816 dev_err(&pdev->dev, "%s initialization failed\n", nic_name(pdev));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002817 return status;
2818}
2819
2820static int be_suspend(struct pci_dev *pdev, pm_message_t state)
2821{
2822 struct be_adapter *adapter = pci_get_drvdata(pdev);
2823 struct net_device *netdev = adapter->netdev;
2824
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002825 if (adapter->wol)
2826 be_setup_wol(adapter, true);
2827
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002828 netif_device_detach(netdev);
2829 if (netif_running(netdev)) {
2830 rtnl_lock();
2831 be_close(netdev);
2832 rtnl_unlock();
2833 }
Ajit Khaparde9e90c962009-11-06 02:06:59 +00002834 be_cmd_get_flow_control(adapter, &adapter->tx_fc, &adapter->rx_fc);
Sarveshwar Bandi9b0365f2009-08-12 21:01:29 +00002835 be_clear(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002836
2837 pci_save_state(pdev);
2838 pci_disable_device(pdev);
2839 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2840 return 0;
2841}
2842
2843static int be_resume(struct pci_dev *pdev)
2844{
2845 int status = 0;
2846 struct be_adapter *adapter = pci_get_drvdata(pdev);
2847 struct net_device *netdev = adapter->netdev;
2848
2849 netif_device_detach(netdev);
2850
2851 status = pci_enable_device(pdev);
2852 if (status)
2853 return status;
2854
2855 pci_set_power_state(pdev, 0);
2856 pci_restore_state(pdev);
2857
Sathya Perla2243e2e2009-11-22 22:02:03 +00002858 /* tell fw we're ready to fire cmds */
2859 status = be_cmd_fw_init(adapter);
2860 if (status)
2861 return status;
2862
Sarveshwar Bandi9b0365f2009-08-12 21:01:29 +00002863 be_setup(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002864 if (netif_running(netdev)) {
2865 rtnl_lock();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002866 be_open(netdev);
2867 rtnl_unlock();
2868 }
2869 netif_device_attach(netdev);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002870
2871 if (adapter->wol)
2872 be_setup_wol(adapter, false);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002873 return 0;
2874}
2875
Sathya Perla82456b02010-02-17 01:35:37 +00002876/*
2877 * An FLR will stop BE from DMAing any data.
2878 */
2879static void be_shutdown(struct pci_dev *pdev)
2880{
2881 struct be_adapter *adapter = pci_get_drvdata(pdev);
2882 struct net_device *netdev = adapter->netdev;
2883
2884 netif_device_detach(netdev);
2885
2886 be_cmd_reset_function(adapter);
2887
2888 if (adapter->wol)
2889 be_setup_wol(adapter, true);
2890
2891 pci_disable_device(pdev);
Sathya Perla82456b02010-02-17 01:35:37 +00002892}
2893
Sathya Perlacf588472010-02-14 21:22:01 +00002894static pci_ers_result_t be_eeh_err_detected(struct pci_dev *pdev,
2895 pci_channel_state_t state)
2896{
2897 struct be_adapter *adapter = pci_get_drvdata(pdev);
2898 struct net_device *netdev = adapter->netdev;
2899
2900 dev_err(&adapter->pdev->dev, "EEH error detected\n");
2901
2902 adapter->eeh_err = true;
2903
2904 netif_device_detach(netdev);
2905
2906 if (netif_running(netdev)) {
2907 rtnl_lock();
2908 be_close(netdev);
2909 rtnl_unlock();
2910 }
2911 be_clear(adapter);
2912
2913 if (state == pci_channel_io_perm_failure)
2914 return PCI_ERS_RESULT_DISCONNECT;
2915
2916 pci_disable_device(pdev);
2917
2918 return PCI_ERS_RESULT_NEED_RESET;
2919}
2920
2921static pci_ers_result_t be_eeh_reset(struct pci_dev *pdev)
2922{
2923 struct be_adapter *adapter = pci_get_drvdata(pdev);
2924 int status;
2925
2926 dev_info(&adapter->pdev->dev, "EEH reset\n");
2927 adapter->eeh_err = false;
2928
2929 status = pci_enable_device(pdev);
2930 if (status)
2931 return PCI_ERS_RESULT_DISCONNECT;
2932
2933 pci_set_master(pdev);
2934 pci_set_power_state(pdev, 0);
2935 pci_restore_state(pdev);
2936
2937 /* Check if card is ok and fw is ready */
2938 status = be_cmd_POST(adapter);
2939 if (status)
2940 return PCI_ERS_RESULT_DISCONNECT;
2941
2942 return PCI_ERS_RESULT_RECOVERED;
2943}
2944
2945static void be_eeh_resume(struct pci_dev *pdev)
2946{
2947 int status = 0;
2948 struct be_adapter *adapter = pci_get_drvdata(pdev);
2949 struct net_device *netdev = adapter->netdev;
2950
2951 dev_info(&adapter->pdev->dev, "EEH resume\n");
2952
2953 pci_save_state(pdev);
2954
2955 /* tell fw we're ready to fire cmds */
2956 status = be_cmd_fw_init(adapter);
2957 if (status)
2958 goto err;
2959
2960 status = be_setup(adapter);
2961 if (status)
2962 goto err;
2963
2964 if (netif_running(netdev)) {
2965 status = be_open(netdev);
2966 if (status)
2967 goto err;
2968 }
2969 netif_device_attach(netdev);
2970 return;
2971err:
2972 dev_err(&adapter->pdev->dev, "EEH resume failed\n");
Sathya Perlacf588472010-02-14 21:22:01 +00002973}
2974
2975static struct pci_error_handlers be_eeh_handlers = {
2976 .error_detected = be_eeh_err_detected,
2977 .slot_reset = be_eeh_reset,
2978 .resume = be_eeh_resume,
2979};
2980
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002981static struct pci_driver be_driver = {
2982 .name = DRV_NAME,
2983 .id_table = be_dev_ids,
2984 .probe = be_probe,
2985 .remove = be_remove,
2986 .suspend = be_suspend,
Sathya Perlacf588472010-02-14 21:22:01 +00002987 .resume = be_resume,
Sathya Perla82456b02010-02-17 01:35:37 +00002988 .shutdown = be_shutdown,
Sathya Perlacf588472010-02-14 21:22:01 +00002989 .err_handler = &be_eeh_handlers
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002990};
2991
2992static int __init be_init_module(void)
2993{
Joe Perches8e95a202009-12-03 07:58:21 +00002994 if (rx_frag_size != 8192 && rx_frag_size != 4096 &&
2995 rx_frag_size != 2048) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002996 printk(KERN_WARNING DRV_NAME
2997 " : Module param rx_frag_size must be 2048/4096/8192."
2998 " Using 2048\n");
2999 rx_frag_size = 2048;
3000 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07003001
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00003002 if (num_vfs > 32) {
3003 printk(KERN_WARNING DRV_NAME
3004 " : Module param num_vfs must not be greater than 32."
3005 "Using 32\n");
3006 num_vfs = 32;
3007 }
3008
Sathya Perla6b7c5b92009-03-11 23:32:03 -07003009 return pci_register_driver(&be_driver);
3010}
3011module_init(be_init_module);
3012
3013static void __exit be_exit_module(void)
3014{
3015 pci_unregister_driver(&be_driver);
3016}
3017module_exit(be_exit_module);