blob: 3e6df47b69735b3c357d1499df8be3dd122aa917 [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Vasundhara Volam40263822014-02-12 16:09:07 +05302 * Copyright (C) 2005 - 2014 Emulex
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:
Ajit Khaparded2145cd2011-03-16 08:20:46 +000011 * linux-drivers@emulex.com
Sathya Perla6b7c5b92009-03-11 23:32:03 -070012 *
Ajit Khaparded2145cd2011-03-16 08:20:46 +000013 * Emulex
14 * 3333 Susan Street
15 * Costa Mesa, CA 92626
Sathya Perla6b7c5b92009-03-11 23:32:03 -070016 */
17
Paul Gortmaker70c71602011-05-22 16:47:17 -040018#include <linux/prefetch.h>
Paul Gortmaker9d9779e2011-07-03 15:21:01 -040019#include <linux/module.h>
Sathya Perla6b7c5b92009-03-11 23:32:03 -070020#include "be.h"
Sathya Perla8788fdc2009-07-27 22:52:03 +000021#include "be_cmds.h"
Stephen Hemminger65f71b82009-03-27 00:25:24 -070022#include <asm/div64.h>
Sathya Perlad6b6d982012-09-05 01:56:48 +000023#include <linux/aer.h>
Ajit Khapardea77dcb82013-08-30 15:01:16 -050024#include <linux/if_bridge.h>
Sathya Perla6384a4d2013-10-25 10:40:16 +053025#include <net/busy_poll.h>
Sathya Perlac9c47142014-03-27 10:46:19 +053026#include <net/vxlan.h>
Sathya Perla6b7c5b92009-03-11 23:32:03 -070027
28MODULE_VERSION(DRV_VER);
29MODULE_DEVICE_TABLE(pci, be_dev_ids);
30MODULE_DESCRIPTION(DRV_DESC " " DRV_VER);
Sarveshwar Bandi00d3d512013-01-28 04:17:01 +000031MODULE_AUTHOR("Emulex Corporation");
Sathya Perla6b7c5b92009-03-11 23:32:03 -070032MODULE_LICENSE("GPL");
33
Sarveshwar Bandiba343c72010-03-31 02:56:12 +000034static unsigned int num_vfs;
Sarveshwar Bandiba343c72010-03-31 02:56:12 +000035module_param(num_vfs, uint, S_IRUGO);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +000036MODULE_PARM_DESC(num_vfs, "Number of PCI VFs to initialize");
Sathya Perla6b7c5b92009-03-11 23:32:03 -070037
Sathya Perla11ac75e2011-12-13 00:58:50 +000038static ushort rx_frag_size = 2048;
39module_param(rx_frag_size, ushort, S_IRUGO);
40MODULE_PARM_DESC(rx_frag_size, "Size of a fragment that holds rcvd data.");
41
Sathya Perla6b7c5b92009-03-11 23:32:03 -070042static DEFINE_PCI_DEVICE_TABLE(be_dev_ids) = {
Ajit Khapardec4ca2372009-05-18 15:38:55 -070043 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID1) },
Ajit Khaparde59fd5d82009-10-29 01:11:06 -070044 { PCI_DEVICE(BE_VENDOR_ID, BE_DEVICE_ID2) },
Ajit Khapardec4ca2372009-05-18 15:38:55 -070045 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID1) },
46 { PCI_DEVICE(BE_VENDOR_ID, OC_DEVICE_ID2) },
Sathya Perlafe6d2a32010-11-21 23:25:50 +000047 { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID3)},
Mammatha Edhala12f4d0a2011-05-18 03:26:22 +000048 { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID4)},
Ajit Khapardeecedb6a2011-12-15 06:31:38 +000049 { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID5)},
Padmanabh Ratnakar76b73532012-10-20 06:04:40 +000050 { PCI_DEVICE(EMULEX_VENDOR_ID, OC_DEVICE_ID6)},
Sathya Perla6b7c5b92009-03-11 23:32:03 -070051 { 0 }
52};
53MODULE_DEVICE_TABLE(pci, be_dev_ids);
Ajit Khaparde7c185272010-07-29 06:16:33 +000054/* UE Status Low CSR */
Joe Perches42c8b112011-07-09 02:56:56 -070055static const char * const ue_status_low_desc[] = {
Ajit Khaparde7c185272010-07-29 06:16:33 +000056 "CEV",
57 "CTX",
58 "DBUF",
59 "ERX",
60 "Host",
61 "MPU",
62 "NDMA",
63 "PTC ",
64 "RDMA ",
65 "RXF ",
66 "RXIPS ",
67 "RXULP0 ",
68 "RXULP1 ",
69 "RXULP2 ",
70 "TIM ",
71 "TPOST ",
72 "TPRE ",
73 "TXIPS ",
74 "TXULP0 ",
75 "TXULP1 ",
76 "UC ",
77 "WDMA ",
78 "TXULP2 ",
79 "HOST1 ",
80 "P0_OB_LINK ",
81 "P1_OB_LINK ",
82 "HOST_GPIO ",
83 "MBOX ",
84 "AXGMAC0",
85 "AXGMAC1",
86 "JTAG",
87 "MPU_INTPEND"
88};
89/* UE Status High CSR */
Joe Perches42c8b112011-07-09 02:56:56 -070090static const char * const ue_status_hi_desc[] = {
Ajit Khaparde7c185272010-07-29 06:16:33 +000091 "LPCMEMHOST",
92 "MGMT_MAC",
93 "PCS0ONLINE",
94 "MPU_IRAM",
95 "PCS1ONLINE",
96 "PCTL0",
97 "PCTL1",
98 "PMEM",
99 "RR",
100 "TXPB",
101 "RXPP",
102 "XAUI",
103 "TXP",
104 "ARM",
105 "IPC",
106 "HOST2",
107 "HOST3",
108 "HOST4",
109 "HOST5",
110 "HOST6",
111 "HOST7",
112 "HOST8",
113 "HOST9",
Joe Perches42c8b112011-07-09 02:56:56 -0700114 "NETC",
Ajit Khaparde7c185272010-07-29 06:16:33 +0000115 "Unknown",
116 "Unknown",
117 "Unknown",
118 "Unknown",
119 "Unknown",
120 "Unknown",
121 "Unknown",
122 "Unknown"
123};
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700124
Sathya Perla752961a2011-10-24 02:45:03 +0000125
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700126static void be_queue_free(struct be_adapter *adapter, struct be_queue_info *q)
127{
128 struct be_dma_mem *mem = &q->dma_mem;
Sathya Perla1cfafab2012-02-23 18:50:15 +0000129 if (mem->va) {
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000130 dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va,
131 mem->dma);
Sathya Perla1cfafab2012-02-23 18:50:15 +0000132 mem->va = NULL;
133 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700134}
135
136static int be_queue_alloc(struct be_adapter *adapter, struct be_queue_info *q,
137 u16 len, u16 entry_size)
138{
139 struct be_dma_mem *mem = &q->dma_mem;
140
141 memset(q, 0, sizeof(*q));
142 q->len = len;
143 q->entry_size = entry_size;
144 mem->size = len * entry_size;
Joe Perchesede23fa2013-08-26 22:45:23 -0700145 mem->va = dma_zalloc_coherent(&adapter->pdev->dev, mem->size, &mem->dma,
146 GFP_KERNEL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700147 if (!mem->va)
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000148 return -ENOMEM;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700149 return 0;
150}
151
Somnath Kotur68c45a22013-03-14 02:42:07 +0000152static void be_reg_intr_set(struct be_adapter *adapter, bool enable)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700153{
Sathya Perladb3ea782011-08-22 19:41:52 +0000154 u32 reg, enabled;
Sathya Perla5f0b8492009-07-27 22:52:56 +0000155
Sathya Perladb3ea782011-08-22 19:41:52 +0000156 pci_read_config_dword(adapter->pdev, PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET,
157 &reg);
158 enabled = reg & MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
159
Sathya Perla5f0b8492009-07-27 22:52:56 +0000160 if (!enabled && enable)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700161 reg |= MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
Sathya Perla5f0b8492009-07-27 22:52:56 +0000162 else if (enabled && !enable)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700163 reg &= ~MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK;
Sathya Perla5f0b8492009-07-27 22:52:56 +0000164 else
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700165 return;
Sathya Perla5f0b8492009-07-27 22:52:56 +0000166
Sathya Perladb3ea782011-08-22 19:41:52 +0000167 pci_write_config_dword(adapter->pdev,
168 PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET, reg);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700169}
170
Somnath Kotur68c45a22013-03-14 02:42:07 +0000171static void be_intr_set(struct be_adapter *adapter, bool enable)
172{
173 int status = 0;
174
175 /* On lancer interrupts can't be controlled via this register */
176 if (lancer_chip(adapter))
177 return;
178
179 if (adapter->eeh_error)
180 return;
181
182 status = be_cmd_intr_set(adapter, enable);
183 if (status)
184 be_reg_intr_set(adapter, enable);
185}
186
Sathya Perla8788fdc2009-07-27 22:52:03 +0000187static void be_rxq_notify(struct be_adapter *adapter, u16 qid, u16 posted)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700188{
189 u32 val = 0;
190 val |= qid & DB_RQ_RING_ID_MASK;
191 val |= posted << DB_RQ_NUM_POSTED_SHIFT;
Sathya Perlaf3eb62d2010-06-29 00:11:17 +0000192
193 wmb();
Sathya Perla8788fdc2009-07-27 22:52:03 +0000194 iowrite32(val, adapter->db + DB_RQ_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700195}
196
Vasundhara Volam94d73aa2013-04-21 23:28:14 +0000197static void be_txq_notify(struct be_adapter *adapter, struct be_tx_obj *txo,
198 u16 posted)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700199{
200 u32 val = 0;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +0000201 val |= txo->q.id & DB_TXULP_RING_ID_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700202 val |= (posted & DB_TXULP_NUM_POSTED_MASK) << DB_TXULP_NUM_POSTED_SHIFT;
Sathya Perlaf3eb62d2010-06-29 00:11:17 +0000203
204 wmb();
Vasundhara Volam94d73aa2013-04-21 23:28:14 +0000205 iowrite32(val, adapter->db + txo->db_offset);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700206}
207
Sathya Perla8788fdc2009-07-27 22:52:03 +0000208static void be_eq_notify(struct be_adapter *adapter, u16 qid,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700209 bool arm, bool clear_int, u16 num_popped)
210{
211 u32 val = 0;
212 val |= qid & DB_EQ_RING_ID_MASK;
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000213 val |= ((qid & DB_EQ_RING_ID_EXT_MASK) <<
214 DB_EQ_RING_ID_EXT_MASK_SHIFT);
Sathya Perlacf588472010-02-14 21:22:01 +0000215
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +0000216 if (adapter->eeh_error)
Sathya Perlacf588472010-02-14 21:22:01 +0000217 return;
218
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700219 if (arm)
220 val |= 1 << DB_EQ_REARM_SHIFT;
221 if (clear_int)
222 val |= 1 << DB_EQ_CLR_SHIFT;
223 val |= 1 << DB_EQ_EVNT_SHIFT;
224 val |= num_popped << DB_EQ_NUM_POPPED_SHIFT;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000225 iowrite32(val, adapter->db + DB_EQ_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700226}
227
Sathya Perla8788fdc2009-07-27 22:52:03 +0000228void be_cq_notify(struct be_adapter *adapter, u16 qid, bool arm, u16 num_popped)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700229{
230 u32 val = 0;
231 val |= qid & DB_CQ_RING_ID_MASK;
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000232 val |= ((qid & DB_CQ_RING_ID_EXT_MASK) <<
233 DB_CQ_RING_ID_EXT_MASK_SHIFT);
Sathya Perlacf588472010-02-14 21:22:01 +0000234
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +0000235 if (adapter->eeh_error)
Sathya Perlacf588472010-02-14 21:22:01 +0000236 return;
237
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700238 if (arm)
239 val |= 1 << DB_CQ_REARM_SHIFT;
240 val |= num_popped << DB_CQ_NUM_POPPED_SHIFT;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000241 iowrite32(val, adapter->db + DB_CQ_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700242}
243
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700244static int be_mac_addr_set(struct net_device *netdev, void *p)
245{
246 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla5a712c12013-07-23 15:24:59 +0530247 struct device *dev = &adapter->pdev->dev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700248 struct sockaddr *addr = p;
Sathya Perla5a712c12013-07-23 15:24:59 +0530249 int status;
250 u8 mac[ETH_ALEN];
251 u32 old_pmac_id = adapter->pmac_id[0], curr_pmac_id = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700252
Ajit Khapardeca9e4982009-11-29 17:56:26 +0000253 if (!is_valid_ether_addr(addr->sa_data))
254 return -EADDRNOTAVAIL;
255
Vasundhara Volamff32f8a2014-01-15 13:23:35 +0530256 /* Proceed further only if, User provided MAC is different
257 * from active MAC
258 */
259 if (ether_addr_equal(addr->sa_data, netdev->dev_addr))
260 return 0;
261
Sathya Perla5a712c12013-07-23 15:24:59 +0530262 /* The PMAC_ADD cmd may fail if the VF doesn't have FILTMGMT
263 * privilege or if PF did not provision the new MAC address.
264 * On BE3, this cmd will always fail if the VF doesn't have the
265 * FILTMGMT privilege. This failure is OK, only if the PF programmed
266 * the MAC for the VF.
Padmanabh Ratnakar704e4c82012-10-20 06:02:13 +0000267 */
Sathya Perla5a712c12013-07-23 15:24:59 +0530268 status = be_cmd_pmac_add(adapter, (u8 *)addr->sa_data,
269 adapter->if_handle, &adapter->pmac_id[0], 0);
270 if (!status) {
271 curr_pmac_id = adapter->pmac_id[0];
272
273 /* Delete the old programmed MAC. This call may fail if the
274 * old MAC was already deleted by the PF driver.
275 */
276 if (adapter->pmac_id[0] != old_pmac_id)
277 be_cmd_pmac_del(adapter, adapter->if_handle,
278 old_pmac_id, 0);
Padmanabh Ratnakar704e4c82012-10-20 06:02:13 +0000279 }
280
Sathya Perla5a712c12013-07-23 15:24:59 +0530281 /* Decide if the new MAC is successfully activated only after
282 * querying the FW
Padmanabh Ratnakar704e4c82012-10-20 06:02:13 +0000283 */
Suresh Reddyb188f092014-01-15 13:23:39 +0530284 status = be_cmd_get_active_mac(adapter, curr_pmac_id, mac,
285 adapter->if_handle, true, 0);
Sathya Perlaa65027e2009-08-17 00:58:04 +0000286 if (status)
Somnath Koture3a7ae22011-10-27 07:14:05 +0000287 goto err;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700288
Sathya Perla5a712c12013-07-23 15:24:59 +0530289 /* The MAC change did not happen, either due to lack of privilege
290 * or PF didn't pre-provision.
291 */
dingtianhong61d23e92013-12-30 15:40:43 +0800292 if (!ether_addr_equal(addr->sa_data, mac)) {
Sathya Perla5a712c12013-07-23 15:24:59 +0530293 status = -EPERM;
294 goto err;
295 }
296
Somnath Koture3a7ae22011-10-27 07:14:05 +0000297 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Sathya Perla5a712c12013-07-23 15:24:59 +0530298 dev_info(dev, "MAC address changed to %pM\n", mac);
Somnath Koture3a7ae22011-10-27 07:14:05 +0000299 return 0;
300err:
Sathya Perla5a712c12013-07-23 15:24:59 +0530301 dev_warn(dev, "MAC address change to %pM failed\n", addr->sa_data);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700302 return status;
303}
304
Sathya Perlaca34fe32012-11-06 17:48:56 +0000305/* BE2 supports only v0 cmd */
306static void *hw_stats_from_cmd(struct be_adapter *adapter)
307{
308 if (BE2_chip(adapter)) {
309 struct be_cmd_resp_get_stats_v0 *cmd = adapter->stats_cmd.va;
310
311 return &cmd->hw_stats;
Ajit Khaparde61000862013-10-03 16:16:33 -0500312 } else if (BE3_chip(adapter)) {
Sathya Perlaca34fe32012-11-06 17:48:56 +0000313 struct be_cmd_resp_get_stats_v1 *cmd = adapter->stats_cmd.va;
314
315 return &cmd->hw_stats;
Ajit Khaparde61000862013-10-03 16:16:33 -0500316 } else {
317 struct be_cmd_resp_get_stats_v2 *cmd = adapter->stats_cmd.va;
318
319 return &cmd->hw_stats;
Sathya Perlaca34fe32012-11-06 17:48:56 +0000320 }
321}
322
323/* BE2 supports only v0 cmd */
324static void *be_erx_stats_from_cmd(struct be_adapter *adapter)
325{
326 if (BE2_chip(adapter)) {
327 struct be_hw_stats_v0 *hw_stats = hw_stats_from_cmd(adapter);
328
329 return &hw_stats->erx;
Ajit Khaparde61000862013-10-03 16:16:33 -0500330 } else if (BE3_chip(adapter)) {
Sathya Perlaca34fe32012-11-06 17:48:56 +0000331 struct be_hw_stats_v1 *hw_stats = hw_stats_from_cmd(adapter);
332
333 return &hw_stats->erx;
Ajit Khaparde61000862013-10-03 16:16:33 -0500334 } else {
335 struct be_hw_stats_v2 *hw_stats = hw_stats_from_cmd(adapter);
336
337 return &hw_stats->erx;
Sathya Perlaca34fe32012-11-06 17:48:56 +0000338 }
339}
340
341static void populate_be_v0_stats(struct be_adapter *adapter)
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000342{
Sathya Perlaac124ff2011-07-25 19:10:14 +0000343 struct be_hw_stats_v0 *hw_stats = hw_stats_from_cmd(adapter);
344 struct be_pmem_stats *pmem_sts = &hw_stats->pmem;
345 struct be_rxf_stats_v0 *rxf_stats = &hw_stats->rxf;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000346 struct be_port_rxf_stats_v0 *port_stats =
Sathya Perlaac124ff2011-07-25 19:10:14 +0000347 &rxf_stats->port[adapter->port_num];
348 struct be_drv_stats *drvs = &adapter->drv_stats;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000349
Sathya Perlaac124ff2011-07-25 19:10:14 +0000350 be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats));
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000351 drvs->rx_pause_frames = port_stats->rx_pause_frames;
352 drvs->rx_crc_errors = port_stats->rx_crc_errors;
353 drvs->rx_control_frames = port_stats->rx_control_frames;
354 drvs->rx_in_range_errors = port_stats->rx_in_range_errors;
355 drvs->rx_frame_too_long = port_stats->rx_frame_too_long;
356 drvs->rx_dropped_runt = port_stats->rx_dropped_runt;
357 drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs;
358 drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs;
359 drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs;
360 drvs->rxpp_fifo_overflow_drop = port_stats->rx_fifo_overflow;
361 drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length;
362 drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small;
363 drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short;
364 drvs->rx_out_range_errors = port_stats->rx_out_range_errors;
Sathya Perlaac124ff2011-07-25 19:10:14 +0000365 drvs->rx_input_fifo_overflow_drop = port_stats->rx_input_fifo_overflow;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000366 drvs->rx_dropped_header_too_small =
367 port_stats->rx_dropped_header_too_small;
Suresh Reddy18fb06a2013-04-25 23:03:21 +0000368 drvs->rx_address_filtered =
369 port_stats->rx_address_filtered +
370 port_stats->rx_vlan_filtered;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000371 drvs->rx_alignment_symbol_errors =
372 port_stats->rx_alignment_symbol_errors;
373
374 drvs->tx_pauseframes = port_stats->tx_pauseframes;
375 drvs->tx_controlframes = port_stats->tx_controlframes;
376
377 if (adapter->port_num)
Sathya Perlaac124ff2011-07-25 19:10:14 +0000378 drvs->jabber_events = rxf_stats->port1_jabber_events;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000379 else
Sathya Perlaac124ff2011-07-25 19:10:14 +0000380 drvs->jabber_events = rxf_stats->port0_jabber_events;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000381 drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000382 drvs->rx_drops_no_erx_descr = rxf_stats->rx_drops_no_erx_descr;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000383 drvs->forwarded_packets = rxf_stats->forwarded_packets;
384 drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu;
Sathya Perlaac124ff2011-07-25 19:10:14 +0000385 drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr;
386 drvs->rx_drops_too_many_frags = rxf_stats->rx_drops_too_many_frags;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000387 adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops;
388}
389
Sathya Perlaca34fe32012-11-06 17:48:56 +0000390static void populate_be_v1_stats(struct be_adapter *adapter)
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000391{
Sathya Perlaac124ff2011-07-25 19:10:14 +0000392 struct be_hw_stats_v1 *hw_stats = hw_stats_from_cmd(adapter);
393 struct be_pmem_stats *pmem_sts = &hw_stats->pmem;
394 struct be_rxf_stats_v1 *rxf_stats = &hw_stats->rxf;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000395 struct be_port_rxf_stats_v1 *port_stats =
Sathya Perlaac124ff2011-07-25 19:10:14 +0000396 &rxf_stats->port[adapter->port_num];
397 struct be_drv_stats *drvs = &adapter->drv_stats;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000398
Sathya Perlaac124ff2011-07-25 19:10:14 +0000399 be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats));
Ajit Khaparde02fe7022011-12-09 13:53:09 +0000400 drvs->pmem_fifo_overflow_drop = port_stats->pmem_fifo_overflow_drop;
401 drvs->rx_priority_pause_frames = port_stats->rx_priority_pause_frames;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000402 drvs->rx_pause_frames = port_stats->rx_pause_frames;
403 drvs->rx_crc_errors = port_stats->rx_crc_errors;
404 drvs->rx_control_frames = port_stats->rx_control_frames;
405 drvs->rx_in_range_errors = port_stats->rx_in_range_errors;
406 drvs->rx_frame_too_long = port_stats->rx_frame_too_long;
407 drvs->rx_dropped_runt = port_stats->rx_dropped_runt;
408 drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs;
409 drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs;
410 drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs;
411 drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length;
412 drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small;
413 drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short;
414 drvs->rx_out_range_errors = port_stats->rx_out_range_errors;
415 drvs->rx_dropped_header_too_small =
416 port_stats->rx_dropped_header_too_small;
417 drvs->rx_input_fifo_overflow_drop =
418 port_stats->rx_input_fifo_overflow_drop;
Suresh Reddy18fb06a2013-04-25 23:03:21 +0000419 drvs->rx_address_filtered = port_stats->rx_address_filtered;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000420 drvs->rx_alignment_symbol_errors =
421 port_stats->rx_alignment_symbol_errors;
Sathya Perlaac124ff2011-07-25 19:10:14 +0000422 drvs->rxpp_fifo_overflow_drop = port_stats->rxpp_fifo_overflow_drop;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000423 drvs->tx_pauseframes = port_stats->tx_pauseframes;
424 drvs->tx_controlframes = port_stats->tx_controlframes;
Ajit Khapardeb5adffc42013-05-01 09:38:00 +0000425 drvs->tx_priority_pauseframes = port_stats->tx_priority_pauseframes;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000426 drvs->jabber_events = port_stats->jabber_events;
427 drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000428 drvs->rx_drops_no_erx_descr = rxf_stats->rx_drops_no_erx_descr;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000429 drvs->forwarded_packets = rxf_stats->forwarded_packets;
430 drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu;
Sathya Perlaac124ff2011-07-25 19:10:14 +0000431 drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr;
432 drvs->rx_drops_too_many_frags = rxf_stats->rx_drops_too_many_frags;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000433 adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops;
434}
435
Ajit Khaparde61000862013-10-03 16:16:33 -0500436static void populate_be_v2_stats(struct be_adapter *adapter)
437{
438 struct be_hw_stats_v2 *hw_stats = hw_stats_from_cmd(adapter);
439 struct be_pmem_stats *pmem_sts = &hw_stats->pmem;
440 struct be_rxf_stats_v2 *rxf_stats = &hw_stats->rxf;
441 struct be_port_rxf_stats_v2 *port_stats =
442 &rxf_stats->port[adapter->port_num];
443 struct be_drv_stats *drvs = &adapter->drv_stats;
444
445 be_dws_le_to_cpu(hw_stats, sizeof(*hw_stats));
446 drvs->pmem_fifo_overflow_drop = port_stats->pmem_fifo_overflow_drop;
447 drvs->rx_priority_pause_frames = port_stats->rx_priority_pause_frames;
448 drvs->rx_pause_frames = port_stats->rx_pause_frames;
449 drvs->rx_crc_errors = port_stats->rx_crc_errors;
450 drvs->rx_control_frames = port_stats->rx_control_frames;
451 drvs->rx_in_range_errors = port_stats->rx_in_range_errors;
452 drvs->rx_frame_too_long = port_stats->rx_frame_too_long;
453 drvs->rx_dropped_runt = port_stats->rx_dropped_runt;
454 drvs->rx_ip_checksum_errs = port_stats->rx_ip_checksum_errs;
455 drvs->rx_tcp_checksum_errs = port_stats->rx_tcp_checksum_errs;
456 drvs->rx_udp_checksum_errs = port_stats->rx_udp_checksum_errs;
457 drvs->rx_dropped_tcp_length = port_stats->rx_dropped_tcp_length;
458 drvs->rx_dropped_too_small = port_stats->rx_dropped_too_small;
459 drvs->rx_dropped_too_short = port_stats->rx_dropped_too_short;
460 drvs->rx_out_range_errors = port_stats->rx_out_range_errors;
461 drvs->rx_dropped_header_too_small =
462 port_stats->rx_dropped_header_too_small;
463 drvs->rx_input_fifo_overflow_drop =
464 port_stats->rx_input_fifo_overflow_drop;
465 drvs->rx_address_filtered = port_stats->rx_address_filtered;
466 drvs->rx_alignment_symbol_errors =
467 port_stats->rx_alignment_symbol_errors;
468 drvs->rxpp_fifo_overflow_drop = port_stats->rxpp_fifo_overflow_drop;
469 drvs->tx_pauseframes = port_stats->tx_pauseframes;
470 drvs->tx_controlframes = port_stats->tx_controlframes;
471 drvs->tx_priority_pauseframes = port_stats->tx_priority_pauseframes;
472 drvs->jabber_events = port_stats->jabber_events;
473 drvs->rx_drops_no_pbuf = rxf_stats->rx_drops_no_pbuf;
474 drvs->rx_drops_no_erx_descr = rxf_stats->rx_drops_no_erx_descr;
475 drvs->forwarded_packets = rxf_stats->forwarded_packets;
476 drvs->rx_drops_mtu = rxf_stats->rx_drops_mtu;
477 drvs->rx_drops_no_tpre_descr = rxf_stats->rx_drops_no_tpre_descr;
478 drvs->rx_drops_too_many_frags = rxf_stats->rx_drops_too_many_frags;
479 adapter->drv_stats.eth_red_drops = pmem_sts->eth_red_drops;
Ajit Khaparde461ae372013-10-03 16:16:50 -0500480 if (be_roce_supported(adapter)) {
481 drvs->rx_roce_bytes_lsd = port_stats->roce_bytes_received_lsd;
482 drvs->rx_roce_bytes_msd = port_stats->roce_bytes_received_msd;
483 drvs->rx_roce_frames = port_stats->roce_frames_received;
484 drvs->roce_drops_crc = port_stats->roce_drops_crc;
485 drvs->roce_drops_payload_len =
486 port_stats->roce_drops_payload_len;
487 }
Ajit Khaparde61000862013-10-03 16:16:33 -0500488}
489
Selvin Xavier005d5692011-05-16 07:36:35 +0000490static void populate_lancer_stats(struct be_adapter *adapter)
491{
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000492
Selvin Xavier005d5692011-05-16 07:36:35 +0000493 struct be_drv_stats *drvs = &adapter->drv_stats;
Sathya Perlaac124ff2011-07-25 19:10:14 +0000494 struct lancer_pport_stats *pport_stats =
495 pport_stats_from_cmd(adapter);
496
497 be_dws_le_to_cpu(pport_stats, sizeof(*pport_stats));
498 drvs->rx_pause_frames = pport_stats->rx_pause_frames_lo;
499 drvs->rx_crc_errors = pport_stats->rx_crc_errors_lo;
500 drvs->rx_control_frames = pport_stats->rx_control_frames_lo;
Selvin Xavier005d5692011-05-16 07:36:35 +0000501 drvs->rx_in_range_errors = pport_stats->rx_in_range_errors;
Sathya Perlaac124ff2011-07-25 19:10:14 +0000502 drvs->rx_frame_too_long = pport_stats->rx_frames_too_long_lo;
Selvin Xavier005d5692011-05-16 07:36:35 +0000503 drvs->rx_dropped_runt = pport_stats->rx_dropped_runt;
504 drvs->rx_ip_checksum_errs = pport_stats->rx_ip_checksum_errors;
505 drvs->rx_tcp_checksum_errs = pport_stats->rx_tcp_checksum_errors;
506 drvs->rx_udp_checksum_errs = pport_stats->rx_udp_checksum_errors;
507 drvs->rx_dropped_tcp_length =
508 pport_stats->rx_dropped_invalid_tcp_length;
509 drvs->rx_dropped_too_small = pport_stats->rx_dropped_too_small;
510 drvs->rx_dropped_too_short = pport_stats->rx_dropped_too_short;
511 drvs->rx_out_range_errors = pport_stats->rx_out_of_range_errors;
512 drvs->rx_dropped_header_too_small =
513 pport_stats->rx_dropped_header_too_small;
514 drvs->rx_input_fifo_overflow_drop = pport_stats->rx_fifo_overflow;
Suresh Reddy18fb06a2013-04-25 23:03:21 +0000515 drvs->rx_address_filtered =
516 pport_stats->rx_address_filtered +
517 pport_stats->rx_vlan_filtered;
Sathya Perlaac124ff2011-07-25 19:10:14 +0000518 drvs->rx_alignment_symbol_errors = pport_stats->rx_symbol_errors_lo;
Selvin Xavier005d5692011-05-16 07:36:35 +0000519 drvs->rxpp_fifo_overflow_drop = pport_stats->rx_fifo_overflow;
Sathya Perlaac124ff2011-07-25 19:10:14 +0000520 drvs->tx_pauseframes = pport_stats->tx_pause_frames_lo;
521 drvs->tx_controlframes = pport_stats->tx_control_frames_lo;
Selvin Xavier005d5692011-05-16 07:36:35 +0000522 drvs->jabber_events = pport_stats->rx_jabbers;
Sathya Perlaac124ff2011-07-25 19:10:14 +0000523 drvs->forwarded_packets = pport_stats->num_forwards_lo;
524 drvs->rx_drops_mtu = pport_stats->rx_drops_mtu_lo;
Selvin Xavier005d5692011-05-16 07:36:35 +0000525 drvs->rx_drops_too_many_frags =
Sathya Perlaac124ff2011-07-25 19:10:14 +0000526 pport_stats->rx_drops_too_many_frags_lo;
Selvin Xavier005d5692011-05-16 07:36:35 +0000527}
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000528
Sathya Perla09c1c682011-08-22 19:41:53 +0000529static void accumulate_16bit_val(u32 *acc, u16 val)
530{
531#define lo(x) (x & 0xFFFF)
532#define hi(x) (x & 0xFFFF0000)
533 bool wrapped = val < lo(*acc);
534 u32 newacc = hi(*acc) + val;
535
536 if (wrapped)
537 newacc += 65536;
538 ACCESS_ONCE(*acc) = newacc;
539}
540
Jingoo Han4188e7d2013-08-05 18:02:02 +0900541static void populate_erx_stats(struct be_adapter *adapter,
Ajit Khapardea6c578e2013-05-01 09:37:27 +0000542 struct be_rx_obj *rxo,
543 u32 erx_stat)
544{
545 if (!BEx_chip(adapter))
546 rx_stats(rxo)->rx_drops_no_frags = erx_stat;
547 else
548 /* below erx HW counter can actually wrap around after
549 * 65535. Driver accumulates a 32-bit value
550 */
551 accumulate_16bit_val(&rx_stats(rxo)->rx_drops_no_frags,
552 (u16)erx_stat);
553}
554
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000555void be_parse_stats(struct be_adapter *adapter)
556{
Ajit Khaparde61000862013-10-03 16:16:33 -0500557 struct be_erx_stats_v2 *erx = be_erx_stats_from_cmd(adapter);
Sathya Perlaac124ff2011-07-25 19:10:14 +0000558 struct be_rx_obj *rxo;
559 int i;
Ajit Khapardea6c578e2013-05-01 09:37:27 +0000560 u32 erx_stat;
Sathya Perlaac124ff2011-07-25 19:10:14 +0000561
Sathya Perlaca34fe32012-11-06 17:48:56 +0000562 if (lancer_chip(adapter)) {
563 populate_lancer_stats(adapter);
Selvin Xavier005d5692011-05-16 07:36:35 +0000564 } else {
Sathya Perlaca34fe32012-11-06 17:48:56 +0000565 if (BE2_chip(adapter))
566 populate_be_v0_stats(adapter);
Ajit Khaparde61000862013-10-03 16:16:33 -0500567 else if (BE3_chip(adapter))
568 /* for BE3 */
Sathya Perlaca34fe32012-11-06 17:48:56 +0000569 populate_be_v1_stats(adapter);
Ajit Khaparde61000862013-10-03 16:16:33 -0500570 else
571 populate_be_v2_stats(adapter);
Sathya Perlaac124ff2011-07-25 19:10:14 +0000572
Ajit Khaparde61000862013-10-03 16:16:33 -0500573 /* erx_v2 is longer than v0, v1. use v2 for v0, v1 access */
Sathya Perlaca34fe32012-11-06 17:48:56 +0000574 for_all_rx_queues(adapter, rxo, i) {
Ajit Khapardea6c578e2013-05-01 09:37:27 +0000575 erx_stat = erx->rx_drops_no_fragments[rxo->q.id];
576 populate_erx_stats(adapter, rxo, erx_stat);
Sathya Perlaca34fe32012-11-06 17:48:56 +0000577 }
Sathya Perla09c1c682011-08-22 19:41:53 +0000578 }
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000579}
580
Sathya Perlaab1594e2011-07-25 19:10:15 +0000581static struct rtnl_link_stats64 *be_get_stats64(struct net_device *netdev,
582 struct rtnl_link_stats64 *stats)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700583{
Sathya Perlaab1594e2011-07-25 19:10:15 +0000584 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000585 struct be_drv_stats *drvs = &adapter->drv_stats;
Sathya Perla3abcded2010-10-03 22:12:27 -0700586 struct be_rx_obj *rxo;
Sathya Perla3c8def92011-06-12 20:01:58 +0000587 struct be_tx_obj *txo;
Sathya Perlaab1594e2011-07-25 19:10:15 +0000588 u64 pkts, bytes;
589 unsigned int start;
Sathya Perla3abcded2010-10-03 22:12:27 -0700590 int i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700591
Sathya Perla3abcded2010-10-03 22:12:27 -0700592 for_all_rx_queues(adapter, rxo, i) {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000593 const struct be_rx_stats *rx_stats = rx_stats(rxo);
594 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700595 start = u64_stats_fetch_begin_irq(&rx_stats->sync);
Sathya Perlaab1594e2011-07-25 19:10:15 +0000596 pkts = rx_stats(rxo)->rx_pkts;
597 bytes = rx_stats(rxo)->rx_bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700598 } while (u64_stats_fetch_retry_irq(&rx_stats->sync, start));
Sathya Perlaab1594e2011-07-25 19:10:15 +0000599 stats->rx_packets += pkts;
600 stats->rx_bytes += bytes;
601 stats->multicast += rx_stats(rxo)->rx_mcast_pkts;
602 stats->rx_dropped += rx_stats(rxo)->rx_drops_no_skbs +
603 rx_stats(rxo)->rx_drops_no_frags;
Sathya Perla3abcded2010-10-03 22:12:27 -0700604 }
605
Sathya Perla3c8def92011-06-12 20:01:58 +0000606 for_all_tx_queues(adapter, txo, i) {
Sathya Perlaab1594e2011-07-25 19:10:15 +0000607 const struct be_tx_stats *tx_stats = tx_stats(txo);
608 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -0700609 start = u64_stats_fetch_begin_irq(&tx_stats->sync);
Sathya Perlaab1594e2011-07-25 19:10:15 +0000610 pkts = tx_stats(txo)->tx_pkts;
611 bytes = tx_stats(txo)->tx_bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -0700612 } while (u64_stats_fetch_retry_irq(&tx_stats->sync, start));
Sathya Perlaab1594e2011-07-25 19:10:15 +0000613 stats->tx_packets += pkts;
614 stats->tx_bytes += bytes;
Sathya Perla3c8def92011-06-12 20:01:58 +0000615 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700616
617 /* bad pkts received */
Sathya Perlaab1594e2011-07-25 19:10:15 +0000618 stats->rx_errors = drvs->rx_crc_errors +
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000619 drvs->rx_alignment_symbol_errors +
620 drvs->rx_in_range_errors +
621 drvs->rx_out_range_errors +
622 drvs->rx_frame_too_long +
623 drvs->rx_dropped_too_small +
624 drvs->rx_dropped_too_short +
625 drvs->rx_dropped_header_too_small +
626 drvs->rx_dropped_tcp_length +
Sathya Perlaab1594e2011-07-25 19:10:15 +0000627 drvs->rx_dropped_runt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700628
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700629 /* detailed rx errors */
Sathya Perlaab1594e2011-07-25 19:10:15 +0000630 stats->rx_length_errors = drvs->rx_in_range_errors +
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000631 drvs->rx_out_range_errors +
632 drvs->rx_frame_too_long;
Sathya Perla68110862009-06-10 02:21:16 +0000633
Sathya Perlaab1594e2011-07-25 19:10:15 +0000634 stats->rx_crc_errors = drvs->rx_crc_errors;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700635
636 /* frame alignment errors */
Sathya Perlaab1594e2011-07-25 19:10:15 +0000637 stats->rx_frame_errors = drvs->rx_alignment_symbol_errors;
Sathya Perla68110862009-06-10 02:21:16 +0000638
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700639 /* receiver fifo overrun */
640 /* drops_no_pbuf is no per i/f, it's per BE card */
Sathya Perlaab1594e2011-07-25 19:10:15 +0000641 stats->rx_fifo_errors = drvs->rxpp_fifo_overflow_drop +
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000642 drvs->rx_input_fifo_overflow_drop +
643 drvs->rx_drops_no_pbuf;
Sathya Perlaab1594e2011-07-25 19:10:15 +0000644 return stats;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700645}
646
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000647void be_link_status_update(struct be_adapter *adapter, u8 link_status)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700648{
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700649 struct net_device *netdev = adapter->netdev;
650
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000651 if (!(adapter->flags & BE_FLAGS_LINK_STATUS_INIT)) {
Sathya Perlaea172a02011-08-02 19:57:42 +0000652 netif_carrier_off(netdev);
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000653 adapter->flags |= BE_FLAGS_LINK_STATUS_INIT;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700654 }
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000655
Suresh Reddybdce2ad2014-03-11 18:53:04 +0530656 if (link_status)
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000657 netif_carrier_on(netdev);
658 else
659 netif_carrier_off(netdev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700660}
661
Sathya Perla3c8def92011-06-12 20:01:58 +0000662static void be_tx_stats_update(struct be_tx_obj *txo,
Ajit Khaparde91992e42010-02-19 13:57:12 +0000663 u32 wrb_cnt, u32 copied, u32 gso_segs, bool stopped)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700664{
Sathya Perla3c8def92011-06-12 20:01:58 +0000665 struct be_tx_stats *stats = tx_stats(txo);
666
Sathya Perlaab1594e2011-07-25 19:10:15 +0000667 u64_stats_update_begin(&stats->sync);
Sathya Perlaac124ff2011-07-25 19:10:14 +0000668 stats->tx_reqs++;
669 stats->tx_wrbs += wrb_cnt;
670 stats->tx_bytes += copied;
671 stats->tx_pkts += (gso_segs ? gso_segs : 1);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700672 if (stopped)
Sathya Perlaac124ff2011-07-25 19:10:14 +0000673 stats->tx_stops++;
Sathya Perlaab1594e2011-07-25 19:10:15 +0000674 u64_stats_update_end(&stats->sync);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700675}
676
677/* Determine number of WRB entries needed to xmit data in an skb */
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000678static u32 wrb_cnt_for_skb(struct be_adapter *adapter, struct sk_buff *skb,
679 bool *dummy)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700680{
David S. Millerebc8d2a2009-06-09 01:01:31 -0700681 int cnt = (skb->len > skb->data_len);
682
683 cnt += skb_shinfo(skb)->nr_frags;
684
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700685 /* to account for hdr wrb */
686 cnt++;
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000687 if (lancer_chip(adapter) || !(cnt & 1)) {
688 *dummy = false;
689 } else {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700690 /* add a dummy to make it an even num */
691 cnt++;
692 *dummy = true;
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000693 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700694 BUG_ON(cnt > BE_MAX_TX_FRAG_COUNT);
695 return cnt;
696}
697
698static inline void wrb_fill(struct be_eth_wrb *wrb, u64 addr, int len)
699{
700 wrb->frag_pa_hi = upper_32_bits(addr);
701 wrb->frag_pa_lo = addr & 0xFFFFFFFF;
702 wrb->frag_len = len & ETH_WRB_FRAG_LEN_MASK;
Somnath Kotur89b1f492012-06-24 19:40:55 +0000703 wrb->rsvd0 = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700704}
705
Ajit Khaparde1ded1322011-12-09 13:53:17 +0000706static inline u16 be_get_tx_vlan_tag(struct be_adapter *adapter,
707 struct sk_buff *skb)
708{
709 u8 vlan_prio;
710 u16 vlan_tag;
711
712 vlan_tag = vlan_tx_tag_get(skb);
713 vlan_prio = (vlan_tag & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
714 /* If vlan priority provided by OS is NOT in available bmap */
715 if (!(adapter->vlan_prio_bmap & (1 << vlan_prio)))
716 vlan_tag = (vlan_tag & ~VLAN_PRIO_MASK) |
717 adapter->recommended_prio;
718
719 return vlan_tag;
720}
721
Sathya Perlac9c47142014-03-27 10:46:19 +0530722/* Used only for IP tunnel packets */
723static u16 skb_inner_ip_proto(struct sk_buff *skb)
724{
725 return (inner_ip_hdr(skb)->version == 4) ?
726 inner_ip_hdr(skb)->protocol : inner_ipv6_hdr(skb)->nexthdr;
727}
728
729static u16 skb_ip_proto(struct sk_buff *skb)
730{
731 return (ip_hdr(skb)->version == 4) ?
732 ip_hdr(skb)->protocol : ipv6_hdr(skb)->nexthdr;
733}
734
Somnath Koturcc4ce022010-10-21 07:11:14 -0700735static void wrb_fill_hdr(struct be_adapter *adapter, struct be_eth_hdr_wrb *hdr,
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000736 struct sk_buff *skb, u32 wrb_cnt, u32 len, bool skip_hw_vlan)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700737{
Sathya Perlac9c47142014-03-27 10:46:19 +0530738 u16 vlan_tag, proto;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700739
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700740 memset(hdr, 0, sizeof(*hdr));
741
742 AMAP_SET_BITS(struct amap_eth_hdr_wrb, crc, hdr, 1);
743
Ajit Khaparde49e4b8472010-06-14 04:56:07 +0000744 if (skb_is_gso(skb)) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700745 AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso, hdr, 1);
746 AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso_mss,
747 hdr, skb_shinfo(skb)->gso_size);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000748 if (skb_is_gso_v6(skb) && !lancer_chip(adapter))
Ajit Khaparde49e4b8472010-06-14 04:56:07 +0000749 AMAP_SET_BITS(struct amap_eth_hdr_wrb, lso6, hdr, 1);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700750 } else if (skb->ip_summed == CHECKSUM_PARTIAL) {
Sathya Perlac9c47142014-03-27 10:46:19 +0530751 if (skb->encapsulation) {
752 AMAP_SET_BITS(struct amap_eth_hdr_wrb, ipcs, hdr, 1);
753 proto = skb_inner_ip_proto(skb);
754 } else {
755 proto = skb_ip_proto(skb);
756 }
757 if (proto == IPPROTO_TCP)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700758 AMAP_SET_BITS(struct amap_eth_hdr_wrb, tcpcs, hdr, 1);
Sathya Perlac9c47142014-03-27 10:46:19 +0530759 else if (proto == IPPROTO_UDP)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700760 AMAP_SET_BITS(struct amap_eth_hdr_wrb, udpcs, hdr, 1);
761 }
762
Ajit Khaparde4c5102f2011-07-12 22:10:01 -0700763 if (vlan_tx_tag_present(skb)) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700764 AMAP_SET_BITS(struct amap_eth_hdr_wrb, vlan, hdr, 1);
Ajit Khaparde1ded1322011-12-09 13:53:17 +0000765 vlan_tag = be_get_tx_vlan_tag(adapter, skb);
Somnath Koturcc4ce022010-10-21 07:11:14 -0700766 AMAP_SET_BITS(struct amap_eth_hdr_wrb, vlan_tag, hdr, vlan_tag);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700767 }
768
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000769 /* To skip HW VLAN tagging: evt = 1, compl = 0 */
770 AMAP_SET_BITS(struct amap_eth_hdr_wrb, complete, hdr, !skip_hw_vlan);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700771 AMAP_SET_BITS(struct amap_eth_hdr_wrb, event, hdr, 1);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700772 AMAP_SET_BITS(struct amap_eth_hdr_wrb, num_wrb, hdr, wrb_cnt);
773 AMAP_SET_BITS(struct amap_eth_hdr_wrb, len, hdr, len);
774}
775
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000776static void unmap_tx_frag(struct device *dev, struct be_eth_wrb *wrb,
Sathya Perla7101e112010-03-22 20:41:12 +0000777 bool unmap_single)
778{
779 dma_addr_t dma;
780
781 be_dws_le_to_cpu(wrb, sizeof(*wrb));
782
783 dma = (u64)wrb->frag_pa_hi << 32 | (u64)wrb->frag_pa_lo;
FUJITA Tomonorib681ee72010-04-04 21:40:18 +0000784 if (wrb->frag_len) {
Sathya Perla7101e112010-03-22 20:41:12 +0000785 if (unmap_single)
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000786 dma_unmap_single(dev, dma, wrb->frag_len,
787 DMA_TO_DEVICE);
Sathya Perla7101e112010-03-22 20:41:12 +0000788 else
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000789 dma_unmap_page(dev, dma, wrb->frag_len, DMA_TO_DEVICE);
Sathya Perla7101e112010-03-22 20:41:12 +0000790 }
791}
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700792
Sathya Perla3c8def92011-06-12 20:01:58 +0000793static int make_tx_wrbs(struct be_adapter *adapter, struct be_queue_info *txq,
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000794 struct sk_buff *skb, u32 wrb_cnt, bool dummy_wrb,
795 bool skip_hw_vlan)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700796{
Sathya Perla7101e112010-03-22 20:41:12 +0000797 dma_addr_t busaddr;
798 int i, copied = 0;
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000799 struct device *dev = &adapter->pdev->dev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700800 struct sk_buff *first_skb = skb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700801 struct be_eth_wrb *wrb;
802 struct be_eth_hdr_wrb *hdr;
Sathya Perla7101e112010-03-22 20:41:12 +0000803 bool map_single = false;
804 u16 map_head;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700805
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700806 hdr = queue_head_node(txq);
807 queue_head_inc(txq);
Sathya Perla7101e112010-03-22 20:41:12 +0000808 map_head = txq->head;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700809
David S. Millerebc8d2a2009-06-09 01:01:31 -0700810 if (skb->len > skb->data_len) {
Eric Dumazete743d312010-04-14 15:59:40 -0700811 int len = skb_headlen(skb);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000812 busaddr = dma_map_single(dev, skb->data, len, DMA_TO_DEVICE);
813 if (dma_mapping_error(dev, busaddr))
Sathya Perla7101e112010-03-22 20:41:12 +0000814 goto dma_err;
815 map_single = true;
David S. Millerebc8d2a2009-06-09 01:01:31 -0700816 wrb = queue_head_node(txq);
817 wrb_fill(wrb, busaddr, len);
818 be_dws_cpu_to_le(wrb, sizeof(*wrb));
819 queue_head_inc(txq);
820 copied += len;
821 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700822
David S. Millerebc8d2a2009-06-09 01:01:31 -0700823 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +0000824 const struct skb_frag_struct *frag =
David S. Millerebc8d2a2009-06-09 01:01:31 -0700825 &skb_shinfo(skb)->frags[i];
Ian Campbellb061b392011-08-29 23:18:23 +0000826 busaddr = skb_frag_dma_map(dev, frag, 0,
Eric Dumazet9e903e02011-10-18 21:00:24 +0000827 skb_frag_size(frag), DMA_TO_DEVICE);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000828 if (dma_mapping_error(dev, busaddr))
Sathya Perla7101e112010-03-22 20:41:12 +0000829 goto dma_err;
David S. Millerebc8d2a2009-06-09 01:01:31 -0700830 wrb = queue_head_node(txq);
Eric Dumazet9e903e02011-10-18 21:00:24 +0000831 wrb_fill(wrb, busaddr, skb_frag_size(frag));
David S. Millerebc8d2a2009-06-09 01:01:31 -0700832 be_dws_cpu_to_le(wrb, sizeof(*wrb));
833 queue_head_inc(txq);
Eric Dumazet9e903e02011-10-18 21:00:24 +0000834 copied += skb_frag_size(frag);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700835 }
836
837 if (dummy_wrb) {
838 wrb = queue_head_node(txq);
839 wrb_fill(wrb, 0, 0);
840 be_dws_cpu_to_le(wrb, sizeof(*wrb));
841 queue_head_inc(txq);
842 }
843
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000844 wrb_fill_hdr(adapter, hdr, first_skb, wrb_cnt, copied, skip_hw_vlan);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700845 be_dws_cpu_to_le(hdr, sizeof(*hdr));
846
847 return copied;
Sathya Perla7101e112010-03-22 20:41:12 +0000848dma_err:
849 txq->head = map_head;
850 while (copied) {
851 wrb = queue_head_node(txq);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +0000852 unmap_tx_frag(dev, wrb, map_single);
Sathya Perla7101e112010-03-22 20:41:12 +0000853 map_single = false;
854 copied -= wrb->frag_len;
855 queue_head_inc(txq);
856 }
857 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700858}
859
Somnath Kotur93040ae2012-06-26 22:32:10 +0000860static struct sk_buff *be_insert_vlan_in_pkt(struct be_adapter *adapter,
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000861 struct sk_buff *skb,
862 bool *skip_hw_vlan)
Somnath Kotur93040ae2012-06-26 22:32:10 +0000863{
864 u16 vlan_tag = 0;
865
866 skb = skb_share_check(skb, GFP_ATOMIC);
867 if (unlikely(!skb))
868 return skb;
869
Sarveshwar Bandiefee8e82013-05-13 20:28:20 +0000870 if (vlan_tx_tag_present(skb))
Somnath Kotur93040ae2012-06-26 22:32:10 +0000871 vlan_tag = be_get_tx_vlan_tag(adapter, skb);
Sarveshwar Bandi52fe29e2013-07-16 12:44:02 +0530872
873 if (qnq_async_evt_rcvd(adapter) && adapter->pvid) {
874 if (!vlan_tag)
875 vlan_tag = adapter->pvid;
876 /* f/w workaround to set skip_hw_vlan = 1, informs the F/W to
877 * skip VLAN insertion
878 */
879 if (skip_hw_vlan)
880 *skip_hw_vlan = true;
881 }
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000882
883 if (vlan_tag) {
David S. Miller58717682013-04-30 03:50:54 -0400884 skb = __vlan_put_tag(skb, htons(ETH_P_8021Q), vlan_tag);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000885 if (unlikely(!skb))
886 return skb;
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000887 skb->vlan_tci = 0;
888 }
889
890 /* Insert the outer VLAN, if any */
891 if (adapter->qnq_vid) {
892 vlan_tag = adapter->qnq_vid;
David S. Miller58717682013-04-30 03:50:54 -0400893 skb = __vlan_put_tag(skb, htons(ETH_P_8021Q), vlan_tag);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000894 if (unlikely(!skb))
895 return skb;
896 if (skip_hw_vlan)
897 *skip_hw_vlan = true;
898 }
899
Somnath Kotur93040ae2012-06-26 22:32:10 +0000900 return skb;
901}
902
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000903static bool be_ipv6_exthdr_check(struct sk_buff *skb)
904{
905 struct ethhdr *eh = (struct ethhdr *)skb->data;
906 u16 offset = ETH_HLEN;
907
908 if (eh->h_proto == htons(ETH_P_IPV6)) {
909 struct ipv6hdr *ip6h = (struct ipv6hdr *)(skb->data + offset);
910
911 offset += sizeof(struct ipv6hdr);
912 if (ip6h->nexthdr != NEXTHDR_TCP &&
913 ip6h->nexthdr != NEXTHDR_UDP) {
914 struct ipv6_opt_hdr *ehdr =
915 (struct ipv6_opt_hdr *) (skb->data + offset);
916
917 /* offending pkt: 2nd byte following IPv6 hdr is 0xff */
918 if (ehdr->hdrlen == 0xff)
919 return true;
920 }
921 }
922 return false;
923}
924
925static int be_vlan_tag_tx_chk(struct be_adapter *adapter, struct sk_buff *skb)
926{
927 return vlan_tx_tag_present(skb) || adapter->pvid || adapter->qnq_vid;
928}
929
Sathya Perlaee9c7992013-05-22 23:04:55 +0000930static int be_ipv6_tx_stall_chk(struct be_adapter *adapter,
931 struct sk_buff *skb)
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000932{
Sathya Perlaee9c7992013-05-22 23:04:55 +0000933 return BE3_chip(adapter) && be_ipv6_exthdr_check(skb);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000934}
935
Vasundhara Volamec495fa2014-03-03 14:25:38 +0530936static struct sk_buff *be_lancer_xmit_workarounds(struct be_adapter *adapter,
937 struct sk_buff *skb,
938 bool *skip_hw_vlan)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700939{
Ajit Khaparded2cb6ce2013-04-24 11:53:08 +0000940 struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
Sathya Perlaee9c7992013-05-22 23:04:55 +0000941 unsigned int eth_hdr_len;
942 struct iphdr *ip;
Somnath Kotur93040ae2012-06-26 22:32:10 +0000943
Ajit Khaparde1297f9d2013-04-24 11:52:28 +0000944 /* For padded packets, BE HW modifies tot_len field in IP header
945 * incorrecly when VLAN tag is inserted by HW.
Somnath Kotur3904dcc2013-05-26 21:09:06 +0000946 * For padded packets, Lancer computes incorrect checksum.
Ajit Khaparde1ded1322011-12-09 13:53:17 +0000947 */
Sathya Perlaee9c7992013-05-22 23:04:55 +0000948 eth_hdr_len = ntohs(skb->protocol) == ETH_P_8021Q ?
949 VLAN_ETH_HLEN : ETH_HLEN;
Somnath Kotur3904dcc2013-05-26 21:09:06 +0000950 if (skb->len <= 60 &&
951 (lancer_chip(adapter) || vlan_tx_tag_present(skb)) &&
Sathya Perlaee9c7992013-05-22 23:04:55 +0000952 is_ipv4_pkt(skb)) {
Somnath Kotur93040ae2012-06-26 22:32:10 +0000953 ip = (struct iphdr *)ip_hdr(skb);
954 pskb_trim(skb, eth_hdr_len + ntohs(ip->tot_len));
955 }
956
Ajit Khaparded2cb6ce2013-04-24 11:53:08 +0000957 /* If vlan tag is already inlined in the packet, skip HW VLAN
Vasundhara Volamf93f1602014-02-12 16:09:25 +0530958 * tagging in pvid-tagging mode
Ajit Khaparded2cb6ce2013-04-24 11:53:08 +0000959 */
Vasundhara Volamf93f1602014-02-12 16:09:25 +0530960 if (be_pvid_tagging_enabled(adapter) &&
Ajit Khaparded2cb6ce2013-04-24 11:53:08 +0000961 veh->h_vlan_proto == htons(ETH_P_8021Q))
Sathya Perlaee9c7992013-05-22 23:04:55 +0000962 *skip_hw_vlan = true;
Ajit Khaparded2cb6ce2013-04-24 11:53:08 +0000963
Somnath Kotur93040ae2012-06-26 22:32:10 +0000964 /* HW has a bug wherein it will calculate CSUM for VLAN
965 * pkts even though it is disabled.
966 * Manually insert VLAN in pkt.
967 */
968 if (skb->ip_summed != CHECKSUM_PARTIAL &&
Sathya Perlaee9c7992013-05-22 23:04:55 +0000969 vlan_tx_tag_present(skb)) {
970 skb = be_insert_vlan_in_pkt(adapter, skb, skip_hw_vlan);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000971 if (unlikely(!skb))
Vasundhara Volamc9128952014-03-03 14:25:07 +0530972 goto err;
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000973 }
974
975 /* HW may lockup when VLAN HW tagging is requested on
976 * certain ipv6 packets. Drop such pkts if the HW workaround to
977 * skip HW tagging is not enabled by FW.
978 */
979 if (unlikely(be_ipv6_tx_stall_chk(adapter, skb) &&
Sathya Perlaee9c7992013-05-22 23:04:55 +0000980 (adapter->pvid || adapter->qnq_vid) &&
981 !qnq_async_evt_rcvd(adapter)))
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000982 goto tx_drop;
983
984 /* Manual VLAN tag insertion to prevent:
985 * ASIC lockup when the ASIC inserts VLAN tag into
986 * certain ipv6 packets. Insert VLAN tags in driver,
987 * and set event, completion, vlan bits accordingly
988 * in the Tx WRB.
989 */
990 if (be_ipv6_tx_stall_chk(adapter, skb) &&
991 be_vlan_tag_tx_chk(adapter, skb)) {
Sathya Perlaee9c7992013-05-22 23:04:55 +0000992 skb = be_insert_vlan_in_pkt(adapter, skb, skip_hw_vlan);
Ajit Khaparde1ded1322011-12-09 13:53:17 +0000993 if (unlikely(!skb))
Vasundhara Volamc9128952014-03-03 14:25:07 +0530994 goto err;
Ajit Khaparde1ded1322011-12-09 13:53:17 +0000995 }
996
Sathya Perlaee9c7992013-05-22 23:04:55 +0000997 return skb;
998tx_drop:
999 dev_kfree_skb_any(skb);
Vasundhara Volamc9128952014-03-03 14:25:07 +05301000err:
Sathya Perlaee9c7992013-05-22 23:04:55 +00001001 return NULL;
1002}
1003
Vasundhara Volamec495fa2014-03-03 14:25:38 +05301004static struct sk_buff *be_xmit_workarounds(struct be_adapter *adapter,
1005 struct sk_buff *skb,
1006 bool *skip_hw_vlan)
1007{
1008 /* Lancer, SH-R ASICs have a bug wherein Packets that are 32 bytes or
1009 * less may cause a transmit stall on that port. So the work-around is
1010 * to pad short packets (<= 32 bytes) to a 36-byte length.
1011 */
1012 if (unlikely(!BEx_chip(adapter) && skb->len <= 32)) {
1013 if (skb_padto(skb, 36))
1014 return NULL;
1015 skb->len = 36;
1016 }
1017
1018 if (BEx_chip(adapter) || lancer_chip(adapter)) {
1019 skb = be_lancer_xmit_workarounds(adapter, skb, skip_hw_vlan);
1020 if (!skb)
1021 return NULL;
1022 }
1023
1024 return skb;
1025}
1026
Sathya Perlaee9c7992013-05-22 23:04:55 +00001027static netdev_tx_t be_xmit(struct sk_buff *skb, struct net_device *netdev)
1028{
1029 struct be_adapter *adapter = netdev_priv(netdev);
1030 struct be_tx_obj *txo = &adapter->tx_obj[skb_get_queue_mapping(skb)];
1031 struct be_queue_info *txq = &txo->q;
1032 bool dummy_wrb, stopped = false;
1033 u32 wrb_cnt = 0, copied = 0;
1034 bool skip_hw_vlan = false;
1035 u32 start = txq->head;
1036
1037 skb = be_xmit_workarounds(adapter, skb, &skip_hw_vlan);
Sathya Perlabc617522013-10-01 16:00:01 +05301038 if (!skb) {
1039 tx_stats(txo)->tx_drv_drops++;
Sathya Perlaee9c7992013-05-22 23:04:55 +00001040 return NETDEV_TX_OK;
Sathya Perlabc617522013-10-01 16:00:01 +05301041 }
Sathya Perlaee9c7992013-05-22 23:04:55 +00001042
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001043 wrb_cnt = wrb_cnt_for_skb(adapter, skb, &dummy_wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001044
Ajit Khapardebc0c3402013-04-24 11:52:50 +00001045 copied = make_tx_wrbs(adapter, txq, skb, wrb_cnt, dummy_wrb,
1046 skip_hw_vlan);
Ajit Khapardec190e3c2009-09-04 03:12:29 +00001047 if (copied) {
Eric Dumazetcd8f76c2012-06-07 22:59:59 +00001048 int gso_segs = skb_shinfo(skb)->gso_segs;
1049
Ajit Khapardec190e3c2009-09-04 03:12:29 +00001050 /* record the sent skb in the sent_skb table */
Sathya Perla3c8def92011-06-12 20:01:58 +00001051 BUG_ON(txo->sent_skb_list[start]);
1052 txo->sent_skb_list[start] = skb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001053
Ajit Khapardec190e3c2009-09-04 03:12:29 +00001054 /* Ensure txq has space for the next skb; Else stop the queue
1055 * *BEFORE* ringing the tx doorbell, so that we serialze the
1056 * tx compls of the current transmit which'll wake up the queue
1057 */
Sathya Perla7101e112010-03-22 20:41:12 +00001058 atomic_add(wrb_cnt, &txq->used);
Ajit Khapardec190e3c2009-09-04 03:12:29 +00001059 if ((BE_MAX_TX_FRAG_COUNT + atomic_read(&txq->used)) >=
1060 txq->len) {
Sathya Perla3c8def92011-06-12 20:01:58 +00001061 netif_stop_subqueue(netdev, skb_get_queue_mapping(skb));
Ajit Khapardec190e3c2009-09-04 03:12:29 +00001062 stopped = true;
1063 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001064
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001065 be_txq_notify(adapter, txo, wrb_cnt);
Ajit Khapardec190e3c2009-09-04 03:12:29 +00001066
Eric Dumazetcd8f76c2012-06-07 22:59:59 +00001067 be_tx_stats_update(txo, wrb_cnt, copied, gso_segs, stopped);
Ajit Khapardec190e3c2009-09-04 03:12:29 +00001068 } else {
1069 txq->head = start;
Sathya Perlabc617522013-10-01 16:00:01 +05301070 tx_stats(txo)->tx_drv_drops++;
Ajit Khapardec190e3c2009-09-04 03:12:29 +00001071 dev_kfree_skb_any(skb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001072 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001073 return NETDEV_TX_OK;
1074}
1075
1076static int be_change_mtu(struct net_device *netdev, int new_mtu)
1077{
1078 struct be_adapter *adapter = netdev_priv(netdev);
1079 if (new_mtu < BE_MIN_MTU ||
Ajit Khaparde34a89b82010-02-09 01:32:43 +00001080 new_mtu > (BE_MAX_JUMBO_FRAME_SIZE -
1081 (ETH_HLEN + ETH_FCS_LEN))) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001082 dev_info(&adapter->pdev->dev,
1083 "MTU must be between %d and %d bytes\n",
Ajit Khaparde34a89b82010-02-09 01:32:43 +00001084 BE_MIN_MTU,
1085 (BE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN)));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001086 return -EINVAL;
1087 }
1088 dev_info(&adapter->pdev->dev, "MTU changed from %d to %d bytes\n",
1089 netdev->mtu, new_mtu);
1090 netdev->mtu = new_mtu;
1091 return 0;
1092}
1093
1094/*
Ajit Khaparde82903e42010-02-09 01:34:57 +00001095 * A max of 64 (BE_NUM_VLANS_SUPPORTED) vlans can be configured in BE.
1096 * If the user configures more, place BE in vlan promiscuous mode.
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001097 */
Sathya Perla10329df2012-06-05 19:37:18 +00001098static int be_vid_config(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001099{
Sathya Perla10329df2012-06-05 19:37:18 +00001100 u16 vids[BE_NUM_VLANS_SUPPORTED];
1101 u16 num = 0, i;
Ajit Khaparde82903e42010-02-09 01:34:57 +00001102 int status = 0;
Ajit Khaparde1da87b72010-07-23 01:51:22 +00001103
Sathya Perlac0e64ef2011-08-02 19:57:43 +00001104 /* No need to further configure vids if in promiscuous mode */
1105 if (adapter->promiscuous)
1106 return 0;
1107
Sathya Perla92bf14a2013-08-27 16:57:32 +05301108 if (adapter->vlans_added > be_max_vlans(adapter))
Padmanabh Ratnakar0fc16eb2012-04-25 01:46:06 +00001109 goto set_vlan_promisc;
1110
1111 /* Construct VLAN Table to give to HW */
1112 for (i = 0; i < VLAN_N_VID; i++)
1113 if (adapter->vlan_tag[i])
Sathya Perla10329df2012-06-05 19:37:18 +00001114 vids[num++] = cpu_to_le16(i);
Padmanabh Ratnakar0fc16eb2012-04-25 01:46:06 +00001115
1116 status = be_cmd_vlan_config(adapter, adapter->if_handle,
Ajit Khaparde012bd382013-11-18 10:44:24 -06001117 vids, num, 0);
Padmanabh Ratnakar0fc16eb2012-04-25 01:46:06 +00001118
Padmanabh Ratnakar0fc16eb2012-04-25 01:46:06 +00001119 if (status) {
Ajit Khaparded9d604f2013-09-27 15:17:58 -05001120 /* Set to VLAN promisc mode as setting VLAN filter failed */
1121 if (status == MCC_ADDL_STS_INSUFFICIENT_RESOURCES)
1122 goto set_vlan_promisc;
1123 dev_err(&adapter->pdev->dev,
1124 "Setting HW VLAN filtering failed.\n");
1125 } else {
1126 if (adapter->flags & BE_FLAGS_VLAN_PROMISC) {
1127 /* hw VLAN filtering re-enabled. */
1128 status = be_cmd_rx_filter(adapter,
1129 BE_FLAGS_VLAN_PROMISC, OFF);
1130 if (!status) {
1131 dev_info(&adapter->pdev->dev,
1132 "Disabling VLAN Promiscuous mode.\n");
1133 adapter->flags &= ~BE_FLAGS_VLAN_PROMISC;
Ajit Khaparded9d604f2013-09-27 15:17:58 -05001134 }
1135 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001136 }
Ajit Khaparde1da87b72010-07-23 01:51:22 +00001137
Sathya Perlab31c50a2009-09-17 10:30:13 -07001138 return status;
Padmanabh Ratnakar0fc16eb2012-04-25 01:46:06 +00001139
1140set_vlan_promisc:
Somnath Kotura6b74e02014-01-21 15:50:55 +05301141 if (adapter->flags & BE_FLAGS_VLAN_PROMISC)
1142 return 0;
Ajit Khaparded9d604f2013-09-27 15:17:58 -05001143
1144 status = be_cmd_rx_filter(adapter, BE_FLAGS_VLAN_PROMISC, ON);
1145 if (!status) {
1146 dev_info(&adapter->pdev->dev, "Enable VLAN Promiscuous mode\n");
Ajit Khaparded9d604f2013-09-27 15:17:58 -05001147 adapter->flags |= BE_FLAGS_VLAN_PROMISC;
1148 } else
1149 dev_err(&adapter->pdev->dev,
1150 "Failed to enable VLAN Promiscuous mode.\n");
Padmanabh Ratnakar0fc16eb2012-04-25 01:46:06 +00001151 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001152}
1153
Patrick McHardy80d5c362013-04-19 02:04:28 +00001154static int be_vlan_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001155{
1156 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khaparde80817cb2011-12-30 12:15:12 +00001157 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001158
Padmanabh Ratnakara85e9982012-10-20 06:02:40 +00001159 /* Packets with VID 0 are always received by Lancer by default */
1160 if (lancer_chip(adapter) && vid == 0)
Vasundhara Volam48291c22014-03-11 18:53:08 +05301161 return status;
1162
1163 if (adapter->vlan_tag[vid])
1164 return status;
Padmanabh Ratnakara85e9982012-10-20 06:02:40 +00001165
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001166 adapter->vlan_tag[vid] = 1;
Somnath Kotura6b74e02014-01-21 15:50:55 +05301167 adapter->vlans_added++;
Jiri Pirko8e586132011-12-08 19:52:37 -05001168
Somnath Kotura6b74e02014-01-21 15:50:55 +05301169 status = be_vid_config(adapter);
1170 if (status) {
1171 adapter->vlans_added--;
Ajit Khaparde80817cb2011-12-30 12:15:12 +00001172 adapter->vlan_tag[vid] = 0;
Somnath Kotura6b74e02014-01-21 15:50:55 +05301173 }
Vasundhara Volam48291c22014-03-11 18:53:08 +05301174
Ajit Khaparde80817cb2011-12-30 12:15:12 +00001175 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001176}
1177
Patrick McHardy80d5c362013-04-19 02:04:28 +00001178static int be_vlan_rem_vid(struct net_device *netdev, __be16 proto, u16 vid)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001179{
1180 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khaparde80817cb2011-12-30 12:15:12 +00001181 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001182
Padmanabh Ratnakara85e9982012-10-20 06:02:40 +00001183 /* Packets with VID 0 are always received by Lancer by default */
1184 if (lancer_chip(adapter) && vid == 0)
1185 goto ret;
1186
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001187 adapter->vlan_tag[vid] = 0;
Somnath Kotura6b74e02014-01-21 15:50:55 +05301188 status = be_vid_config(adapter);
Ajit Khaparde80817cb2011-12-30 12:15:12 +00001189 if (!status)
1190 adapter->vlans_added--;
1191 else
1192 adapter->vlan_tag[vid] = 1;
1193ret:
1194 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001195}
1196
Somnath kotur7ad09452014-03-03 14:24:43 +05301197static void be_clear_promisc(struct be_adapter *adapter)
1198{
1199 adapter->promiscuous = false;
1200 adapter->flags &= ~BE_FLAGS_VLAN_PROMISC;
1201
1202 be_cmd_rx_filter(adapter, IFF_PROMISC, OFF);
1203}
1204
Sathya Perlaa54769f2011-10-24 02:45:00 +00001205static void be_set_rx_mode(struct net_device *netdev)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001206{
1207 struct be_adapter *adapter = netdev_priv(netdev);
Padmanabh Ratnakar0fc16eb2012-04-25 01:46:06 +00001208 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001209
1210 if (netdev->flags & IFF_PROMISC) {
Sathya Perla5b8821b2011-08-02 19:57:44 +00001211 be_cmd_rx_filter(adapter, IFF_PROMISC, ON);
Sathya Perla24307ee2009-06-18 00:09:25 +00001212 adapter->promiscuous = true;
1213 goto done;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001214 }
Sathya Perla24307ee2009-06-18 00:09:25 +00001215
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001216 /* BE was previously in promiscuous mode; disable it */
Sathya Perla24307ee2009-06-18 00:09:25 +00001217 if (adapter->promiscuous) {
Somnath kotur7ad09452014-03-03 14:24:43 +05301218 be_clear_promisc(adapter);
Sathya Perlac0e64ef2011-08-02 19:57:43 +00001219 if (adapter->vlans_added)
Sathya Perla10329df2012-06-05 19:37:18 +00001220 be_vid_config(adapter);
Sathya Perla24307ee2009-06-18 00:09:25 +00001221 }
1222
Sathya Perlae7b909a2009-11-22 22:01:10 +00001223 /* Enable multicast promisc if num configured exceeds what we support */
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001224 if (netdev->flags & IFF_ALLMULTI ||
Sathya Perla92bf14a2013-08-27 16:57:32 +05301225 netdev_mc_count(netdev) > be_max_mc(adapter)) {
Sathya Perla5b8821b2011-08-02 19:57:44 +00001226 be_cmd_rx_filter(adapter, IFF_ALLMULTI, ON);
Sathya Perla24307ee2009-06-18 00:09:25 +00001227 goto done;
1228 }
1229
Ajit Khapardefbc13f02012-03-18 06:23:21 +00001230 if (netdev_uc_count(netdev) != adapter->uc_macs) {
1231 struct netdev_hw_addr *ha;
1232 int i = 1; /* First slot is claimed by the Primary MAC */
1233
1234 for (; adapter->uc_macs > 0; adapter->uc_macs--, i++) {
1235 be_cmd_pmac_del(adapter, adapter->if_handle,
1236 adapter->pmac_id[i], 0);
1237 }
1238
Sathya Perla92bf14a2013-08-27 16:57:32 +05301239 if (netdev_uc_count(netdev) > be_max_uc(adapter)) {
Ajit Khapardefbc13f02012-03-18 06:23:21 +00001240 be_cmd_rx_filter(adapter, IFF_PROMISC, ON);
1241 adapter->promiscuous = true;
1242 goto done;
1243 }
1244
1245 netdev_for_each_uc_addr(ha, adapter->netdev) {
1246 adapter->uc_macs++; /* First slot is for Primary MAC */
1247 be_cmd_pmac_add(adapter, (u8 *)ha->addr,
1248 adapter->if_handle,
1249 &adapter->pmac_id[adapter->uc_macs], 0);
1250 }
1251 }
1252
Padmanabh Ratnakar0fc16eb2012-04-25 01:46:06 +00001253 status = be_cmd_rx_filter(adapter, IFF_MULTICAST, ON);
1254
1255 /* Set to MCAST promisc mode if setting MULTICAST address fails */
1256 if (status) {
1257 dev_info(&adapter->pdev->dev, "Exhausted multicast HW filters.\n");
1258 dev_info(&adapter->pdev->dev, "Disabling HW multicast filtering.\n");
1259 be_cmd_rx_filter(adapter, IFF_ALLMULTI, ON);
1260 }
Sathya Perla24307ee2009-06-18 00:09:25 +00001261done:
1262 return;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001263}
1264
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001265static int be_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
1266{
1267 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla11ac75e2011-12-13 00:58:50 +00001268 struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf];
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001269 int status;
1270
Sathya Perla11ac75e2011-12-13 00:58:50 +00001271 if (!sriov_enabled(adapter))
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001272 return -EPERM;
1273
Sathya Perla11ac75e2011-12-13 00:58:50 +00001274 if (!is_valid_ether_addr(mac) || vf >= adapter->num_vfs)
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001275 return -EINVAL;
1276
Sathya Perla3175d8c2013-07-23 15:25:03 +05301277 if (BEx_chip(adapter)) {
1278 be_cmd_pmac_del(adapter, vf_cfg->if_handle, vf_cfg->pmac_id,
1279 vf + 1);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001280
Sathya Perla11ac75e2011-12-13 00:58:50 +00001281 status = be_cmd_pmac_add(adapter, mac, vf_cfg->if_handle,
1282 &vf_cfg->pmac_id, vf + 1);
Sathya Perla3175d8c2013-07-23 15:25:03 +05301283 } else {
1284 status = be_cmd_set_mac(adapter, mac, vf_cfg->if_handle,
1285 vf + 1);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00001286 }
1287
Ajit Khaparde64600ea2010-07-23 01:50:34 +00001288 if (status)
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001289 dev_err(&adapter->pdev->dev, "MAC %pM set on VF %d Failed\n",
1290 mac, vf);
Ajit Khaparde64600ea2010-07-23 01:50:34 +00001291 else
Sathya Perla11ac75e2011-12-13 00:58:50 +00001292 memcpy(vf_cfg->mac_addr, mac, ETH_ALEN);
Ajit Khaparde64600ea2010-07-23 01:50:34 +00001293
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001294 return status;
1295}
1296
Ajit Khaparde64600ea2010-07-23 01:50:34 +00001297static int be_get_vf_config(struct net_device *netdev, int vf,
1298 struct ifla_vf_info *vi)
1299{
1300 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla11ac75e2011-12-13 00:58:50 +00001301 struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf];
Ajit Khaparde64600ea2010-07-23 01:50:34 +00001302
Sathya Perla11ac75e2011-12-13 00:58:50 +00001303 if (!sriov_enabled(adapter))
Ajit Khaparde64600ea2010-07-23 01:50:34 +00001304 return -EPERM;
1305
Sathya Perla11ac75e2011-12-13 00:58:50 +00001306 if (vf >= adapter->num_vfs)
Ajit Khaparde64600ea2010-07-23 01:50:34 +00001307 return -EINVAL;
1308
1309 vi->vf = vf;
Sathya Perla11ac75e2011-12-13 00:58:50 +00001310 vi->tx_rate = vf_cfg->tx_rate;
Ajit Khapardea60b3a12013-09-27 15:18:56 -05001311 vi->vlan = vf_cfg->vlan_tag & VLAN_VID_MASK;
1312 vi->qos = vf_cfg->vlan_tag >> VLAN_PRIO_SHIFT;
Sathya Perla11ac75e2011-12-13 00:58:50 +00001313 memcpy(&vi->mac, vf_cfg->mac_addr, ETH_ALEN);
Suresh Reddybdce2ad2014-03-11 18:53:04 +05301314 vi->linkstate = adapter->vf_cfg[vf].plink_tracking;
Ajit Khaparde64600ea2010-07-23 01:50:34 +00001315
1316 return 0;
1317}
1318
Ajit Khaparde1da87b72010-07-23 01:51:22 +00001319static int be_set_vf_vlan(struct net_device *netdev,
1320 int vf, u16 vlan, u8 qos)
1321{
1322 struct be_adapter *adapter = netdev_priv(netdev);
Ajit Khapardeb9fc0e532013-09-27 15:18:46 -05001323 struct be_vf_cfg *vf_cfg = &adapter->vf_cfg[vf];
Ajit Khaparde1da87b72010-07-23 01:51:22 +00001324 int status = 0;
1325
Sathya Perla11ac75e2011-12-13 00:58:50 +00001326 if (!sriov_enabled(adapter))
Ajit Khaparde1da87b72010-07-23 01:51:22 +00001327 return -EPERM;
1328
Ajit Khapardeb9fc0e532013-09-27 15:18:46 -05001329 if (vf >= adapter->num_vfs || vlan > 4095 || qos > 7)
Ajit Khaparde1da87b72010-07-23 01:51:22 +00001330 return -EINVAL;
1331
Ajit Khapardeb9fc0e532013-09-27 15:18:46 -05001332 if (vlan || qos) {
1333 vlan |= qos << VLAN_PRIO_SHIFT;
Somnath Koturc5022242014-03-03 14:24:20 +05301334 if (vf_cfg->vlan_tag != vlan)
Ajit Khapardeb9fc0e532013-09-27 15:18:46 -05001335 status = be_cmd_set_hsw_config(adapter, vlan, vf + 1,
1336 vf_cfg->if_handle, 0);
Ajit Khaparde1da87b72010-07-23 01:51:22 +00001337 } else {
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00001338 /* Reset Transparent Vlan Tagging. */
Somnath Koturc5022242014-03-03 14:24:20 +05301339 status = be_cmd_set_hsw_config(adapter, BE_RESET_VLAN_TAG_ID,
1340 vf + 1, vf_cfg->if_handle, 0);
Ajit Khaparde1da87b72010-07-23 01:51:22 +00001341 }
1342
Somnath Koturc5022242014-03-03 14:24:20 +05301343 if (!status)
1344 vf_cfg->vlan_tag = vlan;
1345 else
Ajit Khaparde1da87b72010-07-23 01:51:22 +00001346 dev_info(&adapter->pdev->dev,
Somnath Koturc5022242014-03-03 14:24:20 +05301347 "VLAN %d config on VF %d failed\n", vlan, vf);
Ajit Khaparde1da87b72010-07-23 01:51:22 +00001348 return status;
1349}
1350
Ajit Khapardee1d18732010-07-23 01:52:13 +00001351static int be_set_vf_tx_rate(struct net_device *netdev,
1352 int vf, int rate)
1353{
1354 struct be_adapter *adapter = netdev_priv(netdev);
1355 int status = 0;
1356
Sathya Perla11ac75e2011-12-13 00:58:50 +00001357 if (!sriov_enabled(adapter))
Ajit Khapardee1d18732010-07-23 01:52:13 +00001358 return -EPERM;
1359
Ajit Khaparde94f434c2011-12-30 12:15:30 +00001360 if (vf >= adapter->num_vfs)
Ajit Khapardee1d18732010-07-23 01:52:13 +00001361 return -EINVAL;
1362
Ajit Khaparde94f434c2011-12-30 12:15:30 +00001363 if (rate < 100 || rate > 10000) {
1364 dev_err(&adapter->pdev->dev,
1365 "tx rate must be between 100 and 10000 Mbps\n");
1366 return -EINVAL;
1367 }
Ajit Khapardee1d18732010-07-23 01:52:13 +00001368
Sathya Perlaa4018012014-03-27 10:46:18 +05301369 status = be_cmd_config_qos(adapter, rate / 10, vf + 1);
Ajit Khapardee1d18732010-07-23 01:52:13 +00001370 if (status)
Ajit Khaparde94f434c2011-12-30 12:15:30 +00001371 dev_err(&adapter->pdev->dev,
Ajit Khapardee1d18732010-07-23 01:52:13 +00001372 "tx rate %d on VF %d failed\n", rate, vf);
Ajit Khaparde94f434c2011-12-30 12:15:30 +00001373 else
1374 adapter->vf_cfg[vf].tx_rate = rate;
Ajit Khapardee1d18732010-07-23 01:52:13 +00001375 return status;
1376}
Suresh Reddybdce2ad2014-03-11 18:53:04 +05301377static int be_set_vf_link_state(struct net_device *netdev, int vf,
1378 int link_state)
1379{
1380 struct be_adapter *adapter = netdev_priv(netdev);
1381 int status;
1382
1383 if (!sriov_enabled(adapter))
1384 return -EPERM;
1385
1386 if (vf >= adapter->num_vfs)
1387 return -EINVAL;
1388
1389 status = be_cmd_set_logical_link_config(adapter, link_state, vf+1);
1390 if (!status)
1391 adapter->vf_cfg[vf].plink_tracking = link_state;
1392
1393 return status;
1394}
Ajit Khapardee1d18732010-07-23 01:52:13 +00001395
Sathya Perla2632baf2013-10-01 16:00:00 +05301396static void be_aic_update(struct be_aic_obj *aic, u64 rx_pkts, u64 tx_pkts,
1397 ulong now)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001398{
Sathya Perla2632baf2013-10-01 16:00:00 +05301399 aic->rx_pkts_prev = rx_pkts;
1400 aic->tx_reqs_prev = tx_pkts;
1401 aic->jiffies = now;
1402}
Sathya Perlaac124ff2011-07-25 19:10:14 +00001403
Sathya Perla2632baf2013-10-01 16:00:00 +05301404static void be_eqd_update(struct be_adapter *adapter)
1405{
1406 struct be_set_eqd set_eqd[MAX_EVT_QS];
1407 int eqd, i, num = 0, start;
1408 struct be_aic_obj *aic;
1409 struct be_eq_obj *eqo;
1410 struct be_rx_obj *rxo;
1411 struct be_tx_obj *txo;
1412 u64 rx_pkts, tx_pkts;
1413 ulong now;
1414 u32 pps, delta;
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001415
Sathya Perla2632baf2013-10-01 16:00:00 +05301416 for_all_evt_queues(adapter, eqo, i) {
1417 aic = &adapter->aic_obj[eqo->idx];
1418 if (!aic->enable) {
1419 if (aic->jiffies)
1420 aic->jiffies = 0;
1421 eqd = aic->et_eqd;
1422 goto modify_eqd;
1423 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001424
Sathya Perla2632baf2013-10-01 16:00:00 +05301425 rxo = &adapter->rx_obj[eqo->idx];
1426 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001427 start = u64_stats_fetch_begin_irq(&rxo->stats.sync);
Sathya Perla2632baf2013-10-01 16:00:00 +05301428 rx_pkts = rxo->stats.rx_pkts;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001429 } while (u64_stats_fetch_retry_irq(&rxo->stats.sync, start));
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001430
Sathya Perla2632baf2013-10-01 16:00:00 +05301431 txo = &adapter->tx_obj[eqo->idx];
1432 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07001433 start = u64_stats_fetch_begin_irq(&txo->stats.sync);
Sathya Perla2632baf2013-10-01 16:00:00 +05301434 tx_pkts = txo->stats.tx_reqs;
Eric W. Biederman57a77442014-03-13 21:26:42 -07001435 } while (u64_stats_fetch_retry_irq(&txo->stats.sync, start));
Sathya Perla4097f662009-03-24 16:40:13 -07001436
Sathya Perla4097f662009-03-24 16:40:13 -07001437
Sathya Perla2632baf2013-10-01 16:00:00 +05301438 /* Skip, if wrapped around or first calculation */
1439 now = jiffies;
1440 if (!aic->jiffies || time_before(now, aic->jiffies) ||
1441 rx_pkts < aic->rx_pkts_prev ||
1442 tx_pkts < aic->tx_reqs_prev) {
1443 be_aic_update(aic, rx_pkts, tx_pkts, now);
1444 continue;
1445 }
Sathya Perlaab1594e2011-07-25 19:10:15 +00001446
Sathya Perla2632baf2013-10-01 16:00:00 +05301447 delta = jiffies_to_msecs(now - aic->jiffies);
1448 pps = (((u32)(rx_pkts - aic->rx_pkts_prev) * 1000) / delta) +
1449 (((u32)(tx_pkts - aic->tx_reqs_prev) * 1000) / delta);
1450 eqd = (pps / 15000) << 2;
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001451
Sathya Perla2632baf2013-10-01 16:00:00 +05301452 if (eqd < 8)
1453 eqd = 0;
1454 eqd = min_t(u32, eqd, aic->max_eqd);
1455 eqd = max_t(u32, eqd, aic->min_eqd);
1456
1457 be_aic_update(aic, rx_pkts, tx_pkts, now);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001458modify_eqd:
Sathya Perla2632baf2013-10-01 16:00:00 +05301459 if (eqd != aic->prev_eqd) {
1460 set_eqd[num].delay_multiplier = (eqd * 65)/100;
1461 set_eqd[num].eq_id = eqo->q.id;
1462 aic->prev_eqd = eqd;
1463 num++;
1464 }
Sathya Perlaac124ff2011-07-25 19:10:14 +00001465 }
Sathya Perla2632baf2013-10-01 16:00:00 +05301466
1467 if (num)
1468 be_cmd_modify_eqd(adapter, set_eqd, num);
Sathya Perla4097f662009-03-24 16:40:13 -07001469}
1470
Sathya Perla3abcded2010-10-03 22:12:27 -07001471static void be_rx_stats_update(struct be_rx_obj *rxo,
Sathya Perla2e588f82011-03-11 02:49:26 +00001472 struct be_rx_compl_info *rxcp)
Sathya Perla4097f662009-03-24 16:40:13 -07001473{
Sathya Perlaac124ff2011-07-25 19:10:14 +00001474 struct be_rx_stats *stats = rx_stats(rxo);
Sathya Perla4097f662009-03-24 16:40:13 -07001475
Sathya Perlaab1594e2011-07-25 19:10:15 +00001476 u64_stats_update_begin(&stats->sync);
Sathya Perla3abcded2010-10-03 22:12:27 -07001477 stats->rx_compl++;
Sathya Perla2e588f82011-03-11 02:49:26 +00001478 stats->rx_bytes += rxcp->pkt_size;
Sathya Perla3abcded2010-10-03 22:12:27 -07001479 stats->rx_pkts++;
Sathya Perla2e588f82011-03-11 02:49:26 +00001480 if (rxcp->pkt_type == BE_MULTICAST_PACKET)
Sathya Perla3abcded2010-10-03 22:12:27 -07001481 stats->rx_mcast_pkts++;
Sathya Perla2e588f82011-03-11 02:49:26 +00001482 if (rxcp->err)
Sathya Perlaac124ff2011-07-25 19:10:14 +00001483 stats->rx_compl_err++;
Sathya Perlaab1594e2011-07-25 19:10:15 +00001484 u64_stats_update_end(&stats->sync);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001485}
1486
Sathya Perla2e588f82011-03-11 02:49:26 +00001487static inline bool csum_passed(struct be_rx_compl_info *rxcp)
Ajit Khaparde728a9972009-04-13 15:41:22 -07001488{
Padmanabh Ratnakar19fad862011-03-07 03:08:16 +00001489 /* L4 checksum is not reliable for non TCP/UDP packets.
Sathya Perlac9c47142014-03-27 10:46:19 +05301490 * Also ignore ipcksm for ipv6 pkts
1491 */
Sathya Perla2e588f82011-03-11 02:49:26 +00001492 return (rxcp->tcpf || rxcp->udpf) && rxcp->l4_csum &&
Sathya Perlac9c47142014-03-27 10:46:19 +05301493 (rxcp->ip_csum || rxcp->ipv6) && !rxcp->err;
Ajit Khaparde728a9972009-04-13 15:41:22 -07001494}
1495
Suresh Reddy0b0ef1d2014-01-15 13:23:38 +05301496static struct be_rx_page_info *get_rx_page_info(struct be_rx_obj *rxo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001497{
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001498 struct be_adapter *adapter = rxo->adapter;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001499 struct be_rx_page_info *rx_page_info;
Sathya Perla3abcded2010-10-03 22:12:27 -07001500 struct be_queue_info *rxq = &rxo->q;
Suresh Reddy0b0ef1d2014-01-15 13:23:38 +05301501 u16 frag_idx = rxq->tail;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001502
Sathya Perla3abcded2010-10-03 22:12:27 -07001503 rx_page_info = &rxo->page_info_tbl[frag_idx];
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001504 BUG_ON(!rx_page_info->page);
1505
Sathya Perlae50287b2014-03-04 12:14:38 +05301506 if (rx_page_info->last_frag) {
Ivan Vecera2b7bceb2011-02-02 08:05:12 +00001507 dma_unmap_page(&adapter->pdev->dev,
1508 dma_unmap_addr(rx_page_info, bus),
1509 adapter->big_page_size, DMA_FROM_DEVICE);
Sathya Perlae50287b2014-03-04 12:14:38 +05301510 rx_page_info->last_frag = false;
1511 } else {
1512 dma_sync_single_for_cpu(&adapter->pdev->dev,
1513 dma_unmap_addr(rx_page_info, bus),
1514 rx_frag_size, DMA_FROM_DEVICE);
Ajit Khaparde205859a2010-02-09 01:34:21 +00001515 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001516
Suresh Reddy0b0ef1d2014-01-15 13:23:38 +05301517 queue_tail_inc(rxq);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001518 atomic_dec(&rxq->used);
1519 return rx_page_info;
1520}
1521
1522/* Throwaway the data in the Rx completion */
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001523static void be_rx_compl_discard(struct be_rx_obj *rxo,
1524 struct be_rx_compl_info *rxcp)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001525{
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001526 struct be_rx_page_info *page_info;
Sathya Perla2e588f82011-03-11 02:49:26 +00001527 u16 i, num_rcvd = rxcp->num_rcvd;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001528
Padmanabh Ratnakare80d9da2011-03-07 03:07:58 +00001529 for (i = 0; i < num_rcvd; i++) {
Suresh Reddy0b0ef1d2014-01-15 13:23:38 +05301530 page_info = get_rx_page_info(rxo);
Padmanabh Ratnakare80d9da2011-03-07 03:07:58 +00001531 put_page(page_info->page);
1532 memset(page_info, 0, sizeof(*page_info));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001533 }
1534}
1535
1536/*
1537 * skb_fill_rx_data forms a complete skb for an ether frame
1538 * indicated by rxcp.
1539 */
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001540static void skb_fill_rx_data(struct be_rx_obj *rxo, struct sk_buff *skb,
1541 struct be_rx_compl_info *rxcp)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001542{
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001543 struct be_rx_page_info *page_info;
Sathya Perla2e588f82011-03-11 02:49:26 +00001544 u16 i, j;
1545 u16 hdr_len, curr_frag_len, remaining;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001546 u8 *start;
1547
Suresh Reddy0b0ef1d2014-01-15 13:23:38 +05301548 page_info = get_rx_page_info(rxo);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001549 start = page_address(page_info->page) + page_info->page_offset;
1550 prefetch(start);
1551
1552 /* Copy data in the first descriptor of this completion */
Sathya Perla2e588f82011-03-11 02:49:26 +00001553 curr_frag_len = min(rxcp->pkt_size, rx_frag_size);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001554
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001555 skb->len = curr_frag_len;
1556 if (curr_frag_len <= BE_HDR_LEN) { /* tiny packet */
Eric Dumazetac1ae5f2012-07-13 03:19:41 +00001557 memcpy(skb->data, start, curr_frag_len);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001558 /* Complete packet has now been moved to data */
1559 put_page(page_info->page);
1560 skb->data_len = 0;
1561 skb->tail += curr_frag_len;
1562 } else {
Eric Dumazetac1ae5f2012-07-13 03:19:41 +00001563 hdr_len = ETH_HLEN;
1564 memcpy(skb->data, start, hdr_len);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001565 skb_shinfo(skb)->nr_frags = 1;
Ian Campbellb061b392011-08-29 23:18:23 +00001566 skb_frag_set_page(skb, 0, page_info->page);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001567 skb_shinfo(skb)->frags[0].page_offset =
1568 page_info->page_offset + hdr_len;
Eric Dumazet9e903e02011-10-18 21:00:24 +00001569 skb_frag_size_set(&skb_shinfo(skb)->frags[0], curr_frag_len - hdr_len);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001570 skb->data_len = curr_frag_len - hdr_len;
Eric Dumazetbdb28a92011-10-13 06:31:02 +00001571 skb->truesize += rx_frag_size;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001572 skb->tail += hdr_len;
1573 }
Ajit Khaparde205859a2010-02-09 01:34:21 +00001574 page_info->page = NULL;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001575
Sathya Perla2e588f82011-03-11 02:49:26 +00001576 if (rxcp->pkt_size <= rx_frag_size) {
1577 BUG_ON(rxcp->num_rcvd != 1);
1578 return;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001579 }
1580
1581 /* More frags present for this completion */
Sathya Perla2e588f82011-03-11 02:49:26 +00001582 remaining = rxcp->pkt_size - curr_frag_len;
1583 for (i = 1, j = 0; i < rxcp->num_rcvd; i++) {
Suresh Reddy0b0ef1d2014-01-15 13:23:38 +05301584 page_info = get_rx_page_info(rxo);
Sathya Perla2e588f82011-03-11 02:49:26 +00001585 curr_frag_len = min(remaining, rx_frag_size);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001586
Ajit Khapardebd46cb62009-06-26 02:51:07 +00001587 /* Coalesce all frags from the same physical page in one slot */
1588 if (page_info->page_offset == 0) {
1589 /* Fresh page */
1590 j++;
Ian Campbellb061b392011-08-29 23:18:23 +00001591 skb_frag_set_page(skb, j, page_info->page);
Ajit Khapardebd46cb62009-06-26 02:51:07 +00001592 skb_shinfo(skb)->frags[j].page_offset =
1593 page_info->page_offset;
Eric Dumazet9e903e02011-10-18 21:00:24 +00001594 skb_frag_size_set(&skb_shinfo(skb)->frags[j], 0);
Ajit Khapardebd46cb62009-06-26 02:51:07 +00001595 skb_shinfo(skb)->nr_frags++;
1596 } else {
1597 put_page(page_info->page);
1598 }
1599
Eric Dumazet9e903e02011-10-18 21:00:24 +00001600 skb_frag_size_add(&skb_shinfo(skb)->frags[j], curr_frag_len);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001601 skb->len += curr_frag_len;
1602 skb->data_len += curr_frag_len;
Eric Dumazetbdb28a92011-10-13 06:31:02 +00001603 skb->truesize += rx_frag_size;
Sathya Perla2e588f82011-03-11 02:49:26 +00001604 remaining -= curr_frag_len;
Ajit Khaparde205859a2010-02-09 01:34:21 +00001605 page_info->page = NULL;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001606 }
Ajit Khapardebd46cb62009-06-26 02:51:07 +00001607 BUG_ON(j > MAX_SKB_FRAGS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001608}
1609
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001610/* Process the RX completion indicated by rxcp when GRO is disabled */
Sathya Perla6384a4d2013-10-25 10:40:16 +05301611static void be_rx_compl_process(struct be_rx_obj *rxo, struct napi_struct *napi,
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001612 struct be_rx_compl_info *rxcp)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001613{
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001614 struct be_adapter *adapter = rxo->adapter;
Michał Mirosław6332c8d2011-04-07 02:43:48 +00001615 struct net_device *netdev = adapter->netdev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001616 struct sk_buff *skb;
Sathya Perla89420422010-02-17 01:35:26 +00001617
Eric Dumazetbb349bb2012-01-25 03:56:30 +00001618 skb = netdev_alloc_skb_ip_align(netdev, BE_RX_SKB_ALLOC_SIZE);
Sathya Perlaa058a632010-02-17 01:34:22 +00001619 if (unlikely(!skb)) {
Sathya Perlaac124ff2011-07-25 19:10:14 +00001620 rx_stats(rxo)->rx_drops_no_skbs++;
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001621 be_rx_compl_discard(rxo, rxcp);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001622 return;
1623 }
1624
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001625 skb_fill_rx_data(rxo, skb, rxcp);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001626
Michał Mirosław6332c8d2011-04-07 02:43:48 +00001627 if (likely((netdev->features & NETIF_F_RXCSUM) && csum_passed(rxcp)))
Ajit Khaparde728a9972009-04-13 15:41:22 -07001628 skb->ip_summed = CHECKSUM_UNNECESSARY;
Somnath Koturc6ce2f42010-10-25 01:11:58 +00001629 else
1630 skb_checksum_none_assert(skb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001631
Michał Mirosław6332c8d2011-04-07 02:43:48 +00001632 skb->protocol = eth_type_trans(skb, netdev);
Somnath Koturaaa6dae2012-05-02 03:40:49 +00001633 skb_record_rx_queue(skb, rxo - &adapter->rx_obj[0]);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001634 if (netdev->features & NETIF_F_RXHASH)
Tom Herbertd2464c82013-12-17 23:23:51 -08001635 skb_set_hash(skb, rxcp->rss_hash, PKT_HASH_TYPE_L3);
Sathya Perlac9c47142014-03-27 10:46:19 +05301636
1637 skb->encapsulation = rxcp->tunneled;
Sathya Perla6384a4d2013-10-25 10:40:16 +05301638 skb_mark_napi_id(skb, napi);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001639
Jiri Pirko343e43c2011-08-25 02:50:51 +00001640 if (rxcp->vlanf)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001641 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), rxcp->vlan_tag);
Ajit Khaparde4c5102f2011-07-12 22:10:01 -07001642
1643 netif_receive_skb(skb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001644}
1645
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001646/* Process the RX completion indicated by rxcp when GRO is enabled */
Jingoo Han4188e7d2013-08-05 18:02:02 +09001647static void be_rx_compl_process_gro(struct be_rx_obj *rxo,
1648 struct napi_struct *napi,
1649 struct be_rx_compl_info *rxcp)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001650{
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001651 struct be_adapter *adapter = rxo->adapter;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001652 struct be_rx_page_info *page_info;
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001653 struct sk_buff *skb = NULL;
Sathya Perla2e588f82011-03-11 02:49:26 +00001654 u16 remaining, curr_frag_len;
1655 u16 i, j;
Ajit Khaparde3968fa12011-02-20 11:41:53 +00001656
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001657 skb = napi_get_frags(napi);
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001658 if (!skb) {
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001659 be_rx_compl_discard(rxo, rxcp);
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001660 return;
1661 }
1662
Sathya Perla2e588f82011-03-11 02:49:26 +00001663 remaining = rxcp->pkt_size;
1664 for (i = 0, j = -1; i < rxcp->num_rcvd; i++) {
Suresh Reddy0b0ef1d2014-01-15 13:23:38 +05301665 page_info = get_rx_page_info(rxo);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001666
1667 curr_frag_len = min(remaining, rx_frag_size);
1668
Ajit Khapardebd46cb62009-06-26 02:51:07 +00001669 /* Coalesce all frags from the same physical page in one slot */
1670 if (i == 0 || page_info->page_offset == 0) {
1671 /* First frag or Fresh page */
1672 j++;
Ian Campbellb061b392011-08-29 23:18:23 +00001673 skb_frag_set_page(skb, j, page_info->page);
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001674 skb_shinfo(skb)->frags[j].page_offset =
1675 page_info->page_offset;
Eric Dumazet9e903e02011-10-18 21:00:24 +00001676 skb_frag_size_set(&skb_shinfo(skb)->frags[j], 0);
Ajit Khapardebd46cb62009-06-26 02:51:07 +00001677 } else {
1678 put_page(page_info->page);
1679 }
Eric Dumazet9e903e02011-10-18 21:00:24 +00001680 skb_frag_size_add(&skb_shinfo(skb)->frags[j], curr_frag_len);
Eric Dumazetbdb28a92011-10-13 06:31:02 +00001681 skb->truesize += rx_frag_size;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001682 remaining -= curr_frag_len;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001683 memset(page_info, 0, sizeof(*page_info));
1684 }
Ajit Khapardebd46cb62009-06-26 02:51:07 +00001685 BUG_ON(j > MAX_SKB_FRAGS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001686
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001687 skb_shinfo(skb)->nr_frags = j + 1;
Sathya Perla2e588f82011-03-11 02:49:26 +00001688 skb->len = rxcp->pkt_size;
1689 skb->data_len = rxcp->pkt_size;
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001690 skb->ip_summed = CHECKSUM_UNNECESSARY;
Somnath Koturaaa6dae2012-05-02 03:40:49 +00001691 skb_record_rx_queue(skb, rxo - &adapter->rx_obj[0]);
Ajit Khaparde4b972912011-04-06 18:07:43 +00001692 if (adapter->netdev->features & NETIF_F_RXHASH)
Tom Herbertd2464c82013-12-17 23:23:51 -08001693 skb_set_hash(skb, rxcp->rss_hash, PKT_HASH_TYPE_L3);
Sathya Perlac9c47142014-03-27 10:46:19 +05301694
1695 skb->encapsulation = rxcp->tunneled;
Sathya Perla6384a4d2013-10-25 10:40:16 +05301696 skb_mark_napi_id(skb, napi);
Ajit Khaparde5be93b92009-07-21 12:36:19 -07001697
Jiri Pirko343e43c2011-08-25 02:50:51 +00001698 if (rxcp->vlanf)
Patrick McHardy86a9bad2013-04-19 02:04:30 +00001699 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), rxcp->vlan_tag);
Ajit Khaparde4c5102f2011-07-12 22:10:01 -07001700
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001701 napi_gro_frags(napi);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001702}
1703
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001704static void be_parse_rx_compl_v1(struct be_eth_rx_compl *compl,
1705 struct be_rx_compl_info *rxcp)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001706{
Sathya Perla2e588f82011-03-11 02:49:26 +00001707 rxcp->pkt_size =
1708 AMAP_GET_BITS(struct amap_eth_rx_compl_v1, pktsize, compl);
1709 rxcp->vlanf = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, vtp, compl);
1710 rxcp->err = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, err, compl);
1711 rxcp->tcpf = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, tcpf, compl);
Padmanabh Ratnakar9ecb42f2011-03-15 14:57:09 -07001712 rxcp->udpf = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, udpf, compl);
Sathya Perla2e588f82011-03-11 02:49:26 +00001713 rxcp->ip_csum =
1714 AMAP_GET_BITS(struct amap_eth_rx_compl_v1, ipcksm, compl);
1715 rxcp->l4_csum =
1716 AMAP_GET_BITS(struct amap_eth_rx_compl_v1, l4_cksm, compl);
1717 rxcp->ipv6 =
1718 AMAP_GET_BITS(struct amap_eth_rx_compl_v1, ip_version, compl);
Sathya Perla2e588f82011-03-11 02:49:26 +00001719 rxcp->num_rcvd =
1720 AMAP_GET_BITS(struct amap_eth_rx_compl_v1, numfrags, compl);
1721 rxcp->pkt_type =
1722 AMAP_GET_BITS(struct amap_eth_rx_compl_v1, cast_enc, compl);
Ajit Khaparde4b972912011-04-06 18:07:43 +00001723 rxcp->rss_hash =
Sarveshwar Bandic2979772012-07-25 21:29:50 +00001724 AMAP_GET_BITS(struct amap_eth_rx_compl_v1, rsshash, compl);
Sathya Perla15d72182011-03-21 20:49:26 +00001725 if (rxcp->vlanf) {
Vasundhara Volamf93f1602014-02-12 16:09:25 +05301726 rxcp->qnq = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, qnq,
David S. Miller3c709f82011-05-11 14:26:15 -04001727 compl);
1728 rxcp->vlan_tag = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, vlan_tag,
1729 compl);
Sathya Perla15d72182011-03-21 20:49:26 +00001730 }
Sathya Perla12004ae2011-08-02 19:57:46 +00001731 rxcp->port = AMAP_GET_BITS(struct amap_eth_rx_compl_v1, port, compl);
Sathya Perlac9c47142014-03-27 10:46:19 +05301732 rxcp->tunneled =
1733 AMAP_GET_BITS(struct amap_eth_rx_compl_v1, tunneled, compl);
Sathya Perla2e588f82011-03-11 02:49:26 +00001734}
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001735
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001736static void be_parse_rx_compl_v0(struct be_eth_rx_compl *compl,
1737 struct be_rx_compl_info *rxcp)
Sathya Perla2e588f82011-03-11 02:49:26 +00001738{
1739 rxcp->pkt_size =
1740 AMAP_GET_BITS(struct amap_eth_rx_compl_v0, pktsize, compl);
1741 rxcp->vlanf = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, vtp, compl);
1742 rxcp->err = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, err, compl);
1743 rxcp->tcpf = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, tcpf, compl);
Padmanabh Ratnakar9ecb42f2011-03-15 14:57:09 -07001744 rxcp->udpf = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, udpf, compl);
Sathya Perla2e588f82011-03-11 02:49:26 +00001745 rxcp->ip_csum =
1746 AMAP_GET_BITS(struct amap_eth_rx_compl_v0, ipcksm, compl);
1747 rxcp->l4_csum =
1748 AMAP_GET_BITS(struct amap_eth_rx_compl_v0, l4_cksm, compl);
1749 rxcp->ipv6 =
1750 AMAP_GET_BITS(struct amap_eth_rx_compl_v0, ip_version, compl);
Sathya Perla2e588f82011-03-11 02:49:26 +00001751 rxcp->num_rcvd =
1752 AMAP_GET_BITS(struct amap_eth_rx_compl_v0, numfrags, compl);
1753 rxcp->pkt_type =
1754 AMAP_GET_BITS(struct amap_eth_rx_compl_v0, cast_enc, compl);
Ajit Khaparde4b972912011-04-06 18:07:43 +00001755 rxcp->rss_hash =
Sarveshwar Bandic2979772012-07-25 21:29:50 +00001756 AMAP_GET_BITS(struct amap_eth_rx_compl_v0, rsshash, compl);
Sathya Perla15d72182011-03-21 20:49:26 +00001757 if (rxcp->vlanf) {
Vasundhara Volamf93f1602014-02-12 16:09:25 +05301758 rxcp->qnq = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, qnq,
David S. Miller3c709f82011-05-11 14:26:15 -04001759 compl);
1760 rxcp->vlan_tag = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, vlan_tag,
1761 compl);
Sathya Perla15d72182011-03-21 20:49:26 +00001762 }
Sathya Perla12004ae2011-08-02 19:57:46 +00001763 rxcp->port = AMAP_GET_BITS(struct amap_eth_rx_compl_v0, port, compl);
Somnath Koture38b1702013-05-29 22:55:56 +00001764 rxcp->ip_frag = AMAP_GET_BITS(struct amap_eth_rx_compl_v0,
1765 ip_frag, compl);
Sathya Perla2e588f82011-03-11 02:49:26 +00001766}
1767
1768static struct be_rx_compl_info *be_rx_compl_get(struct be_rx_obj *rxo)
1769{
1770 struct be_eth_rx_compl *compl = queue_tail_node(&rxo->cq);
1771 struct be_rx_compl_info *rxcp = &rxo->rxcp;
1772 struct be_adapter *adapter = rxo->adapter;
1773
1774 /* For checking the valid bit it is Ok to use either definition as the
1775 * valid bit is at the same position in both v0 and v1 Rx compl */
1776 if (compl->dw[offsetof(struct amap_eth_rx_compl_v1, valid) / 32] == 0)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001777 return NULL;
1778
Sathya Perlaf3eb62d2010-06-29 00:11:17 +00001779 rmb();
Sathya Perla2e588f82011-03-11 02:49:26 +00001780 be_dws_le_to_cpu(compl, sizeof(*compl));
1781
1782 if (adapter->be3_native)
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001783 be_parse_rx_compl_v1(compl, rxcp);
Sathya Perla2e588f82011-03-11 02:49:26 +00001784 else
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001785 be_parse_rx_compl_v0(compl, rxcp);
Sathya Perla2e588f82011-03-11 02:49:26 +00001786
Somnath Koture38b1702013-05-29 22:55:56 +00001787 if (rxcp->ip_frag)
1788 rxcp->l4_csum = 0;
1789
Sathya Perla15d72182011-03-21 20:49:26 +00001790 if (rxcp->vlanf) {
Vasundhara Volamf93f1602014-02-12 16:09:25 +05301791 /* In QNQ modes, if qnq bit is not set, then the packet was
1792 * tagged only with the transparent outer vlan-tag and must
1793 * not be treated as a vlan packet by host
1794 */
1795 if (be_is_qnq_mode(adapter) && !rxcp->qnq)
Sathya Perla15d72182011-03-21 20:49:26 +00001796 rxcp->vlanf = 0;
Sathya Perla2e588f82011-03-11 02:49:26 +00001797
Sathya Perla15d72182011-03-21 20:49:26 +00001798 if (!lancer_chip(adapter))
David S. Miller3c709f82011-05-11 14:26:15 -04001799 rxcp->vlan_tag = swab16(rxcp->vlan_tag);
Sathya Perla2e588f82011-03-11 02:49:26 +00001800
Somnath Kotur939cf302011-08-18 21:51:49 -07001801 if (adapter->pvid == (rxcp->vlan_tag & VLAN_VID_MASK) &&
David S. Miller3c709f82011-05-11 14:26:15 -04001802 !adapter->vlan_tag[rxcp->vlan_tag])
Sathya Perla15d72182011-03-21 20:49:26 +00001803 rxcp->vlanf = 0;
1804 }
Sathya Perla2e588f82011-03-11 02:49:26 +00001805
1806 /* As the compl has been parsed, reset it; we wont touch it again */
1807 compl->dw[offsetof(struct amap_eth_rx_compl_v1, valid) / 32] = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001808
Sathya Perla3abcded2010-10-03 22:12:27 -07001809 queue_tail_inc(&rxo->cq);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001810 return rxcp;
1811}
1812
Eric Dumazet1829b082011-03-01 05:48:12 +00001813static inline struct page *be_alloc_pages(u32 size, gfp_t gfp)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001814{
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001815 u32 order = get_order(size);
Eric Dumazet1829b082011-03-01 05:48:12 +00001816
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001817 if (order > 0)
Eric Dumazet1829b082011-03-01 05:48:12 +00001818 gfp |= __GFP_COMP;
1819 return alloc_pages(gfp, order);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001820}
1821
1822/*
1823 * Allocate a page, split it to fragments of size rx_frag_size and post as
1824 * receive buffers to BE
1825 */
Eric Dumazet1829b082011-03-01 05:48:12 +00001826static void be_post_rx_frags(struct be_rx_obj *rxo, gfp_t gfp)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001827{
Sathya Perla3abcded2010-10-03 22:12:27 -07001828 struct be_adapter *adapter = rxo->adapter;
Sathya Perla26d92f92010-01-21 22:52:08 -08001829 struct be_rx_page_info *page_info = NULL, *prev_page_info = NULL;
Sathya Perla3abcded2010-10-03 22:12:27 -07001830 struct be_queue_info *rxq = &rxo->q;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001831 struct page *pagep = NULL;
Ivan Veceraba42fad2014-01-15 11:11:34 +01001832 struct device *dev = &adapter->pdev->dev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001833 struct be_eth_rx_d *rxd;
1834 u64 page_dmaaddr = 0, frag_dmaaddr;
1835 u32 posted, page_offset = 0;
1836
Sathya Perla3abcded2010-10-03 22:12:27 -07001837 page_info = &rxo->page_info_tbl[rxq->head];
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001838 for (posted = 0; posted < MAX_RX_POST && !page_info->page; posted++) {
1839 if (!pagep) {
Eric Dumazet1829b082011-03-01 05:48:12 +00001840 pagep = be_alloc_pages(adapter->big_page_size, gfp);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001841 if (unlikely(!pagep)) {
Sathya Perlaac124ff2011-07-25 19:10:14 +00001842 rx_stats(rxo)->rx_post_fail++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001843 break;
1844 }
Ivan Veceraba42fad2014-01-15 11:11:34 +01001845 page_dmaaddr = dma_map_page(dev, pagep, 0,
1846 adapter->big_page_size,
Ivan Vecera2b7bceb2011-02-02 08:05:12 +00001847 DMA_FROM_DEVICE);
Ivan Veceraba42fad2014-01-15 11:11:34 +01001848 if (dma_mapping_error(dev, page_dmaaddr)) {
1849 put_page(pagep);
1850 pagep = NULL;
1851 rx_stats(rxo)->rx_post_fail++;
1852 break;
1853 }
Sathya Perlae50287b2014-03-04 12:14:38 +05301854 page_offset = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001855 } else {
1856 get_page(pagep);
Sathya Perlae50287b2014-03-04 12:14:38 +05301857 page_offset += rx_frag_size;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001858 }
Sathya Perlae50287b2014-03-04 12:14:38 +05301859 page_info->page_offset = page_offset;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001860 page_info->page = pagep;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001861
1862 rxd = queue_head_node(rxq);
Sathya Perlae50287b2014-03-04 12:14:38 +05301863 frag_dmaaddr = page_dmaaddr + page_info->page_offset;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001864 rxd->fragpa_lo = cpu_to_le32(frag_dmaaddr & 0xFFFFFFFF);
1865 rxd->fragpa_hi = cpu_to_le32(upper_32_bits(frag_dmaaddr));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001866
1867 /* Any space left in the current big page for another frag? */
1868 if ((page_offset + rx_frag_size + rx_frag_size) >
1869 adapter->big_page_size) {
1870 pagep = NULL;
Sathya Perlae50287b2014-03-04 12:14:38 +05301871 page_info->last_frag = true;
1872 dma_unmap_addr_set(page_info, bus, page_dmaaddr);
1873 } else {
1874 dma_unmap_addr_set(page_info, bus, frag_dmaaddr);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001875 }
Sathya Perla26d92f92010-01-21 22:52:08 -08001876
1877 prev_page_info = page_info;
1878 queue_head_inc(rxq);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001879 page_info = &rxo->page_info_tbl[rxq->head];
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001880 }
Sathya Perlae50287b2014-03-04 12:14:38 +05301881
1882 /* Mark the last frag of a page when we break out of the above loop
1883 * with no more slots available in the RXQ
1884 */
1885 if (pagep) {
1886 prev_page_info->last_frag = true;
1887 dma_unmap_addr_set(prev_page_info, bus, page_dmaaddr);
1888 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001889
1890 if (posted) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001891 atomic_add(posted, &rxq->used);
Sathya Perla6384a4d2013-10-25 10:40:16 +05301892 if (rxo->rx_post_starved)
1893 rxo->rx_post_starved = false;
Sathya Perla8788fdc2009-07-27 22:52:03 +00001894 be_rxq_notify(adapter, rxq->id, posted);
Sathya Perlaea1dae12009-03-19 23:56:20 -07001895 } else if (atomic_read(&rxq->used) == 0) {
1896 /* Let be_worker replenish when memory is available */
Sathya Perla3abcded2010-10-03 22:12:27 -07001897 rxo->rx_post_starved = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001898 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001899}
1900
Sathya Perla5fb379e2009-06-18 00:02:59 +00001901static struct be_eth_tx_compl *be_tx_compl_get(struct be_queue_info *tx_cq)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001902{
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001903 struct be_eth_tx_compl *txcp = queue_tail_node(tx_cq);
1904
1905 if (txcp->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] == 0)
1906 return NULL;
1907
Sathya Perlaf3eb62d2010-06-29 00:11:17 +00001908 rmb();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001909 be_dws_le_to_cpu(txcp, sizeof(*txcp));
1910
1911 txcp->dw[offsetof(struct amap_eth_tx_compl, valid) / 32] = 0;
1912
1913 queue_tail_inc(tx_cq);
1914 return txcp;
1915}
1916
Sathya Perla3c8def92011-06-12 20:01:58 +00001917static u16 be_tx_compl_process(struct be_adapter *adapter,
1918 struct be_tx_obj *txo, u16 last_index)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001919{
Sathya Perla3c8def92011-06-12 20:01:58 +00001920 struct be_queue_info *txq = &txo->q;
Alexander Duycka73b7962009-12-02 16:48:18 +00001921 struct be_eth_wrb *wrb;
Sathya Perla3c8def92011-06-12 20:01:58 +00001922 struct sk_buff **sent_skbs = txo->sent_skb_list;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001923 struct sk_buff *sent_skb;
Sathya Perlaec43b1a2010-03-22 20:41:34 +00001924 u16 cur_index, num_wrbs = 1; /* account for hdr wrb */
1925 bool unmap_skb_hdr = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001926
Sathya Perlaec43b1a2010-03-22 20:41:34 +00001927 sent_skb = sent_skbs[txq->tail];
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001928 BUG_ON(!sent_skb);
Sathya Perlaec43b1a2010-03-22 20:41:34 +00001929 sent_skbs[txq->tail] = NULL;
1930
1931 /* skip header wrb */
Alexander Duycka73b7962009-12-02 16:48:18 +00001932 queue_tail_inc(txq);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001933
Sathya Perlaec43b1a2010-03-22 20:41:34 +00001934 do {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001935 cur_index = txq->tail;
Alexander Duycka73b7962009-12-02 16:48:18 +00001936 wrb = queue_tail_node(txq);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +00001937 unmap_tx_frag(&adapter->pdev->dev, wrb,
1938 (unmap_skb_hdr && skb_headlen(sent_skb)));
Sathya Perlaec43b1a2010-03-22 20:41:34 +00001939 unmap_skb_hdr = false;
1940
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001941 num_wrbs++;
1942 queue_tail_inc(txq);
Sathya Perlaec43b1a2010-03-22 20:41:34 +00001943 } while (cur_index != last_index);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001944
Eric W. Biedermand8ec2c02014-03-11 14:19:50 -07001945 dev_kfree_skb_any(sent_skb);
Padmanabh Ratnakar4d586b82011-05-10 05:13:57 +00001946 return num_wrbs;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001947}
1948
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001949/* Return the number of events in the event queue */
1950static inline int events_get(struct be_eq_obj *eqo)
Sathya Perla859b1e42009-08-10 03:43:51 +00001951{
1952 struct be_eq_entry *eqe;
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001953 int num = 0;
Sathya Perla859b1e42009-08-10 03:43:51 +00001954
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001955 do {
1956 eqe = queue_tail_node(&eqo->q);
1957 if (eqe->evt == 0)
1958 break;
1959
1960 rmb();
Sathya Perla859b1e42009-08-10 03:43:51 +00001961 eqe->evt = 0;
1962 num++;
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001963 queue_tail_inc(&eqo->q);
1964 } while (true);
Sathya Perla859b1e42009-08-10 03:43:51 +00001965
1966 return num;
1967}
1968
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001969/* Leaves the EQ is disarmed state */
1970static void be_eq_clean(struct be_eq_obj *eqo)
1971{
1972 int num = events_get(eqo);
1973
1974 be_eq_notify(eqo->adapter, eqo->q.id, false, true, num);
1975}
1976
1977static void be_rx_cq_clean(struct be_rx_obj *rxo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001978{
1979 struct be_rx_page_info *page_info;
Sathya Perla3abcded2010-10-03 22:12:27 -07001980 struct be_queue_info *rxq = &rxo->q;
1981 struct be_queue_info *rx_cq = &rxo->cq;
Sathya Perla2e588f82011-03-11 02:49:26 +00001982 struct be_rx_compl_info *rxcp;
Sathya Perlad23e9462012-12-17 19:38:51 +00001983 struct be_adapter *adapter = rxo->adapter;
1984 int flush_wait = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001985
Sathya Perlad23e9462012-12-17 19:38:51 +00001986 /* Consume pending rx completions.
1987 * Wait for the flush completion (identified by zero num_rcvd)
1988 * to arrive. Notify CQ even when there are no more CQ entries
1989 * for HW to flush partially coalesced CQ entries.
1990 * In Lancer, there is no need to wait for flush compl.
1991 */
1992 for (;;) {
1993 rxcp = be_rx_compl_get(rxo);
1994 if (rxcp == NULL) {
1995 if (lancer_chip(adapter))
1996 break;
1997
1998 if (flush_wait++ > 10 || be_hw_error(adapter)) {
1999 dev_warn(&adapter->pdev->dev,
2000 "did not receive flush compl\n");
2001 break;
2002 }
2003 be_cq_notify(adapter, rx_cq->id, true, 0);
2004 mdelay(1);
2005 } else {
2006 be_rx_compl_discard(rxo, rxcp);
Sathya Perla3f5dffe2013-05-08 02:05:49 +00002007 be_cq_notify(adapter, rx_cq->id, false, 1);
Sathya Perlad23e9462012-12-17 19:38:51 +00002008 if (rxcp->num_rcvd == 0)
2009 break;
2010 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002011 }
2012
Sathya Perlad23e9462012-12-17 19:38:51 +00002013 /* After cleanup, leave the CQ in unarmed state */
2014 be_cq_notify(adapter, rx_cq->id, false, 0);
2015
2016 /* Then free posted rx buffers that were not used */
Suresh Reddy0b0ef1d2014-01-15 13:23:38 +05302017 while (atomic_read(&rxq->used) > 0) {
2018 page_info = get_rx_page_info(rxo);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002019 put_page(page_info->page);
2020 memset(page_info, 0, sizeof(*page_info));
2021 }
2022 BUG_ON(atomic_read(&rxq->used));
Sathya Perla482c9e72011-06-29 23:33:17 +00002023 rxq->tail = rxq->head = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002024}
2025
Sathya Perla0ae57bb2012-02-23 18:50:14 +00002026static void be_tx_compl_clean(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002027{
Sathya Perla0ae57bb2012-02-23 18:50:14 +00002028 struct be_tx_obj *txo;
2029 struct be_queue_info *txq;
Sathya Perlaa8e91792009-08-10 03:42:43 +00002030 struct be_eth_tx_compl *txcp;
Padmanabh Ratnakar4d586b82011-05-10 05:13:57 +00002031 u16 end_idx, cmpl = 0, timeo = 0, num_wrbs = 0;
Sathya Perlab03388d2010-02-18 00:37:17 +00002032 struct sk_buff *sent_skb;
2033 bool dummy_wrb;
Sathya Perla0ae57bb2012-02-23 18:50:14 +00002034 int i, pending_txqs;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002035
Sathya Perlaa8e91792009-08-10 03:42:43 +00002036 /* Wait for a max of 200ms for all the tx-completions to arrive. */
2037 do {
Sathya Perla0ae57bb2012-02-23 18:50:14 +00002038 pending_txqs = adapter->num_tx_qs;
2039
2040 for_all_tx_queues(adapter, txo, i) {
2041 txq = &txo->q;
2042 while ((txcp = be_tx_compl_get(&txo->cq))) {
2043 end_idx =
2044 AMAP_GET_BITS(struct amap_eth_tx_compl,
2045 wrb_index, txcp);
2046 num_wrbs += be_tx_compl_process(adapter, txo,
2047 end_idx);
2048 cmpl++;
2049 }
2050 if (cmpl) {
2051 be_cq_notify(adapter, txo->cq.id, false, cmpl);
2052 atomic_sub(num_wrbs, &txq->used);
2053 cmpl = 0;
2054 num_wrbs = 0;
2055 }
2056 if (atomic_read(&txq->used) == 0)
2057 pending_txqs--;
Sathya Perlaa8e91792009-08-10 03:42:43 +00002058 }
2059
Sathya Perla0ae57bb2012-02-23 18:50:14 +00002060 if (pending_txqs == 0 || ++timeo > 200)
Sathya Perlaa8e91792009-08-10 03:42:43 +00002061 break;
2062
2063 mdelay(1);
2064 } while (true);
2065
Sathya Perla0ae57bb2012-02-23 18:50:14 +00002066 for_all_tx_queues(adapter, txo, i) {
2067 txq = &txo->q;
2068 if (atomic_read(&txq->used))
2069 dev_err(&adapter->pdev->dev, "%d pending tx-compls\n",
2070 atomic_read(&txq->used));
Sathya Perlab03388d2010-02-18 00:37:17 +00002071
Sathya Perla0ae57bb2012-02-23 18:50:14 +00002072 /* free posted tx for which compls will never arrive */
2073 while (atomic_read(&txq->used)) {
2074 sent_skb = txo->sent_skb_list[txq->tail];
2075 end_idx = txq->tail;
2076 num_wrbs = wrb_cnt_for_skb(adapter, sent_skb,
2077 &dummy_wrb);
2078 index_adv(&end_idx, num_wrbs - 1, txq->len);
2079 num_wrbs = be_tx_compl_process(adapter, txo, end_idx);
2080 atomic_sub(num_wrbs, &txq->used);
2081 }
Sathya Perlab03388d2010-02-18 00:37:17 +00002082 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002083}
2084
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002085static void be_evt_queues_destroy(struct be_adapter *adapter)
2086{
2087 struct be_eq_obj *eqo;
2088 int i;
2089
2090 for_all_evt_queues(adapter, eqo, i) {
Padmanabh Ratnakar19d59aa2012-07-12 03:57:21 +00002091 if (eqo->q.created) {
2092 be_eq_clean(eqo);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002093 be_cmd_q_destroy(adapter, &eqo->q, QTYPE_EQ);
Sathya Perla6384a4d2013-10-25 10:40:16 +05302094 napi_hash_del(&eqo->napi);
Sathya Perla68d7bdc2013-08-27 16:57:35 +05302095 netif_napi_del(&eqo->napi);
Padmanabh Ratnakar19d59aa2012-07-12 03:57:21 +00002096 }
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002097 be_queue_free(adapter, &eqo->q);
2098 }
2099}
2100
2101static int be_evt_queues_create(struct be_adapter *adapter)
2102{
2103 struct be_queue_info *eq;
2104 struct be_eq_obj *eqo;
Sathya Perla2632baf2013-10-01 16:00:00 +05302105 struct be_aic_obj *aic;
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002106 int i, rc;
2107
Sathya Perla92bf14a2013-08-27 16:57:32 +05302108 adapter->num_evt_qs = min_t(u16, num_irqs(adapter),
2109 adapter->cfg_num_qs);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002110
2111 for_all_evt_queues(adapter, eqo, i) {
Sathya Perla68d7bdc2013-08-27 16:57:35 +05302112 netif_napi_add(adapter->netdev, &eqo->napi, be_poll,
2113 BE_NAPI_WEIGHT);
Sathya Perla6384a4d2013-10-25 10:40:16 +05302114 napi_hash_add(&eqo->napi);
Sathya Perla2632baf2013-10-01 16:00:00 +05302115 aic = &adapter->aic_obj[i];
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002116 eqo->adapter = adapter;
2117 eqo->tx_budget = BE_TX_BUDGET;
2118 eqo->idx = i;
Sathya Perla2632baf2013-10-01 16:00:00 +05302119 aic->max_eqd = BE_MAX_EQD;
2120 aic->enable = true;
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002121
2122 eq = &eqo->q;
2123 rc = be_queue_alloc(adapter, eq, EVNT_Q_LEN,
2124 sizeof(struct be_eq_entry));
2125 if (rc)
2126 return rc;
2127
Sathya Perlaf2f781a2013-08-27 16:57:30 +05302128 rc = be_cmd_eq_create(adapter, eqo);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002129 if (rc)
2130 return rc;
2131 }
Sathya Perla1cfafab2012-02-23 18:50:15 +00002132 return 0;
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002133}
2134
Sathya Perla5fb379e2009-06-18 00:02:59 +00002135static void be_mcc_queues_destroy(struct be_adapter *adapter)
2136{
2137 struct be_queue_info *q;
Sathya Perla5fb379e2009-06-18 00:02:59 +00002138
Sathya Perla8788fdc2009-07-27 22:52:03 +00002139 q = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +00002140 if (q->created)
Sathya Perla8788fdc2009-07-27 22:52:03 +00002141 be_cmd_q_destroy(adapter, q, QTYPE_MCCQ);
Sathya Perla5fb379e2009-06-18 00:02:59 +00002142 be_queue_free(adapter, q);
2143
Sathya Perla8788fdc2009-07-27 22:52:03 +00002144 q = &adapter->mcc_obj.cq;
Sathya Perla5fb379e2009-06-18 00:02:59 +00002145 if (q->created)
Sathya Perla8788fdc2009-07-27 22:52:03 +00002146 be_cmd_q_destroy(adapter, q, QTYPE_CQ);
Sathya Perla5fb379e2009-06-18 00:02:59 +00002147 be_queue_free(adapter, q);
2148}
2149
2150/* Must be called only after TX qs are created as MCC shares TX EQ */
2151static int be_mcc_queues_create(struct be_adapter *adapter)
2152{
2153 struct be_queue_info *q, *cq;
Sathya Perla5fb379e2009-06-18 00:02:59 +00002154
Sathya Perla8788fdc2009-07-27 22:52:03 +00002155 cq = &adapter->mcc_obj.cq;
Sathya Perla5fb379e2009-06-18 00:02:59 +00002156 if (be_queue_alloc(adapter, cq, MCC_CQ_LEN,
Sathya Perlaefd2e402009-07-27 22:53:10 +00002157 sizeof(struct be_mcc_compl)))
Sathya Perla5fb379e2009-06-18 00:02:59 +00002158 goto err;
2159
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002160 /* Use the default EQ for MCC completions */
2161 if (be_cmd_cq_create(adapter, cq, &mcc_eqo(adapter)->q, true, 0))
Sathya Perla5fb379e2009-06-18 00:02:59 +00002162 goto mcc_cq_free;
2163
Sathya Perla8788fdc2009-07-27 22:52:03 +00002164 q = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +00002165 if (be_queue_alloc(adapter, q, MCC_Q_LEN, sizeof(struct be_mcc_wrb)))
2166 goto mcc_cq_destroy;
2167
Sathya Perla8788fdc2009-07-27 22:52:03 +00002168 if (be_cmd_mccq_create(adapter, q, cq))
Sathya Perla5fb379e2009-06-18 00:02:59 +00002169 goto mcc_q_free;
2170
2171 return 0;
2172
2173mcc_q_free:
2174 be_queue_free(adapter, q);
2175mcc_cq_destroy:
Sathya Perla8788fdc2009-07-27 22:52:03 +00002176 be_cmd_q_destroy(adapter, cq, QTYPE_CQ);
Sathya Perla5fb379e2009-06-18 00:02:59 +00002177mcc_cq_free:
2178 be_queue_free(adapter, cq);
2179err:
2180 return -1;
2181}
2182
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002183static void be_tx_queues_destroy(struct be_adapter *adapter)
2184{
2185 struct be_queue_info *q;
Sathya Perla3c8def92011-06-12 20:01:58 +00002186 struct be_tx_obj *txo;
2187 u8 i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002188
Sathya Perla3c8def92011-06-12 20:01:58 +00002189 for_all_tx_queues(adapter, txo, i) {
2190 q = &txo->q;
2191 if (q->created)
2192 be_cmd_q_destroy(adapter, q, QTYPE_TXQ);
2193 be_queue_free(adapter, q);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002194
Sathya Perla3c8def92011-06-12 20:01:58 +00002195 q = &txo->cq;
2196 if (q->created)
2197 be_cmd_q_destroy(adapter, q, QTYPE_CQ);
2198 be_queue_free(adapter, q);
2199 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002200}
2201
Sathya Perla77071332013-08-27 16:57:34 +05302202static int be_tx_qs_create(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002203{
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002204 struct be_queue_info *cq, *eq;
Sathya Perla3c8def92011-06-12 20:01:58 +00002205 struct be_tx_obj *txo;
Sathya Perla92bf14a2013-08-27 16:57:32 +05302206 int status, i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002207
Sathya Perla92bf14a2013-08-27 16:57:32 +05302208 adapter->num_tx_qs = min(adapter->num_evt_qs, be_max_txqs(adapter));
Sathya Perladafc0fe2011-10-24 02:45:02 +00002209
Sathya Perla3c8def92011-06-12 20:01:58 +00002210 for_all_tx_queues(adapter, txo, i) {
2211 cq = &txo->cq;
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002212 status = be_queue_alloc(adapter, cq, TX_CQ_LEN,
2213 sizeof(struct be_eth_tx_compl));
2214 if (status)
2215 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002216
John Stultz827da442013-10-07 15:51:58 -07002217 u64_stats_init(&txo->stats.sync);
2218 u64_stats_init(&txo->stats.sync_compl);
2219
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002220 /* If num_evt_qs is less than num_tx_qs, then more than
2221 * one txq share an eq
2222 */
2223 eq = &adapter->eq_obj[i % adapter->num_evt_qs].q;
2224 status = be_cmd_cq_create(adapter, cq, eq, false, 3);
2225 if (status)
2226 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002227
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002228 status = be_queue_alloc(adapter, &txo->q, TX_Q_LEN,
2229 sizeof(struct be_eth_wrb));
2230 if (status)
2231 return status;
2232
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00002233 status = be_cmd_txq_create(adapter, txo);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002234 if (status)
2235 return status;
2236 }
2237
Sathya Perlad3791422012-09-28 04:39:44 +00002238 dev_info(&adapter->pdev->dev, "created %d TX queue(s)\n",
2239 adapter->num_tx_qs);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002240 return 0;
2241}
2242
2243static void be_rx_cqs_destroy(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002244{
2245 struct be_queue_info *q;
Sathya Perla3abcded2010-10-03 22:12:27 -07002246 struct be_rx_obj *rxo;
2247 int i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002248
Sathya Perla3abcded2010-10-03 22:12:27 -07002249 for_all_rx_queues(adapter, rxo, i) {
Sathya Perla3abcded2010-10-03 22:12:27 -07002250 q = &rxo->cq;
2251 if (q->created)
2252 be_cmd_q_destroy(adapter, q, QTYPE_CQ);
2253 be_queue_free(adapter, q);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002254 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002255}
2256
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002257static int be_rx_cqs_create(struct be_adapter *adapter)
Sathya Perlaac6a0c42011-03-21 20:49:25 +00002258{
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002259 struct be_queue_info *eq, *cq;
Sathya Perla3abcded2010-10-03 22:12:27 -07002260 struct be_rx_obj *rxo;
2261 int rc, i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002262
Sathya Perla92bf14a2013-08-27 16:57:32 +05302263 /* We can create as many RSS rings as there are EQs. */
2264 adapter->num_rx_qs = adapter->num_evt_qs;
2265
2266 /* We'll use RSS only if atleast 2 RSS rings are supported.
2267 * When RSS is used, we'll need a default RXQ for non-IP traffic.
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002268 */
Sathya Perla92bf14a2013-08-27 16:57:32 +05302269 if (adapter->num_rx_qs > 1)
2270 adapter->num_rx_qs++;
2271
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002272 adapter->big_page_size = (1 << get_order(rx_frag_size)) * PAGE_SIZE;
Sathya Perla3abcded2010-10-03 22:12:27 -07002273 for_all_rx_queues(adapter, rxo, i) {
2274 rxo->adapter = adapter;
Sathya Perla3abcded2010-10-03 22:12:27 -07002275 cq = &rxo->cq;
2276 rc = be_queue_alloc(adapter, cq, RX_CQ_LEN,
2277 sizeof(struct be_eth_rx_compl));
2278 if (rc)
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002279 return rc;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002280
John Stultz827da442013-10-07 15:51:58 -07002281 u64_stats_init(&rxo->stats.sync);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002282 eq = &adapter->eq_obj[i % adapter->num_evt_qs].q;
2283 rc = be_cmd_cq_create(adapter, cq, eq, false, 3);
Sathya Perla3abcded2010-10-03 22:12:27 -07002284 if (rc)
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002285 return rc;
Sathya Perla3abcded2010-10-03 22:12:27 -07002286 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002287
Sathya Perlad3791422012-09-28 04:39:44 +00002288 dev_info(&adapter->pdev->dev,
2289 "created %d RSS queue(s) and 1 default RX queue\n",
2290 adapter->num_rx_qs - 1);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002291 return 0;
Sathya Perlab628bde2009-08-17 00:58:26 +00002292}
2293
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002294static irqreturn_t be_intx(int irq, void *dev)
2295{
Sathya Perlae49cc342012-11-27 19:50:02 +00002296 struct be_eq_obj *eqo = dev;
2297 struct be_adapter *adapter = eqo->adapter;
2298 int num_evts = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002299
Sathya Perlad0b9cec2013-01-11 22:47:02 +00002300 /* IRQ is not expected when NAPI is scheduled as the EQ
2301 * will not be armed.
2302 * But, this can happen on Lancer INTx where it takes
2303 * a while to de-assert INTx or in BE2 where occasionaly
2304 * an interrupt may be raised even when EQ is unarmed.
2305 * If NAPI is already scheduled, then counting & notifying
2306 * events will orphan them.
Sathya Perlae49cc342012-11-27 19:50:02 +00002307 */
Sathya Perlad0b9cec2013-01-11 22:47:02 +00002308 if (napi_schedule_prep(&eqo->napi)) {
Sathya Perlae49cc342012-11-27 19:50:02 +00002309 num_evts = events_get(eqo);
Sathya Perlad0b9cec2013-01-11 22:47:02 +00002310 __napi_schedule(&eqo->napi);
2311 if (num_evts)
2312 eqo->spurious_intr = 0;
2313 }
Sathya Perlae49cc342012-11-27 19:50:02 +00002314 be_eq_notify(adapter, eqo->q.id, false, true, num_evts);
Sathya Perlad0b9cec2013-01-11 22:47:02 +00002315
2316 /* Return IRQ_HANDLED only for the the first spurious intr
2317 * after a valid intr to stop the kernel from branding
2318 * this irq as a bad one!
2319 */
2320 if (num_evts || eqo->spurious_intr++ == 0)
2321 return IRQ_HANDLED;
2322 else
2323 return IRQ_NONE;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002324}
2325
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002326static irqreturn_t be_msix(int irq, void *dev)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002327{
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002328 struct be_eq_obj *eqo = dev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002329
Sathya Perla0b545a62012-11-23 00:27:18 +00002330 be_eq_notify(eqo->adapter, eqo->q.id, false, true, 0);
2331 napi_schedule(&eqo->napi);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002332 return IRQ_HANDLED;
2333}
2334
Sathya Perla2e588f82011-03-11 02:49:26 +00002335static inline bool do_gro(struct be_rx_compl_info *rxcp)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002336{
Somnath Koture38b1702013-05-29 22:55:56 +00002337 return (rxcp->tcpf && !rxcp->err && rxcp->l4_csum) ? true : false;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002338}
2339
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002340static int be_process_rx(struct be_rx_obj *rxo, struct napi_struct *napi,
Sathya Perla6384a4d2013-10-25 10:40:16 +05302341 int budget, int polling)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002342{
Sathya Perla3abcded2010-10-03 22:12:27 -07002343 struct be_adapter *adapter = rxo->adapter;
2344 struct be_queue_info *rx_cq = &rxo->cq;
Sathya Perla2e588f82011-03-11 02:49:26 +00002345 struct be_rx_compl_info *rxcp;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002346 u32 work_done;
2347
2348 for (work_done = 0; work_done < budget; work_done++) {
Sathya Perla3abcded2010-10-03 22:12:27 -07002349 rxcp = be_rx_compl_get(rxo);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002350 if (!rxcp)
2351 break;
2352
Sathya Perla12004ae2011-08-02 19:57:46 +00002353 /* Is it a flush compl that has no data */
2354 if (unlikely(rxcp->num_rcvd == 0))
2355 goto loop_continue;
2356
2357 /* Discard compl with partial DMA Lancer B0 */
2358 if (unlikely(!rxcp->pkt_size)) {
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002359 be_rx_compl_discard(rxo, rxcp);
Sathya Perla12004ae2011-08-02 19:57:46 +00002360 goto loop_continue;
Sathya Perla64642812010-12-01 01:04:17 +00002361 }
Padmanabh Ratnakar009dd872011-05-10 05:12:17 +00002362
Sathya Perla12004ae2011-08-02 19:57:46 +00002363 /* On BE drop pkts that arrive due to imperfect filtering in
2364 * promiscuous mode on some skews
2365 */
2366 if (unlikely(rxcp->port != adapter->port_num &&
2367 !lancer_chip(adapter))) {
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002368 be_rx_compl_discard(rxo, rxcp);
Sathya Perla12004ae2011-08-02 19:57:46 +00002369 goto loop_continue;
2370 }
2371
Sathya Perla6384a4d2013-10-25 10:40:16 +05302372 /* Don't do gro when we're busy_polling */
2373 if (do_gro(rxcp) && polling != BUSY_POLLING)
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002374 be_rx_compl_process_gro(rxo, napi, rxcp);
Sathya Perla12004ae2011-08-02 19:57:46 +00002375 else
Sathya Perla6384a4d2013-10-25 10:40:16 +05302376 be_rx_compl_process(rxo, napi, rxcp);
2377
Sathya Perla12004ae2011-08-02 19:57:46 +00002378loop_continue:
Sathya Perla2e588f82011-03-11 02:49:26 +00002379 be_rx_stats_update(rxo, rxcp);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002380 }
2381
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002382 if (work_done) {
2383 be_cq_notify(adapter, rx_cq->id, true, work_done);
Padmanabh Ratnakar9372cac2011-11-03 01:49:55 +00002384
Sathya Perla6384a4d2013-10-25 10:40:16 +05302385 /* When an rx-obj gets into post_starved state, just
2386 * let be_worker do the posting.
2387 */
2388 if (atomic_read(&rxo->q.used) < RX_FRAGS_REFILL_WM &&
2389 !rxo->rx_post_starved)
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002390 be_post_rx_frags(rxo, GFP_ATOMIC);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002391 }
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002392
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002393 return work_done;
2394}
2395
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002396static bool be_process_tx(struct be_adapter *adapter, struct be_tx_obj *txo,
2397 int budget, int idx)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002398{
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002399 struct be_eth_tx_compl *txcp;
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002400 int num_wrbs = 0, work_done;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002401
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002402 for (work_done = 0; work_done < budget; work_done++) {
2403 txcp = be_tx_compl_get(&txo->cq);
2404 if (!txcp)
2405 break;
2406 num_wrbs += be_tx_compl_process(adapter, txo,
Sathya Perla3c8def92011-06-12 20:01:58 +00002407 AMAP_GET_BITS(struct amap_eth_tx_compl,
2408 wrb_index, txcp));
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002409 }
2410
2411 if (work_done) {
2412 be_cq_notify(adapter, txo->cq.id, true, work_done);
2413 atomic_sub(num_wrbs, &txo->q.used);
2414
2415 /* As Tx wrbs have been freed up, wake up netdev queue
2416 * if it was stopped due to lack of tx wrbs. */
2417 if (__netif_subqueue_stopped(adapter->netdev, idx) &&
2418 atomic_read(&txo->q.used) < txo->q.len / 2) {
2419 netif_wake_subqueue(adapter->netdev, idx);
Sathya Perla3c8def92011-06-12 20:01:58 +00002420 }
Sathya Perla3c8def92011-06-12 20:01:58 +00002421
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002422 u64_stats_update_begin(&tx_stats(txo)->sync_compl);
2423 tx_stats(txo)->tx_compl += work_done;
2424 u64_stats_update_end(&tx_stats(txo)->sync_compl);
2425 }
2426 return (work_done < budget); /* Done */
2427}
Sathya Perla3c8def92011-06-12 20:01:58 +00002428
Sathya Perla68d7bdc2013-08-27 16:57:35 +05302429int be_poll(struct napi_struct *napi, int budget)
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002430{
2431 struct be_eq_obj *eqo = container_of(napi, struct be_eq_obj, napi);
2432 struct be_adapter *adapter = eqo->adapter;
Sathya Perla0b545a62012-11-23 00:27:18 +00002433 int max_work = 0, work, i, num_evts;
Sathya Perla6384a4d2013-10-25 10:40:16 +05302434 struct be_rx_obj *rxo;
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002435 bool tx_done;
Sathya Perla3c8def92011-06-12 20:01:58 +00002436
Sathya Perla0b545a62012-11-23 00:27:18 +00002437 num_evts = events_get(eqo);
2438
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002439 /* Process all TXQs serviced by this EQ */
2440 for (i = eqo->idx; i < adapter->num_tx_qs; i += adapter->num_evt_qs) {
2441 tx_done = be_process_tx(adapter, &adapter->tx_obj[i],
2442 eqo->tx_budget, i);
2443 if (!tx_done)
2444 max_work = budget;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002445 }
2446
Sathya Perla6384a4d2013-10-25 10:40:16 +05302447 if (be_lock_napi(eqo)) {
2448 /* This loop will iterate twice for EQ0 in which
2449 * completions of the last RXQ (default one) are also processed
2450 * For other EQs the loop iterates only once
2451 */
2452 for_all_rx_queues_on_eq(adapter, eqo, rxo, i) {
2453 work = be_process_rx(rxo, napi, budget, NAPI_POLLING);
2454 max_work = max(work, max_work);
2455 }
2456 be_unlock_napi(eqo);
2457 } else {
2458 max_work = budget;
Sathya Perlaf31e50a2010-03-02 03:56:39 -08002459 }
2460
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002461 if (is_mcc_eqo(eqo))
2462 be_process_mcc(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +00002463
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002464 if (max_work < budget) {
2465 napi_complete(napi);
Sathya Perla0b545a62012-11-23 00:27:18 +00002466 be_eq_notify(adapter, eqo->q.id, true, false, num_evts);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002467 } else {
2468 /* As we'll continue in polling mode, count and clear events */
Sathya Perla0b545a62012-11-23 00:27:18 +00002469 be_eq_notify(adapter, eqo->q.id, false, false, num_evts);
Padmanabh Ratnakar93c86702011-12-19 01:53:35 +00002470 }
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002471 return max_work;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002472}
2473
Sathya Perla6384a4d2013-10-25 10:40:16 +05302474#ifdef CONFIG_NET_RX_BUSY_POLL
2475static int be_busy_poll(struct napi_struct *napi)
2476{
2477 struct be_eq_obj *eqo = container_of(napi, struct be_eq_obj, napi);
2478 struct be_adapter *adapter = eqo->adapter;
2479 struct be_rx_obj *rxo;
2480 int i, work = 0;
2481
2482 if (!be_lock_busy_poll(eqo))
2483 return LL_FLUSH_BUSY;
2484
2485 for_all_rx_queues_on_eq(adapter, eqo, rxo, i) {
2486 work = be_process_rx(rxo, napi, 4, BUSY_POLLING);
2487 if (work)
2488 break;
2489 }
2490
2491 be_unlock_busy_poll(eqo);
2492 return work;
2493}
2494#endif
2495
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002496void be_detect_error(struct be_adapter *adapter)
Ajit Khaparde7c185272010-07-29 06:16:33 +00002497{
Padmanabh Ratnakare1cfb672011-11-03 01:50:08 +00002498 u32 ue_lo = 0, ue_hi = 0, ue_lo_mask = 0, ue_hi_mask = 0;
2499 u32 sliport_status = 0, sliport_err1 = 0, sliport_err2 = 0;
Ajit Khaparde7c185272010-07-29 06:16:33 +00002500 u32 i;
Somnath Kotureb0eecc2014-02-12 16:07:54 +05302501 bool error_detected = false;
2502 struct device *dev = &adapter->pdev->dev;
2503 struct net_device *netdev = adapter->netdev;
Ajit Khaparde7c185272010-07-29 06:16:33 +00002504
Sathya Perlad23e9462012-12-17 19:38:51 +00002505 if (be_hw_error(adapter))
Sathya Perla72f02482011-11-10 19:17:58 +00002506 return;
2507
Padmanabh Ratnakare1cfb672011-11-03 01:50:08 +00002508 if (lancer_chip(adapter)) {
2509 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
2510 if (sliport_status & SLIPORT_STATUS_ERR_MASK) {
2511 sliport_err1 = ioread32(adapter->db +
2512 SLIPORT_ERROR1_OFFSET);
2513 sliport_err2 = ioread32(adapter->db +
2514 SLIPORT_ERROR2_OFFSET);
Somnath Kotureb0eecc2014-02-12 16:07:54 +05302515 adapter->hw_error = true;
2516 /* Do not log error messages if its a FW reset */
2517 if (sliport_err1 == SLIPORT_ERROR_FW_RESET1 &&
2518 sliport_err2 == SLIPORT_ERROR_FW_RESET2) {
2519 dev_info(dev, "Firmware update in progress\n");
2520 } else {
2521 error_detected = true;
2522 dev_err(dev, "Error detected in the card\n");
2523 dev_err(dev, "ERR: sliport status 0x%x\n",
2524 sliport_status);
2525 dev_err(dev, "ERR: sliport error1 0x%x\n",
2526 sliport_err1);
2527 dev_err(dev, "ERR: sliport error2 0x%x\n",
2528 sliport_err2);
2529 }
Padmanabh Ratnakare1cfb672011-11-03 01:50:08 +00002530 }
2531 } else {
2532 pci_read_config_dword(adapter->pdev,
2533 PCICFG_UE_STATUS_LOW, &ue_lo);
2534 pci_read_config_dword(adapter->pdev,
2535 PCICFG_UE_STATUS_HIGH, &ue_hi);
2536 pci_read_config_dword(adapter->pdev,
2537 PCICFG_UE_STATUS_LOW_MASK, &ue_lo_mask);
2538 pci_read_config_dword(adapter->pdev,
2539 PCICFG_UE_STATUS_HI_MASK, &ue_hi_mask);
Ajit Khaparde7c185272010-07-29 06:16:33 +00002540
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002541 ue_lo = (ue_lo & ~ue_lo_mask);
2542 ue_hi = (ue_hi & ~ue_hi_mask);
Ajit Khaparde7c185272010-07-29 06:16:33 +00002543
Somnath Kotureb0eecc2014-02-12 16:07:54 +05302544 /* On certain platforms BE hardware can indicate spurious UEs.
2545 * Allow HW to stop working completely in case of a real UE.
2546 * Hence not setting the hw_error for UE detection.
2547 */
2548
2549 if (ue_lo || ue_hi) {
2550 error_detected = true;
2551 dev_err(dev,
2552 "Unrecoverable Error detected in the adapter");
2553 dev_err(dev, "Please reboot server to recover");
2554 if (skyhawk_chip(adapter))
2555 adapter->hw_error = true;
2556 for (i = 0; ue_lo; ue_lo >>= 1, i++) {
2557 if (ue_lo & 1)
2558 dev_err(dev, "UE: %s bit set\n",
2559 ue_status_low_desc[i]);
2560 }
2561 for (i = 0; ue_hi; ue_hi >>= 1, i++) {
2562 if (ue_hi & 1)
2563 dev_err(dev, "UE: %s bit set\n",
2564 ue_status_hi_desc[i]);
2565 }
Somnath Kotur4bebb562013-12-05 12:07:55 +05302566 }
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002567 }
Somnath Kotureb0eecc2014-02-12 16:07:54 +05302568 if (error_detected)
2569 netif_carrier_off(netdev);
Ajit Khaparde7c185272010-07-29 06:16:33 +00002570}
2571
Sathya Perla8d56ff12009-11-22 22:02:26 +00002572static void be_msix_disable(struct be_adapter *adapter)
2573{
Sathya Perlaac6a0c42011-03-21 20:49:25 +00002574 if (msix_enabled(adapter)) {
Sathya Perla8d56ff12009-11-22 22:02:26 +00002575 pci_disable_msix(adapter->pdev);
Sathya Perlaac6a0c42011-03-21 20:49:25 +00002576 adapter->num_msix_vec = 0;
Sathya Perla68d7bdc2013-08-27 16:57:35 +05302577 adapter->num_msix_roce_vec = 0;
Sathya Perla3abcded2010-10-03 22:12:27 -07002578 }
2579}
2580
Somnath Koturc2bba3d2013-05-02 03:37:08 +00002581static int be_msix_enable(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002582{
Alexander Gordeev7dc4c062014-02-18 11:11:40 +01002583 int i, num_vec;
Sathya Perlad3791422012-09-28 04:39:44 +00002584 struct device *dev = &adapter->pdev->dev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002585
Sathya Perla92bf14a2013-08-27 16:57:32 +05302586 /* If RoCE is supported, program the max number of NIC vectors that
2587 * may be configured via set-channels, along with vectors needed for
2588 * RoCe. Else, just program the number we'll use initially.
2589 */
2590 if (be_roce_supported(adapter))
2591 num_vec = min_t(int, 2 * be_max_eqs(adapter),
2592 2 * num_online_cpus());
2593 else
2594 num_vec = adapter->cfg_num_qs;
Sathya Perla3abcded2010-10-03 22:12:27 -07002595
Sathya Perlaac6a0c42011-03-21 20:49:25 +00002596 for (i = 0; i < num_vec; i++)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002597 adapter->msix_entries[i].entry = i;
2598
Alexander Gordeev7dc4c062014-02-18 11:11:40 +01002599 num_vec = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
2600 MIN_MSIX_VECTORS, num_vec);
2601 if (num_vec < 0)
2602 goto fail;
Sathya Perlad3791422012-09-28 04:39:44 +00002603
Sathya Perla92bf14a2013-08-27 16:57:32 +05302604 if (be_roce_supported(adapter) && num_vec > MIN_MSIX_VECTORS) {
2605 adapter->num_msix_roce_vec = num_vec / 2;
2606 dev_info(dev, "enabled %d MSI-x vector(s) for RoCE\n",
2607 adapter->num_msix_roce_vec);
2608 }
2609
2610 adapter->num_msix_vec = num_vec - adapter->num_msix_roce_vec;
2611
2612 dev_info(dev, "enabled %d MSI-x vector(s) for NIC\n",
2613 adapter->num_msix_vec);
Somnath Koturc2bba3d2013-05-02 03:37:08 +00002614 return 0;
Alexander Gordeev7dc4c062014-02-18 11:11:40 +01002615
2616fail:
2617 dev_warn(dev, "MSIx enable failed\n");
2618
2619 /* INTx is not supported in VFs, so fail probe if enable_msix fails */
2620 if (!be_physfn(adapter))
2621 return num_vec;
2622 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002623}
2624
Sathya Perlafe6d2a32010-11-21 23:25:50 +00002625static inline int be_msix_vec_get(struct be_adapter *adapter,
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002626 struct be_eq_obj *eqo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002627{
Sathya Perlaf2f781a2013-08-27 16:57:30 +05302628 return adapter->msix_entries[eqo->msix_idx].vector;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002629}
2630
2631static int be_msix_register(struct be_adapter *adapter)
2632{
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002633 struct net_device *netdev = adapter->netdev;
2634 struct be_eq_obj *eqo;
2635 int status, i, vec;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002636
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002637 for_all_evt_queues(adapter, eqo, i) {
2638 sprintf(eqo->desc, "%s-q%d", netdev->name, i);
2639 vec = be_msix_vec_get(adapter, eqo);
2640 status = request_irq(vec, be_msix, 0, eqo->desc, eqo);
Sathya Perla3abcded2010-10-03 22:12:27 -07002641 if (status)
2642 goto err_msix;
2643 }
Sathya Perlab628bde2009-08-17 00:58:26 +00002644
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002645 return 0;
Sathya Perla3abcded2010-10-03 22:12:27 -07002646err_msix:
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002647 for (i--, eqo = &adapter->eq_obj[i]; i >= 0; i--, eqo--)
2648 free_irq(be_msix_vec_get(adapter, eqo), eqo);
2649 dev_warn(&adapter->pdev->dev, "MSIX Request IRQ failed - err %d\n",
2650 status);
Sathya Perlaac6a0c42011-03-21 20:49:25 +00002651 be_msix_disable(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002652 return status;
2653}
2654
2655static int be_irq_register(struct be_adapter *adapter)
2656{
2657 struct net_device *netdev = adapter->netdev;
2658 int status;
2659
Sathya Perlaac6a0c42011-03-21 20:49:25 +00002660 if (msix_enabled(adapter)) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002661 status = be_msix_register(adapter);
2662 if (status == 0)
2663 goto done;
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00002664 /* INTx is not supported for VF */
2665 if (!be_physfn(adapter))
2666 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002667 }
2668
Sathya Perlae49cc342012-11-27 19:50:02 +00002669 /* INTx: only the first EQ is used */
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002670 netdev->irq = adapter->pdev->irq;
2671 status = request_irq(netdev->irq, be_intx, IRQF_SHARED, netdev->name,
Sathya Perlae49cc342012-11-27 19:50:02 +00002672 &adapter->eq_obj[0]);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002673 if (status) {
2674 dev_err(&adapter->pdev->dev,
2675 "INTx request IRQ failed - err %d\n", status);
2676 return status;
2677 }
2678done:
2679 adapter->isr_registered = true;
2680 return 0;
2681}
2682
2683static void be_irq_unregister(struct be_adapter *adapter)
2684{
2685 struct net_device *netdev = adapter->netdev;
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002686 struct be_eq_obj *eqo;
Sathya Perla3abcded2010-10-03 22:12:27 -07002687 int i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002688
2689 if (!adapter->isr_registered)
2690 return;
2691
2692 /* INTx */
Sathya Perlaac6a0c42011-03-21 20:49:25 +00002693 if (!msix_enabled(adapter)) {
Sathya Perlae49cc342012-11-27 19:50:02 +00002694 free_irq(netdev->irq, &adapter->eq_obj[0]);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002695 goto done;
2696 }
2697
2698 /* MSIx */
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002699 for_all_evt_queues(adapter, eqo, i)
2700 free_irq(be_msix_vec_get(adapter, eqo), eqo);
Sathya Perla3abcded2010-10-03 22:12:27 -07002701
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002702done:
2703 adapter->isr_registered = false;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002704}
2705
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002706static void be_rx_qs_destroy(struct be_adapter *adapter)
Sathya Perla482c9e72011-06-29 23:33:17 +00002707{
2708 struct be_queue_info *q;
2709 struct be_rx_obj *rxo;
2710 int i;
2711
2712 for_all_rx_queues(adapter, rxo, i) {
2713 q = &rxo->q;
2714 if (q->created) {
2715 be_cmd_rxq_destroy(adapter, q);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002716 be_rx_cq_clean(rxo);
Sathya Perla482c9e72011-06-29 23:33:17 +00002717 }
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002718 be_queue_free(adapter, q);
Sathya Perla482c9e72011-06-29 23:33:17 +00002719 }
2720}
2721
Sathya Perla889cd4b2010-05-30 23:33:45 +00002722static int be_close(struct net_device *netdev)
2723{
2724 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002725 struct be_eq_obj *eqo;
2726 int i;
Sathya Perla889cd4b2010-05-30 23:33:45 +00002727
Parav Pandit045508a2012-03-26 14:27:13 +00002728 be_roce_dev_close(adapter);
2729
Ivan Veceradff345c52013-11-27 08:59:32 +01002730 if (adapter->flags & BE_FLAGS_NAPI_ENABLED) {
2731 for_all_evt_queues(adapter, eqo, i) {
Somnath Kotur04d3d622013-05-02 03:36:55 +00002732 napi_disable(&eqo->napi);
Sathya Perla6384a4d2013-10-25 10:40:16 +05302733 be_disable_busy_poll(eqo);
2734 }
David S. Miller71237b62013-11-28 18:53:36 -05002735 adapter->flags &= ~BE_FLAGS_NAPI_ENABLED;
Somnath Kotur04d3d622013-05-02 03:36:55 +00002736 }
Sathya Perlaa323d9b2012-12-17 19:38:50 +00002737
2738 be_async_mcc_disable(adapter);
2739
2740 /* Wait for all pending tx completions to arrive so that
2741 * all tx skbs are freed.
2742 */
Sathya Perlafba87552013-05-08 02:05:50 +00002743 netif_tx_disable(netdev);
Sathya Perla6e1f9972013-08-22 12:23:41 +05302744 be_tx_compl_clean(adapter);
Sathya Perlaa323d9b2012-12-17 19:38:50 +00002745
2746 be_rx_qs_destroy(adapter);
2747
Ajit Khaparded11a3472013-11-18 10:44:37 -06002748 for (i = 1; i < (adapter->uc_macs + 1); i++)
2749 be_cmd_pmac_del(adapter, adapter->if_handle,
2750 adapter->pmac_id[i], 0);
2751 adapter->uc_macs = 0;
2752
Sathya Perlaa323d9b2012-12-17 19:38:50 +00002753 for_all_evt_queues(adapter, eqo, i) {
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002754 if (msix_enabled(adapter))
2755 synchronize_irq(be_msix_vec_get(adapter, eqo));
2756 else
2757 synchronize_irq(netdev->irq);
2758 be_eq_clean(eqo);
Padmanabh Ratnakar63fcb272011-03-07 03:09:17 +00002759 }
2760
Sathya Perla889cd4b2010-05-30 23:33:45 +00002761 be_irq_unregister(adapter);
2762
Sathya Perla482c9e72011-06-29 23:33:17 +00002763 return 0;
2764}
2765
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002766static int be_rx_qs_create(struct be_adapter *adapter)
Sathya Perla482c9e72011-06-29 23:33:17 +00002767{
2768 struct be_rx_obj *rxo;
Padmanabh Ratnakare9008ee2011-11-25 05:48:53 +00002769 int rc, i, j;
2770 u8 rsstable[128];
Sathya Perla482c9e72011-06-29 23:33:17 +00002771
2772 for_all_rx_queues(adapter, rxo, i) {
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002773 rc = be_queue_alloc(adapter, &rxo->q, RX_Q_LEN,
2774 sizeof(struct be_eth_rx_d));
2775 if (rc)
2776 return rc;
2777 }
2778
2779 /* The FW would like the default RXQ to be created first */
2780 rxo = default_rxo(adapter);
2781 rc = be_cmd_rxq_create(adapter, &rxo->q, rxo->cq.id, rx_frag_size,
2782 adapter->if_handle, false, &rxo->rss_id);
2783 if (rc)
2784 return rc;
2785
2786 for_all_rss_queues(adapter, rxo, i) {
Sathya Perla482c9e72011-06-29 23:33:17 +00002787 rc = be_cmd_rxq_create(adapter, &rxo->q, rxo->cq.id,
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002788 rx_frag_size, adapter->if_handle,
2789 true, &rxo->rss_id);
Sathya Perla482c9e72011-06-29 23:33:17 +00002790 if (rc)
2791 return rc;
2792 }
2793
2794 if (be_multi_rxq(adapter)) {
Padmanabh Ratnakare9008ee2011-11-25 05:48:53 +00002795 for (j = 0; j < 128; j += adapter->num_rx_qs - 1) {
2796 for_all_rss_queues(adapter, rxo, i) {
2797 if ((j + i) >= 128)
2798 break;
2799 rsstable[j + i] = rxo->rss_id;
2800 }
2801 }
Suresh Reddy594ad542013-04-25 23:03:20 +00002802 adapter->rss_flags = RSS_ENABLE_TCP_IPV4 | RSS_ENABLE_IPV4 |
2803 RSS_ENABLE_TCP_IPV6 | RSS_ENABLE_IPV6;
2804
2805 if (!BEx_chip(adapter))
2806 adapter->rss_flags |= RSS_ENABLE_UDP_IPV4 |
2807 RSS_ENABLE_UDP_IPV6;
Vasundhara Volamda1388d2014-01-06 13:02:23 +05302808 } else {
2809 /* Disable RSS, if only default RX Q is created */
2810 adapter->rss_flags = RSS_ENABLE_NONE;
2811 }
Suresh Reddy594ad542013-04-25 23:03:20 +00002812
Vasundhara Volamda1388d2014-01-06 13:02:23 +05302813 rc = be_cmd_rss_config(adapter, rsstable, adapter->rss_flags,
2814 128);
2815 if (rc) {
2816 adapter->rss_flags = RSS_ENABLE_NONE;
2817 return rc;
Sathya Perla482c9e72011-06-29 23:33:17 +00002818 }
2819
2820 /* First time posting */
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002821 for_all_rx_queues(adapter, rxo, i)
Sathya Perla482c9e72011-06-29 23:33:17 +00002822 be_post_rx_frags(rxo, GFP_KERNEL);
Sathya Perla889cd4b2010-05-30 23:33:45 +00002823 return 0;
2824}
2825
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002826static int be_open(struct net_device *netdev)
2827{
2828 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002829 struct be_eq_obj *eqo;
Sathya Perla3abcded2010-10-03 22:12:27 -07002830 struct be_rx_obj *rxo;
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002831 struct be_tx_obj *txo;
Ajit Khapardeb236916a2011-12-30 12:15:40 +00002832 u8 link_status;
Sathya Perla3abcded2010-10-03 22:12:27 -07002833 int status, i;
Sathya Perla5fb379e2009-06-18 00:02:59 +00002834
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002835 status = be_rx_qs_create(adapter);
Sathya Perla482c9e72011-06-29 23:33:17 +00002836 if (status)
2837 goto err;
2838
Somnath Koturc2bba3d2013-05-02 03:37:08 +00002839 status = be_irq_register(adapter);
2840 if (status)
2841 goto err;
Sathya Perla5fb379e2009-06-18 00:02:59 +00002842
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002843 for_all_rx_queues(adapter, rxo, i)
Sathya Perla3abcded2010-10-03 22:12:27 -07002844 be_cq_notify(adapter, rxo->cq.id, true, 0);
Sathya Perla5fb379e2009-06-18 00:02:59 +00002845
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002846 for_all_tx_queues(adapter, txo, i)
2847 be_cq_notify(adapter, txo->cq.id, true, 0);
2848
Sathya Perla7a1e9b22010-02-17 01:35:11 +00002849 be_async_mcc_enable(adapter);
2850
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002851 for_all_evt_queues(adapter, eqo, i) {
2852 napi_enable(&eqo->napi);
Sathya Perla6384a4d2013-10-25 10:40:16 +05302853 be_enable_busy_poll(eqo);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002854 be_eq_notify(adapter, eqo->q.id, true, false, 0);
2855 }
Somnath Kotur04d3d622013-05-02 03:36:55 +00002856 adapter->flags |= BE_FLAGS_NAPI_ENABLED;
Sathya Perla10ef9ab2012-02-09 18:05:27 +00002857
Sathya Perla323ff712012-09-28 04:39:43 +00002858 status = be_cmd_link_status_query(adapter, NULL, &link_status, 0);
Ajit Khapardeb236916a2011-12-30 12:15:40 +00002859 if (!status)
2860 be_link_status_update(adapter, link_status);
2861
Sathya Perlafba87552013-05-08 02:05:50 +00002862 netif_tx_start_all_queues(netdev);
Parav Pandit045508a2012-03-26 14:27:13 +00002863 be_roce_dev_open(adapter);
Sathya Perlac9c47142014-03-27 10:46:19 +05302864
Sathya Perlac5abe7c2014-04-01 12:33:59 +05302865#ifdef CONFIG_BE2NET_VXLAN
Sathya Perlac9c47142014-03-27 10:46:19 +05302866 if (skyhawk_chip(adapter))
2867 vxlan_get_rx_port(netdev);
Sathya Perlac5abe7c2014-04-01 12:33:59 +05302868#endif
2869
Sathya Perla889cd4b2010-05-30 23:33:45 +00002870 return 0;
2871err:
2872 be_close(adapter->netdev);
2873 return -EIO;
Sathya Perla5fb379e2009-06-18 00:02:59 +00002874}
2875
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002876static int be_setup_wol(struct be_adapter *adapter, bool enable)
2877{
2878 struct be_dma_mem cmd;
2879 int status = 0;
2880 u8 mac[ETH_ALEN];
2881
2882 memset(mac, 0, ETH_ALEN);
2883
2884 cmd.size = sizeof(struct be_cmd_req_acpi_wol_magic_config);
Joe Perchesede23fa2013-08-26 22:45:23 -07002885 cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma,
2886 GFP_KERNEL);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002887 if (cmd.va == NULL)
2888 return -1;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002889
2890 if (enable) {
2891 status = pci_write_config_dword(adapter->pdev,
2892 PCICFG_PM_CONTROL_OFFSET, PCICFG_PM_CONTROL_MASK);
2893 if (status) {
2894 dev_err(&adapter->pdev->dev,
Frans Pop2381a552010-03-24 07:57:36 +00002895 "Could not enable Wake-on-lan\n");
Ivan Vecera2b7bceb2011-02-02 08:05:12 +00002896 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va,
2897 cmd.dma);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002898 return status;
2899 }
2900 status = be_cmd_enable_magic_wol(adapter,
2901 adapter->netdev->dev_addr, &cmd);
2902 pci_enable_wake(adapter->pdev, PCI_D3hot, 1);
2903 pci_enable_wake(adapter->pdev, PCI_D3cold, 1);
2904 } else {
2905 status = be_cmd_enable_magic_wol(adapter, mac, &cmd);
2906 pci_enable_wake(adapter->pdev, PCI_D3hot, 0);
2907 pci_enable_wake(adapter->pdev, PCI_D3cold, 0);
2908 }
2909
Ivan Vecera2b7bceb2011-02-02 08:05:12 +00002910 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002911 return status;
2912}
2913
Ajit Khaparde6d87f5c2010-08-25 00:32:33 +00002914/*
2915 * Generate a seed MAC address from the PF MAC Address using jhash.
2916 * MAC Address for VFs are assigned incrementally starting from the seed.
2917 * These addresses are programmed in the ASIC by the PF and the VF driver
2918 * queries for the MAC address during its probe.
2919 */
Sathya Perla4c876612013-02-03 20:30:11 +00002920static int be_vf_eth_addr_config(struct be_adapter *adapter)
Ajit Khaparde6d87f5c2010-08-25 00:32:33 +00002921{
Sathya Perlaf9449ab2011-10-24 02:45:01 +00002922 u32 vf;
Sathya Perla3abcded2010-10-03 22:12:27 -07002923 int status = 0;
Ajit Khaparde6d87f5c2010-08-25 00:32:33 +00002924 u8 mac[ETH_ALEN];
Sathya Perla11ac75e2011-12-13 00:58:50 +00002925 struct be_vf_cfg *vf_cfg;
Ajit Khaparde6d87f5c2010-08-25 00:32:33 +00002926
2927 be_vf_eth_addr_generate(adapter, mac);
2928
Sathya Perla11ac75e2011-12-13 00:58:50 +00002929 for_all_vfs(adapter, vf_cfg, vf) {
Sathya Perla3175d8c2013-07-23 15:25:03 +05302930 if (BEx_chip(adapter))
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002931 status = be_cmd_pmac_add(adapter, mac,
Sathya Perla11ac75e2011-12-13 00:58:50 +00002932 vf_cfg->if_handle,
2933 &vf_cfg->pmac_id, vf + 1);
Sathya Perla3175d8c2013-07-23 15:25:03 +05302934 else
2935 status = be_cmd_set_mac(adapter, mac, vf_cfg->if_handle,
2936 vf + 1);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002937
Ajit Khaparde6d87f5c2010-08-25 00:32:33 +00002938 if (status)
2939 dev_err(&adapter->pdev->dev,
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002940 "Mac address assignment failed for VF %d\n", vf);
Ajit Khaparde6d87f5c2010-08-25 00:32:33 +00002941 else
Sathya Perla11ac75e2011-12-13 00:58:50 +00002942 memcpy(vf_cfg->mac_addr, mac, ETH_ALEN);
Ajit Khaparde6d87f5c2010-08-25 00:32:33 +00002943
2944 mac[5] += 1;
2945 }
2946 return status;
2947}
2948
Sathya Perla4c876612013-02-03 20:30:11 +00002949static int be_vfs_mac_query(struct be_adapter *adapter)
2950{
2951 int status, vf;
2952 u8 mac[ETH_ALEN];
2953 struct be_vf_cfg *vf_cfg;
Sathya Perla4c876612013-02-03 20:30:11 +00002954
2955 for_all_vfs(adapter, vf_cfg, vf) {
Suresh Reddyb188f092014-01-15 13:23:39 +05302956 status = be_cmd_get_active_mac(adapter, vf_cfg->pmac_id,
2957 mac, vf_cfg->if_handle,
2958 false, vf+1);
Sathya Perla4c876612013-02-03 20:30:11 +00002959 if (status)
2960 return status;
2961 memcpy(vf_cfg->mac_addr, mac, ETH_ALEN);
2962 }
2963 return 0;
2964}
2965
Sathya Perlaf9449ab2011-10-24 02:45:01 +00002966static void be_vf_clear(struct be_adapter *adapter)
Ajit Khaparde6d87f5c2010-08-25 00:32:33 +00002967{
Sathya Perla11ac75e2011-12-13 00:58:50 +00002968 struct be_vf_cfg *vf_cfg;
Ajit Khaparde6d87f5c2010-08-25 00:32:33 +00002969 u32 vf;
2970
Sathya Perla257a3fe2013-06-14 15:54:51 +05302971 if (pci_vfs_assigned(adapter->pdev)) {
Sathya Perla4c876612013-02-03 20:30:11 +00002972 dev_warn(&adapter->pdev->dev,
2973 "VFs are assigned to VMs: not disabling VFs\n");
Sathya Perla39f1d942012-05-08 19:41:24 +00002974 goto done;
2975 }
2976
Sathya Perlab4c1df92013-05-08 02:05:47 +00002977 pci_disable_sriov(adapter->pdev);
2978
Sathya Perla11ac75e2011-12-13 00:58:50 +00002979 for_all_vfs(adapter, vf_cfg, vf) {
Sathya Perla3175d8c2013-07-23 15:25:03 +05302980 if (BEx_chip(adapter))
Sathya Perla11ac75e2011-12-13 00:58:50 +00002981 be_cmd_pmac_del(adapter, vf_cfg->if_handle,
2982 vf_cfg->pmac_id, vf + 1);
Sathya Perla3175d8c2013-07-23 15:25:03 +05302983 else
2984 be_cmd_set_mac(adapter, NULL, vf_cfg->if_handle,
2985 vf + 1);
Sathya Perlaf9449ab2011-10-24 02:45:01 +00002986
Sathya Perla11ac75e2011-12-13 00:58:50 +00002987 be_cmd_if_destroy(adapter, vf_cfg->if_handle, vf + 1);
2988 }
Sathya Perla39f1d942012-05-08 19:41:24 +00002989done:
2990 kfree(adapter->vf_cfg);
2991 adapter->num_vfs = 0;
Ajit Khaparde6d87f5c2010-08-25 00:32:33 +00002992}
2993
Sathya Perla77071332013-08-27 16:57:34 +05302994static void be_clear_queues(struct be_adapter *adapter)
2995{
2996 be_mcc_queues_destroy(adapter);
2997 be_rx_cqs_destroy(adapter);
2998 be_tx_queues_destroy(adapter);
2999 be_evt_queues_destroy(adapter);
3000}
3001
Sathya Perla68d7bdc2013-08-27 16:57:35 +05303002static void be_cancel_worker(struct be_adapter *adapter)
Sathya Perlaa54769f2011-10-24 02:45:00 +00003003{
Sathya Perla191eb752012-02-23 18:50:13 +00003004 if (adapter->flags & BE_FLAGS_WORKER_SCHEDULED) {
3005 cancel_delayed_work_sync(&adapter->work);
3006 adapter->flags &= ~BE_FLAGS_WORKER_SCHEDULED;
3007 }
Sathya Perla68d7bdc2013-08-27 16:57:35 +05303008}
3009
Somnath Koturb05004a2013-12-05 12:08:16 +05303010static void be_mac_clear(struct be_adapter *adapter)
Sathya Perla68d7bdc2013-08-27 16:57:35 +05303011{
3012 int i;
3013
Somnath Koturb05004a2013-12-05 12:08:16 +05303014 if (adapter->pmac_id) {
3015 for (i = 0; i < (adapter->uc_macs + 1); i++)
3016 be_cmd_pmac_del(adapter, adapter->if_handle,
3017 adapter->pmac_id[i], 0);
3018 adapter->uc_macs = 0;
3019
3020 kfree(adapter->pmac_id);
3021 adapter->pmac_id = NULL;
3022 }
3023}
3024
Sathya Perlac5abe7c2014-04-01 12:33:59 +05303025#ifdef CONFIG_BE2NET_VXLAN
Sathya Perlac9c47142014-03-27 10:46:19 +05303026static void be_disable_vxlan_offloads(struct be_adapter *adapter)
3027{
3028 if (adapter->flags & BE_FLAGS_VXLAN_OFFLOADS)
3029 be_cmd_manage_iface(adapter, adapter->if_handle,
3030 OP_CONVERT_TUNNEL_TO_NORMAL);
3031
3032 if (adapter->vxlan_port)
3033 be_cmd_set_vxlan_port(adapter, 0);
3034
3035 adapter->flags &= ~BE_FLAGS_VXLAN_OFFLOADS;
3036 adapter->vxlan_port = 0;
3037}
Sathya Perlac5abe7c2014-04-01 12:33:59 +05303038#endif
Sathya Perlac9c47142014-03-27 10:46:19 +05303039
Somnath Koturb05004a2013-12-05 12:08:16 +05303040static int be_clear(struct be_adapter *adapter)
3041{
Sathya Perla68d7bdc2013-08-27 16:57:35 +05303042 be_cancel_worker(adapter);
Sathya Perla191eb752012-02-23 18:50:13 +00003043
Sathya Perla11ac75e2011-12-13 00:58:50 +00003044 if (sriov_enabled(adapter))
Sathya Perlaf9449ab2011-10-24 02:45:01 +00003045 be_vf_clear(adapter);
3046
Sathya Perlac5abe7c2014-04-01 12:33:59 +05303047#ifdef CONFIG_BE2NET_VXLAN
Sathya Perlac9c47142014-03-27 10:46:19 +05303048 be_disable_vxlan_offloads(adapter);
Sathya Perlac5abe7c2014-04-01 12:33:59 +05303049#endif
Sathya Perla2d17f402013-07-23 15:25:04 +05303050 /* delete the primary mac along with the uc-mac list */
Somnath Koturb05004a2013-12-05 12:08:16 +05303051 be_mac_clear(adapter);
Ajit Khapardefbc13f02012-03-18 06:23:21 +00003052
Sathya Perlaf9449ab2011-10-24 02:45:01 +00003053 be_cmd_if_destroy(adapter, adapter->if_handle, 0);
Sathya Perlaa54769f2011-10-24 02:45:00 +00003054
Sathya Perla77071332013-08-27 16:57:34 +05303055 be_clear_queues(adapter);
Sathya Perlaa54769f2011-10-24 02:45:00 +00003056
Sathya Perla10ef9ab2012-02-09 18:05:27 +00003057 be_msix_disable(adapter);
Sathya Perlaa54769f2011-10-24 02:45:00 +00003058 return 0;
3059}
3060
Sathya Perla4c876612013-02-03 20:30:11 +00003061static int be_vfs_if_create(struct be_adapter *adapter)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003062{
Sathya Perla92bf14a2013-08-27 16:57:32 +05303063 struct be_resources res = {0};
Sathya Perla4c876612013-02-03 20:30:11 +00003064 struct be_vf_cfg *vf_cfg;
3065 u32 cap_flags, en_flags, vf;
Antonio Alecrim Jr922bbe82013-09-13 14:05:49 -03003066 int status = 0;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003067
Sathya Perla4c876612013-02-03 20:30:11 +00003068 cap_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST |
3069 BE_IF_FLAGS_MULTICAST;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003070
Sathya Perla4c876612013-02-03 20:30:11 +00003071 for_all_vfs(adapter, vf_cfg, vf) {
Sathya Perla92bf14a2013-08-27 16:57:32 +05303072 if (!BE3_chip(adapter)) {
3073 status = be_cmd_get_profile_config(adapter, &res,
3074 vf + 1);
3075 if (!status)
3076 cap_flags = res.if_cap_flags;
3077 }
Sathya Perla4c876612013-02-03 20:30:11 +00003078
3079 /* If a FW profile exists, then cap_flags are updated */
3080 en_flags = cap_flags & (BE_IF_FLAGS_UNTAGGED |
3081 BE_IF_FLAGS_BROADCAST | BE_IF_FLAGS_MULTICAST);
3082 status = be_cmd_if_create(adapter, cap_flags, en_flags,
3083 &vf_cfg->if_handle, vf + 1);
3084 if (status)
3085 goto err;
3086 }
3087err:
3088 return status;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003089}
3090
Sathya Perla39f1d942012-05-08 19:41:24 +00003091static int be_vf_setup_init(struct be_adapter *adapter)
Sathya Perla30128032011-11-10 19:17:57 +00003092{
Sathya Perla11ac75e2011-12-13 00:58:50 +00003093 struct be_vf_cfg *vf_cfg;
Sathya Perla30128032011-11-10 19:17:57 +00003094 int vf;
3095
Sathya Perla39f1d942012-05-08 19:41:24 +00003096 adapter->vf_cfg = kcalloc(adapter->num_vfs, sizeof(*vf_cfg),
3097 GFP_KERNEL);
3098 if (!adapter->vf_cfg)
3099 return -ENOMEM;
3100
Sathya Perla11ac75e2011-12-13 00:58:50 +00003101 for_all_vfs(adapter, vf_cfg, vf) {
3102 vf_cfg->if_handle = -1;
3103 vf_cfg->pmac_id = -1;
Sathya Perla30128032011-11-10 19:17:57 +00003104 }
Sathya Perla39f1d942012-05-08 19:41:24 +00003105 return 0;
Sathya Perla30128032011-11-10 19:17:57 +00003106}
3107
Sathya Perlaf9449ab2011-10-24 02:45:01 +00003108static int be_vf_setup(struct be_adapter *adapter)
3109{
Sathya Perla4c876612013-02-03 20:30:11 +00003110 struct device *dev = &adapter->pdev->dev;
Somnath Koturc5022242014-03-03 14:24:20 +05303111 struct be_vf_cfg *vf_cfg;
3112 int status, old_vfs, vf;
Sathya Perla04a06022013-07-23 15:25:00 +05303113 u32 privileges;
Somnath Koturc5022242014-03-03 14:24:20 +05303114 u16 lnk_speed;
Sathya Perlaf9449ab2011-10-24 02:45:01 +00003115
Sathya Perla257a3fe2013-06-14 15:54:51 +05303116 old_vfs = pci_num_vf(adapter->pdev);
Sathya Perla4c876612013-02-03 20:30:11 +00003117 if (old_vfs) {
3118 dev_info(dev, "%d VFs are already enabled\n", old_vfs);
3119 if (old_vfs != num_vfs)
3120 dev_warn(dev, "Ignoring num_vfs=%d setting\n", num_vfs);
3121 adapter->num_vfs = old_vfs;
Sathya Perla39f1d942012-05-08 19:41:24 +00003122 } else {
Sathya Perla92bf14a2013-08-27 16:57:32 +05303123 if (num_vfs > be_max_vfs(adapter))
Sathya Perla4c876612013-02-03 20:30:11 +00003124 dev_info(dev, "Device supports %d VFs and not %d\n",
Sathya Perla92bf14a2013-08-27 16:57:32 +05303125 be_max_vfs(adapter), num_vfs);
3126 adapter->num_vfs = min_t(u16, num_vfs, be_max_vfs(adapter));
Sathya Perlab4c1df92013-05-08 02:05:47 +00003127 if (!adapter->num_vfs)
Sathya Perla4c876612013-02-03 20:30:11 +00003128 return 0;
Sathya Perla39f1d942012-05-08 19:41:24 +00003129 }
3130
3131 status = be_vf_setup_init(adapter);
3132 if (status)
3133 goto err;
Sathya Perla30128032011-11-10 19:17:57 +00003134
Sathya Perla4c876612013-02-03 20:30:11 +00003135 if (old_vfs) {
3136 for_all_vfs(adapter, vf_cfg, vf) {
3137 status = be_cmd_get_if_id(adapter, vf_cfg, vf);
3138 if (status)
3139 goto err;
3140 }
3141 } else {
3142 status = be_vfs_if_create(adapter);
Sathya Perlaf9449ab2011-10-24 02:45:01 +00003143 if (status)
3144 goto err;
Sathya Perlaf9449ab2011-10-24 02:45:01 +00003145 }
3146
Sathya Perla4c876612013-02-03 20:30:11 +00003147 if (old_vfs) {
3148 status = be_vfs_mac_query(adapter);
3149 if (status)
3150 goto err;
3151 } else {
Sathya Perla39f1d942012-05-08 19:41:24 +00003152 status = be_vf_eth_addr_config(adapter);
3153 if (status)
3154 goto err;
3155 }
Sathya Perlaf9449ab2011-10-24 02:45:01 +00003156
Sathya Perla11ac75e2011-12-13 00:58:50 +00003157 for_all_vfs(adapter, vf_cfg, vf) {
Sathya Perla04a06022013-07-23 15:25:00 +05303158 /* Allow VFs to programs MAC/VLAN filters */
3159 status = be_cmd_get_fn_privileges(adapter, &privileges, vf + 1);
3160 if (!status && !(privileges & BE_PRIV_FILTMGMT)) {
3161 status = be_cmd_set_fn_privileges(adapter,
3162 privileges |
3163 BE_PRIV_FILTMGMT,
3164 vf + 1);
3165 if (!status)
3166 dev_info(dev, "VF%d has FILTMGMT privilege\n",
3167 vf);
3168 }
3169
Sathya Perla4c876612013-02-03 20:30:11 +00003170 /* BE3 FW, by default, caps VF TX-rate to 100mbps.
3171 * Allow full available bandwidth
3172 */
3173 if (BE3_chip(adapter) && !old_vfs)
Sathya Perlaa4018012014-03-27 10:46:18 +05303174 be_cmd_config_qos(adapter, 1000, vf + 1);
Sathya Perla4c876612013-02-03 20:30:11 +00003175
3176 status = be_cmd_link_status_query(adapter, &lnk_speed,
3177 NULL, vf + 1);
3178 if (!status)
3179 vf_cfg->tx_rate = lnk_speed;
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003180
Suresh Reddybdce2ad2014-03-11 18:53:04 +05303181 if (!old_vfs) {
Vasundhara Volam05998632013-10-01 15:59:59 +05303182 be_cmd_enable_vf(adapter, vf + 1);
Suresh Reddybdce2ad2014-03-11 18:53:04 +05303183 be_cmd_set_logical_link_config(adapter,
3184 IFLA_VF_LINK_STATE_AUTO,
3185 vf+1);
3186 }
Sathya Perlaf9449ab2011-10-24 02:45:01 +00003187 }
Sathya Perlab4c1df92013-05-08 02:05:47 +00003188
3189 if (!old_vfs) {
3190 status = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
3191 if (status) {
3192 dev_err(dev, "SRIOV enable failed\n");
3193 adapter->num_vfs = 0;
3194 goto err;
3195 }
3196 }
Sathya Perlaf9449ab2011-10-24 02:45:01 +00003197 return 0;
3198err:
Sathya Perla4c876612013-02-03 20:30:11 +00003199 dev_err(dev, "VF setup failed\n");
3200 be_vf_clear(adapter);
Sathya Perlaf9449ab2011-10-24 02:45:01 +00003201 return status;
3202}
3203
Vasundhara Volamf93f1602014-02-12 16:09:25 +05303204/* Converting function_mode bits on BE3 to SH mc_type enums */
3205
3206static u8 be_convert_mc_type(u32 function_mode)
3207{
3208 if (function_mode & VNIC_MODE && function_mode & FLEX10_MODE)
3209 return vNIC1;
3210 else if (function_mode & FLEX10_MODE)
3211 return FLEX10;
3212 else if (function_mode & VNIC_MODE)
3213 return vNIC2;
3214 else if (function_mode & UMC_ENABLED)
3215 return UMC;
3216 else
3217 return MC_NONE;
3218}
3219
Sathya Perla92bf14a2013-08-27 16:57:32 +05303220/* On BE2/BE3 FW does not suggest the supported limits */
3221static void BEx_get_resources(struct be_adapter *adapter,
3222 struct be_resources *res)
3223{
3224 struct pci_dev *pdev = adapter->pdev;
3225 bool use_sriov = false;
Suresh Reddyecf1f6e2014-03-11 18:53:03 +05303226 int max_vfs = 0;
Suresh Reddye3dc8672014-01-06 13:02:25 +05303227
Suresh Reddyecf1f6e2014-03-11 18:53:03 +05303228 if (be_physfn(adapter) && BE3_chip(adapter)) {
3229 be_cmd_get_profile_config(adapter, res, 0);
3230 /* Some old versions of BE3 FW don't report max_vfs value */
3231 if (res->max_vfs == 0) {
3232 max_vfs = pci_sriov_get_totalvfs(pdev);
3233 res->max_vfs = max_vfs > 0 ? min(MAX_VFS, max_vfs) : 0;
3234 }
3235 use_sriov = res->max_vfs && sriov_want(adapter);
Sathya Perla92bf14a2013-08-27 16:57:32 +05303236 }
3237
3238 if (be_physfn(adapter))
3239 res->max_uc_mac = BE_UC_PMAC_COUNT;
3240 else
3241 res->max_uc_mac = BE_VF_UC_PMAC_COUNT;
3242
Vasundhara Volamf93f1602014-02-12 16:09:25 +05303243 adapter->mc_type = be_convert_mc_type(adapter->function_mode);
3244
3245 if (be_is_mc(adapter)) {
3246 /* Assuming that there are 4 channels per port,
3247 * when multi-channel is enabled
3248 */
3249 if (be_is_qnq_mode(adapter))
3250 res->max_vlans = BE_NUM_VLANS_SUPPORTED/8;
3251 else
3252 /* In a non-qnq multichannel mode, the pvid
3253 * takes up one vlan entry
3254 */
3255 res->max_vlans = (BE_NUM_VLANS_SUPPORTED / 4) - 1;
3256 } else {
Sathya Perla92bf14a2013-08-27 16:57:32 +05303257 res->max_vlans = BE_NUM_VLANS_SUPPORTED;
Vasundhara Volamf93f1602014-02-12 16:09:25 +05303258 }
3259
Sathya Perla92bf14a2013-08-27 16:57:32 +05303260 res->max_mcast_mac = BE_MAX_MC;
3261
Vasundhara Volama5243da2014-03-11 18:53:07 +05303262 /* 1) For BE3 1Gb ports, FW does not support multiple TXQs
3263 * 2) Create multiple TX rings on a BE3-R multi-channel interface
3264 * *only* if it is RSS-capable.
3265 */
3266 if (BE2_chip(adapter) || use_sriov || (adapter->port_num > 1) ||
3267 !be_physfn(adapter) || (be_is_mc(adapter) &&
3268 !(adapter->function_caps & BE_FUNCTION_CAPS_RSS)))
Sathya Perla92bf14a2013-08-27 16:57:32 +05303269 res->max_tx_qs = 1;
3270 else
3271 res->max_tx_qs = BE3_MAX_TX_QS;
3272
3273 if ((adapter->function_caps & BE_FUNCTION_CAPS_RSS) &&
3274 !use_sriov && be_physfn(adapter))
3275 res->max_rss_qs = (adapter->be3_native) ?
3276 BE3_MAX_RSS_QS : BE2_MAX_RSS_QS;
3277 res->max_rx_qs = res->max_rss_qs + 1;
3278
Suresh Reddye3dc8672014-01-06 13:02:25 +05303279 if (be_physfn(adapter))
Suresh Reddyecf1f6e2014-03-11 18:53:03 +05303280 res->max_evt_qs = (res->max_vfs > 0) ?
Suresh Reddye3dc8672014-01-06 13:02:25 +05303281 BE3_SRIOV_MAX_EVT_QS : BE3_MAX_EVT_QS;
3282 else
3283 res->max_evt_qs = 1;
Sathya Perla92bf14a2013-08-27 16:57:32 +05303284
3285 res->if_cap_flags = BE_IF_CAP_FLAGS_WANT;
3286 if (!(adapter->function_caps & BE_FUNCTION_CAPS_RSS))
3287 res->if_cap_flags &= ~BE_IF_FLAGS_RSS;
3288}
3289
Sathya Perla30128032011-11-10 19:17:57 +00003290static void be_setup_init(struct be_adapter *adapter)
3291{
3292 adapter->vlan_prio_bmap = 0xff;
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00003293 adapter->phy.link_speed = -1;
Sathya Perla30128032011-11-10 19:17:57 +00003294 adapter->if_handle = -1;
3295 adapter->be3_native = false;
3296 adapter->promiscuous = false;
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00003297 if (be_physfn(adapter))
3298 adapter->cmd_privileges = MAX_PRIVILEGES;
3299 else
3300 adapter->cmd_privileges = MIN_PRIVILEGES;
Sathya Perla30128032011-11-10 19:17:57 +00003301}
3302
Sathya Perla92bf14a2013-08-27 16:57:32 +05303303static int be_get_resources(struct be_adapter *adapter)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003304{
Sathya Perla92bf14a2013-08-27 16:57:32 +05303305 struct device *dev = &adapter->pdev->dev;
3306 struct be_resources res = {0};
3307 int status;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003308
Sathya Perla92bf14a2013-08-27 16:57:32 +05303309 if (BEx_chip(adapter)) {
3310 BEx_get_resources(adapter, &res);
3311 adapter->res = res;
3312 }
3313
Sathya Perla92bf14a2013-08-27 16:57:32 +05303314 /* For Lancer, SH etc read per-function resource limits from FW.
3315 * GET_FUNC_CONFIG returns per function guaranteed limits.
3316 * GET_PROFILE_CONFIG returns PCI-E related limits PF-pool limits
3317 */
Sathya Perla4c876612013-02-03 20:30:11 +00003318 if (!BEx_chip(adapter)) {
Sathya Perla92bf14a2013-08-27 16:57:32 +05303319 status = be_cmd_get_func_config(adapter, &res);
3320 if (status)
3321 return status;
3322
3323 /* If RoCE may be enabled stash away half the EQs for RoCE */
3324 if (be_roce_supported(adapter))
3325 res.max_evt_qs /= 2;
3326 adapter->res = res;
3327
3328 if (be_physfn(adapter)) {
3329 status = be_cmd_get_profile_config(adapter, &res, 0);
3330 if (status)
3331 return status;
3332 adapter->res.max_vfs = res.max_vfs;
3333 }
3334
3335 dev_info(dev, "Max: txqs %d, rxqs %d, rss %d, eqs %d, vfs %d\n",
3336 be_max_txqs(adapter), be_max_rxqs(adapter),
3337 be_max_rss(adapter), be_max_eqs(adapter),
3338 be_max_vfs(adapter));
3339 dev_info(dev, "Max: uc-macs %d, mc-macs %d, vlans %d\n",
3340 be_max_uc(adapter), be_max_mc(adapter),
3341 be_max_vlans(adapter));
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003342 }
3343
Sathya Perla92bf14a2013-08-27 16:57:32 +05303344 return 0;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003345}
3346
Sathya Perla39f1d942012-05-08 19:41:24 +00003347/* Routine to query per function resource limits */
3348static int be_get_config(struct be_adapter *adapter)
3349{
Vasundhara Volam542963b2014-01-15 13:23:33 +05303350 u16 profile_id;
Sathya Perla4c876612013-02-03 20:30:11 +00003351 int status;
Sathya Perla39f1d942012-05-08 19:41:24 +00003352
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003353 status = be_cmd_query_fw_cfg(adapter, &adapter->port_num,
3354 &adapter->function_mode,
Vasundhara Volam0ad31572013-04-21 23:28:16 +00003355 &adapter->function_caps,
3356 &adapter->asic_rev);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003357 if (status)
Sathya Perla92bf14a2013-08-27 16:57:32 +05303358 return status;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003359
Vasundhara Volam542963b2014-01-15 13:23:33 +05303360 if (be_physfn(adapter)) {
3361 status = be_cmd_get_active_profile(adapter, &profile_id);
3362 if (!status)
3363 dev_info(&adapter->pdev->dev,
3364 "Using profile 0x%x\n", profile_id);
3365 }
3366
Sathya Perla92bf14a2013-08-27 16:57:32 +05303367 status = be_get_resources(adapter);
3368 if (status)
3369 return status;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003370
Ravikumar Nelavelli46ee9c12014-03-11 18:53:06 +05303371 adapter->pmac_id = kcalloc(be_max_uc(adapter),
3372 sizeof(*adapter->pmac_id), GFP_KERNEL);
Sathya Perla92bf14a2013-08-27 16:57:32 +05303373 if (!adapter->pmac_id)
3374 return -ENOMEM;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003375
Sathya Perla92bf14a2013-08-27 16:57:32 +05303376 /* Sanitize cfg_num_qs based on HW and platform limits */
3377 adapter->cfg_num_qs = min(adapter->cfg_num_qs, be_max_qs(adapter));
3378
3379 return 0;
Sathya Perla39f1d942012-05-08 19:41:24 +00003380}
3381
Sathya Perla95046b92013-07-23 15:25:02 +05303382static int be_mac_setup(struct be_adapter *adapter)
3383{
3384 u8 mac[ETH_ALEN];
3385 int status;
3386
3387 if (is_zero_ether_addr(adapter->netdev->dev_addr)) {
3388 status = be_cmd_get_perm_mac(adapter, mac);
3389 if (status)
3390 return status;
3391
3392 memcpy(adapter->netdev->dev_addr, mac, ETH_ALEN);
3393 memcpy(adapter->netdev->perm_addr, mac, ETH_ALEN);
3394 } else {
3395 /* Maybe the HW was reset; dev_addr must be re-programmed */
3396 memcpy(mac, adapter->netdev->dev_addr, ETH_ALEN);
3397 }
3398
Ajit Khaparde2c7a9dc2013-11-22 12:51:28 -06003399 /* For BE3-R VFs, the PF programs the initial MAC address */
3400 if (!(BEx_chip(adapter) && be_virtfn(adapter)))
3401 be_cmd_pmac_add(adapter, mac, adapter->if_handle,
3402 &adapter->pmac_id[0], 0);
Sathya Perla95046b92013-07-23 15:25:02 +05303403 return 0;
3404}
3405
Sathya Perla68d7bdc2013-08-27 16:57:35 +05303406static void be_schedule_worker(struct be_adapter *adapter)
3407{
3408 schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000));
3409 adapter->flags |= BE_FLAGS_WORKER_SCHEDULED;
3410}
3411
Sathya Perla77071332013-08-27 16:57:34 +05303412static int be_setup_queues(struct be_adapter *adapter)
3413{
Sathya Perla68d7bdc2013-08-27 16:57:35 +05303414 struct net_device *netdev = adapter->netdev;
Sathya Perla77071332013-08-27 16:57:34 +05303415 int status;
3416
3417 status = be_evt_queues_create(adapter);
3418 if (status)
3419 goto err;
3420
3421 status = be_tx_qs_create(adapter);
3422 if (status)
3423 goto err;
3424
3425 status = be_rx_cqs_create(adapter);
3426 if (status)
3427 goto err;
3428
3429 status = be_mcc_queues_create(adapter);
3430 if (status)
3431 goto err;
3432
Sathya Perla68d7bdc2013-08-27 16:57:35 +05303433 status = netif_set_real_num_rx_queues(netdev, adapter->num_rx_qs);
3434 if (status)
3435 goto err;
3436
3437 status = netif_set_real_num_tx_queues(netdev, adapter->num_tx_qs);
3438 if (status)
3439 goto err;
3440
Sathya Perla77071332013-08-27 16:57:34 +05303441 return 0;
3442err:
3443 dev_err(&adapter->pdev->dev, "queue_setup failed\n");
3444 return status;
3445}
3446
Sathya Perla68d7bdc2013-08-27 16:57:35 +05303447int be_update_queues(struct be_adapter *adapter)
3448{
3449 struct net_device *netdev = adapter->netdev;
3450 int status;
3451
3452 if (netif_running(netdev))
3453 be_close(netdev);
3454
3455 be_cancel_worker(adapter);
3456
3457 /* If any vectors have been shared with RoCE we cannot re-program
3458 * the MSIx table.
3459 */
3460 if (!adapter->num_msix_roce_vec)
3461 be_msix_disable(adapter);
3462
3463 be_clear_queues(adapter);
3464
3465 if (!msix_enabled(adapter)) {
3466 status = be_msix_enable(adapter);
3467 if (status)
3468 return status;
3469 }
3470
3471 status = be_setup_queues(adapter);
3472 if (status)
3473 return status;
3474
3475 be_schedule_worker(adapter);
3476
3477 if (netif_running(netdev))
3478 status = be_open(netdev);
3479
3480 return status;
3481}
3482
Sathya Perla5fb379e2009-06-18 00:02:59 +00003483static int be_setup(struct be_adapter *adapter)
3484{
Sathya Perla39f1d942012-05-08 19:41:24 +00003485 struct device *dev = &adapter->pdev->dev;
Sathya Perla77071332013-08-27 16:57:34 +05303486 u32 tx_fc, rx_fc, en_flags;
Sathya Perla10ef9ab2012-02-09 18:05:27 +00003487 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07003488
Sathya Perla30128032011-11-10 19:17:57 +00003489 be_setup_init(adapter);
Sathya Perlaf9449ab2011-10-24 02:45:01 +00003490
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003491 if (!lancer_chip(adapter))
3492 be_cmd_req_native_mode(adapter);
Sathya Perla39f1d942012-05-08 19:41:24 +00003493
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003494 status = be_get_config(adapter);
3495 if (status)
3496 goto err;
Sathya Perla2dc1deb2011-07-19 19:52:33 +00003497
Somnath Koturc2bba3d2013-05-02 03:37:08 +00003498 status = be_msix_enable(adapter);
3499 if (status)
3500 goto err;
Sathya Perla10ef9ab2012-02-09 18:05:27 +00003501
Sathya Perla77071332013-08-27 16:57:34 +05303502 en_flags = BE_IF_FLAGS_UNTAGGED | BE_IF_FLAGS_BROADCAST |
3503 BE_IF_FLAGS_MULTICAST | BE_IF_FLAGS_PASS_L3L4_ERRORS;
3504 if (adapter->function_caps & BE_FUNCTION_CAPS_RSS)
3505 en_flags |= BE_IF_FLAGS_RSS;
3506 en_flags = en_flags & be_if_cap_flags(adapter);
3507 status = be_cmd_if_create(adapter, be_if_cap_flags(adapter), en_flags,
3508 &adapter->if_handle, 0);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00003509 if (status)
Sathya Perlaa54769f2011-10-24 02:45:00 +00003510 goto err;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07003511
Sathya Perla68d7bdc2013-08-27 16:57:35 +05303512 /* Updating real_num_tx/rx_queues() requires rtnl_lock() */
3513 rtnl_lock();
Sathya Perla77071332013-08-27 16:57:34 +05303514 status = be_setup_queues(adapter);
Sathya Perla68d7bdc2013-08-27 16:57:35 +05303515 rtnl_unlock();
Sathya Perla10ef9ab2012-02-09 18:05:27 +00003516 if (status)
Sathya Perlaa54769f2011-10-24 02:45:00 +00003517 goto err;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07003518
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00003519 be_cmd_get_fn_privileges(adapter, &adapter->cmd_privileges, 0);
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00003520
Sathya Perla95046b92013-07-23 15:25:02 +05303521 status = be_mac_setup(adapter);
3522 if (status)
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00003523 goto err;
3524
Somnath Kotureeb65ce2013-05-26 21:08:36 +00003525 be_cmd_get_fw_ver(adapter, adapter->fw_ver, adapter->fw_on_flash);
Somnath Kotur5a56eb12011-09-30 07:24:28 +00003526
Somnath Koture9e2a902013-10-24 14:37:53 +05303527 if (BE2_chip(adapter) && fw_major_num(adapter->fw_ver) < 4) {
3528 dev_err(dev, "Firmware on card is old(%s), IRQs may not work.",
3529 adapter->fw_ver);
3530 dev_err(dev, "Please upgrade firmware to version >= 4.0\n");
3531 }
3532
Sathya Perla1d1e9a42012-06-05 19:37:17 +00003533 if (adapter->vlans_added)
Sathya Perla10329df2012-06-05 19:37:18 +00003534 be_vid_config(adapter);
Sathya Perlaa54769f2011-10-24 02:45:00 +00003535
3536 be_set_rx_mode(adapter->netdev);
3537
Suresh Reddy76a9e082014-01-15 13:23:40 +05303538 be_cmd_get_acpi_wol_cap(adapter);
3539
Ajit Khapardeddc3f5c2012-04-26 15:42:31 +00003540 be_cmd_get_flow_control(adapter, &tx_fc, &rx_fc);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003541
Ajit Khapardeddc3f5c2012-04-26 15:42:31 +00003542 if (rx_fc != adapter->rx_fc || tx_fc != adapter->tx_fc)
3543 be_cmd_set_flow_control(adapter, adapter->tx_fc,
Sathya Perlaa54769f2011-10-24 02:45:00 +00003544 adapter->rx_fc);
Sathya Perlaa54769f2011-10-24 02:45:00 +00003545
Suresh Reddybdce2ad2014-03-11 18:53:04 +05303546 if (be_physfn(adapter))
3547 be_cmd_set_logical_link_config(adapter,
3548 IFLA_VF_LINK_STATE_AUTO, 0);
3549
Vasundhara Volamb905b5d2013-10-01 15:59:56 +05303550 if (sriov_want(adapter)) {
Sathya Perla92bf14a2013-08-27 16:57:32 +05303551 if (be_max_vfs(adapter))
Sathya Perla39f1d942012-05-08 19:41:24 +00003552 be_vf_setup(adapter);
3553 else
3554 dev_warn(dev, "device doesn't support SRIOV\n");
Sathya Perlaf9449ab2011-10-24 02:45:01 +00003555 }
3556
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00003557 status = be_cmd_get_phy_info(adapter);
3558 if (!status && be_pause_supported(adapter))
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00003559 adapter->phy.fc_autoneg = 1;
3560
Sathya Perla68d7bdc2013-08-27 16:57:35 +05303561 be_schedule_worker(adapter);
Sathya Perlaf9449ab2011-10-24 02:45:01 +00003562 return 0;
Sathya Perlaa54769f2011-10-24 02:45:00 +00003563err:
3564 be_clear(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07003565 return status;
3566}
3567
Ivan Vecera66268732011-12-08 01:31:21 +00003568#ifdef CONFIG_NET_POLL_CONTROLLER
3569static void be_netpoll(struct net_device *netdev)
3570{
3571 struct be_adapter *adapter = netdev_priv(netdev);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00003572 struct be_eq_obj *eqo;
Ivan Vecera66268732011-12-08 01:31:21 +00003573 int i;
3574
Sathya Perlae49cc342012-11-27 19:50:02 +00003575 for_all_evt_queues(adapter, eqo, i) {
3576 be_eq_notify(eqo->adapter, eqo->q.id, false, true, 0);
3577 napi_schedule(&eqo->napi);
3578 }
Sathya Perla10ef9ab2012-02-09 18:05:27 +00003579
3580 return;
Ivan Vecera66268732011-12-08 01:31:21 +00003581}
3582#endif
3583
Ajit Khaparde84517482009-09-04 03:12:16 +00003584#define FW_FILE_HDR_SIGN "ServerEngines Corp. "
Jingoo Han4188e7d2013-08-05 18:02:02 +09003585static char flash_cookie[2][16] = {"*** SE FLAS", "H DIRECTORY *** "};
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00003586
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08003587static bool be_flash_redboot(struct be_adapter *adapter,
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00003588 const u8 *p, u32 img_start, int image_size,
3589 int hdr_size)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08003590{
3591 u32 crc_offset;
3592 u8 flashed_crc[4];
3593 int status;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00003594
3595 crc_offset = hdr_size + img_start + image_size - 4;
3596
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08003597 p += crc_offset;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00003598
3599 status = be_cmd_get_flash_crc(adapter, flashed_crc,
Ajit Khapardef510fc62010-03-31 01:47:45 +00003600 (image_size - 4));
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08003601 if (status) {
3602 dev_err(&adapter->pdev->dev,
3603 "could not get crc from flash, not flashing redboot\n");
3604 return false;
3605 }
3606
3607 /*update redboot only if crc does not match*/
3608 if (!memcmp(flashed_crc, p, 4))
3609 return false;
3610 else
3611 return true;
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08003612}
3613
Sathya Perla306f1342011-08-02 19:57:45 +00003614static bool phy_flashing_required(struct be_adapter *adapter)
3615{
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00003616 return (adapter->phy.phy_type == TN_8022 &&
3617 adapter->phy.interface_type == PHY_TYPE_BASET_10GB);
Sathya Perla306f1342011-08-02 19:57:45 +00003618}
3619
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00003620static bool is_comp_in_ufi(struct be_adapter *adapter,
3621 struct flash_section_info *fsec, int type)
3622{
3623 int i = 0, img_type = 0;
3624 struct flash_section_info_g2 *fsec_g2 = NULL;
3625
Sathya Perlaca34fe32012-11-06 17:48:56 +00003626 if (BE2_chip(adapter))
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00003627 fsec_g2 = (struct flash_section_info_g2 *)fsec;
3628
3629 for (i = 0; i < MAX_FLASH_COMP; i++) {
3630 if (fsec_g2)
3631 img_type = le32_to_cpu(fsec_g2->fsec_entry[i].type);
3632 else
3633 img_type = le32_to_cpu(fsec->fsec_entry[i].type);
3634
3635 if (img_type == type)
3636 return true;
3637 }
3638 return false;
3639
3640}
3641
Jingoo Han4188e7d2013-08-05 18:02:02 +09003642static struct flash_section_info *get_fsec_info(struct be_adapter *adapter,
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00003643 int header_size,
3644 const struct firmware *fw)
3645{
3646 struct flash_section_info *fsec = NULL;
3647 const u8 *p = fw->data;
3648
3649 p += header_size;
3650 while (p < (fw->data + fw->size)) {
3651 fsec = (struct flash_section_info *)p;
3652 if (!memcmp(flash_cookie, fsec->cookie, sizeof(flash_cookie)))
3653 return fsec;
3654 p += 32;
3655 }
3656 return NULL;
3657}
3658
Padmanabh Ratnakar773a2d72012-10-20 06:04:16 +00003659static int be_flash(struct be_adapter *adapter, const u8 *img,
3660 struct be_dma_mem *flash_cmd, int optype, int img_size)
3661{
3662 u32 total_bytes = 0, flash_op, num_bytes = 0;
3663 int status = 0;
3664 struct be_cmd_write_flashrom *req = flash_cmd->va;
3665
3666 total_bytes = img_size;
3667 while (total_bytes) {
3668 num_bytes = min_t(u32, 32*1024, total_bytes);
3669
3670 total_bytes -= num_bytes;
3671
3672 if (!total_bytes) {
3673 if (optype == OPTYPE_PHY_FW)
3674 flash_op = FLASHROM_OPER_PHY_FLASH;
3675 else
3676 flash_op = FLASHROM_OPER_FLASH;
3677 } else {
3678 if (optype == OPTYPE_PHY_FW)
3679 flash_op = FLASHROM_OPER_PHY_SAVE;
3680 else
3681 flash_op = FLASHROM_OPER_SAVE;
3682 }
3683
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00003684 memcpy(req->data_buf, img, num_bytes);
Padmanabh Ratnakar773a2d72012-10-20 06:04:16 +00003685 img += num_bytes;
3686 status = be_cmd_write_flashrom(adapter, flash_cmd, optype,
3687 flash_op, num_bytes);
3688 if (status) {
3689 if (status == ILLEGAL_IOCTL_REQ &&
3690 optype == OPTYPE_PHY_FW)
3691 break;
3692 dev_err(&adapter->pdev->dev,
3693 "cmd to write to flash rom failed.\n");
3694 return status;
3695 }
3696 }
3697 return 0;
3698}
3699
Vasundhara Volam0ad31572013-04-21 23:28:16 +00003700/* For BE2, BE3 and BE3-R */
Sathya Perlaca34fe32012-11-06 17:48:56 +00003701static int be_flash_BEx(struct be_adapter *adapter,
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00003702 const struct firmware *fw,
3703 struct be_dma_mem *flash_cmd,
3704 int num_of_images)
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00003705
Ajit Khaparde84517482009-09-04 03:12:16 +00003706{
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00003707 int status = 0, i, filehdr_size = 0;
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00003708 int img_hdrs_size = (num_of_images * sizeof(struct image_hdr));
Ajit Khaparde84517482009-09-04 03:12:16 +00003709 const u8 *p = fw->data;
Joe Perches215faf92010-12-21 02:16:10 -08003710 const struct flash_comp *pflashcomp;
Padmanabh Ratnakar773a2d72012-10-20 06:04:16 +00003711 int num_comp, redboot;
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00003712 struct flash_section_info *fsec = NULL;
Ajit Khaparde84517482009-09-04 03:12:16 +00003713
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00003714 struct flash_comp gen3_flash_types[] = {
3715 { FLASH_iSCSI_PRIMARY_IMAGE_START_g3, OPTYPE_ISCSI_ACTIVE,
3716 FLASH_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_iSCSI},
3717 { FLASH_REDBOOT_START_g3, OPTYPE_REDBOOT,
3718 FLASH_REDBOOT_IMAGE_MAX_SIZE_g3, IMAGE_BOOT_CODE},
3719 { FLASH_iSCSI_BIOS_START_g3, OPTYPE_BIOS,
3720 FLASH_BIOS_IMAGE_MAX_SIZE_g3, IMAGE_OPTION_ROM_ISCSI},
3721 { FLASH_PXE_BIOS_START_g3, OPTYPE_PXE_BIOS,
3722 FLASH_BIOS_IMAGE_MAX_SIZE_g3, IMAGE_OPTION_ROM_PXE},
3723 { FLASH_FCoE_BIOS_START_g3, OPTYPE_FCOE_BIOS,
3724 FLASH_BIOS_IMAGE_MAX_SIZE_g3, IMAGE_OPTION_ROM_FCoE},
3725 { FLASH_iSCSI_BACKUP_IMAGE_START_g3, OPTYPE_ISCSI_BACKUP,
3726 FLASH_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_BACKUP_iSCSI},
3727 { FLASH_FCoE_PRIMARY_IMAGE_START_g3, OPTYPE_FCOE_FW_ACTIVE,
3728 FLASH_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_FCoE},
3729 { FLASH_FCoE_BACKUP_IMAGE_START_g3, OPTYPE_FCOE_FW_BACKUP,
3730 FLASH_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_BACKUP_FCoE},
3731 { FLASH_NCSI_START_g3, OPTYPE_NCSI_FW,
3732 FLASH_NCSI_IMAGE_MAX_SIZE_g3, IMAGE_NCSI},
3733 { FLASH_PHY_FW_START_g3, OPTYPE_PHY_FW,
3734 FLASH_PHY_FW_IMAGE_MAX_SIZE_g3, IMAGE_FIRMWARE_PHY}
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00003735 };
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00003736
3737 struct flash_comp gen2_flash_types[] = {
3738 { FLASH_iSCSI_PRIMARY_IMAGE_START_g2, OPTYPE_ISCSI_ACTIVE,
3739 FLASH_IMAGE_MAX_SIZE_g2, IMAGE_FIRMWARE_iSCSI},
3740 { FLASH_REDBOOT_START_g2, OPTYPE_REDBOOT,
3741 FLASH_REDBOOT_IMAGE_MAX_SIZE_g2, IMAGE_BOOT_CODE},
3742 { FLASH_iSCSI_BIOS_START_g2, OPTYPE_BIOS,
3743 FLASH_BIOS_IMAGE_MAX_SIZE_g2, IMAGE_OPTION_ROM_ISCSI},
3744 { FLASH_PXE_BIOS_START_g2, OPTYPE_PXE_BIOS,
3745 FLASH_BIOS_IMAGE_MAX_SIZE_g2, IMAGE_OPTION_ROM_PXE},
3746 { FLASH_FCoE_BIOS_START_g2, OPTYPE_FCOE_BIOS,
3747 FLASH_BIOS_IMAGE_MAX_SIZE_g2, IMAGE_OPTION_ROM_FCoE},
3748 { FLASH_iSCSI_BACKUP_IMAGE_START_g2, OPTYPE_ISCSI_BACKUP,
3749 FLASH_IMAGE_MAX_SIZE_g2, IMAGE_FIRMWARE_BACKUP_iSCSI},
3750 { FLASH_FCoE_PRIMARY_IMAGE_START_g2, OPTYPE_FCOE_FW_ACTIVE,
3751 FLASH_IMAGE_MAX_SIZE_g2, IMAGE_FIRMWARE_FCoE},
3752 { FLASH_FCoE_BACKUP_IMAGE_START_g2, OPTYPE_FCOE_FW_BACKUP,
3753 FLASH_IMAGE_MAX_SIZE_g2, IMAGE_FIRMWARE_BACKUP_FCoE}
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00003754 };
3755
Sathya Perlaca34fe32012-11-06 17:48:56 +00003756 if (BE3_chip(adapter)) {
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00003757 pflashcomp = gen3_flash_types;
3758 filehdr_size = sizeof(struct flash_file_hdr_g3);
Joe Perches215faf92010-12-21 02:16:10 -08003759 num_comp = ARRAY_SIZE(gen3_flash_types);
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00003760 } else {
3761 pflashcomp = gen2_flash_types;
3762 filehdr_size = sizeof(struct flash_file_hdr_g2);
Joe Perches215faf92010-12-21 02:16:10 -08003763 num_comp = ARRAY_SIZE(gen2_flash_types);
Ajit Khaparde84517482009-09-04 03:12:16 +00003764 }
Sathya Perlaca34fe32012-11-06 17:48:56 +00003765
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00003766 /* Get flash section info*/
3767 fsec = get_fsec_info(adapter, filehdr_size + img_hdrs_size, fw);
3768 if (!fsec) {
3769 dev_err(&adapter->pdev->dev,
3770 "Invalid Cookie. UFI corrupted ?\n");
3771 return -1;
3772 }
Sarveshwar Bandi9fe96932010-03-02 22:37:28 +00003773 for (i = 0; i < num_comp; i++) {
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00003774 if (!is_comp_in_ufi(adapter, fsec, pflashcomp[i].img_type))
Sarveshwar Bandi9fe96932010-03-02 22:37:28 +00003775 continue;
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00003776
3777 if ((pflashcomp[i].optype == OPTYPE_NCSI_FW) &&
3778 memcmp(adapter->fw_ver, "3.102.148.0", 11) < 0)
3779 continue;
3780
Padmanabh Ratnakar773a2d72012-10-20 06:04:16 +00003781 if (pflashcomp[i].optype == OPTYPE_PHY_FW &&
3782 !phy_flashing_required(adapter))
3783 continue;
3784
3785 if (pflashcomp[i].optype == OPTYPE_REDBOOT) {
3786 redboot = be_flash_redboot(adapter, fw->data,
3787 pflashcomp[i].offset, pflashcomp[i].size,
3788 filehdr_size + img_hdrs_size);
3789 if (!redboot)
Sathya Perla306f1342011-08-02 19:57:45 +00003790 continue;
3791 }
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00003792
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00003793 p = fw->data;
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00003794 p += filehdr_size + pflashcomp[i].offset + img_hdrs_size;
Sathya Perla306f1342011-08-02 19:57:45 +00003795 if (p + pflashcomp[i].size > fw->data + fw->size)
3796 return -1;
Padmanabh Ratnakar773a2d72012-10-20 06:04:16 +00003797
3798 status = be_flash(adapter, p, flash_cmd, pflashcomp[i].optype,
3799 pflashcomp[i].size);
3800 if (status) {
3801 dev_err(&adapter->pdev->dev,
3802 "Flashing section type %d failed.\n",
3803 pflashcomp[i].img_type);
3804 return status;
Ajit Khaparde84517482009-09-04 03:12:16 +00003805 }
Ajit Khaparde84517482009-09-04 03:12:16 +00003806 }
Ajit Khaparde84517482009-09-04 03:12:16 +00003807 return 0;
3808}
3809
Padmanabh Ratnakar773a2d72012-10-20 06:04:16 +00003810static int be_flash_skyhawk(struct be_adapter *adapter,
3811 const struct firmware *fw,
3812 struct be_dma_mem *flash_cmd, int num_of_images)
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00003813{
Padmanabh Ratnakar773a2d72012-10-20 06:04:16 +00003814 int status = 0, i, filehdr_size = 0;
3815 int img_offset, img_size, img_optype, redboot;
3816 int img_hdrs_size = num_of_images * sizeof(struct image_hdr);
3817 const u8 *p = fw->data;
3818 struct flash_section_info *fsec = NULL;
3819
3820 filehdr_size = sizeof(struct flash_file_hdr_g3);
3821 fsec = get_fsec_info(adapter, filehdr_size + img_hdrs_size, fw);
3822 if (!fsec) {
3823 dev_err(&adapter->pdev->dev,
3824 "Invalid Cookie. UFI corrupted ?\n");
3825 return -1;
3826 }
3827
3828 for (i = 0; i < le32_to_cpu(fsec->fsec_hdr.num_images); i++) {
3829 img_offset = le32_to_cpu(fsec->fsec_entry[i].offset);
3830 img_size = le32_to_cpu(fsec->fsec_entry[i].pad_size);
3831
3832 switch (le32_to_cpu(fsec->fsec_entry[i].type)) {
3833 case IMAGE_FIRMWARE_iSCSI:
3834 img_optype = OPTYPE_ISCSI_ACTIVE;
3835 break;
3836 case IMAGE_BOOT_CODE:
3837 img_optype = OPTYPE_REDBOOT;
3838 break;
3839 case IMAGE_OPTION_ROM_ISCSI:
3840 img_optype = OPTYPE_BIOS;
3841 break;
3842 case IMAGE_OPTION_ROM_PXE:
3843 img_optype = OPTYPE_PXE_BIOS;
3844 break;
3845 case IMAGE_OPTION_ROM_FCoE:
3846 img_optype = OPTYPE_FCOE_BIOS;
3847 break;
3848 case IMAGE_FIRMWARE_BACKUP_iSCSI:
3849 img_optype = OPTYPE_ISCSI_BACKUP;
3850 break;
3851 case IMAGE_NCSI:
3852 img_optype = OPTYPE_NCSI_FW;
3853 break;
3854 default:
3855 continue;
3856 }
3857
3858 if (img_optype == OPTYPE_REDBOOT) {
3859 redboot = be_flash_redboot(adapter, fw->data,
3860 img_offset, img_size,
3861 filehdr_size + img_hdrs_size);
3862 if (!redboot)
3863 continue;
3864 }
3865
3866 p = fw->data;
3867 p += filehdr_size + img_offset + img_hdrs_size;
3868 if (p + img_size > fw->data + fw->size)
3869 return -1;
3870
3871 status = be_flash(adapter, p, flash_cmd, img_optype, img_size);
3872 if (status) {
3873 dev_err(&adapter->pdev->dev,
3874 "Flashing section type %d failed.\n",
3875 fsec->fsec_entry[i].type);
3876 return status;
3877 }
3878 }
3879 return 0;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00003880}
3881
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00003882static int lancer_fw_download(struct be_adapter *adapter,
3883 const struct firmware *fw)
Ajit Khaparde84517482009-09-04 03:12:16 +00003884{
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00003885#define LANCER_FW_DOWNLOAD_CHUNK (32 * 1024)
3886#define LANCER_FW_DOWNLOAD_LOCATION "/prg"
3887 struct be_dma_mem flash_cmd;
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00003888 const u8 *data_ptr = NULL;
3889 u8 *dest_image_ptr = NULL;
3890 size_t image_size = 0;
3891 u32 chunk_size = 0;
3892 u32 data_written = 0;
3893 u32 offset = 0;
3894 int status = 0;
3895 u8 add_status = 0;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00003896 u8 change_status;
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00003897
3898 if (!IS_ALIGNED(fw->size, sizeof(u32))) {
3899 dev_err(&adapter->pdev->dev,
3900 "FW Image not properly aligned. "
3901 "Length must be 4 byte aligned.\n");
3902 status = -EINVAL;
3903 goto lancer_fw_exit;
3904 }
3905
3906 flash_cmd.size = sizeof(struct lancer_cmd_req_write_object)
3907 + LANCER_FW_DOWNLOAD_CHUNK;
3908 flash_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, flash_cmd.size,
Joe Perchesd0320f72013-03-14 13:07:21 +00003909 &flash_cmd.dma, GFP_KERNEL);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00003910 if (!flash_cmd.va) {
3911 status = -ENOMEM;
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00003912 goto lancer_fw_exit;
3913 }
3914
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00003915 dest_image_ptr = flash_cmd.va +
3916 sizeof(struct lancer_cmd_req_write_object);
3917 image_size = fw->size;
3918 data_ptr = fw->data;
3919
3920 while (image_size) {
3921 chunk_size = min_t(u32, image_size, LANCER_FW_DOWNLOAD_CHUNK);
3922
3923 /* Copy the image chunk content. */
3924 memcpy(dest_image_ptr, data_ptr, chunk_size);
3925
3926 status = lancer_cmd_write_object(adapter, &flash_cmd,
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00003927 chunk_size, offset,
3928 LANCER_FW_DOWNLOAD_LOCATION,
3929 &data_written, &change_status,
3930 &add_status);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00003931 if (status)
3932 break;
3933
3934 offset += data_written;
3935 data_ptr += data_written;
3936 image_size -= data_written;
3937 }
3938
3939 if (!status) {
3940 /* Commit the FW written */
3941 status = lancer_cmd_write_object(adapter, &flash_cmd,
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00003942 0, offset,
3943 LANCER_FW_DOWNLOAD_LOCATION,
3944 &data_written, &change_status,
3945 &add_status);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00003946 }
3947
3948 dma_free_coherent(&adapter->pdev->dev, flash_cmd.size, flash_cmd.va,
3949 flash_cmd.dma);
3950 if (status) {
3951 dev_err(&adapter->pdev->dev,
3952 "Firmware load error. "
3953 "Status code: 0x%x Additional Status: 0x%x\n",
3954 status, add_status);
3955 goto lancer_fw_exit;
3956 }
3957
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00003958 if (change_status == LANCER_FW_RESET_NEEDED) {
Somnath Kotur4bebb562013-12-05 12:07:55 +05303959 dev_info(&adapter->pdev->dev,
3960 "Resetting adapter to activate new FW\n");
Somnath Kotur5c510812013-05-30 02:52:23 +00003961 status = lancer_physdev_ctrl(adapter,
3962 PHYSDEV_CONTROL_FW_RESET_MASK);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00003963 if (status) {
3964 dev_err(&adapter->pdev->dev,
3965 "Adapter busy for FW reset.\n"
3966 "New FW will not be active.\n");
3967 goto lancer_fw_exit;
3968 }
3969 } else if (change_status != LANCER_NO_RESET_NEEDED) {
3970 dev_err(&adapter->pdev->dev,
3971 "System reboot required for new FW"
3972 " to be active\n");
3973 }
3974
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00003975 dev_info(&adapter->pdev->dev, "Firmware flashed successfully\n");
3976lancer_fw_exit:
3977 return status;
3978}
3979
Sathya Perlaca34fe32012-11-06 17:48:56 +00003980#define UFI_TYPE2 2
3981#define UFI_TYPE3 3
Vasundhara Volam0ad31572013-04-21 23:28:16 +00003982#define UFI_TYPE3R 10
Sathya Perlaca34fe32012-11-06 17:48:56 +00003983#define UFI_TYPE4 4
3984static int be_get_ufi_type(struct be_adapter *adapter,
Vasundhara Volam0ad31572013-04-21 23:28:16 +00003985 struct flash_file_hdr_g3 *fhdr)
Padmanabh Ratnakar773a2d72012-10-20 06:04:16 +00003986{
3987 if (fhdr == NULL)
3988 goto be_get_ufi_exit;
3989
Sathya Perlaca34fe32012-11-06 17:48:56 +00003990 if (skyhawk_chip(adapter) && fhdr->build[0] == '4')
3991 return UFI_TYPE4;
Vasundhara Volam0ad31572013-04-21 23:28:16 +00003992 else if (BE3_chip(adapter) && fhdr->build[0] == '3') {
3993 if (fhdr->asic_type_rev == 0x10)
3994 return UFI_TYPE3R;
3995 else
3996 return UFI_TYPE3;
3997 } else if (BE2_chip(adapter) && fhdr->build[0] == '2')
Sathya Perlaca34fe32012-11-06 17:48:56 +00003998 return UFI_TYPE2;
Padmanabh Ratnakar773a2d72012-10-20 06:04:16 +00003999
4000be_get_ufi_exit:
4001 dev_err(&adapter->pdev->dev,
4002 "UFI and Interface are not compatible for flashing\n");
4003 return -1;
4004}
4005
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00004006static int be_fw_download(struct be_adapter *adapter, const struct firmware* fw)
4007{
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00004008 struct flash_file_hdr_g3 *fhdr3;
4009 struct image_hdr *img_hdr_ptr = NULL;
Ajit Khaparde84517482009-09-04 03:12:16 +00004010 struct be_dma_mem flash_cmd;
Ajit Khaparde84517482009-09-04 03:12:16 +00004011 const u8 *p;
Padmanabh Ratnakar773a2d72012-10-20 06:04:16 +00004012 int status = 0, i = 0, num_imgs = 0, ufi_type = 0;
Ajit Khaparde84517482009-09-04 03:12:16 +00004013
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00004014 flash_cmd.size = sizeof(struct be_cmd_write_flashrom);
Ivan Vecera2b7bceb2011-02-02 08:05:12 +00004015 flash_cmd.va = dma_alloc_coherent(&adapter->pdev->dev, flash_cmd.size,
4016 &flash_cmd.dma, GFP_KERNEL);
Ajit Khaparde84517482009-09-04 03:12:16 +00004017 if (!flash_cmd.va) {
4018 status = -ENOMEM;
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00004019 goto be_fw_exit;
Ajit Khaparde84517482009-09-04 03:12:16 +00004020 }
4021
Padmanabh Ratnakar773a2d72012-10-20 06:04:16 +00004022 p = fw->data;
Vasundhara Volam0ad31572013-04-21 23:28:16 +00004023 fhdr3 = (struct flash_file_hdr_g3 *)p;
Padmanabh Ratnakar773a2d72012-10-20 06:04:16 +00004024
Vasundhara Volam0ad31572013-04-21 23:28:16 +00004025 ufi_type = be_get_ufi_type(adapter, fhdr3);
Padmanabh Ratnakar773a2d72012-10-20 06:04:16 +00004026
Padmanabh Ratnakar773a2d72012-10-20 06:04:16 +00004027 num_imgs = le32_to_cpu(fhdr3->num_imgs);
4028 for (i = 0; i < num_imgs; i++) {
4029 img_hdr_ptr = (struct image_hdr *)(fw->data +
4030 (sizeof(struct flash_file_hdr_g3) +
4031 i * sizeof(struct image_hdr)));
4032 if (le32_to_cpu(img_hdr_ptr->imageid) == 1) {
Vasundhara Volam0ad31572013-04-21 23:28:16 +00004033 switch (ufi_type) {
4034 case UFI_TYPE4:
Padmanabh Ratnakar773a2d72012-10-20 06:04:16 +00004035 status = be_flash_skyhawk(adapter, fw,
4036 &flash_cmd, num_imgs);
Vasundhara Volam0ad31572013-04-21 23:28:16 +00004037 break;
4038 case UFI_TYPE3R:
Sathya Perlaca34fe32012-11-06 17:48:56 +00004039 status = be_flash_BEx(adapter, fw, &flash_cmd,
4040 num_imgs);
Vasundhara Volam0ad31572013-04-21 23:28:16 +00004041 break;
4042 case UFI_TYPE3:
4043 /* Do not flash this ufi on BE3-R cards */
4044 if (adapter->asic_rev < 0x10)
4045 status = be_flash_BEx(adapter, fw,
4046 &flash_cmd,
4047 num_imgs);
4048 else {
4049 status = -1;
4050 dev_err(&adapter->pdev->dev,
4051 "Can't load BE3 UFI on BE3R\n");
4052 }
4053 }
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00004054 }
Ajit Khaparde84517482009-09-04 03:12:16 +00004055 }
4056
Sathya Perlaca34fe32012-11-06 17:48:56 +00004057 if (ufi_type == UFI_TYPE2)
4058 status = be_flash_BEx(adapter, fw, &flash_cmd, 0);
Padmanabh Ratnakar773a2d72012-10-20 06:04:16 +00004059 else if (ufi_type == -1)
4060 status = -1;
4061
Ivan Vecera2b7bceb2011-02-02 08:05:12 +00004062 dma_free_coherent(&adapter->pdev->dev, flash_cmd.size, flash_cmd.va,
4063 flash_cmd.dma);
Ajit Khaparde84517482009-09-04 03:12:16 +00004064 if (status) {
4065 dev_err(&adapter->pdev->dev, "Firmware load error\n");
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00004066 goto be_fw_exit;
Ajit Khaparde84517482009-09-04 03:12:16 +00004067 }
4068
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004069 dev_info(&adapter->pdev->dev, "Firmware flashed successfully\n");
Ajit Khaparde84517482009-09-04 03:12:16 +00004070
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00004071be_fw_exit:
4072 return status;
4073}
4074
4075int be_load_fw(struct be_adapter *adapter, u8 *fw_file)
4076{
4077 const struct firmware *fw;
4078 int status;
4079
4080 if (!netif_running(adapter->netdev)) {
4081 dev_err(&adapter->pdev->dev,
4082 "Firmware load not allowed (interface is down)\n");
4083 return -1;
4084 }
4085
4086 status = request_firmware(&fw, fw_file, &adapter->pdev->dev);
4087 if (status)
4088 goto fw_exit;
4089
4090 dev_info(&adapter->pdev->dev, "Flashing firmware file %s\n", fw_file);
4091
4092 if (lancer_chip(adapter))
4093 status = lancer_fw_download(adapter, fw);
4094 else
4095 status = be_fw_download(adapter, fw);
4096
Somnath Kotureeb65ce2013-05-26 21:08:36 +00004097 if (!status)
4098 be_cmd_get_fw_ver(adapter, adapter->fw_ver,
4099 adapter->fw_on_flash);
4100
Ajit Khaparde84517482009-09-04 03:12:16 +00004101fw_exit:
4102 release_firmware(fw);
4103 return status;
4104}
4105
Ajit Khapardea77dcb82013-08-30 15:01:16 -05004106static int be_ndo_bridge_setlink(struct net_device *dev,
4107 struct nlmsghdr *nlh)
4108{
4109 struct be_adapter *adapter = netdev_priv(dev);
4110 struct nlattr *attr, *br_spec;
4111 int rem;
4112 int status = 0;
4113 u16 mode = 0;
4114
4115 if (!sriov_enabled(adapter))
4116 return -EOPNOTSUPP;
4117
4118 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
4119
4120 nla_for_each_nested(attr, br_spec, rem) {
4121 if (nla_type(attr) != IFLA_BRIDGE_MODE)
4122 continue;
4123
4124 mode = nla_get_u16(attr);
4125 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
4126 return -EINVAL;
4127
4128 status = be_cmd_set_hsw_config(adapter, 0, 0,
4129 adapter->if_handle,
4130 mode == BRIDGE_MODE_VEPA ?
4131 PORT_FWD_TYPE_VEPA :
4132 PORT_FWD_TYPE_VEB);
4133 if (status)
4134 goto err;
4135
4136 dev_info(&adapter->pdev->dev, "enabled switch mode: %s\n",
4137 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
4138
4139 return status;
4140 }
4141err:
4142 dev_err(&adapter->pdev->dev, "Failed to set switch mode %s\n",
4143 mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
4144
4145 return status;
4146}
4147
4148static int be_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
4149 struct net_device *dev,
4150 u32 filter_mask)
4151{
4152 struct be_adapter *adapter = netdev_priv(dev);
4153 int status = 0;
4154 u8 hsw_mode;
4155
4156 if (!sriov_enabled(adapter))
4157 return 0;
4158
4159 /* BE and Lancer chips support VEB mode only */
4160 if (BEx_chip(adapter) || lancer_chip(adapter)) {
4161 hsw_mode = PORT_FWD_TYPE_VEB;
4162 } else {
4163 status = be_cmd_get_hsw_config(adapter, NULL, 0,
4164 adapter->if_handle, &hsw_mode);
4165 if (status)
4166 return 0;
4167 }
4168
4169 return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
4170 hsw_mode == PORT_FWD_TYPE_VEPA ?
4171 BRIDGE_MODE_VEPA : BRIDGE_MODE_VEB);
4172}
4173
Sathya Perlac5abe7c2014-04-01 12:33:59 +05304174#ifdef CONFIG_BE2NET_VXLAN
Sathya Perlac9c47142014-03-27 10:46:19 +05304175static void be_add_vxlan_port(struct net_device *netdev, sa_family_t sa_family,
4176 __be16 port)
4177{
4178 struct be_adapter *adapter = netdev_priv(netdev);
4179 struct device *dev = &adapter->pdev->dev;
4180 int status;
4181
4182 if (lancer_chip(adapter) || BEx_chip(adapter))
4183 return;
4184
4185 if (adapter->flags & BE_FLAGS_VXLAN_OFFLOADS) {
4186 dev_warn(dev, "Cannot add UDP port %d for VxLAN offloads\n",
4187 be16_to_cpu(port));
4188 dev_info(dev,
4189 "Only one UDP port supported for VxLAN offloads\n");
4190 return;
4191 }
4192
4193 status = be_cmd_manage_iface(adapter, adapter->if_handle,
4194 OP_CONVERT_NORMAL_TO_TUNNEL);
4195 if (status) {
4196 dev_warn(dev, "Failed to convert normal interface to tunnel\n");
4197 goto err;
4198 }
4199
4200 status = be_cmd_set_vxlan_port(adapter, port);
4201 if (status) {
4202 dev_warn(dev, "Failed to add VxLAN port\n");
4203 goto err;
4204 }
4205 adapter->flags |= BE_FLAGS_VXLAN_OFFLOADS;
4206 adapter->vxlan_port = port;
4207
4208 dev_info(dev, "Enabled VxLAN offloads for UDP port %d\n",
4209 be16_to_cpu(port));
4210 return;
4211err:
4212 be_disable_vxlan_offloads(adapter);
4213 return;
4214}
4215
4216static void be_del_vxlan_port(struct net_device *netdev, sa_family_t sa_family,
4217 __be16 port)
4218{
4219 struct be_adapter *adapter = netdev_priv(netdev);
4220
4221 if (lancer_chip(adapter) || BEx_chip(adapter))
4222 return;
4223
4224 if (adapter->vxlan_port != port)
4225 return;
4226
4227 be_disable_vxlan_offloads(adapter);
4228
4229 dev_info(&adapter->pdev->dev,
4230 "Disabled VxLAN offloads for UDP port %d\n",
4231 be16_to_cpu(port));
4232}
Sathya Perlac5abe7c2014-04-01 12:33:59 +05304233#endif
Sathya Perlac9c47142014-03-27 10:46:19 +05304234
stephen hemmingere5686ad2012-01-05 19:10:25 +00004235static const struct net_device_ops be_netdev_ops = {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004236 .ndo_open = be_open,
4237 .ndo_stop = be_close,
4238 .ndo_start_xmit = be_xmit,
Sathya Perlaa54769f2011-10-24 02:45:00 +00004239 .ndo_set_rx_mode = be_set_rx_mode,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004240 .ndo_set_mac_address = be_mac_addr_set,
4241 .ndo_change_mtu = be_change_mtu,
Sathya Perlaab1594e2011-07-25 19:10:15 +00004242 .ndo_get_stats64 = be_get_stats64,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004243 .ndo_validate_addr = eth_validate_addr,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004244 .ndo_vlan_rx_add_vid = be_vlan_add_vid,
4245 .ndo_vlan_rx_kill_vid = be_vlan_rem_vid,
Ajit Khaparde64600ea2010-07-23 01:50:34 +00004246 .ndo_set_vf_mac = be_set_vf_mac,
Ajit Khaparde1da87b72010-07-23 01:51:22 +00004247 .ndo_set_vf_vlan = be_set_vf_vlan,
Ajit Khapardee1d18732010-07-23 01:52:13 +00004248 .ndo_set_vf_tx_rate = be_set_vf_tx_rate,
Ivan Vecera66268732011-12-08 01:31:21 +00004249 .ndo_get_vf_config = be_get_vf_config,
Suresh Reddybdce2ad2014-03-11 18:53:04 +05304250 .ndo_set_vf_link_state = be_set_vf_link_state,
Ivan Vecera66268732011-12-08 01:31:21 +00004251#ifdef CONFIG_NET_POLL_CONTROLLER
4252 .ndo_poll_controller = be_netpoll,
4253#endif
Ajit Khapardea77dcb82013-08-30 15:01:16 -05004254 .ndo_bridge_setlink = be_ndo_bridge_setlink,
4255 .ndo_bridge_getlink = be_ndo_bridge_getlink,
Sathya Perla6384a4d2013-10-25 10:40:16 +05304256#ifdef CONFIG_NET_RX_BUSY_POLL
Sathya Perlac9c47142014-03-27 10:46:19 +05304257 .ndo_busy_poll = be_busy_poll,
Sathya Perla6384a4d2013-10-25 10:40:16 +05304258#endif
Sathya Perlac5abe7c2014-04-01 12:33:59 +05304259#ifdef CONFIG_BE2NET_VXLAN
Sathya Perlac9c47142014-03-27 10:46:19 +05304260 .ndo_add_vxlan_port = be_add_vxlan_port,
4261 .ndo_del_vxlan_port = be_del_vxlan_port,
Sathya Perlac5abe7c2014-04-01 12:33:59 +05304262#endif
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004263};
4264
4265static void be_netdev_init(struct net_device *netdev)
4266{
4267 struct be_adapter *adapter = netdev_priv(netdev);
4268
Sathya Perlac9c47142014-03-27 10:46:19 +05304269 if (skyhawk_chip(adapter)) {
4270 netdev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
4271 NETIF_F_TSO | NETIF_F_TSO6 |
4272 NETIF_F_GSO_UDP_TUNNEL;
4273 netdev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
4274 }
Michał Mirosław6332c8d2011-04-07 02:43:48 +00004275 netdev->hw_features |= NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 |
Michał Mirosław8b8ddc62011-04-08 02:38:47 +00004276 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_RXCSUM |
Patrick McHardyf6469682013-04-19 02:04:27 +00004277 NETIF_F_HW_VLAN_CTAG_TX;
Michał Mirosław8b8ddc62011-04-08 02:38:47 +00004278 if (be_multi_rxq(adapter))
4279 netdev->hw_features |= NETIF_F_RXHASH;
Michał Mirosław6332c8d2011-04-07 02:43:48 +00004280
4281 netdev->features |= netdev->hw_features |
Patrick McHardyf6469682013-04-19 02:04:27 +00004282 NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_FILTER;
Ajit Khaparde4b972912011-04-06 18:07:43 +00004283
Padmanabh Ratnakareb8a50d2011-06-11 15:58:46 -07004284 netdev->vlan_features |= NETIF_F_SG | NETIF_F_TSO | NETIF_F_TSO6 |
Michał Mirosław79032642010-11-30 06:38:00 +00004285 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
Ajit Khaparde51c59872009-11-29 17:54:54 +00004286
Ajit Khapardefbc13f02012-03-18 06:23:21 +00004287 netdev->priv_flags |= IFF_UNICAST_FLT;
4288
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004289 netdev->flags |= IFF_MULTICAST;
4290
Sarveshwar Bandib7e58872012-06-13 19:51:43 +00004291 netif_set_gso_max_size(netdev, 65535 - ETH_HLEN);
Ajit Khapardec190e3c2009-09-04 03:12:29 +00004292
Sathya Perla10ef9ab2012-02-09 18:05:27 +00004293 netdev->netdev_ops = &be_netdev_ops;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004294
4295 SET_ETHTOOL_OPS(netdev, &be_ethtool_ops);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004296}
4297
4298static void be_unmap_pci_bars(struct be_adapter *adapter)
4299{
Sathya Perlac5b3ad42013-03-05 22:23:20 +00004300 if (adapter->csr)
4301 pci_iounmap(adapter->pdev, adapter->csr);
Sathya Perla8788fdc2009-07-27 22:52:03 +00004302 if (adapter->db)
Sathya Perlace66f782012-11-06 17:48:58 +00004303 pci_iounmap(adapter->pdev, adapter->db);
Parav Pandit045508a2012-03-26 14:27:13 +00004304}
4305
Sathya Perlace66f782012-11-06 17:48:58 +00004306static int db_bar(struct be_adapter *adapter)
4307{
4308 if (lancer_chip(adapter) || !be_physfn(adapter))
4309 return 0;
4310 else
4311 return 4;
4312}
4313
4314static int be_roce_map_pci_bars(struct be_adapter *adapter)
Parav Pandit045508a2012-03-26 14:27:13 +00004315{
Sathya Perladbf0f2a2012-11-06 17:49:00 +00004316 if (skyhawk_chip(adapter)) {
Sathya Perlace66f782012-11-06 17:48:58 +00004317 adapter->roce_db.size = 4096;
4318 adapter->roce_db.io_addr = pci_resource_start(adapter->pdev,
4319 db_bar(adapter));
4320 adapter->roce_db.total_size = pci_resource_len(adapter->pdev,
4321 db_bar(adapter));
4322 }
Parav Pandit045508a2012-03-26 14:27:13 +00004323 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004324}
4325
4326static int be_map_pci_bars(struct be_adapter *adapter)
4327{
4328 u8 __iomem *addr;
Sathya Perlafe6d2a32010-11-21 23:25:50 +00004329
Sathya Perlac5b3ad42013-03-05 22:23:20 +00004330 if (BEx_chip(adapter) && be_physfn(adapter)) {
4331 adapter->csr = pci_iomap(adapter->pdev, 2, 0);
4332 if (adapter->csr == NULL)
4333 return -ENOMEM;
4334 }
4335
Sathya Perlace66f782012-11-06 17:48:58 +00004336 addr = pci_iomap(adapter->pdev, db_bar(adapter), 0);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004337 if (addr == NULL)
4338 goto pci_map_err;
Sathya Perla8788fdc2009-07-27 22:52:03 +00004339 adapter->db = addr;
Sathya Perlace66f782012-11-06 17:48:58 +00004340
4341 be_roce_map_pci_bars(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004342 return 0;
Sathya Perlace66f782012-11-06 17:48:58 +00004343
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004344pci_map_err:
4345 be_unmap_pci_bars(adapter);
4346 return -ENOMEM;
4347}
4348
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004349static void be_ctrl_cleanup(struct be_adapter *adapter)
4350{
Sathya Perla8788fdc2009-07-27 22:52:03 +00004351 struct be_dma_mem *mem = &adapter->mbox_mem_alloced;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004352
4353 be_unmap_pci_bars(adapter);
4354
4355 if (mem->va)
Ivan Vecera2b7bceb2011-02-02 08:05:12 +00004356 dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va,
4357 mem->dma);
Sathya Perlae7b909a2009-11-22 22:01:10 +00004358
Sathya Perla5b8821b2011-08-02 19:57:44 +00004359 mem = &adapter->rx_filter;
Sathya Perlae7b909a2009-11-22 22:01:10 +00004360 if (mem->va)
Ivan Vecera2b7bceb2011-02-02 08:05:12 +00004361 dma_free_coherent(&adapter->pdev->dev, mem->size, mem->va,
4362 mem->dma);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004363}
4364
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004365static int be_ctrl_init(struct be_adapter *adapter)
4366{
Sathya Perla8788fdc2009-07-27 22:52:03 +00004367 struct be_dma_mem *mbox_mem_alloc = &adapter->mbox_mem_alloced;
4368 struct be_dma_mem *mbox_mem_align = &adapter->mbox_mem;
Sathya Perla5b8821b2011-08-02 19:57:44 +00004369 struct be_dma_mem *rx_filter = &adapter->rx_filter;
Sathya Perlace66f782012-11-06 17:48:58 +00004370 u32 sli_intf;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004371 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004372
Sathya Perlace66f782012-11-06 17:48:58 +00004373 pci_read_config_dword(adapter->pdev, SLI_INTF_REG_OFFSET, &sli_intf);
4374 adapter->sli_family = (sli_intf & SLI_INTF_FAMILY_MASK) >>
4375 SLI_INTF_FAMILY_SHIFT;
4376 adapter->virtfn = (sli_intf & SLI_INTF_FT_MASK) ? 1 : 0;
4377
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004378 status = be_map_pci_bars(adapter);
4379 if (status)
Sathya Perlae7b909a2009-11-22 22:01:10 +00004380 goto done;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004381
4382 mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
Ivan Vecera2b7bceb2011-02-02 08:05:12 +00004383 mbox_mem_alloc->va = dma_alloc_coherent(&adapter->pdev->dev,
4384 mbox_mem_alloc->size,
4385 &mbox_mem_alloc->dma,
4386 GFP_KERNEL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004387 if (!mbox_mem_alloc->va) {
Sathya Perlae7b909a2009-11-22 22:01:10 +00004388 status = -ENOMEM;
4389 goto unmap_pci_bars;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004390 }
4391 mbox_mem_align->size = sizeof(struct be_mcc_mailbox);
4392 mbox_mem_align->va = PTR_ALIGN(mbox_mem_alloc->va, 16);
4393 mbox_mem_align->dma = PTR_ALIGN(mbox_mem_alloc->dma, 16);
4394 memset(mbox_mem_align->va, 0, sizeof(struct be_mcc_mailbox));
Sathya Perlae7b909a2009-11-22 22:01:10 +00004395
Sathya Perla5b8821b2011-08-02 19:57:44 +00004396 rx_filter->size = sizeof(struct be_cmd_req_rx_filter);
Joe Perchesede23fa2013-08-26 22:45:23 -07004397 rx_filter->va = dma_zalloc_coherent(&adapter->pdev->dev,
4398 rx_filter->size, &rx_filter->dma,
4399 GFP_KERNEL);
Sathya Perla5b8821b2011-08-02 19:57:44 +00004400 if (rx_filter->va == NULL) {
Sathya Perlae7b909a2009-11-22 22:01:10 +00004401 status = -ENOMEM;
4402 goto free_mbox;
4403 }
Joe Perches1f9061d22013-03-15 07:23:58 +00004404
Ivan Vecera29849612010-12-14 05:43:19 +00004405 mutex_init(&adapter->mbox_lock);
Sathya Perla8788fdc2009-07-27 22:52:03 +00004406 spin_lock_init(&adapter->mcc_lock);
4407 spin_lock_init(&adapter->mcc_cq_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004408
Suresh Reddy5eeff632014-01-06 13:02:24 +05304409 init_completion(&adapter->et_cmd_compl);
Sathya Perlacf588472010-02-14 21:22:01 +00004410 pci_save_state(adapter->pdev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004411 return 0;
Sathya Perlae7b909a2009-11-22 22:01:10 +00004412
4413free_mbox:
Ivan Vecera2b7bceb2011-02-02 08:05:12 +00004414 dma_free_coherent(&adapter->pdev->dev, mbox_mem_alloc->size,
4415 mbox_mem_alloc->va, mbox_mem_alloc->dma);
Sathya Perlae7b909a2009-11-22 22:01:10 +00004416
4417unmap_pci_bars:
4418 be_unmap_pci_bars(adapter);
4419
4420done:
4421 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004422}
4423
4424static void be_stats_cleanup(struct be_adapter *adapter)
4425{
Sathya Perla3abcded2010-10-03 22:12:27 -07004426 struct be_dma_mem *cmd = &adapter->stats_cmd;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004427
4428 if (cmd->va)
Ivan Vecera2b7bceb2011-02-02 08:05:12 +00004429 dma_free_coherent(&adapter->pdev->dev, cmd->size,
4430 cmd->va, cmd->dma);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004431}
4432
4433static int be_stats_init(struct be_adapter *adapter)
4434{
Sathya Perla3abcded2010-10-03 22:12:27 -07004435 struct be_dma_mem *cmd = &adapter->stats_cmd;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004436
Sathya Perlaca34fe32012-11-06 17:48:56 +00004437 if (lancer_chip(adapter))
4438 cmd->size = sizeof(struct lancer_cmd_req_pport_stats);
4439 else if (BE2_chip(adapter))
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00004440 cmd->size = sizeof(struct be_cmd_req_get_stats_v0);
Ajit Khaparde61000862013-10-03 16:16:33 -05004441 else if (BE3_chip(adapter))
Sathya Perlaca34fe32012-11-06 17:48:56 +00004442 cmd->size = sizeof(struct be_cmd_req_get_stats_v1);
Ajit Khaparde61000862013-10-03 16:16:33 -05004443 else
4444 /* ALL non-BE ASICs */
4445 cmd->size = sizeof(struct be_cmd_req_get_stats_v2);
Sathya Perlaca34fe32012-11-06 17:48:56 +00004446
Joe Perchesede23fa2013-08-26 22:45:23 -07004447 cmd->va = dma_zalloc_coherent(&adapter->pdev->dev, cmd->size, &cmd->dma,
4448 GFP_KERNEL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004449 if (cmd->va == NULL)
4450 return -1;
4451 return 0;
4452}
4453
Bill Pemberton3bc6b062012-12-03 09:23:09 -05004454static void be_remove(struct pci_dev *pdev)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004455{
4456 struct be_adapter *adapter = pci_get_drvdata(pdev);
Sathya Perla8d56ff12009-11-22 22:02:26 +00004457
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004458 if (!adapter)
4459 return;
4460
Parav Pandit045508a2012-03-26 14:27:13 +00004461 be_roce_dev_remove(adapter);
Somnath Kotur8cef7a72013-03-14 02:41:51 +00004462 be_intr_set(adapter, false);
Parav Pandit045508a2012-03-26 14:27:13 +00004463
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004464 cancel_delayed_work_sync(&adapter->func_recovery_work);
4465
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004466 unregister_netdev(adapter->netdev);
4467
Sathya Perla5fb379e2009-06-18 00:02:59 +00004468 be_clear(adapter);
4469
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00004470 /* tell fw we're done with firing cmds */
4471 be_cmd_fw_clean(adapter);
4472
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004473 be_stats_cleanup(adapter);
4474
4475 be_ctrl_cleanup(adapter);
4476
Sathya Perlad6b6d982012-09-05 01:56:48 +00004477 pci_disable_pcie_error_reporting(pdev);
4478
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004479 pci_release_regions(pdev);
4480 pci_disable_device(pdev);
4481
4482 free_netdev(adapter->netdev);
4483}
4484
Sathya Perla39f1d942012-05-08 19:41:24 +00004485static int be_get_initial_config(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004486{
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05304487 int status, level;
Sathya Perla43a04fdc2009-10-14 20:21:17 +00004488
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00004489 status = be_cmd_get_cntl_attributes(adapter);
4490 if (status)
4491 return status;
4492
Padmanabh Ratnakar7aeb2152012-07-12 03:56:46 +00004493 /* Must be a power of 2 or else MODULO will BUG_ON */
4494 adapter->be_get_temp_freq = 64;
4495
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05304496 if (BEx_chip(adapter)) {
4497 level = be_cmd_get_fw_log_level(adapter);
4498 adapter->msg_enable =
4499 level <= FW_LOG_LEVEL_DEFAULT ? NETIF_MSG_HW : 0;
4500 }
Somnath Kotur941a77d2012-05-17 22:59:03 +00004501
Sathya Perla92bf14a2013-08-27 16:57:32 +05304502 adapter->cfg_num_qs = netif_get_num_default_rss_queues();
Sathya Perla2243e2e2009-11-22 22:02:03 +00004503 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004504}
4505
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004506static int lancer_recover_func(struct be_adapter *adapter)
Padmanabh Ratnakard8110f62011-11-25 05:48:23 +00004507{
Somnath Kotur01e5b2c2013-05-29 22:56:17 +00004508 struct device *dev = &adapter->pdev->dev;
Padmanabh Ratnakard8110f62011-11-25 05:48:23 +00004509 int status;
Padmanabh Ratnakard8110f62011-11-25 05:48:23 +00004510
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004511 status = lancer_test_and_set_rdy_state(adapter);
4512 if (status)
4513 goto err;
Padmanabh Ratnakard8110f62011-11-25 05:48:23 +00004514
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004515 if (netif_running(adapter->netdev))
4516 be_close(adapter->netdev);
Padmanabh Ratnakard8110f62011-11-25 05:48:23 +00004517
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004518 be_clear(adapter);
Padmanabh Ratnakard8110f62011-11-25 05:48:23 +00004519
Somnath Kotur01e5b2c2013-05-29 22:56:17 +00004520 be_clear_all_error(adapter);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004521
4522 status = be_setup(adapter);
4523 if (status)
4524 goto err;
4525
4526 if (netif_running(adapter->netdev)) {
4527 status = be_open(adapter->netdev);
Padmanabh Ratnakard8110f62011-11-25 05:48:23 +00004528 if (status)
4529 goto err;
Padmanabh Ratnakard8110f62011-11-25 05:48:23 +00004530 }
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004531
Somnath Kotur4bebb562013-12-05 12:07:55 +05304532 dev_err(dev, "Adapter recovery successful\n");
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004533 return 0;
Padmanabh Ratnakard8110f62011-11-25 05:48:23 +00004534err:
Somnath Kotur01e5b2c2013-05-29 22:56:17 +00004535 if (status == -EAGAIN)
4536 dev_err(dev, "Waiting for resource provisioning\n");
4537 else
Somnath Kotur4bebb562013-12-05 12:07:55 +05304538 dev_err(dev, "Adapter recovery failed\n");
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004539
4540 return status;
4541}
4542
4543static void be_func_recovery_task(struct work_struct *work)
4544{
4545 struct be_adapter *adapter =
4546 container_of(work, struct be_adapter, func_recovery_work.work);
Somnath Kotur01e5b2c2013-05-29 22:56:17 +00004547 int status = 0;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004548
4549 be_detect_error(adapter);
4550
4551 if (adapter->hw_error && lancer_chip(adapter)) {
4552
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004553 rtnl_lock();
4554 netif_device_detach(adapter->netdev);
4555 rtnl_unlock();
4556
4557 status = lancer_recover_func(adapter);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004558 if (!status)
4559 netif_device_attach(adapter->netdev);
4560 }
4561
Somnath Kotur01e5b2c2013-05-29 22:56:17 +00004562 /* In Lancer, for all errors other than provisioning error (-EAGAIN),
4563 * no need to attempt further recovery.
4564 */
4565 if (!status || status == -EAGAIN)
4566 schedule_delayed_work(&adapter->func_recovery_work,
4567 msecs_to_jiffies(1000));
Padmanabh Ratnakard8110f62011-11-25 05:48:23 +00004568}
4569
4570static void be_worker(struct work_struct *work)
4571{
4572 struct be_adapter *adapter =
4573 container_of(work, struct be_adapter, work.work);
4574 struct be_rx_obj *rxo;
4575 int i;
4576
Padmanabh Ratnakard8110f62011-11-25 05:48:23 +00004577 /* when interrupts are not yet enabled, just reap any pending
4578 * mcc completions */
4579 if (!netif_running(adapter->netdev)) {
Amerigo Wang072a9c42012-08-24 21:41:11 +00004580 local_bh_disable();
Sathya Perla10ef9ab2012-02-09 18:05:27 +00004581 be_process_mcc(adapter);
Amerigo Wang072a9c42012-08-24 21:41:11 +00004582 local_bh_enable();
Padmanabh Ratnakard8110f62011-11-25 05:48:23 +00004583 goto reschedule;
4584 }
4585
4586 if (!adapter->stats_cmd_sent) {
4587 if (lancer_chip(adapter))
4588 lancer_cmd_get_pport_stats(adapter,
4589 &adapter->stats_cmd);
4590 else
4591 be_cmd_get_stats(adapter, &adapter->stats_cmd);
4592 }
4593
Vasundhara Volamd696b5e2013-08-06 09:27:16 +05304594 if (be_physfn(adapter) &&
4595 MODULO(adapter->work_counter, adapter->be_get_temp_freq) == 0)
Padmanabh Ratnakar7aeb2152012-07-12 03:56:46 +00004596 be_cmd_get_die_temperature(adapter);
4597
Padmanabh Ratnakard8110f62011-11-25 05:48:23 +00004598 for_all_rx_queues(adapter, rxo, i) {
Sathya Perla6384a4d2013-10-25 10:40:16 +05304599 /* Replenish RX-queues starved due to memory
4600 * allocation failures.
4601 */
4602 if (rxo->rx_post_starved)
Padmanabh Ratnakard8110f62011-11-25 05:48:23 +00004603 be_post_rx_frags(rxo, GFP_KERNEL);
Padmanabh Ratnakard8110f62011-11-25 05:48:23 +00004604 }
4605
Sathya Perla2632baf2013-10-01 16:00:00 +05304606 be_eqd_update(adapter);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00004607
Padmanabh Ratnakard8110f62011-11-25 05:48:23 +00004608reschedule:
4609 adapter->work_counter++;
4610 schedule_delayed_work(&adapter->work, msecs_to_jiffies(1000));
4611}
4612
Sathya Perla257a3fe2013-06-14 15:54:51 +05304613/* If any VFs are already enabled don't FLR the PF */
Sathya Perla39f1d942012-05-08 19:41:24 +00004614static bool be_reset_required(struct be_adapter *adapter)
4615{
Sathya Perla257a3fe2013-06-14 15:54:51 +05304616 return pci_num_vf(adapter->pdev) ? false : true;
Sathya Perla39f1d942012-05-08 19:41:24 +00004617}
4618
Sathya Perlad3791422012-09-28 04:39:44 +00004619static char *mc_name(struct be_adapter *adapter)
4620{
Vasundhara Volamf93f1602014-02-12 16:09:25 +05304621 char *str = ""; /* default */
4622
4623 switch (adapter->mc_type) {
4624 case UMC:
4625 str = "UMC";
4626 break;
4627 case FLEX10:
4628 str = "FLEX10";
4629 break;
4630 case vNIC1:
4631 str = "vNIC-1";
4632 break;
4633 case nPAR:
4634 str = "nPAR";
4635 break;
4636 case UFP:
4637 str = "UFP";
4638 break;
4639 case vNIC2:
4640 str = "vNIC-2";
4641 break;
4642 default:
4643 str = "";
4644 }
4645
4646 return str;
Sathya Perlad3791422012-09-28 04:39:44 +00004647}
4648
4649static inline char *func_name(struct be_adapter *adapter)
4650{
4651 return be_physfn(adapter) ? "PF" : "VF";
4652}
4653
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00004654static int be_probe(struct pci_dev *pdev, const struct pci_device_id *pdev_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004655{
4656 int status = 0;
4657 struct be_adapter *adapter;
4658 struct net_device *netdev;
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00004659 char port_name;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004660
4661 status = pci_enable_device(pdev);
4662 if (status)
4663 goto do_none;
4664
4665 status = pci_request_regions(pdev, DRV_NAME);
4666 if (status)
4667 goto disable_dev;
4668 pci_set_master(pdev);
4669
Sathya Perla7f640062012-06-05 19:37:20 +00004670 netdev = alloc_etherdev_mqs(sizeof(*adapter), MAX_TX_QS, MAX_RX_QS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004671 if (netdev == NULL) {
4672 status = -ENOMEM;
4673 goto rel_reg;
4674 }
4675 adapter = netdev_priv(netdev);
4676 adapter->pdev = pdev;
4677 pci_set_drvdata(pdev, adapter);
4678 adapter->netdev = netdev;
Sathya Perla2243e2e2009-11-22 22:02:03 +00004679 SET_NETDEV_DEV(netdev, &pdev->dev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004680
Russell King4c15c242013-06-26 23:49:11 +01004681 status = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004682 if (!status) {
4683 netdev->features |= NETIF_F_HIGHDMA;
4684 } else {
Russell King4c15c242013-06-26 23:49:11 +01004685 status = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004686 if (status) {
4687 dev_err(&pdev->dev, "Could not set PCI DMA Mask\n");
4688 goto free_netdev;
4689 }
4690 }
4691
Ajit Khapardeea58c182013-10-18 16:06:24 -05004692 if (be_physfn(adapter)) {
4693 status = pci_enable_pcie_error_reporting(pdev);
4694 if (!status)
4695 dev_info(&pdev->dev, "PCIe error reporting enabled\n");
4696 }
Sathya Perlad6b6d982012-09-05 01:56:48 +00004697
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004698 status = be_ctrl_init(adapter);
4699 if (status)
Sathya Perla39f1d942012-05-08 19:41:24 +00004700 goto free_netdev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004701
Sathya Perla2243e2e2009-11-22 22:02:03 +00004702 /* sync up with fw's ready state */
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00004703 if (be_physfn(adapter)) {
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00004704 status = be_fw_wait_ready(adapter);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00004705 if (status)
4706 goto ctrl_clean;
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00004707 }
Sathya Perla2243e2e2009-11-22 22:02:03 +00004708
Sathya Perla39f1d942012-05-08 19:41:24 +00004709 if (be_reset_required(adapter)) {
4710 status = be_cmd_reset_function(adapter);
4711 if (status)
4712 goto ctrl_clean;
Sarveshwar Bandi556ae192010-05-24 18:38:25 -07004713
Kalesh AP2d177be2013-04-28 22:22:29 +00004714 /* Wait for interrupts to quiesce after an FLR */
4715 msleep(100);
4716 }
Somnath Kotur8cef7a72013-03-14 02:41:51 +00004717
4718 /* Allow interrupts for other ULPs running on NIC function */
4719 be_intr_set(adapter, true);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00004720
Kalesh AP2d177be2013-04-28 22:22:29 +00004721 /* tell fw we're ready to fire cmds */
4722 status = be_cmd_fw_init(adapter);
4723 if (status)
4724 goto ctrl_clean;
4725
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004726 status = be_stats_init(adapter);
4727 if (status)
4728 goto ctrl_clean;
4729
Sathya Perla39f1d942012-05-08 19:41:24 +00004730 status = be_get_initial_config(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004731 if (status)
4732 goto stats_clean;
4733
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004734 INIT_DELAYED_WORK(&adapter->work, be_worker);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004735 INIT_DELAYED_WORK(&adapter->func_recovery_work, be_func_recovery_task);
Sathya Perlaa54769f2011-10-24 02:45:00 +00004736 adapter->rx_fc = adapter->tx_fc = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004737
Sathya Perla5fb379e2009-06-18 00:02:59 +00004738 status = be_setup(adapter);
4739 if (status)
Sathya Perla55f5c3c2012-09-28 04:39:42 +00004740 goto stats_clean;
Sathya Perla2243e2e2009-11-22 22:02:03 +00004741
Sathya Perla3abcded2010-10-03 22:12:27 -07004742 be_netdev_init(netdev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004743 status = register_netdev(netdev);
4744 if (status != 0)
Sathya Perla5fb379e2009-06-18 00:02:59 +00004745 goto unsetup;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004746
Parav Pandit045508a2012-03-26 14:27:13 +00004747 be_roce_dev_add(adapter);
4748
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004749 schedule_delayed_work(&adapter->func_recovery_work,
4750 msecs_to_jiffies(1000));
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00004751
4752 be_cmd_query_port_name(adapter, &port_name);
4753
Sathya Perlad3791422012-09-28 04:39:44 +00004754 dev_info(&pdev->dev, "%s: %s %s port %c\n", nic_name(pdev),
4755 func_name(adapter), mc_name(adapter), port_name);
Somnath Kotur34b1ef02011-06-01 00:33:22 +00004756
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004757 return 0;
4758
Sathya Perla5fb379e2009-06-18 00:02:59 +00004759unsetup:
4760 be_clear(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004761stats_clean:
4762 be_stats_cleanup(adapter);
4763ctrl_clean:
4764 be_ctrl_cleanup(adapter);
Sathya Perlaf9449ab2011-10-24 02:45:01 +00004765free_netdev:
Sathya Perlafe6d2a32010-11-21 23:25:50 +00004766 free_netdev(netdev);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004767rel_reg:
4768 pci_release_regions(pdev);
4769disable_dev:
4770 pci_disable_device(pdev);
4771do_none:
Ajit Khapardec4ca2372009-05-18 15:38:55 -07004772 dev_err(&pdev->dev, "%s initialization failed\n", nic_name(pdev));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004773 return status;
4774}
4775
4776static int be_suspend(struct pci_dev *pdev, pm_message_t state)
4777{
4778 struct be_adapter *adapter = pci_get_drvdata(pdev);
4779 struct net_device *netdev = adapter->netdev;
4780
Suresh Reddy76a9e082014-01-15 13:23:40 +05304781 if (adapter->wol_en)
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00004782 be_setup_wol(adapter, true);
4783
Ajit Khaparded4360d62013-11-22 12:51:09 -06004784 be_intr_set(adapter, false);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004785 cancel_delayed_work_sync(&adapter->func_recovery_work);
4786
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004787 netif_device_detach(netdev);
4788 if (netif_running(netdev)) {
4789 rtnl_lock();
4790 be_close(netdev);
4791 rtnl_unlock();
4792 }
Sarveshwar Bandi9b0365f2009-08-12 21:01:29 +00004793 be_clear(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004794
4795 pci_save_state(pdev);
4796 pci_disable_device(pdev);
4797 pci_set_power_state(pdev, pci_choose_state(pdev, state));
4798 return 0;
4799}
4800
4801static int be_resume(struct pci_dev *pdev)
4802{
4803 int status = 0;
4804 struct be_adapter *adapter = pci_get_drvdata(pdev);
4805 struct net_device *netdev = adapter->netdev;
4806
4807 netif_device_detach(netdev);
4808
4809 status = pci_enable_device(pdev);
4810 if (status)
4811 return status;
4812
Yijing Wang1ca01512013-06-27 20:53:42 +08004813 pci_set_power_state(pdev, PCI_D0);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004814 pci_restore_state(pdev);
4815
Sarveshwar Bandidd5746b2013-08-23 14:59:33 +05304816 status = be_fw_wait_ready(adapter);
4817 if (status)
4818 return status;
4819
Ajit Khaparded4360d62013-11-22 12:51:09 -06004820 be_intr_set(adapter, true);
Sathya Perla2243e2e2009-11-22 22:02:03 +00004821 /* tell fw we're ready to fire cmds */
4822 status = be_cmd_fw_init(adapter);
4823 if (status)
4824 return status;
4825
Sarveshwar Bandi9b0365f2009-08-12 21:01:29 +00004826 be_setup(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004827 if (netif_running(netdev)) {
4828 rtnl_lock();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004829 be_open(netdev);
4830 rtnl_unlock();
4831 }
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004832
4833 schedule_delayed_work(&adapter->func_recovery_work,
4834 msecs_to_jiffies(1000));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004835 netif_device_attach(netdev);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00004836
Suresh Reddy76a9e082014-01-15 13:23:40 +05304837 if (adapter->wol_en)
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00004838 be_setup_wol(adapter, false);
Ajit Khapardea4ca0552011-02-11 13:38:03 +00004839
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004840 return 0;
4841}
4842
Sathya Perla82456b02010-02-17 01:35:37 +00004843/*
4844 * An FLR will stop BE from DMAing any data.
4845 */
4846static void be_shutdown(struct pci_dev *pdev)
4847{
4848 struct be_adapter *adapter = pci_get_drvdata(pdev);
Sathya Perla82456b02010-02-17 01:35:37 +00004849
Ajit Khaparde2d5d4152011-04-06 05:53:13 +00004850 if (!adapter)
4851 return;
Sathya Perla82456b02010-02-17 01:35:37 +00004852
Sathya Perla0f4a6822011-03-21 20:49:28 +00004853 cancel_delayed_work_sync(&adapter->work);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004854 cancel_delayed_work_sync(&adapter->func_recovery_work);
Ajit Khapardea4ca0552011-02-11 13:38:03 +00004855
Ajit Khaparde2d5d4152011-04-06 05:53:13 +00004856 netif_device_detach(adapter->netdev);
Sathya Perla82456b02010-02-17 01:35:37 +00004857
Ajit Khaparde57841862011-04-06 18:08:43 +00004858 be_cmd_reset_function(adapter);
4859
Sathya Perla82456b02010-02-17 01:35:37 +00004860 pci_disable_device(pdev);
Sathya Perla82456b02010-02-17 01:35:37 +00004861}
4862
Sathya Perlacf588472010-02-14 21:22:01 +00004863static pci_ers_result_t be_eeh_err_detected(struct pci_dev *pdev,
4864 pci_channel_state_t state)
4865{
4866 struct be_adapter *adapter = pci_get_drvdata(pdev);
4867 struct net_device *netdev = adapter->netdev;
4868
4869 dev_err(&adapter->pdev->dev, "EEH error detected\n");
4870
Somnath Kotur01e5b2c2013-05-29 22:56:17 +00004871 if (!adapter->eeh_error) {
4872 adapter->eeh_error = true;
Sathya Perlacf588472010-02-14 21:22:01 +00004873
Somnath Kotur01e5b2c2013-05-29 22:56:17 +00004874 cancel_delayed_work_sync(&adapter->func_recovery_work);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004875
Sathya Perlacf588472010-02-14 21:22:01 +00004876 rtnl_lock();
Somnath Kotur01e5b2c2013-05-29 22:56:17 +00004877 netif_device_detach(netdev);
4878 if (netif_running(netdev))
4879 be_close(netdev);
Sathya Perlacf588472010-02-14 21:22:01 +00004880 rtnl_unlock();
Somnath Kotur01e5b2c2013-05-29 22:56:17 +00004881
4882 be_clear(adapter);
Sathya Perlacf588472010-02-14 21:22:01 +00004883 }
Sathya Perlacf588472010-02-14 21:22:01 +00004884
4885 if (state == pci_channel_io_perm_failure)
4886 return PCI_ERS_RESULT_DISCONNECT;
4887
4888 pci_disable_device(pdev);
4889
Somnath Kotureeb7fc72012-05-02 03:41:01 +00004890 /* The error could cause the FW to trigger a flash debug dump.
4891 * Resetting the card while flash dump is in progress
Padmanabh Ratnakarc8a54162012-10-20 06:03:37 +00004892 * can cause it not to recover; wait for it to finish.
4893 * Wait only for first function as it is needed only once per
4894 * adapter.
Somnath Kotureeb7fc72012-05-02 03:41:01 +00004895 */
Padmanabh Ratnakarc8a54162012-10-20 06:03:37 +00004896 if (pdev->devfn == 0)
4897 ssleep(30);
4898
Sathya Perlacf588472010-02-14 21:22:01 +00004899 return PCI_ERS_RESULT_NEED_RESET;
4900}
4901
4902static pci_ers_result_t be_eeh_reset(struct pci_dev *pdev)
4903{
4904 struct be_adapter *adapter = pci_get_drvdata(pdev);
4905 int status;
4906
4907 dev_info(&adapter->pdev->dev, "EEH reset\n");
Sathya Perlacf588472010-02-14 21:22:01 +00004908
4909 status = pci_enable_device(pdev);
4910 if (status)
4911 return PCI_ERS_RESULT_DISCONNECT;
4912
4913 pci_set_master(pdev);
Yijing Wang1ca01512013-06-27 20:53:42 +08004914 pci_set_power_state(pdev, PCI_D0);
Sathya Perlacf588472010-02-14 21:22:01 +00004915 pci_restore_state(pdev);
4916
4917 /* Check if card is ok and fw is ready */
Sathya Perlac5b3ad42013-03-05 22:23:20 +00004918 dev_info(&adapter->pdev->dev,
4919 "Waiting for FW to be ready after EEH reset\n");
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00004920 status = be_fw_wait_ready(adapter);
Sathya Perlacf588472010-02-14 21:22:01 +00004921 if (status)
4922 return PCI_ERS_RESULT_DISCONNECT;
4923
Sathya Perlad6b6d982012-09-05 01:56:48 +00004924 pci_cleanup_aer_uncorrect_error_status(pdev);
Somnath Kotur01e5b2c2013-05-29 22:56:17 +00004925 be_clear_all_error(adapter);
Sathya Perlacf588472010-02-14 21:22:01 +00004926 return PCI_ERS_RESULT_RECOVERED;
4927}
4928
4929static void be_eeh_resume(struct pci_dev *pdev)
4930{
4931 int status = 0;
4932 struct be_adapter *adapter = pci_get_drvdata(pdev);
4933 struct net_device *netdev = adapter->netdev;
4934
4935 dev_info(&adapter->pdev->dev, "EEH resume\n");
4936
4937 pci_save_state(pdev);
4938
Kalesh AP2d177be2013-04-28 22:22:29 +00004939 status = be_cmd_reset_function(adapter);
Sathya Perlacf588472010-02-14 21:22:01 +00004940 if (status)
4941 goto err;
4942
Kalesh AP2d177be2013-04-28 22:22:29 +00004943 /* tell fw we're ready to fire cmds */
4944 status = be_cmd_fw_init(adapter);
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00004945 if (status)
4946 goto err;
4947
Sathya Perlacf588472010-02-14 21:22:01 +00004948 status = be_setup(adapter);
4949 if (status)
4950 goto err;
4951
4952 if (netif_running(netdev)) {
4953 status = be_open(netdev);
4954 if (status)
4955 goto err;
4956 }
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00004957
4958 schedule_delayed_work(&adapter->func_recovery_work,
4959 msecs_to_jiffies(1000));
Sathya Perlacf588472010-02-14 21:22:01 +00004960 netif_device_attach(netdev);
4961 return;
4962err:
4963 dev_err(&adapter->pdev->dev, "EEH resume failed\n");
Sathya Perlacf588472010-02-14 21:22:01 +00004964}
4965
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07004966static const struct pci_error_handlers be_eeh_handlers = {
Sathya Perlacf588472010-02-14 21:22:01 +00004967 .error_detected = be_eeh_err_detected,
4968 .slot_reset = be_eeh_reset,
4969 .resume = be_eeh_resume,
4970};
4971
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004972static struct pci_driver be_driver = {
4973 .name = DRV_NAME,
4974 .id_table = be_dev_ids,
4975 .probe = be_probe,
4976 .remove = be_remove,
4977 .suspend = be_suspend,
Sathya Perlacf588472010-02-14 21:22:01 +00004978 .resume = be_resume,
Sathya Perla82456b02010-02-17 01:35:37 +00004979 .shutdown = be_shutdown,
Sathya Perlacf588472010-02-14 21:22:01 +00004980 .err_handler = &be_eeh_handlers
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004981};
4982
4983static int __init be_init_module(void)
4984{
Joe Perches8e95a202009-12-03 07:58:21 +00004985 if (rx_frag_size != 8192 && rx_frag_size != 4096 &&
4986 rx_frag_size != 2048) {
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004987 printk(KERN_WARNING DRV_NAME
4988 " : Module param rx_frag_size must be 2048/4096/8192."
4989 " Using 2048\n");
4990 rx_frag_size = 2048;
4991 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004992
Sathya Perla6b7c5b92009-03-11 23:32:03 -07004993 return pci_register_driver(&be_driver);
4994}
4995module_init(be_init_module);
4996
4997static void __exit be_exit_module(void)
4998{
4999 pci_unregister_driver(&be_driver);
5000}
5001module_exit(be_exit_module);