blob: 3516e17a399d3137ccf0e2eea06318c0171aeba4 [file] [log] [blame]
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001/*
Paul Gortmaker3396c782012-01-27 13:36:01 +00002 * linux/drivers/net/ethernet/ibm/ehea/ehea_main.c
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003 *
4 * eHEA ethernet device driver for IBM eServer System p
5 *
6 * (C) Copyright IBM Corp. 2006
7 *
8 * Authors:
Doug Maxey508d2b52008-01-31 20:20:49 -06009 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020012 *
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
Joe Perches8c4877a2010-12-13 10:05:14 -080029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020031#include <linux/in.h>
32#include <linux/ip.h>
33#include <linux/tcp.h>
34#include <linux/udp.h>
35#include <linux/if.h>
36#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020038#include <linux/if_ether.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020039#include <linux/notifier.h>
40#include <linux/reboot.h>
Hannes Hering48cfb142008-05-07 14:43:36 +020041#include <linux/memory.h>
Thomas Klein21eee2d2008-02-13 16:18:33 +010042#include <asm/kexec.h>
Daniel Walker06f89ed2008-03-28 14:41:26 -070043#include <linux/mutex.h>
Linus Torvalds268bb0c2011-05-20 12:50:29 -070044#include <linux/prefetch.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020045
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020046#include <net/ip.h>
47
48#include "ehea.h"
49#include "ehea_qmr.h"
50#include "ehea_phyp.h"
51
52
53MODULE_LICENSE("GPL");
54MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
55MODULE_DESCRIPTION("IBM eServer HEA Driver");
56MODULE_VERSION(DRV_VERSION);
57
58
59static int msg_level = -1;
60static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
61static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
62static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
63static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Anton Blanchardb9564462011-10-14 05:30:59 +000064static int use_mcs = 1;
Doug Maxey508d2b52008-01-31 20:20:49 -060065static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020066
67module_param(msg_level, int, 0);
68module_param(rq1_entries, int, 0);
69module_param(rq2_entries, int, 0);
70module_param(rq3_entries, int, 0);
71module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020072module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010073module_param(use_mcs, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020074
75MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020076MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
77 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020078MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
79 "[2^x - 1], x = [6..14]. Default = "
80 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
81MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
82 "[2^x - 1], x = [6..14]. Default = "
83 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
84MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
85 "[2^x - 1], x = [6..14]. Default = "
86 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
87MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
88 "[2^x - 1], x = [6..14]. Default = "
89 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Anton Blanchardb9564462011-10-14 05:30:59 +000090MODULE_PARM_DESC(use_mcs, " Multiple receive queues, 1: enable, 0: disable, "
91 "Default = 1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020092
Doug Maxey508d2b52008-01-31 20:20:49 -060093static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +020094static LIST_HEAD(adapter_list);
Stephen Rothwell48e4cc72009-01-05 16:06:02 -080095static unsigned long ehea_driver_flags;
Daniel Walker06f89ed2008-03-28 14:41:26 -070096static DEFINE_MUTEX(dlpar_mem_lock);
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +000097static struct ehea_fw_handle_array ehea_fw_handles;
98static struct ehea_bcmc_reg_array ehea_bcmc_regs;
Thomas Klein21eee2d2008-02-13 16:18:33 +010099
Thomas Kleind1dea382007-04-26 11:56:13 +0200100
Grant Likely2dc11582010-08-06 09:25:50 -0600101static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200102 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200103
Grant Likely2dc11582010-08-06 09:25:50 -0600104static int __devexit ehea_remove(struct platform_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200105
106static struct of_device_id ehea_device_table[] = {
107 {
108 .name = "lhea",
109 .compatible = "IBM,lhea",
110 },
111 {},
112};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100113MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200114
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000115static struct of_platform_driver ehea_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700116 .driver = {
117 .name = "ehea",
118 .owner = THIS_MODULE,
119 .of_match_table = ehea_device_table,
120 },
Thomas Kleind1dea382007-04-26 11:56:13 +0200121 .probe = ehea_probe_adapter,
122 .remove = ehea_remove,
123};
124
Doug Maxey508d2b52008-01-31 20:20:49 -0600125void ehea_dump(void *adr, int len, char *msg)
126{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200127 int x;
128 unsigned char *deb = adr;
129 for (x = 0; x < len; x += 16) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800130 pr_info("%s adr=%p ofs=%04x %016llx %016llx\n",
131 msg, deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200132 deb += 16;
133 }
134}
135
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +0000136static void ehea_schedule_port_reset(struct ehea_port *port)
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100137{
138 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
139 schedule_work(&port->reset_task);
140}
141
Thomas Klein21eee2d2008-02-13 16:18:33 +0100142static void ehea_update_firmware_handles(void)
143{
144 struct ehea_fw_handle_entry *arr = NULL;
145 struct ehea_adapter *adapter;
146 int num_adapters = 0;
147 int num_ports = 0;
148 int num_portres = 0;
149 int i = 0;
150 int num_fw_handles, k, l;
151
152 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700153 mutex_lock(&ehea_fw_handles.lock);
154
Thomas Klein21eee2d2008-02-13 16:18:33 +0100155 list_for_each_entry(adapter, &adapter_list, list) {
156 num_adapters++;
157
158 for (k = 0; k < EHEA_MAX_PORTS; k++) {
159 struct ehea_port *port = adapter->port[k];
160
161 if (!port || (port->state != EHEA_PORT_UP))
162 continue;
163
164 num_ports++;
Anton Blanchard723f28e2011-10-14 05:31:01 +0000165 num_portres += port->num_def_qps;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100166 }
167 }
168
169 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
170 num_ports * EHEA_NUM_PORT_FW_HANDLES +
171 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
172
173 if (num_fw_handles) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000174 arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100175 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700176 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100177 } else
178 goto out_update;
179
180 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700181 if (num_adapters == 0)
182 break;
183
Thomas Klein21eee2d2008-02-13 16:18:33 +0100184 for (k = 0; k < EHEA_MAX_PORTS; k++) {
185 struct ehea_port *port = adapter->port[k];
186
Joe Perches8e95a202009-12-03 07:58:21 +0000187 if (!port || (port->state != EHEA_PORT_UP) ||
188 (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100189 continue;
190
Anton Blanchard723f28e2011-10-14 05:31:01 +0000191 for (l = 0; l < port->num_def_qps; l++) {
Thomas Klein21eee2d2008-02-13 16:18:33 +0100192 struct ehea_port_res *pr = &port->port_res[l];
193
194 arr[i].adh = adapter->handle;
195 arr[i++].fwh = pr->qp->fw_handle;
196 arr[i].adh = adapter->handle;
197 arr[i++].fwh = pr->send_cq->fw_handle;
198 arr[i].adh = adapter->handle;
199 arr[i++].fwh = pr->recv_cq->fw_handle;
200 arr[i].adh = adapter->handle;
201 arr[i++].fwh = pr->eq->fw_handle;
202 arr[i].adh = adapter->handle;
203 arr[i++].fwh = pr->send_mr.handle;
204 arr[i].adh = adapter->handle;
205 arr[i++].fwh = pr->recv_mr.handle;
206 }
207 arr[i].adh = adapter->handle;
208 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700209 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100210 }
211
212 arr[i].adh = adapter->handle;
213 arr[i++].fwh = adapter->neq->fw_handle;
214
215 if (adapter->mr.handle) {
216 arr[i].adh = adapter->handle;
217 arr[i++].fwh = adapter->mr.handle;
218 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700219 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100220 }
221
222out_update:
223 kfree(ehea_fw_handles.arr);
224 ehea_fw_handles.arr = arr;
225 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700226out:
227 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100228}
229
230static void ehea_update_bcmc_registrations(void)
231{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700232 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100233 struct ehea_bcmc_reg_entry *arr = NULL;
234 struct ehea_adapter *adapter;
235 struct ehea_mc_list *mc_entry;
236 int num_registrations = 0;
237 int i = 0;
238 int k;
239
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700240 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
241
Thomas Klein21eee2d2008-02-13 16:18:33 +0100242 /* Determine number of registrations */
243 list_for_each_entry(adapter, &adapter_list, list)
244 for (k = 0; k < EHEA_MAX_PORTS; k++) {
245 struct ehea_port *port = adapter->port[k];
246
247 if (!port || (port->state != EHEA_PORT_UP))
248 continue;
249
250 num_registrations += 2; /* Broadcast registrations */
251
252 list_for_each_entry(mc_entry, &port->mc_list->list,list)
253 num_registrations += 2;
254 }
255
256 if (num_registrations) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000257 arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100258 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700259 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100260 } else
261 goto out_update;
262
263 list_for_each_entry(adapter, &adapter_list, list) {
264 for (k = 0; k < EHEA_MAX_PORTS; k++) {
265 struct ehea_port *port = adapter->port[k];
266
267 if (!port || (port->state != EHEA_PORT_UP))
268 continue;
269
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700270 if (num_registrations == 0)
271 goto out_update;
272
Thomas Klein21eee2d2008-02-13 16:18:33 +0100273 arr[i].adh = adapter->handle;
274 arr[i].port_id = port->logical_port_id;
275 arr[i].reg_type = EHEA_BCMC_BROADCAST |
276 EHEA_BCMC_UNTAGGED;
277 arr[i++].macaddr = port->mac_addr;
278
279 arr[i].adh = adapter->handle;
280 arr[i].port_id = port->logical_port_id;
281 arr[i].reg_type = EHEA_BCMC_BROADCAST |
282 EHEA_BCMC_VLANID_ALL;
283 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700284 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100285
286 list_for_each_entry(mc_entry,
287 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700288 if (num_registrations == 0)
289 goto out_update;
290
Thomas Klein21eee2d2008-02-13 16:18:33 +0100291 arr[i].adh = adapter->handle;
292 arr[i].port_id = port->logical_port_id;
293 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
294 EHEA_BCMC_MULTICAST |
295 EHEA_BCMC_UNTAGGED;
296 arr[i++].macaddr = mc_entry->macaddr;
297
298 arr[i].adh = adapter->handle;
299 arr[i].port_id = port->logical_port_id;
300 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
301 EHEA_BCMC_MULTICAST |
302 EHEA_BCMC_VLANID_ALL;
303 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700304 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100305 }
306 }
307 }
308
309out_update:
310 kfree(ehea_bcmc_regs.arr);
311 ehea_bcmc_regs.arr = arr;
312 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700313out:
314 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100315}
316
Anton Blanchard239c5622011-10-14 05:31:09 +0000317static struct rtnl_link_stats64 *ehea_get_stats64(struct net_device *dev,
318 struct rtnl_link_stats64 *stats)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200319{
320 struct ehea_port *port = netdev_priv(dev);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000321 u64 rx_packets = 0, tx_packets = 0, rx_bytes = 0, tx_bytes = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200322 int i;
323
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000324 for (i = 0; i < port->num_def_qps; i++) {
325 rx_packets += port->port_res[i].rx_packets;
326 rx_bytes += port->port_res[i].rx_bytes;
327 }
328
Anton Blanchard723f28e2011-10-14 05:31:01 +0000329 for (i = 0; i < port->num_def_qps; i++) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000330 tx_packets += port->port_res[i].tx_packets;
331 tx_bytes += port->port_res[i].tx_bytes;
332 }
333
334 stats->tx_packets = tx_packets;
335 stats->rx_bytes = rx_bytes;
336 stats->tx_bytes = tx_bytes;
337 stats->rx_packets = rx_packets;
338
Eric Dumazet09c1d442012-03-06 19:46:41 +0000339 stats->multicast = port->stats.multicast;
340 stats->rx_errors = port->stats.rx_errors;
341 return stats;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000342}
343
344static void ehea_update_stats(struct work_struct *work)
345{
346 struct ehea_port *port =
347 container_of(work, struct ehea_port, stats_work.work);
348 struct net_device *dev = port->netdev;
Anton Blanchard239c5622011-10-14 05:31:09 +0000349 struct rtnl_link_stats64 *stats = &port->stats;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000350 struct hcp_ehea_port_cb2 *cb2;
351 u64 hret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200352
Brian King3d8009c2010-06-30 11:59:12 +0000353 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200354 if (!cb2) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000355 netdev_err(dev, "No mem for cb2. Some interface statistics were not updated\n");
356 goto resched;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200357 }
358
359 hret = ehea_h_query_ehea_port(port->adapter->handle,
360 port->logical_port_id,
361 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
362 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800363 netdev_err(dev, "query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200364 goto out_herr;
365 }
366
367 if (netif_msg_hw(port))
368 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
369
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200370 stats->multicast = cb2->rxmcp;
371 stats->rx_errors = cb2->rxuerr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200372
373out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800374 free_page((unsigned long)cb2);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000375resched:
Anton Blanchard67c170a2011-11-23 00:13:54 +0000376 schedule_delayed_work(&port->stats_work,
377 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200378}
379
380static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
381{
382 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
383 struct net_device *dev = pr->port->netdev;
384 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200385 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
386 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200387 int i;
388
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200389 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200390
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200391 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200392 if (nr_of_wqes > 0)
393 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200394 pr->rq1_skba.os_skbs = fill_wqes;
395 return;
396 }
397
398 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200399 if (!skb_arr_rq1[index]) {
400 skb_arr_rq1[index] = netdev_alloc_skb(dev,
401 EHEA_L_PKT_SIZE);
402 if (!skb_arr_rq1[index]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800403 netdev_info(dev, "Unable to allocate enough skb in the array\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200404 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200405 break;
406 }
407 }
408 index--;
409 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200410 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200411 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200412
413 if (adder == 0)
414 return;
415
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200416 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200417 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200418}
419
Thomas Kleine2878802009-01-21 14:45:57 -0800420static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200421{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200422 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
423 struct net_device *dev = pr->port->netdev;
424 int i;
425
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000426 if (nr_rq1a > pr->rq1_skba.len) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800427 netdev_err(dev, "NR_RQ1A bigger than skb array len\n");
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000428 return;
429 }
430
431 for (i = 0; i < nr_rq1a; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200432 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000433 if (!skb_arr_rq1[i]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800434 netdev_info(dev, "Not enough memory to allocate skb array\n");
Thomas Kleine2878802009-01-21 14:45:57 -0800435 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000436 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200437 }
438 /* Ring doorbell */
Breno Leitaof76957f2011-01-11 07:45:57 +0000439 ehea_update_rq1a(pr->qp, i - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200440}
441
442static int ehea_refill_rq_def(struct ehea_port_res *pr,
443 struct ehea_q_skb_arr *q_skba, int rq_nr,
444 int num_wqes, int wqe_type, int packet_size)
445{
446 struct net_device *dev = pr->port->netdev;
447 struct ehea_qp *qp = pr->qp;
448 struct sk_buff **skb_arr = q_skba->arr;
449 struct ehea_rwqe *rwqe;
450 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200451 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200452 int ret = 0;
453
454 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200455 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200456
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200457 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
458 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200459 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200460 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200461
462 index = q_skba->index;
463 max_index_mask = q_skba->len - 1;
464 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200465 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000466 struct sk_buff *skb;
467
468 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200469 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200470 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800471 if (q_skba->os_skbs == q_skba->len - 2) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800472 netdev_info(pr->port->netdev,
473 "rq%i ran dry - no mem for skb\n",
474 rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800475 ret = -ENOMEM;
476 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200477 break;
478 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200479
480 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200481 tmp_addr = ehea_map_vaddr(skb->data);
482 if (tmp_addr == -1) {
483 dev_kfree_skb(skb);
484 q_skba->os_skbs = fill_wqes - i;
485 ret = 0;
486 break;
487 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200488
489 rwqe = ehea_get_next_rwqe(qp, rq_nr);
490 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200491 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200492 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200493 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200494 rwqe->sg_list[0].len = packet_size;
495 rwqe->data_segments = 1;
496
497 index++;
498 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200499 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200500 }
Thomas Klein44c82152007-07-11 16:32:00 +0200501
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200502 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200503 if (adder == 0)
504 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200505
506 /* Ring doorbell */
507 iosync();
508 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200509 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200510 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200511 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200512out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200513 return ret;
514}
515
516
517static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
518{
519 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
520 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000521 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200522}
523
524
525static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
526{
527 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
528 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000529 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200530}
531
532static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
533{
534 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
535 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
536 return 0;
537 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
538 (cqe->header_length == 0))
539 return 0;
540 return -EINVAL;
541}
542
543static inline void ehea_fill_skb(struct net_device *dev,
Anton Blanchardb9564462011-10-14 05:30:59 +0000544 struct sk_buff *skb, struct ehea_cqe *cqe,
545 struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200546{
547 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
548
549 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200550 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000551
552 /* The packet was not an IPV4 packet so a complemented checksum was
553 calculated. The value is found in the Internet Checksum field. */
554 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
555 skb->ip_summed = CHECKSUM_COMPLETE;
556 skb->csum = csum_unfold(~cqe->inet_checksum_value);
557 } else
558 skb->ip_summed = CHECKSUM_UNNECESSARY;
Anton Blanchardb9564462011-10-14 05:30:59 +0000559
560 skb_record_rx_queue(skb, pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200561}
562
563static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
564 int arr_len,
565 struct ehea_cqe *cqe)
566{
567 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
568 struct sk_buff *skb;
569 void *pref;
570 int x;
571
572 x = skb_index + 1;
573 x &= (arr_len - 1);
574
575 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700576 if (pref) {
577 prefetchw(pref);
578 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200579
Hannes Hering0b2febf2009-05-04 11:06:37 -0700580 pref = (skb_array[x]->data);
581 prefetch(pref);
582 prefetch(pref + EHEA_CACHE_LINE);
583 prefetch(pref + EHEA_CACHE_LINE * 2);
584 prefetch(pref + EHEA_CACHE_LINE * 3);
585 }
586
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200587 skb = skb_array[skb_index];
588 skb_array[skb_index] = NULL;
589 return skb;
590}
591
592static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
593 int arr_len, int wqe_index)
594{
595 struct sk_buff *skb;
596 void *pref;
597 int x;
598
599 x = wqe_index + 1;
600 x &= (arr_len - 1);
601
602 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700603 if (pref) {
604 prefetchw(pref);
605 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200606
Hannes Hering0b2febf2009-05-04 11:06:37 -0700607 pref = (skb_array[x]->data);
608 prefetchw(pref);
609 prefetchw(pref + EHEA_CACHE_LINE);
610 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200611
612 skb = skb_array[wqe_index];
613 skb_array[wqe_index] = NULL;
614 return skb;
615}
616
617static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
618 struct ehea_cqe *cqe, int *processed_rq2,
619 int *processed_rq3)
620{
621 struct sk_buff *skb;
622
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100623 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
624 pr->p_stats.err_tcp_cksum++;
625 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
626 pr->p_stats.err_ip_cksum++;
627 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
628 pr->p_stats.err_frame_crc++;
629
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200630 if (rq == 2) {
631 *processed_rq2 += 1;
632 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
633 dev_kfree_skb(skb);
634 } else if (rq == 3) {
635 *processed_rq3 += 1;
636 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
637 dev_kfree_skb(skb);
638 }
639
640 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100641 if (netif_msg_rx_err(pr->port)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800642 pr_err("Critical receive error for QP %d. Resetting port.\n",
643 pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100644 ehea_dump(cqe, sizeof(*cqe), "CQE");
645 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100646 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200647 return 1;
648 }
649
650 return 0;
651}
652
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700653static int ehea_proc_rwqes(struct net_device *dev,
654 struct ehea_port_res *pr,
655 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200656{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100657 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200658 struct ehea_qp *qp = pr->qp;
659 struct ehea_cqe *cqe;
660 struct sk_buff *skb;
661 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
662 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
663 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
664 int skb_arr_rq1_len = pr->rq1_skba.len;
665 int skb_arr_rq2_len = pr->rq2_skba.len;
666 int skb_arr_rq3_len = pr->rq3_skba.len;
667 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000668 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700669 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200670
671 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
672 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200673
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200674 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700675 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200676 ehea_inc_rq1(qp);
677 processed_rq1++;
678 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200679 if (netif_msg_rx_status(port))
680 ehea_dump(cqe, sizeof(*cqe), "CQE");
681
682 last_wqe_index = wqe_index;
683 rmb();
684 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600685 if (rq == 1) {
686 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200687 skb = get_skb_by_index_ll(skb_arr_rq1,
688 skb_arr_rq1_len,
689 wqe_index);
690 if (unlikely(!skb)) {
Breno Leitao782615a2010-12-20 10:35:25 -0800691 netif_info(port, rx_err, dev,
Joe Perches8c4877a2010-12-13 10:05:14 -0800692 "LL rq1: skb=NULL\n");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100693
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700694 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200695 EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000696 if (!skb) {
Breno Leitao782615a2010-12-20 10:35:25 -0800697 netdev_err(dev, "Not enough memory to allocate skb\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200698 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000699 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200700 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600701 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200702 cqe->num_bytes_transfered - 4);
Anton Blanchardb9564462011-10-14 05:30:59 +0000703 ehea_fill_skb(dev, skb, cqe, pr);
Doug Maxey508d2b52008-01-31 20:20:49 -0600704 } else if (rq == 2) {
705 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200706 skb = get_skb_by_index(skb_arr_rq2,
707 skb_arr_rq2_len, cqe);
708 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800709 netif_err(port, rx_err, dev,
710 "rq2: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200711 break;
712 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000713 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200714 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600715 } else {
716 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200717 skb = get_skb_by_index(skb_arr_rq3,
718 skb_arr_rq3_len, cqe);
719 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800720 netif_err(port, rx_err, dev,
721 "rq3: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200722 break;
723 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000724 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200725 processed_rq3++;
726 }
727
Breno Leitaoce45b872010-10-27 08:45:14 +0000728 processed_bytes += skb->len;
Anton Blanchard34284142011-10-14 05:31:11 +0000729
730 if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
731 __vlan_hwaccel_put_tag(skb, cqe->vlan_tag);
732
733 napi_gro_receive(&pr->napi, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100734 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100735 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200736 port_reset = ehea_treat_poll_error(pr, rq, cqe,
737 &processed_rq2,
738 &processed_rq3);
739 if (port_reset)
740 break;
741 }
742 cqe = ehea_poll_rq1(qp, &wqe_index);
743 }
744
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200745 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000746 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200747
748 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
749 ehea_refill_rq2(pr, processed_rq2);
750 ehea_refill_rq3(pr, processed_rq3);
751
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700752 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200753}
754
Andre Detsch2928db42010-08-17 05:49:12 +0000755#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
756
757static void reset_sq_restart_flag(struct ehea_port *port)
758{
759 int i;
760
Anton Blanchard723f28e2011-10-14 05:31:01 +0000761 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000762 struct ehea_port_res *pr = &port->port_res[i];
763 pr->sq_restart_flag = 0;
764 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000765 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000766}
767
768static void check_sqs(struct ehea_port *port)
769{
770 struct ehea_swqe *swqe;
771 int swqe_index;
772 int i, k;
773
Anton Blanchard723f28e2011-10-14 05:31:01 +0000774 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000775 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000776 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000777 k = 0;
778 swqe = ehea_get_swqe(pr->qp, &swqe_index);
779 memset(swqe, 0, SWQE_HEADER_SIZE);
780 atomic_dec(&pr->swqe_avail);
781
782 swqe->tx_control |= EHEA_SWQE_PURGE;
783 swqe->wr_id = SWQE_RESTART_CHECK;
784 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
785 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
786 swqe->immediate_data_length = 80;
787
788 ehea_post_swqe(pr->qp, swqe);
789
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000790 ret = wait_event_timeout(port->restart_wq,
791 pr->sq_restart_flag == 0,
792 msecs_to_jiffies(100));
793
794 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800795 pr_err("HW/SW queues out of sync\n");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000796 ehea_schedule_port_reset(pr->port);
797 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000798 }
799 }
Andre Detsch2928db42010-08-17 05:49:12 +0000800}
801
802
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100803static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200804{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100805 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200806 struct ehea_cq *send_cq = pr->send_cq;
807 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100808 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200809 int cqe_counter = 0;
810 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100811 int index;
Anton Blanchardb9564462011-10-14 05:30:59 +0000812 struct netdev_queue *txq = netdev_get_tx_queue(pr->port->netdev,
813 pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200814
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100815 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600816 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100817 ehea_inc_cq(send_cq);
818
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200819 cqe_counter++;
820 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000821
822 if (cqe->wr_id == SWQE_RESTART_CHECK) {
823 pr->sq_restart_flag = 1;
824 swqe_av++;
825 break;
826 }
827
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200828 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800829 pr_err("Bad send completion status=0x%04X\n",
830 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000831
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200832 if (netif_msg_tx_err(pr->port))
833 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000834
835 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800836 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000837 ehea_schedule_port_reset(pr->port);
838 break;
839 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200840 }
841
842 if (netif_msg_tx_done(pr->port))
843 ehea_dump(cqe, sizeof(*cqe), "CQE");
844
845 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100846 == EHEA_SWQE2_TYPE)) {
847
848 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
849 skb = pr->sq_skba.arr[index];
850 dev_kfree_skb(skb);
851 pr->sq_skba.arr[index] = NULL;
852 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200853
854 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
855 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100856
857 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700858 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200859
860 ehea_update_feca(send_cq, cqe_counter);
861 atomic_add(swqe_av, &pr->swqe_avail);
862
Anton Blanchardb9564462011-10-14 05:30:59 +0000863 if (unlikely(netif_tx_queue_stopped(txq) &&
864 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))) {
865 __netif_tx_lock(txq, smp_processor_id());
866 if (netif_tx_queue_stopped(txq) &&
867 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))
868 netif_tx_wake_queue(txq);
869 __netif_tx_unlock(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200870 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000871
Breno Leitao5b27d422010-10-05 13:16:22 +0000872 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200873
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100874 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200875}
876
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700877#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100878
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700879static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200880{
Doug Maxey508d2b52008-01-31 20:20:49 -0600881 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
882 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700883 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100884 struct ehea_cqe *cqe;
885 struct ehea_cqe *cqe_skb = NULL;
Anton Blanchard222ca962011-10-14 05:31:00 +0000886 int wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700887 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100888
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700889 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Anton Blanchard222ca962011-10-14 05:31:00 +0000890 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100891
Anton Blanchard222ca962011-10-14 05:31:00 +0000892 while (rx != budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -0800893 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100894 ehea_reset_cq_ep(pr->recv_cq);
895 ehea_reset_cq_ep(pr->send_cq);
896 ehea_reset_cq_n1(pr->recv_cq);
897 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000898 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100899 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
900 cqe_skb = ehea_poll_cq(pr->send_cq);
901
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100902 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700903 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100904
Ben Hutchings288379f2009-01-19 16:43:59 -0800905 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700906 return rx;
907
908 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
909 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100910 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100911
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700912 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200913}
914
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200915#ifdef CONFIG_NET_POLL_CONTROLLER
916static void ehea_netpoll(struct net_device *dev)
917{
918 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700919 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200920
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700921 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800922 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200923}
924#endif
925
David Howells7d12e782006-10-05 14:55:46 +0100926static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200927{
928 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100929
Ben Hutchings288379f2009-01-19 16:43:59 -0800930 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100931
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200932 return IRQ_HANDLED;
933}
934
David Howells7d12e782006-10-05 14:55:46 +0100935static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200936{
937 struct ehea_port *port = param;
938 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100939 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200940 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000941 u64 resource_type, aer, aerr;
942 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200943
944 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100945
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200946 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200947 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Joe Perches8c4877a2010-12-13 10:05:14 -0800948 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
949 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100950
951 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000952
953 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
954 &aer, &aerr);
955
956 if (resource_type == EHEA_AER_RESTYPE_QP) {
957 if ((aer & EHEA_AER_RESET_MASK) ||
958 (aerr & EHEA_AERR_RESET_MASK))
959 reset_port = 1;
960 } else
961 reset_port = 1; /* Reset in case of CQ or EQ error */
962
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100963 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200964 }
965
Thomas Kleinea96cea2010-04-20 23:10:55 +0000966 if (reset_port) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800967 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000968 ehea_schedule_port_reset(port);
969 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100970
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200971 return IRQ_HANDLED;
972}
973
974static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
975 int logical_port)
976{
977 int i;
978
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100979 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100980 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200981 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +0100982 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200983 return NULL;
984}
985
986int ehea_sense_port_attr(struct ehea_port *port)
987{
988 int ret;
989 u64 hret;
990 struct hcp_ehea_port_cb0 *cb0;
991
Doug Maxey508d2b52008-01-31 20:20:49 -0600992 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -0800993 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -0600994 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800995 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200996 ret = -ENOMEM;
997 goto out;
998 }
999
1000 hret = ehea_h_query_ehea_port(port->adapter->handle,
1001 port->logical_port_id, H_PORT_CB0,
1002 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1003 cb0);
1004 if (hret != H_SUCCESS) {
1005 ret = -EIO;
1006 goto out_free;
1007 }
1008
1009 /* MAC address */
1010 port->mac_addr = cb0->port_mac_addr << 16;
1011
Doug Maxey508d2b52008-01-31 20:20:49 -06001012 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001013 ret = -EADDRNOTAVAIL;
1014 goto out_free;
1015 }
1016
1017 /* Port speed */
1018 switch (cb0->port_speed) {
1019 case H_SPEED_10M_H:
1020 port->port_speed = EHEA_SPEED_10M;
1021 port->full_duplex = 0;
1022 break;
1023 case H_SPEED_10M_F:
1024 port->port_speed = EHEA_SPEED_10M;
1025 port->full_duplex = 1;
1026 break;
1027 case H_SPEED_100M_H:
1028 port->port_speed = EHEA_SPEED_100M;
1029 port->full_duplex = 0;
1030 break;
1031 case H_SPEED_100M_F:
1032 port->port_speed = EHEA_SPEED_100M;
1033 port->full_duplex = 1;
1034 break;
1035 case H_SPEED_1G_F:
1036 port->port_speed = EHEA_SPEED_1G;
1037 port->full_duplex = 1;
1038 break;
1039 case H_SPEED_10G_F:
1040 port->port_speed = EHEA_SPEED_10G;
1041 port->full_duplex = 1;
1042 break;
1043 default:
1044 port->port_speed = 0;
1045 port->full_duplex = 0;
1046 break;
1047 }
1048
Thomas Kleine919b592007-01-22 12:53:20 +01001049 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001050 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001051
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001052 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001053 if (use_mcs)
1054 port->num_def_qps = cb0->num_default_qps;
1055 else
1056 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001057
1058 if (!port->num_def_qps) {
1059 ret = -EINVAL;
1060 goto out_free;
1061 }
1062
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001063 ret = 0;
1064out_free:
1065 if (ret || netif_msg_probe(port))
1066 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001067 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001068out:
1069 return ret;
1070}
1071
1072int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1073{
1074 struct hcp_ehea_port_cb4 *cb4;
1075 u64 hret;
1076 int ret = 0;
1077
Thomas Klein3faf2692009-01-21 14:45:33 -08001078 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001079 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001080 pr_err("no mem for cb4\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001081 ret = -ENOMEM;
1082 goto out;
1083 }
1084
1085 cb4->port_speed = port_speed;
1086
1087 netif_carrier_off(port->netdev);
1088
1089 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1090 port->logical_port_id,
1091 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1092 if (hret == H_SUCCESS) {
1093 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1094
1095 hret = ehea_h_query_ehea_port(port->adapter->handle,
1096 port->logical_port_id,
1097 H_PORT_CB4, H_PORT_CB4_SPEED,
1098 cb4);
1099 if (hret == H_SUCCESS) {
1100 switch (cb4->port_speed) {
1101 case H_SPEED_10M_H:
1102 port->port_speed = EHEA_SPEED_10M;
1103 port->full_duplex = 0;
1104 break;
1105 case H_SPEED_10M_F:
1106 port->port_speed = EHEA_SPEED_10M;
1107 port->full_duplex = 1;
1108 break;
1109 case H_SPEED_100M_H:
1110 port->port_speed = EHEA_SPEED_100M;
1111 port->full_duplex = 0;
1112 break;
1113 case H_SPEED_100M_F:
1114 port->port_speed = EHEA_SPEED_100M;
1115 port->full_duplex = 1;
1116 break;
1117 case H_SPEED_1G_F:
1118 port->port_speed = EHEA_SPEED_1G;
1119 port->full_duplex = 1;
1120 break;
1121 case H_SPEED_10G_F:
1122 port->port_speed = EHEA_SPEED_10G;
1123 port->full_duplex = 1;
1124 break;
1125 default:
1126 port->port_speed = 0;
1127 port->full_duplex = 0;
1128 break;
1129 }
1130 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001131 pr_err("Failed sensing port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001132 ret = -EIO;
1133 }
1134 } else {
1135 if (hret == H_AUTHORITY) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001136 pr_info("Hypervisor denied setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001137 ret = -EPERM;
1138 } else {
1139 ret = -EIO;
Joe Perches8c4877a2010-12-13 10:05:14 -08001140 pr_err("Failed setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001141 }
1142 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001143 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1144 netif_carrier_on(port->netdev);
1145
Thomas Klein3faf2692009-01-21 14:45:33 -08001146 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001147out:
1148 return ret;
1149}
1150
1151static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1152{
1153 int ret;
1154 u8 ec;
1155 u8 portnum;
1156 struct ehea_port *port;
Joe Perches8c4877a2010-12-13 10:05:14 -08001157 struct net_device *dev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001158
1159 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1160 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1161 port = ehea_get_port(adapter, portnum);
Joe Perches8c4877a2010-12-13 10:05:14 -08001162 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001163
1164 switch (ec) {
1165 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1166
1167 if (!port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001168 netdev_err(dev, "unknown portnum %x\n", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001169 break;
1170 }
1171
1172 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001173 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001174 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001175 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001176 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001177 break;
1178 }
1179
Joe Perches8c4877a2010-12-13 10:05:14 -08001180 netif_info(port, link, dev,
1181 "Logical port up: %dMbps %s Duplex\n",
1182 port->port_speed,
1183 port->full_duplex == 1 ?
1184 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001185
Joe Perches8c4877a2010-12-13 10:05:14 -08001186 netif_carrier_on(dev);
1187 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001188 }
1189 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001190 if (netif_carrier_ok(dev)) {
1191 netif_info(port, link, dev,
1192 "Logical port down\n");
1193 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001194 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001195 }
1196
1197 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001198 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches8c4877a2010-12-13 10:05:14 -08001199 netif_info(port, link, dev,
1200 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001201 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001202 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001203 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001204 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches8c4877a2010-12-13 10:05:14 -08001205 netif_info(port, link, dev,
1206 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001207 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001208 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001209 }
1210
1211 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches8c4877a2010-12-13 10:05:14 -08001212 netdev_info(dev,
1213 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001214 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001215 netdev_info(dev,
1216 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001217
1218 break;
1219 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001220 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001221 break;
1222 case EHEA_EC_PORT_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001223 netdev_info(dev, "Port malfunction\n");
1224 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001225 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001226 break;
1227 default:
Joe Perches8c4877a2010-12-13 10:05:14 -08001228 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001229 break;
1230 }
1231}
1232
1233static void ehea_neq_tasklet(unsigned long data)
1234{
Doug Maxey508d2b52008-01-31 20:20:49 -06001235 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001236 struct ehea_eqe *eqe;
1237 u64 event_mask;
1238
1239 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001240 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001241
1242 while (eqe) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001243 pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001244 ehea_parse_eqe(adapter, eqe->entry);
1245 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001246 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001247 }
1248
1249 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1250 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1251 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1252
1253 ehea_h_reset_events(adapter->handle,
1254 adapter->neq->fw_handle, event_mask);
1255}
1256
David Howells7d12e782006-10-05 14:55:46 +01001257static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001258{
1259 struct ehea_adapter *adapter = param;
1260 tasklet_hi_schedule(&adapter->neq_tasklet);
1261 return IRQ_HANDLED;
1262}
1263
1264
1265static int ehea_fill_port_res(struct ehea_port_res *pr)
1266{
1267 int ret;
1268 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1269
Breno Leitaof76957f2011-01-11 07:45:57 +00001270 ehea_init_fill_rq1(pr, pr->rq1_skba.len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001271
Thomas Kleine2878802009-01-21 14:45:57 -08001272 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001273
1274 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1275
1276 return ret;
1277}
1278
1279static int ehea_reg_interrupts(struct net_device *dev)
1280{
1281 struct ehea_port *port = netdev_priv(dev);
1282 struct ehea_port_res *pr;
1283 int i, ret;
1284
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001285
1286 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1287 dev->name);
1288
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001289 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001290 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001291 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001292 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001293 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1294 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001295 goto out_free_qpeq;
1296 }
1297
Joe Perches8c4877a2010-12-13 10:05:14 -08001298 netif_info(port, ifup, dev,
1299 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1300 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001301
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001302
Anton Blanchard723f28e2011-10-14 05:31:01 +00001303 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001304 pr = &port->port_res[i];
1305 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001306 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001307 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001308 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001309 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001310 pr);
1311 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001312 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1313 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001314 goto out_free_req;
1315 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001316 netif_info(port, ifup, dev,
1317 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1318 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001319 }
1320out:
1321 return ret;
1322
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001323
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001324out_free_req:
1325 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001326 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001327 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001328 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001329
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001330out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001331 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001332 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001333
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001334 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001335
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001336}
1337
1338static void ehea_free_interrupts(struct net_device *dev)
1339{
1340 struct ehea_port *port = netdev_priv(dev);
1341 struct ehea_port_res *pr;
1342 int i;
1343
1344 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001345
Anton Blanchard723f28e2011-10-14 05:31:01 +00001346 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001347 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001348 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001349 netif_info(port, intr, dev,
1350 "free send irq for res %d with handle 0x%X\n",
1351 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001352 }
1353
1354 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001355 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001356 netif_info(port, intr, dev,
1357 "associated event interrupt for handle 0x%X freed\n",
1358 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001359}
1360
1361static int ehea_configure_port(struct ehea_port *port)
1362{
1363 int ret, i;
1364 u64 hret, mask;
1365 struct hcp_ehea_port_cb0 *cb0;
1366
1367 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001368 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001369 if (!cb0)
1370 goto out;
1371
1372 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1373 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1374 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1375 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1376 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1377 PXLY_RC_VLAN_FILTER)
1378 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1379
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001380 for (i = 0; i < port->num_mcs; i++)
1381 if (use_mcs)
1382 cb0->default_qpn_arr[i] =
1383 port->port_res[i].qp->init_attr.qp_nr;
1384 else
1385 cb0->default_qpn_arr[i] =
1386 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001387
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001388 if (netif_msg_ifup(port))
1389 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1390
1391 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1392 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1393
1394 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1395 port->logical_port_id,
1396 H_PORT_CB0, mask, cb0);
1397 ret = -EIO;
1398 if (hret != H_SUCCESS)
1399 goto out_free;
1400
1401 ret = 0;
1402
1403out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001404 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001405out:
1406 return ret;
1407}
1408
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00001409static int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001410{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001411 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001412 struct ehea_adapter *adapter = pr->port->adapter;
1413
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001414 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1415 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001416 goto out;
1417
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001418 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1419 if (ret)
1420 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001421
1422 return 0;
1423
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001424out_free:
1425 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001426out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001427 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001428 return -EIO;
1429}
1430
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00001431static int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001432{
Joe Perches8e95a202009-12-03 07:58:21 +00001433 if ((ehea_rem_mr(&pr->send_mr)) ||
1434 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001435 return -EIO;
1436 else
1437 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001438}
1439
1440static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1441{
Doug Maxey508d2b52008-01-31 20:20:49 -06001442 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001443
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001444 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001445 if (!q_skba->arr)
1446 return -ENOMEM;
1447
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001448 q_skba->len = max_q_entries;
1449 q_skba->index = 0;
1450 q_skba->os_skbs = 0;
1451
1452 return 0;
1453}
1454
1455static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1456 struct port_res_cfg *pr_cfg, int queue_token)
1457{
1458 struct ehea_adapter *adapter = port->adapter;
1459 enum ehea_eq_type eq_type = EHEA_EQ;
1460 struct ehea_qp_init_attr *init_attr = NULL;
1461 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001462 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1463
1464 tx_bytes = pr->tx_bytes;
1465 tx_packets = pr->tx_packets;
1466 rx_bytes = pr->rx_bytes;
1467 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001468
1469 memset(pr, 0, sizeof(struct ehea_port_res));
1470
Breno Leitaoce45b872010-10-27 08:45:14 +00001471 pr->tx_bytes = rx_bytes;
1472 pr->tx_packets = tx_packets;
1473 pr->rx_bytes = rx_bytes;
1474 pr->rx_packets = rx_packets;
1475
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001476 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001477
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001478 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1479 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001480 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001481 goto out_free;
1482 }
1483
1484 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001485 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001486 port->logical_port_id);
1487 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001488 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001489 goto out_free;
1490 }
1491
1492 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001493 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001494 port->logical_port_id);
1495 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001496 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001497 goto out_free;
1498 }
1499
1500 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001501 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1502 pr->send_cq->attr.act_nr_of_cqes,
1503 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001504
1505 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1506 if (!init_attr) {
1507 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001508 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001509 goto out_free;
1510 }
1511
1512 init_attr->low_lat_rq1 = 1;
1513 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1514 init_attr->rq_count = 3;
1515 init_attr->qp_token = queue_token;
1516 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1517 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1518 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1519 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1520 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1521 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1522 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1523 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1524 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1525 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1526 init_attr->port_nr = port->logical_port_id;
1527 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1528 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1529 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1530
1531 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1532 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001533 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001534 ret = -EIO;
1535 goto out_free;
1536 }
1537
1538 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001539 pr_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d\n",
1540 init_attr->qp_nr,
1541 init_attr->act_nr_send_wqes,
1542 init_attr->act_nr_rwqes_rq1,
1543 init_attr->act_nr_rwqes_rq2,
1544 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001545
Thomas Klein44fb3122008-04-04 15:04:53 +02001546 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1547
1548 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001549 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1550 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1551 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1552 if (ret)
1553 goto out_free;
1554
1555 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1556 if (ehea_gen_smrs(pr) != 0) {
1557 ret = -EIO;
1558 goto out_free;
1559 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001560
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001561 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1562
1563 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001564
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001565 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001566
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001567 ret = 0;
1568 goto out;
1569
1570out_free:
1571 kfree(init_attr);
1572 vfree(pr->sq_skba.arr);
1573 vfree(pr->rq1_skba.arr);
1574 vfree(pr->rq2_skba.arr);
1575 vfree(pr->rq3_skba.arr);
1576 ehea_destroy_qp(pr->qp);
1577 ehea_destroy_cq(pr->send_cq);
1578 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001579 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001580out:
1581 return ret;
1582}
1583
1584static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1585{
1586 int ret, i;
1587
Hannes Hering357eb462009-08-04 11:48:39 -07001588 if (pr->qp)
1589 netif_napi_del(&pr->napi);
1590
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001591 ret = ehea_destroy_qp(pr->qp);
1592
1593 if (!ret) {
1594 ehea_destroy_cq(pr->send_cq);
1595 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001596 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001597
1598 for (i = 0; i < pr->rq1_skba.len; i++)
1599 if (pr->rq1_skba.arr[i])
1600 dev_kfree_skb(pr->rq1_skba.arr[i]);
1601
1602 for (i = 0; i < pr->rq2_skba.len; i++)
1603 if (pr->rq2_skba.arr[i])
1604 dev_kfree_skb(pr->rq2_skba.arr[i]);
1605
1606 for (i = 0; i < pr->rq3_skba.len; i++)
1607 if (pr->rq3_skba.arr[i])
1608 dev_kfree_skb(pr->rq3_skba.arr[i]);
1609
1610 for (i = 0; i < pr->sq_skba.len; i++)
1611 if (pr->sq_skba.arr[i])
1612 dev_kfree_skb(pr->sq_skba.arr[i]);
1613
1614 vfree(pr->rq1_skba.arr);
1615 vfree(pr->rq2_skba.arr);
1616 vfree(pr->rq3_skba.arr);
1617 vfree(pr->sq_skba.arr);
1618 ret = ehea_rem_smrs(pr);
1619 }
1620 return ret;
1621}
1622
Anton Blanchard13946f52011-10-14 05:31:06 +00001623static void write_swqe2_immediate(struct sk_buff *skb, struct ehea_swqe *swqe,
1624 u32 lkey)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001625{
Eric Dumazete743d312010-04-14 15:59:40 -07001626 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001627 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1628 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Anton Blanchard13946f52011-10-14 05:31:06 +00001629 unsigned int immediate_len = SWQE2_MAX_IMM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001630
Anton Blanchard13946f52011-10-14 05:31:06 +00001631 swqe->descriptors = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001632
Anton Blanchard13946f52011-10-14 05:31:06 +00001633 if (skb_is_gso(skb)) {
1634 swqe->tx_control |= EHEA_SWQE_TSO;
1635 swqe->mss = skb_shinfo(skb)->gso_size;
1636 /*
1637 * For TSO packets we only copy the headers into the
1638 * immediate area.
1639 */
1640 immediate_len = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
1641 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001642
Anton Blanchard13946f52011-10-14 05:31:06 +00001643 if (skb_is_gso(skb) || skb_data_size >= SWQE2_MAX_IMM) {
1644 skb_copy_from_linear_data(skb, imm_data, immediate_len);
1645 swqe->immediate_data_length = immediate_len;
1646
1647 if (skb_data_size > immediate_len) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001648 sg1entry->l_key = lkey;
Anton Blanchard13946f52011-10-14 05:31:06 +00001649 sg1entry->len = skb_data_size - immediate_len;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001650 sg1entry->vaddr =
Anton Blanchard13946f52011-10-14 05:31:06 +00001651 ehea_map_vaddr(skb->data + immediate_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001652 swqe->descriptors++;
1653 }
1654 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001655 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001656 swqe->immediate_data_length = skb_data_size;
1657 }
1658}
1659
1660static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1661 struct ehea_swqe *swqe, u32 lkey)
1662{
1663 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1664 skb_frag_t *frag;
1665 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001666
1667 nfrags = skb_shinfo(skb)->nr_frags;
1668 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001669 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001670 sg1entry_contains_frag_data = 0;
1671
Anton Blanchard13946f52011-10-14 05:31:06 +00001672 write_swqe2_immediate(skb, swqe, lkey);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001673
1674 /* write descriptors */
1675 if (nfrags > 0) {
1676 if (swqe->descriptors == 0) {
1677 /* sg1entry not yet used */
1678 frag = &skb_shinfo(skb)->frags[0];
1679
1680 /* copy sg1entry data */
1681 sg1entry->l_key = lkey;
Eric Dumazet9e903e02011-10-18 21:00:24 +00001682 sg1entry->len = skb_frag_size(frag);
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001683 sg1entry->vaddr =
Ian Campbell618c4a02011-10-10 01:11:38 +00001684 ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001685 swqe->descriptors++;
1686 sg1entry_contains_frag_data = 1;
1687 }
1688
1689 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1690
1691 frag = &skb_shinfo(skb)->frags[i];
1692 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1693
1694 sgentry->l_key = lkey;
Eric Dumazet0110bba2011-10-25 16:16:10 +02001695 sgentry->len = skb_frag_size(frag);
Ian Campbell618c4a02011-10-10 01:11:38 +00001696 sgentry->vaddr = ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001697 swqe->descriptors++;
1698 }
1699 }
1700}
1701
1702static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1703{
1704 int ret = 0;
1705 u64 hret;
1706 u8 reg_type;
1707
1708 /* De/Register untagged packets */
1709 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1710 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1711 port->logical_port_id,
1712 reg_type, port->mac_addr, 0, hcallid);
1713 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001714 pr_err("%sregistering bc address failed (tagged)\n",
1715 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001716 ret = -EIO;
1717 goto out_herr;
1718 }
1719
1720 /* De/Register VLAN packets */
1721 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1722 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1723 port->logical_port_id,
1724 reg_type, port->mac_addr, 0, hcallid);
1725 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001726 pr_err("%sregistering bc address failed (vlan)\n",
1727 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001728 ret = -EIO;
1729 }
1730out_herr:
1731 return ret;
1732}
1733
1734static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1735{
1736 struct ehea_port *port = netdev_priv(dev);
1737 struct sockaddr *mac_addr = sa;
1738 struct hcp_ehea_port_cb0 *cb0;
1739 int ret;
1740 u64 hret;
1741
1742 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1743 ret = -EADDRNOTAVAIL;
1744 goto out;
1745 }
1746
Thomas Klein3faf2692009-01-21 14:45:33 -08001747 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001748 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001749 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001750 ret = -ENOMEM;
1751 goto out;
1752 }
1753
1754 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1755
1756 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1757
1758 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1759 port->logical_port_id, H_PORT_CB0,
1760 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1761 if (hret != H_SUCCESS) {
1762 ret = -EIO;
1763 goto out_free;
1764 }
1765
1766 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1767
1768 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001769 if (port->state == EHEA_PORT_UP) {
1770 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1771 if (ret)
1772 goto out_upregs;
1773 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001774
1775 port->mac_addr = cb0->port_mac_addr << 16;
1776
1777 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001778 if (port->state == EHEA_PORT_UP) {
1779 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1780 if (ret)
1781 goto out_upregs;
1782 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001783
1784 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001785
1786out_upregs:
1787 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001788out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001789 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001790out:
1791 return ret;
1792}
1793
1794static void ehea_promiscuous_error(u64 hret, int enable)
1795{
Thomas Klein7674a582007-01-22 12:54:20 +01001796 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001797 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1798 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001799 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001800 pr_err("failed %sabling promiscuous mode\n",
1801 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001802}
1803
1804static void ehea_promiscuous(struct net_device *dev, int enable)
1805{
1806 struct ehea_port *port = netdev_priv(dev);
1807 struct hcp_ehea_port_cb7 *cb7;
1808 u64 hret;
1809
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001810 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001811 return;
1812
Thomas Klein3faf2692009-01-21 14:45:33 -08001813 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001814 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001815 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001816 goto out;
1817 }
1818
1819 /* Modify Pxs_DUCQPN in CB7 */
1820 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1821
1822 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1823 port->logical_port_id,
1824 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1825 if (hret) {
1826 ehea_promiscuous_error(hret, enable);
1827 goto out;
1828 }
1829
1830 port->promisc = enable;
1831out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001832 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001833}
1834
1835static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1836 u32 hcallid)
1837{
1838 u64 hret;
1839 u8 reg_type;
1840
1841 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1842 | EHEA_BCMC_UNTAGGED;
1843
1844 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1845 port->logical_port_id,
1846 reg_type, mc_mac_addr, 0, hcallid);
1847 if (hret)
1848 goto out;
1849
1850 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1851 | EHEA_BCMC_VLANID_ALL;
1852
1853 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1854 port->logical_port_id,
1855 reg_type, mc_mac_addr, 0, hcallid);
1856out:
1857 return hret;
1858}
1859
1860static int ehea_drop_multicast_list(struct net_device *dev)
1861{
1862 struct ehea_port *port = netdev_priv(dev);
1863 struct ehea_mc_list *mc_entry = port->mc_list;
1864 struct list_head *pos;
1865 struct list_head *temp;
1866 int ret = 0;
1867 u64 hret;
1868
1869 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1870 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1871
1872 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1873 H_DEREG_BCMC);
1874 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001875 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001876 ret = -EIO;
1877 }
1878
1879 list_del(pos);
1880 kfree(mc_entry);
1881 }
1882 return ret;
1883}
1884
1885static void ehea_allmulti(struct net_device *dev, int enable)
1886{
1887 struct ehea_port *port = netdev_priv(dev);
1888 u64 hret;
1889
1890 if (!port->allmulti) {
1891 if (enable) {
1892 /* Enable ALLMULTI */
1893 ehea_drop_multicast_list(dev);
1894 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1895 if (!hret)
1896 port->allmulti = 1;
1897 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001898 netdev_err(dev,
1899 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001900 }
1901 } else
1902 if (!enable) {
1903 /* Disable ALLMULTI */
1904 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1905 if (!hret)
1906 port->allmulti = 0;
1907 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001908 netdev_err(dev,
1909 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001910 }
1911}
1912
Doug Maxey508d2b52008-01-31 20:20:49 -06001913static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001914{
1915 struct ehea_mc_list *ehea_mcl_entry;
1916 u64 hret;
1917
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001918 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001919 if (!ehea_mcl_entry) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001920 pr_err("no mem for mcl_entry\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001921 return;
1922 }
1923
1924 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1925
1926 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1927
1928 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1929 H_REG_BCMC);
1930 if (!hret)
1931 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1932 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001933 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001934 kfree(ehea_mcl_entry);
1935 }
1936}
1937
1938static void ehea_set_multicast_list(struct net_device *dev)
1939{
1940 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00001941 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00001942 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001943
Breno Leitaoa4910b72011-05-23 03:36:35 +00001944 if (port->promisc) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001945 ehea_promiscuous(dev, 1);
1946 return;
1947 }
1948 ehea_promiscuous(dev, 0);
1949
1950 if (dev->flags & IFF_ALLMULTI) {
1951 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001952 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001953 }
1954 ehea_allmulti(dev, 0);
1955
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001956 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001957 ret = ehea_drop_multicast_list(dev);
1958 if (ret) {
1959 /* Dropping the current multicast list failed.
1960 * Enabling ALL_MULTI is the best we can do.
1961 */
1962 ehea_allmulti(dev, 1);
1963 }
1964
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001965 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001966 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
1967 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001968 goto out;
1969 }
1970
Jiri Pirko22bedad32010-04-01 21:22:57 +00001971 netdev_for_each_mc_addr(ha, dev)
1972 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06001973
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001974 }
1975out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01001976 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001977}
1978
1979static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1980{
1981 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1982 return -EINVAL;
1983 dev->mtu = new_mtu;
1984 return 0;
1985}
1986
Anton Blanchardd695c332011-10-14 05:31:05 +00001987static void xmit_common(struct sk_buff *skb, struct ehea_swqe *swqe)
1988{
1989 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT | EHEA_SWQE_CRC;
1990
1991 if (skb->protocol != htons(ETH_P_IP))
1992 return;
1993
1994 if (skb->ip_summed == CHECKSUM_PARTIAL)
1995 swqe->tx_control |= EHEA_SWQE_IP_CHECKSUM;
1996
1997 swqe->ip_start = skb_network_offset(skb);
1998 swqe->ip_end = swqe->ip_start + ip_hdrlen(skb) - 1;
1999
2000 switch (ip_hdr(skb)->protocol) {
2001 case IPPROTO_UDP:
2002 if (skb->ip_summed == CHECKSUM_PARTIAL)
2003 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2004
2005 swqe->tcp_offset = swqe->ip_end + 1 +
2006 offsetof(struct udphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002007 break;
2008
2009 case IPPROTO_TCP:
2010 if (skb->ip_summed == CHECKSUM_PARTIAL)
2011 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2012
2013 swqe->tcp_offset = swqe->ip_end + 1 +
2014 offsetof(struct tcphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002015 break;
2016 }
2017}
2018
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002019static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2020 struct ehea_swqe *swqe, u32 lkey)
2021{
Anton Blanchardd695c332011-10-14 05:31:05 +00002022 swqe->tx_control |= EHEA_SWQE_DESCRIPTORS_PRESENT;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002023
Anton Blanchardd695c332011-10-14 05:31:05 +00002024 xmit_common(skb, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002025
2026 write_swqe2_data(skb, dev, swqe, lkey);
2027}
2028
2029static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2030 struct ehea_swqe *swqe)
2031{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002032 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002033
Anton Blanchardd695c332011-10-14 05:31:05 +00002034 xmit_common(skb, swqe);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002035
Anton Blanchard30e2e902011-10-14 05:31:07 +00002036 if (!skb->data_len)
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002037 skb_copy_from_linear_data(skb, imm_data, skb->len);
Anton Blanchard30e2e902011-10-14 05:31:07 +00002038 else
2039 skb_copy_bits(skb, 0, imm_data, skb->len);
Anton Blanchardd695c332011-10-14 05:31:05 +00002040
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002041 swqe->immediate_data_length = skb->len;
2042 dev_kfree_skb(skb);
2043}
2044
2045static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2046{
2047 struct ehea_port *port = netdev_priv(dev);
2048 struct ehea_swqe *swqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002049 u32 lkey;
2050 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002051 struct ehea_port_res *pr;
Anton Blanchardb9564462011-10-14 05:30:59 +00002052 struct netdev_queue *txq;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002053
Anton Blanchardb9564462011-10-14 05:30:59 +00002054 pr = &port->port_res[skb_get_queue_mapping(skb)];
2055 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002056
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002057 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2058 memset(swqe, 0, SWQE_HEADER_SIZE);
2059 atomic_dec(&pr->swqe_avail);
2060
Eric Dumazete5ccd962010-10-26 19:21:07 +00002061 if (vlan_tx_tag_present(skb)) {
2062 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2063 swqe->vlan_tag = vlan_tx_tag_get(skb);
2064 }
2065
Breno Leitaoce45b872010-10-27 08:45:14 +00002066 pr->tx_packets++;
2067 pr->tx_bytes += skb->len;
2068
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002069 if (skb->len <= SWQE3_MAX_IMM) {
2070 u32 sig_iv = port->sig_comp_iv;
2071 u32 swqe_num = pr->swqe_id_counter;
2072 ehea_xmit3(skb, dev, swqe);
2073 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2074 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2075 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2076 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2077 sig_iv);
2078 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2079 pr->swqe_ll_count = 0;
2080 } else
2081 pr->swqe_ll_count += 1;
2082 } else {
2083 swqe->wr_id =
2084 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2085 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002086 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002087 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2088 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2089
2090 pr->sq_skba.index++;
2091 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2092
2093 lkey = pr->send_mr.lkey;
2094 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002095 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002096 }
2097 pr->swqe_id_counter += 1;
2098
Joe Perches8c4877a2010-12-13 10:05:14 -08002099 netif_info(port, tx_queued, dev,
2100 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2101 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002102 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002103
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002104 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002105 netif_tx_stop_queue(txq);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002106 swqe->tx_control |= EHEA_SWQE_PURGE;
2107 }
Thomas Klein44c82152007-07-11 16:32:00 +02002108
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002109 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002110
2111 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002112 pr->p_stats.queue_stopped++;
2113 netif_tx_stop_queue(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002114 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002115
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002116 return NETDEV_TX_OK;
2117}
2118
Jiri Pirko8e586132011-12-08 19:52:37 -05002119static int ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002120{
2121 struct ehea_port *port = netdev_priv(dev);
2122 struct ehea_adapter *adapter = port->adapter;
2123 struct hcp_ehea_port_cb1 *cb1;
2124 int index;
2125 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002126 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002127
Thomas Klein3faf2692009-01-21 14:45:33 -08002128 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002129 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002130 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002131 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002132 goto out;
2133 }
2134
2135 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2136 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2137 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002138 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002139 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002140 goto out;
2141 }
2142
2143 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002144 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002145
2146 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2147 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002148 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002149 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002150 err = -EINVAL;
2151 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002152out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002153 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002154 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002155}
2156
Jiri Pirko8e586132011-12-08 19:52:37 -05002157static int ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002158{
2159 struct ehea_port *port = netdev_priv(dev);
2160 struct ehea_adapter *adapter = port->adapter;
2161 struct hcp_ehea_port_cb1 *cb1;
2162 int index;
2163 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002164 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002165
Thomas Klein3faf2692009-01-21 14:45:33 -08002166 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002167 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002168 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002169 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002170 goto out;
2171 }
2172
2173 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2174 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2175 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002176 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002177 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002178 goto out;
2179 }
2180
2181 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002182 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002183
2184 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2185 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002186 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002187 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002188 err = -EINVAL;
2189 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002190out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002191 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002192 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002193}
2194
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002195static int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002196{
2197 int ret = -EIO;
2198 u64 hret;
2199 u16 dummy16 = 0;
2200 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002201 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002202
Thomas Klein3faf2692009-01-21 14:45:33 -08002203 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002204 if (!cb0) {
2205 ret = -ENOMEM;
2206 goto out;
2207 }
2208
2209 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2210 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2211 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002212 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002213 goto out;
2214 }
2215
2216 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2217 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2218 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2219 &dummy64, &dummy64, &dummy16, &dummy16);
2220 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002221 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002222 goto out;
2223 }
2224
2225 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2226 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2227 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002228 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002229 goto out;
2230 }
2231
2232 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2233 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2234 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2235 &dummy64, &dummy64, &dummy16, &dummy16);
2236 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002237 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002238 goto out;
2239 }
2240
2241 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2242 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2243 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002244 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002245 goto out;
2246 }
2247
2248 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2249 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2250 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2251 &dummy64, &dummy64, &dummy16, &dummy16);
2252 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002253 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002254 goto out;
2255 }
2256
2257 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2258 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2259 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002260 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002261 goto out;
2262 }
2263
2264 ret = 0;
2265out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002266 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002267 return ret;
2268}
2269
Anton Blanchard723f28e2011-10-14 05:31:01 +00002270static int ehea_port_res_setup(struct ehea_port *port, int def_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002271{
2272 int ret, i;
2273 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2274 enum ehea_eq_type eq_type = EHEA_EQ;
2275
2276 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2277 EHEA_MAX_ENTRIES_EQ, 1);
2278 if (!port->qp_eq) {
2279 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002280 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002281 goto out_kill_eq;
2282 }
2283
2284 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002285 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002286 pr_cfg.max_entries_sq = sq_entries;
2287 pr_cfg.max_entries_rq1 = rq1_entries;
2288 pr_cfg.max_entries_rq2 = rq2_entries;
2289 pr_cfg.max_entries_rq3 = rq3_entries;
2290
2291 pr_cfg_small_rx.max_entries_rcq = 1;
2292 pr_cfg_small_rx.max_entries_scq = sq_entries;
2293 pr_cfg_small_rx.max_entries_sq = sq_entries;
2294 pr_cfg_small_rx.max_entries_rq1 = 1;
2295 pr_cfg_small_rx.max_entries_rq2 = 1;
2296 pr_cfg_small_rx.max_entries_rq3 = 1;
2297
2298 for (i = 0; i < def_qps; i++) {
2299 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2300 if (ret)
2301 goto out_clean_pr;
2302 }
Anton Blanchard723f28e2011-10-14 05:31:01 +00002303 for (i = def_qps; i < def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002304 ret = ehea_init_port_res(port, &port->port_res[i],
2305 &pr_cfg_small_rx, i);
2306 if (ret)
2307 goto out_clean_pr;
2308 }
2309
2310 return 0;
2311
2312out_clean_pr:
2313 while (--i >= 0)
2314 ehea_clean_portres(port, &port->port_res[i]);
2315
2316out_kill_eq:
2317 ehea_destroy_eq(port->qp_eq);
2318 return ret;
2319}
2320
2321static int ehea_clean_all_portres(struct ehea_port *port)
2322{
2323 int ret = 0;
2324 int i;
2325
Anton Blanchard723f28e2011-10-14 05:31:01 +00002326 for (i = 0; i < port->num_def_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002327 ret |= ehea_clean_portres(port, &port->port_res[i]);
2328
2329 ret |= ehea_destroy_eq(port->qp_eq);
2330
2331 return ret;
2332}
2333
Thomas Klein35cf2e22007-08-06 13:55:14 +02002334static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002335{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002336 if (adapter->active_ports)
2337 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002338
2339 ehea_rem_mr(&adapter->mr);
2340}
2341
Thomas Klein35cf2e22007-08-06 13:55:14 +02002342static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002343{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002344 if (adapter->active_ports)
2345 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002346
2347 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2348}
2349
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002350static int ehea_up(struct net_device *dev)
2351{
2352 int ret, i;
2353 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002354
2355 if (port->state == EHEA_PORT_UP)
2356 return 0;
2357
Anton Blanchard723f28e2011-10-14 05:31:01 +00002358 ret = ehea_port_res_setup(port, port->num_def_qps);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002359 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002360 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002361 goto out;
2362 }
2363
2364 /* Set default QP for this port */
2365 ret = ehea_configure_port(port);
2366 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002367 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002368 goto out_clean_pr;
2369 }
2370
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002371 ret = ehea_reg_interrupts(dev);
2372 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002373 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002374 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002375 }
2376
Anton Blanchard723f28e2011-10-14 05:31:01 +00002377 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002378 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2379 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002380 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002381 goto out_free_irqs;
2382 }
2383 }
2384
Doug Maxey508d2b52008-01-31 20:20:49 -06002385 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002386 ret = ehea_fill_port_res(&port->port_res[i]);
2387 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002388 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002389 goto out_free_irqs;
2390 }
2391 }
2392
Thomas Klein21eee2d2008-02-13 16:18:33 +01002393 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2394 if (ret) {
2395 ret = -EIO;
2396 goto out_free_irqs;
2397 }
2398
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002399 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002400
2401 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002402 goto out;
2403
2404out_free_irqs:
2405 ehea_free_interrupts(dev);
2406
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002407out_clean_pr:
2408 ehea_clean_all_portres(port);
2409out:
Thomas Klein44c82152007-07-11 16:32:00 +02002410 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002411 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002412
Thomas Klein21eee2d2008-02-13 16:18:33 +01002413 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002414 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002415
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002416 return ret;
2417}
2418
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002419static void port_napi_disable(struct ehea_port *port)
2420{
2421 int i;
2422
Anton Blanchard723f28e2011-10-14 05:31:01 +00002423 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002424 napi_disable(&port->port_res[i].napi);
2425}
2426
2427static void port_napi_enable(struct ehea_port *port)
2428{
2429 int i;
2430
Anton Blanchard723f28e2011-10-14 05:31:01 +00002431 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002432 napi_enable(&port->port_res[i].napi);
2433}
2434
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002435static int ehea_open(struct net_device *dev)
2436{
2437 int ret;
2438 struct ehea_port *port = netdev_priv(dev);
2439
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002440 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002441
Joe Perches8c4877a2010-12-13 10:05:14 -08002442 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002443
2444 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002445 if (!ret) {
2446 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002447 netif_tx_start_all_queues(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002448 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002449
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002450 mutex_unlock(&port->port_lock);
Anton Blanchard67c170a2011-11-23 00:13:54 +00002451 schedule_delayed_work(&port->stats_work,
2452 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002453
2454 return ret;
2455}
2456
2457static int ehea_down(struct net_device *dev)
2458{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002459 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002460 struct ehea_port *port = netdev_priv(dev);
2461
2462 if (port->state == EHEA_PORT_DOWN)
2463 return 0;
2464
2465 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002466 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2467
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002468 ehea_free_interrupts(dev);
2469
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002470 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002471
Thomas Klein21eee2d2008-02-13 16:18:33 +01002472 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002473
Thomas Klein44c82152007-07-11 16:32:00 +02002474 ret = ehea_clean_all_portres(port);
2475 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002476 netdev_info(dev, "Failed freeing resources. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002477
Thomas Klein21eee2d2008-02-13 16:18:33 +01002478 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002479
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002480 return ret;
2481}
2482
2483static int ehea_stop(struct net_device *dev)
2484{
2485 int ret;
2486 struct ehea_port *port = netdev_priv(dev);
2487
Joe Perches8c4877a2010-12-13 10:05:14 -08002488 netif_info(port, ifdown, dev, "disabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002489
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002490 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002491 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00002492 cancel_delayed_work_sync(&port->stats_work);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002493 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002494 netif_tx_stop_all_queues(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002495 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002496 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002497 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002498 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002499 return ret;
2500}
2501
Andrew Morton22559c52008-04-18 13:50:39 -07002502static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002503{
2504 struct ehea_qp qp = *orig_qp;
2505 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2506 struct ehea_swqe *swqe;
2507 int wqe_index;
2508 int i;
2509
2510 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2511 swqe = ehea_get_swqe(&qp, &wqe_index);
2512 swqe->tx_control |= EHEA_SWQE_PURGE;
2513 }
2514}
2515
Andrew Morton22559c52008-04-18 13:50:39 -07002516static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002517{
2518 int i;
2519
Anton Blanchard723f28e2011-10-14 05:31:01 +00002520 for (i = 0; i < port->num_def_qps; i++) {
Thomas Klein44fb3122008-04-04 15:04:53 +02002521 struct ehea_port_res *pr = &port->port_res[i];
2522 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002523 int ret;
2524
2525 ret = wait_event_timeout(port->swqe_avail_wq,
2526 atomic_read(&pr->swqe_avail) >= swqe_max,
2527 msecs_to_jiffies(100));
2528
2529 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002530 pr_err("WARNING: sq not flushed completely\n");
Breno Leitao5b27d422010-10-05 13:16:22 +00002531 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002532 }
2533 }
2534}
2535
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002536static int ehea_stop_qps(struct net_device *dev)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002537{
2538 struct ehea_port *port = netdev_priv(dev);
2539 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002540 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002541 int ret = -EIO;
2542 int dret;
2543 int i;
2544 u64 hret;
2545 u64 dummy64 = 0;
2546 u16 dummy16 = 0;
2547
Thomas Klein3faf2692009-01-21 14:45:33 -08002548 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002549 if (!cb0) {
2550 ret = -ENOMEM;
2551 goto out;
2552 }
2553
Anton Blanchard723f28e2011-10-14 05:31:01 +00002554 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002555 struct ehea_port_res *pr = &port->port_res[i];
2556 struct ehea_qp *qp = pr->qp;
2557
2558 /* Purge send queue */
2559 ehea_purge_sq(qp);
2560
2561 /* Disable queue pair */
2562 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2563 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2564 cb0);
2565 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002566 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002567 goto out;
2568 }
2569
2570 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2571 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2572
2573 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2574 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2575 1), cb0, &dummy64,
2576 &dummy64, &dummy16, &dummy16);
2577 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002578 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002579 goto out;
2580 }
2581
2582 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2583 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2584 cb0);
2585 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002586 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002587 goto out;
2588 }
2589
2590 /* deregister shared memory regions */
2591 dret = ehea_rem_smrs(pr);
2592 if (dret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002593 pr_err("unreg shared memory region failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002594 goto out;
2595 }
2596 }
2597
2598 ret = 0;
2599out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002600 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002601
2602 return ret;
2603}
2604
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002605static void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002606{
2607 struct ehea_qp qp = *orig_qp;
2608 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2609 struct ehea_rwqe *rwqe;
2610 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2611 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2612 struct sk_buff *skb;
2613 u32 lkey = pr->recv_mr.lkey;
2614
2615
2616 int i;
2617 int index;
2618
2619 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2620 rwqe = ehea_get_next_rwqe(&qp, 2);
2621 rwqe->sg_list[0].l_key = lkey;
2622 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2623 skb = skba_rq2[index];
2624 if (skb)
2625 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2626 }
2627
2628 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2629 rwqe = ehea_get_next_rwqe(&qp, 3);
2630 rwqe->sg_list[0].l_key = lkey;
2631 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2632 skb = skba_rq3[index];
2633 if (skb)
2634 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2635 }
2636}
2637
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002638static int ehea_restart_qps(struct net_device *dev)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002639{
2640 struct ehea_port *port = netdev_priv(dev);
2641 struct ehea_adapter *adapter = port->adapter;
2642 int ret = 0;
2643 int i;
2644
Doug Maxey508d2b52008-01-31 20:20:49 -06002645 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002646 u64 hret;
2647 u64 dummy64 = 0;
2648 u16 dummy16 = 0;
2649
Thomas Klein3faf2692009-01-21 14:45:33 -08002650 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002651 if (!cb0) {
2652 ret = -ENOMEM;
2653 goto out;
2654 }
2655
Anton Blanchard723f28e2011-10-14 05:31:01 +00002656 for (i = 0; i < (port->num_def_qps); i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002657 struct ehea_port_res *pr = &port->port_res[i];
2658 struct ehea_qp *qp = pr->qp;
2659
2660 ret = ehea_gen_smrs(pr);
2661 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002662 netdev_err(dev, "creation of shared memory regions failed\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002663 goto out;
2664 }
2665
2666 ehea_update_rqs(qp, pr);
2667
2668 /* Enable queue pair */
2669 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2670 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2671 cb0);
2672 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002673 netdev_err(dev, "query_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002674 goto out;
2675 }
2676
2677 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2678 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2679
2680 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2681 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2682 1), cb0, &dummy64,
2683 &dummy64, &dummy16, &dummy16);
2684 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002685 netdev_err(dev, "modify_ehea_qp failed (1)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002686 goto out;
2687 }
2688
2689 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2690 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2691 cb0);
2692 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002693 netdev_err(dev, "query_ehea_qp failed (2)\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002694 goto out;
2695 }
2696
2697 /* refill entire queue */
2698 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2699 ehea_refill_rq2(pr, 0);
2700 ehea_refill_rq3(pr, 0);
2701 }
2702out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002703 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002704
2705 return ret;
2706}
2707
David Howellsc4028952006-11-22 14:57:56 +00002708static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002709{
2710 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002711 struct ehea_port *port =
2712 container_of(work, struct ehea_port, reset_task);
2713 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002714
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002715 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002716 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002717 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002718 netif_tx_disable(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002719
2720 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002721
Thomas Klein44c82152007-07-11 16:32:00 +02002722 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002723
2724 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002725 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002726 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002727
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002728 ehea_set_multicast_list(dev);
2729
Joe Perches8c4877a2010-12-13 10:05:14 -08002730 netif_info(port, timer, dev, "reset successful\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002731
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002732 port_napi_enable(port);
2733
Anton Blanchardb9564462011-10-14 05:30:59 +00002734 netif_tx_wake_all_queues(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002735out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002736 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002737 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002738}
2739
Tejun Heo3d6b8922010-12-12 16:45:14 +01002740static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002741{
2742 int ret, i;
2743 struct ehea_adapter *adapter;
2744
Joe Perches8c4877a2010-12-13 10:05:14 -08002745 pr_info("LPAR memory changed - re-initializing driver\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002746
2747 list_for_each_entry(adapter, &adapter_list, list)
2748 if (adapter->active_ports) {
2749 /* Shutdown all ports */
2750 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2751 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002752 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002753
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002754 if (!port)
2755 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002756
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002757 dev = port->netdev;
2758
2759 if (dev->flags & IFF_UP) {
2760 mutex_lock(&port->port_lock);
Anton Blanchardb9564462011-10-14 05:30:59 +00002761 netif_tx_disable(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002762 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002763 ret = ehea_stop_qps(dev);
2764 if (ret) {
2765 mutex_unlock(&port->port_lock);
2766 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002767 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002768 port_napi_disable(port);
2769 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002770 }
Andre Detsch2928db42010-08-17 05:49:12 +00002771 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002772 }
2773
2774 /* Unregister old memory region */
2775 ret = ehea_rem_mr(&adapter->mr);
2776 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002777 pr_err("unregister MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002778 goto out;
2779 }
2780 }
2781
Thomas Klein44c82152007-07-11 16:32:00 +02002782 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2783
2784 list_for_each_entry(adapter, &adapter_list, list)
2785 if (adapter->active_ports) {
2786 /* Register new memory region */
2787 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2788 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002789 pr_err("register MR failed - driver inoperable!\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002790 goto out;
2791 }
2792
2793 /* Restart all ports */
2794 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2795 struct ehea_port *port = adapter->port[i];
2796
2797 if (port) {
2798 struct net_device *dev = port->netdev;
2799
2800 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002801 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002802 ret = ehea_restart_qps(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002803 if (!ret) {
2804 check_sqs(port);
2805 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002806 netif_tx_wake_all_queues(dev);
Breno Leitao6f4d6dc2011-04-19 09:39:22 +00002807 } else {
2808 netdev_err(dev, "Unable to restart QPS\n");
2809 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002810 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002811 }
2812 }
2813 }
2814 }
Joe Perches8c4877a2010-12-13 10:05:14 -08002815 pr_info("re-initializing driver complete\n");
Thomas Klein44c82152007-07-11 16:32:00 +02002816out:
2817 return;
2818}
2819
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002820static void ehea_tx_watchdog(struct net_device *dev)
2821{
2822 struct ehea_port *port = netdev_priv(dev);
2823
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002824 if (netif_carrier_ok(dev) &&
2825 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002826 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002827}
2828
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002829static int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002830{
2831 struct hcp_query_ehea *cb;
2832 u64 hret;
2833 int ret;
2834
Thomas Klein3faf2692009-01-21 14:45:33 -08002835 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002836 if (!cb) {
2837 ret = -ENOMEM;
2838 goto out;
2839 }
2840
2841 hret = ehea_h_query_ehea(adapter->handle, cb);
2842
2843 if (hret != H_SUCCESS) {
2844 ret = -EIO;
2845 goto out_herr;
2846 }
2847
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002848 adapter->max_mc_mac = cb->max_mc_mac - 1;
2849 ret = 0;
2850
2851out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08002852 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002853out:
2854 return ret;
2855}
2856
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002857static int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002858{
2859 struct hcp_ehea_port_cb4 *cb4;
2860 u64 hret;
2861 int ret = 0;
2862
2863 *jumbo = 0;
2864
2865 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08002866 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002867 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002868 pr_err("no mem for cb4\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002869 ret = -ENOMEM;
2870 goto out;
2871 } else {
2872 hret = ehea_h_query_ehea_port(port->adapter->handle,
2873 port->logical_port_id,
2874 H_PORT_CB4,
2875 H_PORT_CB4_JUMBO, cb4);
2876 if (hret == H_SUCCESS) {
2877 if (cb4->jumbo_frame)
2878 *jumbo = 1;
2879 else {
2880 cb4->jumbo_frame = 1;
2881 hret = ehea_h_modify_ehea_port(port->adapter->
2882 handle,
2883 port->
2884 logical_port_id,
2885 H_PORT_CB4,
2886 H_PORT_CB4_JUMBO,
2887 cb4);
2888 if (hret == H_SUCCESS)
2889 *jumbo = 1;
2890 }
2891 } else
2892 ret = -EINVAL;
2893
Thomas Klein3faf2692009-01-21 14:45:33 -08002894 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002895 }
2896out:
2897 return ret;
2898}
2899
2900static ssize_t ehea_show_port_id(struct device *dev,
2901 struct device_attribute *attr, char *buf)
2902{
2903 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02002904 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002905}
2906
2907static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
2908 NULL);
2909
2910static void __devinit logical_port_release(struct device *dev)
2911{
2912 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07002913 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002914}
2915
2916static struct device *ehea_register_port(struct ehea_port *port,
2917 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002918{
2919 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002920
Grant Likely61c7a082010-04-13 16:12:29 -07002921 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10002922 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02002923 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002924
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08002925 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002926 port->ofdev.dev.release = logical_port_release;
2927
2928 ret = of_device_register(&port->ofdev);
2929 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002930 pr_err("failed to register device. ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002931 goto out;
2932 }
2933
2934 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002935 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002936 pr_err("failed to register attributes, ret=%d\n", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002937 goto out_unreg_of_dev;
2938 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01002939
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002940 return &port->ofdev.dev;
2941
2942out_unreg_of_dev:
2943 of_device_unregister(&port->ofdev);
2944out:
2945 return NULL;
2946}
2947
2948static void ehea_unregister_port(struct ehea_port *port)
2949{
2950 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
2951 of_device_unregister(&port->ofdev);
2952}
2953
Thomas Klein086c1b22009-01-21 14:43:59 -08002954static const struct net_device_ops ehea_netdev_ops = {
2955 .ndo_open = ehea_open,
2956 .ndo_stop = ehea_stop,
2957 .ndo_start_xmit = ehea_start_xmit,
2958#ifdef CONFIG_NET_POLL_CONTROLLER
2959 .ndo_poll_controller = ehea_netpoll,
2960#endif
Anton Blanchard239c5622011-10-14 05:31:09 +00002961 .ndo_get_stats64 = ehea_get_stats64,
Thomas Klein086c1b22009-01-21 14:43:59 -08002962 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00002963 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00002964 .ndo_set_rx_mode = ehea_set_multicast_list,
Thomas Klein086c1b22009-01-21 14:43:59 -08002965 .ndo_change_mtu = ehea_change_mtu,
Thomas Klein086c1b22009-01-21 14:43:59 -08002966 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07002967 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
2968 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08002969};
2970
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002971static struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002972 u32 logical_port_id,
2973 struct device_node *dn)
2974{
2975 int ret;
2976 struct net_device *dev;
2977 struct ehea_port *port;
2978 struct device *port_dev;
2979 int jumbo;
2980
2981 /* allocate memory for the port structures */
Anton Blanchardb9564462011-10-14 05:30:59 +00002982 dev = alloc_etherdev_mq(sizeof(struct ehea_port), EHEA_MAX_PORT_RES);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002983
2984 if (!dev) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002985 ret = -ENOMEM;
2986 goto out_err;
2987 }
2988
2989 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002990
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002991 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002992 port->state = EHEA_PORT_DOWN;
2993 port->sig_comp_iv = sq_entries / 10;
2994
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002995 port->adapter = adapter;
2996 port->netdev = dev;
2997 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002998
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002999 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003000
3001 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3002 if (!port->mc_list) {
3003 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003004 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003005 }
3006
3007 INIT_LIST_HEAD(&port->mc_list->list);
3008
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003009 ret = ehea_sense_port_attr(port);
3010 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003011 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003012
Anton Blanchardb9564462011-10-14 05:30:59 +00003013 netif_set_real_num_rx_queues(dev, port->num_def_qps);
Anton Blanchard723f28e2011-10-14 05:31:01 +00003014 netif_set_real_num_tx_queues(dev, port->num_def_qps);
Anton Blanchardb9564462011-10-14 05:30:59 +00003015
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003016 port_dev = ehea_register_port(port, dn);
3017 if (!port_dev)
3018 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003019
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003020 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003021
3022 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003023 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3024
Thomas Klein086c1b22009-01-21 14:43:59 -08003025 dev->netdev_ops = &ehea_netdev_ops;
3026 ehea_set_ethtool_ops(dev);
3027
Anton Blanchardd695c332011-10-14 05:31:05 +00003028 dev->hw_features = NETIF_F_SG | NETIF_F_TSO
Michał Mirosławf4786a92011-04-17 00:15:47 +00003029 | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX | NETIF_F_LRO;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003030 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003031 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003032 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
Anton Blanchard3f7947b2011-10-14 05:30:58 +00003033 | NETIF_F_RXCSUM;
Anton Blanchard076f2032011-10-14 05:31:03 +00003034 dev->vlan_features = NETIF_F_SG | NETIF_F_TSO | NETIF_F_HIGHDMA |
3035 NETIF_F_IP_CSUM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003036 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3037
David Howellsc4028952006-11-22 14:57:56 +00003038 INIT_WORK(&port->reset_task, ehea_reset_port);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003039 INIT_DELAYED_WORK(&port->stats_work, ehea_update_stats);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003040
Anton Blanchard21ccc792011-05-10 16:17:10 +00003041 init_waitqueue_head(&port->swqe_avail_wq);
3042 init_waitqueue_head(&port->restart_wq);
3043
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003044 memset(&port->stats, 0, sizeof(struct net_device_stats));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003045 ret = register_netdev(dev);
3046 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003047 pr_err("register_netdev failed. ret=%d\n", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003048 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003049 }
3050
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003051 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003052 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003053 netdev_err(dev, "failed determining jumbo frame status\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003054
Joe Perches8c4877a2010-12-13 10:05:14 -08003055 netdev_info(dev, "Jumbo frames are %sabled\n",
3056 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003057
Thomas Klein44c82152007-07-11 16:32:00 +02003058 adapter->active_ports++;
3059
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003060 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003061
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003062out_unreg_port:
3063 ehea_unregister_port(port);
3064
3065out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003066 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003067
3068out_free_ethdev:
3069 free_netdev(dev);
3070
3071out_err:
Joe Perches8c4877a2010-12-13 10:05:14 -08003072 pr_err("setting up logical port with id=%d failed, ret=%d\n",
3073 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003074 return NULL;
3075}
3076
3077static void ehea_shutdown_single_port(struct ehea_port *port)
3078{
Brian King7fb1c2a2008-05-14 09:48:25 -05003079 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003080
3081 cancel_work_sync(&port->reset_task);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +00003082 cancel_delayed_work_sync(&port->stats_work);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003083 unregister_netdev(port->netdev);
3084 ehea_unregister_port(port);
3085 kfree(port->mc_list);
3086 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003087 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003088}
3089
3090static int ehea_setup_ports(struct ehea_adapter *adapter)
3091{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003092 struct device_node *lhea_dn;
3093 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003094
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003095 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003096 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003097
Grant Likely61c7a082010-04-13 16:12:29 -07003098 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003099 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003100
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003101 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003102 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003103 if (!dn_log_port_id) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003104 pr_err("bad device node: eth_dn name=%s\n",
3105 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003106 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003107 }
3108
Thomas Klein1211bb62007-04-26 11:56:43 +02003109 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003110 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003111 of_node_put(eth_dn);
3112 return -EIO;
3113 }
3114
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003115 adapter->port[i] = ehea_setup_single_port(adapter,
3116 *dn_log_port_id,
3117 eth_dn);
3118 if (adapter->port[i])
Joe Perches8c4877a2010-12-13 10:05:14 -08003119 netdev_info(adapter->port[i]->netdev,
3120 "logical port id #%d\n", *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003121 else
3122 ehea_remove_adapter_mr(adapter);
3123
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003124 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003125 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003126 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003127}
3128
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003129static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3130 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003131{
3132 struct device_node *lhea_dn;
3133 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003134 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003135
Grant Likely61c7a082010-04-13 16:12:29 -07003136 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003137 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003138
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003139 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003140 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003141 if (dn_log_port_id)
3142 if (*dn_log_port_id == logical_port_id)
3143 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003144 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003145
3146 return NULL;
3147}
3148
3149static ssize_t ehea_probe_port(struct device *dev,
3150 struct device_attribute *attr,
3151 const char *buf, size_t count)
3152{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003153 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003154 struct ehea_port *port;
3155 struct device_node *eth_dn = NULL;
3156 int i;
3157
3158 u32 logical_port_id;
3159
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003160 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003161
3162 port = ehea_get_port(adapter, logical_port_id);
3163
3164 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003165 netdev_info(port->netdev, "adding port with logical port id=%d failed: port already configured\n",
3166 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003167 return -EINVAL;
3168 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003169
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003170 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3171
3172 if (!eth_dn) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003173 pr_info("no logical port with id %d found\n", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003174 return -EINVAL;
3175 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003176
Thomas Klein1211bb62007-04-26 11:56:43 +02003177 if (ehea_add_adapter_mr(adapter)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003178 pr_err("creating MR failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003179 return -EIO;
3180 }
3181
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003182 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3183
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003184 of_node_put(eth_dn);
3185
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003186 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003187 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003188 if (!adapter->port[i]) {
3189 adapter->port[i] = port;
3190 break;
3191 }
3192
Joe Perches8c4877a2010-12-13 10:05:14 -08003193 netdev_info(port->netdev, "added: (logical port id=%d)\n",
3194 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003195 } else {
3196 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003197 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003198 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003199
3200 return (ssize_t) count;
3201}
3202
3203static ssize_t ehea_remove_port(struct device *dev,
3204 struct device_attribute *attr,
3205 const char *buf, size_t count)
3206{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003207 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003208 struct ehea_port *port;
3209 int i;
3210 u32 logical_port_id;
3211
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003212 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003213
3214 port = ehea_get_port(adapter, logical_port_id);
3215
3216 if (port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003217 netdev_info(port->netdev, "removed: (logical port id=%d)\n",
3218 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003219
3220 ehea_shutdown_single_port(port);
3221
Doug Maxey508d2b52008-01-31 20:20:49 -06003222 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003223 if (adapter->port[i] == port) {
3224 adapter->port[i] = NULL;
3225 break;
3226 }
3227 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08003228 pr_err("removing port with logical port id=%d failed. port not configured.\n",
3229 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003230 return -EINVAL;
3231 }
3232
Thomas Klein1211bb62007-04-26 11:56:43 +02003233 ehea_remove_adapter_mr(adapter);
3234
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003235 return (ssize_t) count;
3236}
3237
3238static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3239static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3240
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003241static int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003242{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003243 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003244 if (ret)
3245 goto out;
3246
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003247 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003248out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003249 return ret;
3250}
3251
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003252static void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003253{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003254 device_remove_file(&dev->dev, &dev_attr_probe_port);
3255 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003256}
3257
Grant Likely2dc11582010-08-06 09:25:50 -06003258static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003259 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003260{
3261 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003262 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003263 int ret;
3264
Grant Likely61c7a082010-04-13 16:12:29 -07003265 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003266 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003267 return -EINVAL;
3268 }
3269
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003270 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3271 if (!adapter) {
3272 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003273 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003274 goto out;
3275 }
3276
Thomas Klein44c82152007-07-11 16:32:00 +02003277 list_add(&adapter->list, &adapter_list);
3278
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003279 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003280
Grant Likely61c7a082010-04-13 16:12:29 -07003281 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003282 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003283 if (adapter_handle)
3284 adapter->handle = *adapter_handle;
3285
3286 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003287 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003288 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003289 ret = -ENODEV;
3290 goto out_free_ad;
3291 }
3292
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003293 adapter->pd = EHEA_PD_ID;
3294
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003295 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003296
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003297
3298 /* initialize adapter and ports */
3299 /* get adapter properties */
3300 ret = ehea_sense_adapter_attr(adapter);
3301 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003302 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003303 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003304 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003305
3306 adapter->neq = ehea_create_eq(adapter,
3307 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3308 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003309 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003310 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003311 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003312 }
3313
3314 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3315 (unsigned long)adapter);
3316
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003317 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003318 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003319 "ehea_neq", adapter);
3320 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003321 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003322 goto out_kill_eq;
3323 }
3324
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003325 ret = ehea_create_device_sysfs(dev);
3326 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003327 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003328
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003329 ret = ehea_setup_ports(adapter);
3330 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003331 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003332 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003333 }
3334
3335 ret = 0;
3336 goto out;
3337
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003338out_rem_dev_sysfs:
3339 ehea_remove_device_sysfs(dev);
3340
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003341out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003342 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003343
3344out_kill_eq:
3345 ehea_destroy_eq(adapter->neq);
3346
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003347out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003348 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003349 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003350
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003351out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003352 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003353
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003354 return ret;
3355}
3356
Grant Likely2dc11582010-08-06 09:25:50 -06003357static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003358{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003359 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003360 int i;
3361
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003362 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003363 if (adapter->port[i]) {
3364 ehea_shutdown_single_port(adapter->port[i]);
3365 adapter->port[i] = NULL;
3366 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003367
3368 ehea_remove_device_sysfs(dev);
3369
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003370 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003371 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003372
3373 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003374 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003375 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003376 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003377
Thomas Klein21eee2d2008-02-13 16:18:33 +01003378 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003379
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003380 return 0;
3381}
3382
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003383static void ehea_crash_handler(void)
Thomas Klein21eee2d2008-02-13 16:18:33 +01003384{
3385 int i;
3386
3387 if (ehea_fw_handles.arr)
3388 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3389 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3390 ehea_fw_handles.arr[i].fwh,
3391 FORCE_FREE);
3392
3393 if (ehea_bcmc_regs.arr)
3394 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3395 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3396 ehea_bcmc_regs.arr[i].port_id,
3397 ehea_bcmc_regs.arr[i].reg_type,
3398 ehea_bcmc_regs.arr[i].macaddr,
3399 0, H_DEREG_BCMC);
3400}
3401
Hannes Hering48cfb142008-05-07 14:43:36 +02003402static int ehea_mem_notifier(struct notifier_block *nb,
3403 unsigned long action, void *data)
3404{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003405 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003406 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003407
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003408 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003409
Hannes Hering48cfb142008-05-07 14:43:36 +02003410 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003411 case MEM_CANCEL_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003412 pr_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003413 /* Readd canceled memory block */
3414 case MEM_ONLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003415 pr_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003416 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003417 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003418 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003419 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003420 break;
3421 case MEM_GOING_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003422 pr_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003423 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003424 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003425 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003426 ehea_rereg_mrs();
Hannes Hering48cfb142008-05-07 14:43:36 +02003427 break;
3428 default:
3429 break;
3430 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003431
3432 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003433 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003434
Thomas Kleina7c561f22010-04-20 23:11:31 +00003435out_unlock:
3436 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003437 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003438}
3439
3440static struct notifier_block ehea_mem_nb = {
3441 .notifier_call = ehea_mem_notifier,
3442};
3443
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003444static int ehea_reboot_notifier(struct notifier_block *nb,
3445 unsigned long action, void *unused)
3446{
3447 if (action == SYS_RESTART) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003448 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003449 ibmebus_unregister_driver(&ehea_driver);
3450 }
3451 return NOTIFY_DONE;
3452}
3453
3454static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003455 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003456};
3457
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003458static int check_module_parm(void)
3459{
3460 int ret = 0;
3461
3462 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3463 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003464 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003465 ret = -EINVAL;
3466 }
3467 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3468 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003469 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003470 ret = -EINVAL;
3471 }
3472 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3473 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003474 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003475 ret = -EINVAL;
3476 }
3477 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3478 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003479 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003480 ret = -EINVAL;
3481 }
3482
3483 return ret;
3484}
3485
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003486static ssize_t ehea_show_capabilities(struct device_driver *drv,
3487 char *buf)
3488{
3489 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3490}
3491
3492static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3493 ehea_show_capabilities, NULL);
3494
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003495static int __init ehea_module_init(void)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003496{
3497 int ret;
3498
Joe Perches8c4877a2010-12-13 10:05:14 -08003499 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003500
Thomas Klein21eee2d2008-02-13 16:18:33 +01003501 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3502 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3503
Daniel Walker9f71a562008-03-28 14:41:26 -07003504 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003505 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003506
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003507 ret = check_module_parm();
3508 if (ret)
3509 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003510
3511 ret = ehea_create_busmap();
3512 if (ret)
3513 goto out;
3514
Thomas Klein21eee2d2008-02-13 16:18:33 +01003515 ret = register_reboot_notifier(&ehea_reboot_nb);
3516 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003517 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003518
Hannes Hering48cfb142008-05-07 14:43:36 +02003519 ret = register_memory_notifier(&ehea_mem_nb);
3520 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003521 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003522
Joe Perchesc061b182010-08-23 18:20:03 +00003523 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003524 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003525 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003526
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003527 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003528 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003529 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003530 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003531 }
3532
3533 ret = driver_create_file(&ehea_driver.driver,
3534 &driver_attr_capabilities);
3535 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003536 pr_err("failed to register capabilities attribute, ret=%d\n",
3537 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003538 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003539 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003540
Thomas Klein21eee2d2008-02-13 16:18:33 +01003541 return ret;
3542
3543out3:
3544 ibmebus_unregister_driver(&ehea_driver);
3545out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003546 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003547 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003548 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003549out:
3550 return ret;
3551}
3552
3553static void __exit ehea_module_exit(void)
3554{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003555 int ret;
3556
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003557 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003558 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003559 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003560 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003561 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003562 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003563 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003564 kfree(ehea_fw_handles.arr);
3565 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003566 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003567}
3568
3569module_init(ehea_module_init);
3570module_exit(ehea_module_exit);