blob: 328f47c92e26e2df74e9008f73127b5cd0cbc337 [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 "
Dave Young31d17532013-02-15 20:19:19 +000079 "[2^x - 1], x = [7..14]. Default = "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020080 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
81MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
Dave Young31d17532013-02-15 20:19:19 +000082 "[2^x - 1], x = [7..14]. Default = "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020083 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
84MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
Dave Young31d17532013-02-15 20:19:19 +000085 "[2^x - 1], x = [7..14]. Default = "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020086 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
87MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
Dave Young31d17532013-02-15 20:19:19 +000088 "[2^x - 1], x = [7..14]. Default = "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020089 __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
Bill Pemberton0297be02012-12-03 09:23:10 -0500101static int ehea_probe_adapter(struct platform_device *dev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000102 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200103
Bill Pemberton0297be02012-12-03 09:23:10 -0500104static int 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;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000293 arr[i].reg_type = EHEA_BCMC_MULTICAST |
Thomas Klein21eee2d2008-02-13 16:18:33 +0100294 EHEA_BCMC_UNTAGGED;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000295 if (mc_entry->macaddr == 0)
296 arr[i].reg_type |= EHEA_BCMC_SCOPE_ALL;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100297 arr[i++].macaddr = mc_entry->macaddr;
298
299 arr[i].adh = adapter->handle;
300 arr[i].port_id = port->logical_port_id;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000301 arr[i].reg_type = EHEA_BCMC_MULTICAST |
Thomas Klein21eee2d2008-02-13 16:18:33 +0100302 EHEA_BCMC_VLANID_ALL;
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +0000303 if (mc_entry->macaddr == 0)
304 arr[i].reg_type |= EHEA_BCMC_SCOPE_ALL;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100305 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700306 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100307 }
308 }
309 }
310
311out_update:
312 kfree(ehea_bcmc_regs.arr);
313 ehea_bcmc_regs.arr = arr;
314 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700315out:
316 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100317}
318
Anton Blanchard239c5622011-10-14 05:31:09 +0000319static struct rtnl_link_stats64 *ehea_get_stats64(struct net_device *dev,
320 struct rtnl_link_stats64 *stats)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200321{
322 struct ehea_port *port = netdev_priv(dev);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000323 u64 rx_packets = 0, tx_packets = 0, rx_bytes = 0, tx_bytes = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200324 int i;
325
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000326 for (i = 0; i < port->num_def_qps; i++) {
327 rx_packets += port->port_res[i].rx_packets;
328 rx_bytes += port->port_res[i].rx_bytes;
329 }
330
Anton Blanchard723f28e2011-10-14 05:31:01 +0000331 for (i = 0; i < port->num_def_qps; i++) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000332 tx_packets += port->port_res[i].tx_packets;
333 tx_bytes += port->port_res[i].tx_bytes;
334 }
335
336 stats->tx_packets = tx_packets;
337 stats->rx_bytes = rx_bytes;
338 stats->tx_bytes = tx_bytes;
339 stats->rx_packets = rx_packets;
340
Eric Dumazet09c1d442012-03-06 19:46:41 +0000341 stats->multicast = port->stats.multicast;
342 stats->rx_errors = port->stats.rx_errors;
343 return stats;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000344}
345
346static void ehea_update_stats(struct work_struct *work)
347{
348 struct ehea_port *port =
349 container_of(work, struct ehea_port, stats_work.work);
350 struct net_device *dev = port->netdev;
Anton Blanchard239c5622011-10-14 05:31:09 +0000351 struct rtnl_link_stats64 *stats = &port->stats;
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000352 struct hcp_ehea_port_cb2 *cb2;
353 u64 hret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200354
Brian King3d8009c2010-06-30 11:59:12 +0000355 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200356 if (!cb2) {
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000357 netdev_err(dev, "No mem for cb2. Some interface statistics were not updated\n");
358 goto resched;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200359 }
360
361 hret = ehea_h_query_ehea_port(port->adapter->handle,
362 port->logical_port_id,
363 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
364 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800365 netdev_err(dev, "query_ehea_port failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200366 goto out_herr;
367 }
368
369 if (netif_msg_hw(port))
370 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
371
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200372 stats->multicast = cb2->rxmcp;
373 stats->rx_errors = cb2->rxuerr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200374
375out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800376 free_page((unsigned long)cb2);
brenohl@br.ibm.com2aefcad2011-09-26 10:11:03 +0000377resched:
Anton Blanchard67c170a2011-11-23 00:13:54 +0000378 schedule_delayed_work(&port->stats_work,
379 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200380}
381
382static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
383{
384 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
385 struct net_device *dev = pr->port->netdev;
386 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200387 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
388 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200389 int i;
390
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200391 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200392
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200393 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200394 if (nr_of_wqes > 0)
395 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200396 pr->rq1_skba.os_skbs = fill_wqes;
397 return;
398 }
399
400 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200401 if (!skb_arr_rq1[index]) {
402 skb_arr_rq1[index] = netdev_alloc_skb(dev,
403 EHEA_L_PKT_SIZE);
404 if (!skb_arr_rq1[index]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800405 netdev_info(dev, "Unable to allocate enough skb in the array\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200406 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200407 break;
408 }
409 }
410 index--;
411 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200412 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200413 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200414
415 if (adder == 0)
416 return;
417
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200418 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200419 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200420}
421
Thomas Kleine2878802009-01-21 14:45:57 -0800422static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200423{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200424 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
425 struct net_device *dev = pr->port->netdev;
426 int i;
427
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000428 if (nr_rq1a > pr->rq1_skba.len) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800429 netdev_err(dev, "NR_RQ1A bigger than skb array len\n");
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000430 return;
431 }
432
433 for (i = 0; i < nr_rq1a; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200434 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000435 if (!skb_arr_rq1[i]) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800436 netdev_info(dev, "Not enough memory to allocate skb array\n");
Thomas Kleine2878802009-01-21 14:45:57 -0800437 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000438 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200439 }
440 /* Ring doorbell */
Breno Leitaof76957f2011-01-11 07:45:57 +0000441 ehea_update_rq1a(pr->qp, i - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200442}
443
444static int ehea_refill_rq_def(struct ehea_port_res *pr,
445 struct ehea_q_skb_arr *q_skba, int rq_nr,
446 int num_wqes, int wqe_type, int packet_size)
447{
448 struct net_device *dev = pr->port->netdev;
449 struct ehea_qp *qp = pr->qp;
450 struct sk_buff **skb_arr = q_skba->arr;
451 struct ehea_rwqe *rwqe;
452 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200453 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200454 int ret = 0;
455
456 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200457 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200458
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200459 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
460 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200461 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200462 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200463
464 index = q_skba->index;
465 max_index_mask = q_skba->len - 1;
466 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200467 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000468 struct sk_buff *skb;
469
470 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200471 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200472 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800473 if (q_skba->os_skbs == q_skba->len - 2) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800474 netdev_info(pr->port->netdev,
475 "rq%i ran dry - no mem for skb\n",
476 rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800477 ret = -ENOMEM;
478 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200479 break;
480 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200481
482 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200483 tmp_addr = ehea_map_vaddr(skb->data);
484 if (tmp_addr == -1) {
485 dev_kfree_skb(skb);
486 q_skba->os_skbs = fill_wqes - i;
487 ret = 0;
488 break;
489 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200490
491 rwqe = ehea_get_next_rwqe(qp, rq_nr);
492 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200493 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200494 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200495 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200496 rwqe->sg_list[0].len = packet_size;
497 rwqe->data_segments = 1;
498
499 index++;
500 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200501 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200502 }
Thomas Klein44c82152007-07-11 16:32:00 +0200503
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200504 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200505 if (adder == 0)
506 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200507
508 /* Ring doorbell */
509 iosync();
510 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200511 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200512 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200513 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200514out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200515 return ret;
516}
517
518
519static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
520{
521 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
522 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000523 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200524}
525
526
527static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
528{
529 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
530 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000531 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200532}
533
534static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
535{
536 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
537 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
538 return 0;
539 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
540 (cqe->header_length == 0))
541 return 0;
542 return -EINVAL;
543}
544
545static inline void ehea_fill_skb(struct net_device *dev,
Anton Blanchardb9564462011-10-14 05:30:59 +0000546 struct sk_buff *skb, struct ehea_cqe *cqe,
547 struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200548{
549 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
550
551 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200552 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000553
554 /* The packet was not an IPV4 packet so a complemented checksum was
555 calculated. The value is found in the Internet Checksum field. */
556 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
557 skb->ip_summed = CHECKSUM_COMPLETE;
558 skb->csum = csum_unfold(~cqe->inet_checksum_value);
559 } else
560 skb->ip_summed = CHECKSUM_UNNECESSARY;
Anton Blanchardb9564462011-10-14 05:30:59 +0000561
562 skb_record_rx_queue(skb, pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200563}
564
565static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
566 int arr_len,
567 struct ehea_cqe *cqe)
568{
569 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
570 struct sk_buff *skb;
571 void *pref;
572 int x;
573
574 x = skb_index + 1;
575 x &= (arr_len - 1);
576
577 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700578 if (pref) {
579 prefetchw(pref);
580 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200581
Hannes Hering0b2febf2009-05-04 11:06:37 -0700582 pref = (skb_array[x]->data);
583 prefetch(pref);
584 prefetch(pref + EHEA_CACHE_LINE);
585 prefetch(pref + EHEA_CACHE_LINE * 2);
586 prefetch(pref + EHEA_CACHE_LINE * 3);
587 }
588
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200589 skb = skb_array[skb_index];
590 skb_array[skb_index] = NULL;
591 return skb;
592}
593
594static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
595 int arr_len, int wqe_index)
596{
597 struct sk_buff *skb;
598 void *pref;
599 int x;
600
601 x = wqe_index + 1;
602 x &= (arr_len - 1);
603
604 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700605 if (pref) {
606 prefetchw(pref);
607 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200608
Hannes Hering0b2febf2009-05-04 11:06:37 -0700609 pref = (skb_array[x]->data);
610 prefetchw(pref);
611 prefetchw(pref + EHEA_CACHE_LINE);
612 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200613
614 skb = skb_array[wqe_index];
615 skb_array[wqe_index] = NULL;
616 return skb;
617}
618
619static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
620 struct ehea_cqe *cqe, int *processed_rq2,
621 int *processed_rq3)
622{
623 struct sk_buff *skb;
624
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100625 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
626 pr->p_stats.err_tcp_cksum++;
627 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
628 pr->p_stats.err_ip_cksum++;
629 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
630 pr->p_stats.err_frame_crc++;
631
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200632 if (rq == 2) {
633 *processed_rq2 += 1;
634 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
635 dev_kfree_skb(skb);
636 } else if (rq == 3) {
637 *processed_rq3 += 1;
638 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
639 dev_kfree_skb(skb);
640 }
641
642 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100643 if (netif_msg_rx_err(pr->port)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800644 pr_err("Critical receive error for QP %d. Resetting port.\n",
645 pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100646 ehea_dump(cqe, sizeof(*cqe), "CQE");
647 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100648 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200649 return 1;
650 }
651
652 return 0;
653}
654
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700655static int ehea_proc_rwqes(struct net_device *dev,
656 struct ehea_port_res *pr,
657 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200658{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100659 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200660 struct ehea_qp *qp = pr->qp;
661 struct ehea_cqe *cqe;
662 struct sk_buff *skb;
663 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
664 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
665 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
666 int skb_arr_rq1_len = pr->rq1_skba.len;
667 int skb_arr_rq2_len = pr->rq2_skba.len;
668 int skb_arr_rq3_len = pr->rq3_skba.len;
669 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000670 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700671 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200672
673 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
674 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200675
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200676 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700677 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200678 ehea_inc_rq1(qp);
679 processed_rq1++;
680 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200681 if (netif_msg_rx_status(port))
682 ehea_dump(cqe, sizeof(*cqe), "CQE");
683
684 last_wqe_index = wqe_index;
685 rmb();
686 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600687 if (rq == 1) {
688 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200689 skb = get_skb_by_index_ll(skb_arr_rq1,
690 skb_arr_rq1_len,
691 wqe_index);
692 if (unlikely(!skb)) {
Breno Leitao782615a2010-12-20 10:35:25 -0800693 netif_info(port, rx_err, dev,
Joe Perches8c4877a2010-12-13 10:05:14 -0800694 "LL rq1: skb=NULL\n");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100695
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700696 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200697 EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000698 if (!skb) {
Breno Leitao782615a2010-12-20 10:35:25 -0800699 netdev_err(dev, "Not enough memory to allocate skb\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200700 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000701 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200702 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600703 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200704 cqe->num_bytes_transfered - 4);
Anton Blanchardb9564462011-10-14 05:30:59 +0000705 ehea_fill_skb(dev, skb, cqe, pr);
Doug Maxey508d2b52008-01-31 20:20:49 -0600706 } else if (rq == 2) {
707 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200708 skb = get_skb_by_index(skb_arr_rq2,
709 skb_arr_rq2_len, cqe);
710 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800711 netif_err(port, rx_err, dev,
712 "rq2: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200713 break;
714 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000715 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200716 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600717 } else {
718 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200719 skb = get_skb_by_index(skb_arr_rq3,
720 skb_arr_rq3_len, cqe);
721 if (unlikely(!skb)) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800722 netif_err(port, rx_err, dev,
723 "rq3: skb=NULL\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200724 break;
725 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000726 ehea_fill_skb(dev, skb, cqe, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200727 processed_rq3++;
728 }
729
Breno Leitaoce45b872010-10-27 08:45:14 +0000730 processed_bytes += skb->len;
Anton Blanchard34284142011-10-14 05:31:11 +0000731
732 if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
733 __vlan_hwaccel_put_tag(skb, cqe->vlan_tag);
734
735 napi_gro_receive(&pr->napi, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100736 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100737 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200738 port_reset = ehea_treat_poll_error(pr, rq, cqe,
739 &processed_rq2,
740 &processed_rq3);
741 if (port_reset)
742 break;
743 }
744 cqe = ehea_poll_rq1(qp, &wqe_index);
745 }
746
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200747 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000748 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200749
750 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
751 ehea_refill_rq2(pr, processed_rq2);
752 ehea_refill_rq3(pr, processed_rq3);
753
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700754 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200755}
756
Andre Detsch2928db42010-08-17 05:49:12 +0000757#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
758
759static void reset_sq_restart_flag(struct ehea_port *port)
760{
761 int i;
762
Anton Blanchard723f28e2011-10-14 05:31:01 +0000763 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000764 struct ehea_port_res *pr = &port->port_res[i];
765 pr->sq_restart_flag = 0;
766 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000767 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000768}
769
770static void check_sqs(struct ehea_port *port)
771{
772 struct ehea_swqe *swqe;
773 int swqe_index;
774 int i, k;
775
Anton Blanchard723f28e2011-10-14 05:31:01 +0000776 for (i = 0; i < port->num_def_qps; i++) {
Andre Detsch2928db42010-08-17 05:49:12 +0000777 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000778 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000779 k = 0;
780 swqe = ehea_get_swqe(pr->qp, &swqe_index);
781 memset(swqe, 0, SWQE_HEADER_SIZE);
782 atomic_dec(&pr->swqe_avail);
783
784 swqe->tx_control |= EHEA_SWQE_PURGE;
785 swqe->wr_id = SWQE_RESTART_CHECK;
786 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
787 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
788 swqe->immediate_data_length = 80;
789
790 ehea_post_swqe(pr->qp, swqe);
791
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000792 ret = wait_event_timeout(port->restart_wq,
793 pr->sq_restart_flag == 0,
794 msecs_to_jiffies(100));
795
796 if (!ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800797 pr_err("HW/SW queues out of sync\n");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000798 ehea_schedule_port_reset(pr->port);
799 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000800 }
801 }
Andre Detsch2928db42010-08-17 05:49:12 +0000802}
803
804
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100805static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200806{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100807 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200808 struct ehea_cq *send_cq = pr->send_cq;
809 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100810 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200811 int cqe_counter = 0;
812 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100813 int index;
Anton Blanchardb9564462011-10-14 05:30:59 +0000814 struct netdev_queue *txq = netdev_get_tx_queue(pr->port->netdev,
815 pr - &pr->port->port_res[0]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200816
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100817 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600818 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100819 ehea_inc_cq(send_cq);
820
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200821 cqe_counter++;
822 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000823
824 if (cqe->wr_id == SWQE_RESTART_CHECK) {
825 pr->sq_restart_flag = 1;
826 swqe_av++;
827 break;
828 }
829
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200830 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800831 pr_err("Bad send completion status=0x%04X\n",
832 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000833
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200834 if (netif_msg_tx_err(pr->port))
835 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000836
837 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800838 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000839 ehea_schedule_port_reset(pr->port);
840 break;
841 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200842 }
843
844 if (netif_msg_tx_done(pr->port))
845 ehea_dump(cqe, sizeof(*cqe), "CQE");
846
847 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100848 == EHEA_SWQE2_TYPE)) {
849
850 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
851 skb = pr->sq_skba.arr[index];
852 dev_kfree_skb(skb);
853 pr->sq_skba.arr[index] = NULL;
854 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200855
856 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
857 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100858
859 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700860 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200861
862 ehea_update_feca(send_cq, cqe_counter);
863 atomic_add(swqe_av, &pr->swqe_avail);
864
Anton Blanchardb9564462011-10-14 05:30:59 +0000865 if (unlikely(netif_tx_queue_stopped(txq) &&
866 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))) {
867 __netif_tx_lock(txq, smp_processor_id());
868 if (netif_tx_queue_stopped(txq) &&
869 (atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))
870 netif_tx_wake_queue(txq);
871 __netif_tx_unlock(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200872 }
Anton Blanchardb9564462011-10-14 05:30:59 +0000873
Breno Leitao5b27d422010-10-05 13:16:22 +0000874 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200875
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100876 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200877}
878
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700879#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100880
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700881static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200882{
Doug Maxey508d2b52008-01-31 20:20:49 -0600883 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
884 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700885 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100886 struct ehea_cqe *cqe;
887 struct ehea_cqe *cqe_skb = NULL;
Anton Blanchard222ca962011-10-14 05:31:00 +0000888 int wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700889 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100890
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700891 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Anton Blanchard222ca962011-10-14 05:31:00 +0000892 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100893
Anton Blanchard222ca962011-10-14 05:31:00 +0000894 while (rx != budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -0800895 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100896 ehea_reset_cq_ep(pr->recv_cq);
897 ehea_reset_cq_ep(pr->send_cq);
898 ehea_reset_cq_n1(pr->recv_cq);
899 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000900 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100901 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
902 cqe_skb = ehea_poll_cq(pr->send_cq);
903
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100904 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700905 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100906
Ben Hutchings288379f2009-01-19 16:43:59 -0800907 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700908 return rx;
909
910 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
911 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100912 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100913
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700914 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200915}
916
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200917#ifdef CONFIG_NET_POLL_CONTROLLER
918static void ehea_netpoll(struct net_device *dev)
919{
920 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700921 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200922
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700923 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800924 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200925}
926#endif
927
David Howells7d12e782006-10-05 14:55:46 +0100928static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200929{
930 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100931
Ben Hutchings288379f2009-01-19 16:43:59 -0800932 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100933
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200934 return IRQ_HANDLED;
935}
936
David Howells7d12e782006-10-05 14:55:46 +0100937static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200938{
939 struct ehea_port *port = param;
940 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100941 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200942 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000943 u64 resource_type, aer, aerr;
944 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200945
946 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100947
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200948 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200949 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Joe Perches8c4877a2010-12-13 10:05:14 -0800950 pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
951 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100952
953 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000954
955 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
956 &aer, &aerr);
957
958 if (resource_type == EHEA_AER_RESTYPE_QP) {
959 if ((aer & EHEA_AER_RESET_MASK) ||
960 (aerr & EHEA_AERR_RESET_MASK))
961 reset_port = 1;
962 } else
963 reset_port = 1; /* Reset in case of CQ or EQ error */
964
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100965 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200966 }
967
Thomas Kleinea96cea2010-04-20 23:10:55 +0000968 if (reset_port) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800969 pr_err("Resetting port\n");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000970 ehea_schedule_port_reset(port);
971 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100972
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200973 return IRQ_HANDLED;
974}
975
976static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
977 int logical_port)
978{
979 int i;
980
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100981 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100982 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200983 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +0100984 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200985 return NULL;
986}
987
988int ehea_sense_port_attr(struct ehea_port *port)
989{
990 int ret;
991 u64 hret;
992 struct hcp_ehea_port_cb0 *cb0;
993
Doug Maxey508d2b52008-01-31 20:20:49 -0600994 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -0800995 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -0600996 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -0800997 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200998 ret = -ENOMEM;
999 goto out;
1000 }
1001
1002 hret = ehea_h_query_ehea_port(port->adapter->handle,
1003 port->logical_port_id, H_PORT_CB0,
1004 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1005 cb0);
1006 if (hret != H_SUCCESS) {
1007 ret = -EIO;
1008 goto out_free;
1009 }
1010
1011 /* MAC address */
1012 port->mac_addr = cb0->port_mac_addr << 16;
1013
Doug Maxey508d2b52008-01-31 20:20:49 -06001014 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001015 ret = -EADDRNOTAVAIL;
1016 goto out_free;
1017 }
1018
1019 /* Port speed */
1020 switch (cb0->port_speed) {
1021 case H_SPEED_10M_H:
1022 port->port_speed = EHEA_SPEED_10M;
1023 port->full_duplex = 0;
1024 break;
1025 case H_SPEED_10M_F:
1026 port->port_speed = EHEA_SPEED_10M;
1027 port->full_duplex = 1;
1028 break;
1029 case H_SPEED_100M_H:
1030 port->port_speed = EHEA_SPEED_100M;
1031 port->full_duplex = 0;
1032 break;
1033 case H_SPEED_100M_F:
1034 port->port_speed = EHEA_SPEED_100M;
1035 port->full_duplex = 1;
1036 break;
1037 case H_SPEED_1G_F:
1038 port->port_speed = EHEA_SPEED_1G;
1039 port->full_duplex = 1;
1040 break;
1041 case H_SPEED_10G_F:
1042 port->port_speed = EHEA_SPEED_10G;
1043 port->full_duplex = 1;
1044 break;
1045 default:
1046 port->port_speed = 0;
1047 port->full_duplex = 0;
1048 break;
1049 }
1050
Thomas Kleine919b592007-01-22 12:53:20 +01001051 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001052 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001053
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001054 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001055 if (use_mcs)
1056 port->num_def_qps = cb0->num_default_qps;
1057 else
1058 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001059
1060 if (!port->num_def_qps) {
1061 ret = -EINVAL;
1062 goto out_free;
1063 }
1064
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001065 ret = 0;
1066out_free:
1067 if (ret || netif_msg_probe(port))
1068 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001069 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001070out:
1071 return ret;
1072}
1073
1074int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1075{
1076 struct hcp_ehea_port_cb4 *cb4;
1077 u64 hret;
1078 int ret = 0;
1079
Thomas Klein3faf2692009-01-21 14:45:33 -08001080 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001081 if (!cb4) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001082 pr_err("no mem for cb4\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001083 ret = -ENOMEM;
1084 goto out;
1085 }
1086
1087 cb4->port_speed = port_speed;
1088
1089 netif_carrier_off(port->netdev);
1090
1091 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1092 port->logical_port_id,
1093 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1094 if (hret == H_SUCCESS) {
1095 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1096
1097 hret = ehea_h_query_ehea_port(port->adapter->handle,
1098 port->logical_port_id,
1099 H_PORT_CB4, H_PORT_CB4_SPEED,
1100 cb4);
1101 if (hret == H_SUCCESS) {
1102 switch (cb4->port_speed) {
1103 case H_SPEED_10M_H:
1104 port->port_speed = EHEA_SPEED_10M;
1105 port->full_duplex = 0;
1106 break;
1107 case H_SPEED_10M_F:
1108 port->port_speed = EHEA_SPEED_10M;
1109 port->full_duplex = 1;
1110 break;
1111 case H_SPEED_100M_H:
1112 port->port_speed = EHEA_SPEED_100M;
1113 port->full_duplex = 0;
1114 break;
1115 case H_SPEED_100M_F:
1116 port->port_speed = EHEA_SPEED_100M;
1117 port->full_duplex = 1;
1118 break;
1119 case H_SPEED_1G_F:
1120 port->port_speed = EHEA_SPEED_1G;
1121 port->full_duplex = 1;
1122 break;
1123 case H_SPEED_10G_F:
1124 port->port_speed = EHEA_SPEED_10G;
1125 port->full_duplex = 1;
1126 break;
1127 default:
1128 port->port_speed = 0;
1129 port->full_duplex = 0;
1130 break;
1131 }
1132 } else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001133 pr_err("Failed sensing port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001134 ret = -EIO;
1135 }
1136 } else {
1137 if (hret == H_AUTHORITY) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001138 pr_info("Hypervisor denied setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001139 ret = -EPERM;
1140 } else {
1141 ret = -EIO;
Joe Perches8c4877a2010-12-13 10:05:14 -08001142 pr_err("Failed setting port speed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001143 }
1144 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001145 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1146 netif_carrier_on(port->netdev);
1147
Thomas Klein3faf2692009-01-21 14:45:33 -08001148 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001149out:
1150 return ret;
1151}
1152
1153static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1154{
1155 int ret;
1156 u8 ec;
1157 u8 portnum;
1158 struct ehea_port *port;
Joe Perches8c4877a2010-12-13 10:05:14 -08001159 struct net_device *dev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001160
1161 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1162 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1163 port = ehea_get_port(adapter, portnum);
Joe Perches8c4877a2010-12-13 10:05:14 -08001164 dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001165
1166 switch (ec) {
1167 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1168
1169 if (!port) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001170 netdev_err(dev, "unknown portnum %x\n", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001171 break;
1172 }
1173
1174 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001175 if (!netif_carrier_ok(dev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001176 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001177 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001178 netdev_err(dev, "failed resensing port attributes\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001179 break;
1180 }
1181
Joe Perches8c4877a2010-12-13 10:05:14 -08001182 netif_info(port, link, dev,
1183 "Logical port up: %dMbps %s Duplex\n",
1184 port->port_speed,
1185 port->full_duplex == 1 ?
1186 "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001187
Joe Perches8c4877a2010-12-13 10:05:14 -08001188 netif_carrier_on(dev);
1189 netif_wake_queue(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001190 }
1191 } else
Joe Perches8c4877a2010-12-13 10:05:14 -08001192 if (netif_carrier_ok(dev)) {
1193 netif_info(port, link, dev,
1194 "Logical port down\n");
1195 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001196 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001197 }
1198
1199 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001200 port->phy_link = EHEA_PHY_LINK_UP;
Joe Perches8c4877a2010-12-13 10:05:14 -08001201 netif_info(port, link, dev,
1202 "Physical port up\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001203 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001204 netif_carrier_on(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001205 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001206 port->phy_link = EHEA_PHY_LINK_DOWN;
Joe Perches8c4877a2010-12-13 10:05:14 -08001207 netif_info(port, link, dev,
1208 "Physical port down\n");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001209 if (prop_carrier_state)
Joe Perches8c4877a2010-12-13 10:05:14 -08001210 netif_carrier_off(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001211 }
1212
1213 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
Joe Perches8c4877a2010-12-13 10:05:14 -08001214 netdev_info(dev,
1215 "External switch port is primary port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001216 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001217 netdev_info(dev,
1218 "External switch port is backup port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001219
1220 break;
1221 case EHEA_EC_ADAPTER_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001222 netdev_err(dev, "Adapter malfunction\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001223 break;
1224 case EHEA_EC_PORT_MALFUNC:
Joe Perches8c4877a2010-12-13 10:05:14 -08001225 netdev_info(dev, "Port malfunction\n");
1226 netif_carrier_off(dev);
Anton Blanchardb9564462011-10-14 05:30:59 +00001227 netif_tx_disable(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001228 break;
1229 default:
Joe Perches8c4877a2010-12-13 10:05:14 -08001230 netdev_err(dev, "unknown event code %x, eqe=0x%llX\n", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001231 break;
1232 }
1233}
1234
1235static void ehea_neq_tasklet(unsigned long data)
1236{
Doug Maxey508d2b52008-01-31 20:20:49 -06001237 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001238 struct ehea_eqe *eqe;
1239 u64 event_mask;
1240
1241 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001242 pr_debug("eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001243
1244 while (eqe) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001245 pr_debug("*eqe=%lx\n", (unsigned long) eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001246 ehea_parse_eqe(adapter, eqe->entry);
1247 eqe = ehea_poll_eq(adapter->neq);
Joe Perches8c4877a2010-12-13 10:05:14 -08001248 pr_debug("next eqe=%p\n", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001249 }
1250
1251 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1252 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1253 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1254
1255 ehea_h_reset_events(adapter->handle,
1256 adapter->neq->fw_handle, event_mask);
1257}
1258
David Howells7d12e782006-10-05 14:55:46 +01001259static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001260{
1261 struct ehea_adapter *adapter = param;
1262 tasklet_hi_schedule(&adapter->neq_tasklet);
1263 return IRQ_HANDLED;
1264}
1265
1266
1267static int ehea_fill_port_res(struct ehea_port_res *pr)
1268{
1269 int ret;
1270 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1271
Breno Leitaof76957f2011-01-11 07:45:57 +00001272 ehea_init_fill_rq1(pr, pr->rq1_skba.len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001273
Thomas Kleine2878802009-01-21 14:45:57 -08001274 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001275
1276 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1277
1278 return ret;
1279}
1280
1281static int ehea_reg_interrupts(struct net_device *dev)
1282{
1283 struct ehea_port *port = netdev_priv(dev);
1284 struct ehea_port_res *pr;
1285 int i, ret;
1286
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001287
1288 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1289 dev->name);
1290
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001291 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001292 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001293 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001294 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001295 netdev_err(dev, "failed registering irq for qp_aff_irq_handler:ist=%X\n",
1296 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001297 goto out_free_qpeq;
1298 }
1299
Joe Perches8c4877a2010-12-13 10:05:14 -08001300 netif_info(port, ifup, dev,
1301 "irq_handle 0x%X for function qp_aff_irq_handler registered\n",
1302 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001303
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001304
Anton Blanchard723f28e2011-10-14 05:31:01 +00001305 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001306 pr = &port->port_res[i];
1307 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001308 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001309 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001310 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001311 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001312 pr);
1313 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001314 netdev_err(dev, "failed registering irq for ehea_queue port_res_nr:%d, ist=%X\n",
1315 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001316 goto out_free_req;
1317 }
Joe Perches8c4877a2010-12-13 10:05:14 -08001318 netif_info(port, ifup, dev,
1319 "irq_handle 0x%X for function ehea_queue_int %d registered\n",
1320 pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001321 }
1322out:
1323 return ret;
1324
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001325
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001326out_free_req:
1327 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001328 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001329 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001330 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001331
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001332out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001333 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001334 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001335
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001336 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001337
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001338}
1339
1340static void ehea_free_interrupts(struct net_device *dev)
1341{
1342 struct ehea_port *port = netdev_priv(dev);
1343 struct ehea_port_res *pr;
1344 int i;
1345
1346 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001347
Anton Blanchard723f28e2011-10-14 05:31:01 +00001348 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001349 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001350 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Joe Perches8c4877a2010-12-13 10:05:14 -08001351 netif_info(port, intr, dev,
1352 "free send irq for res %d with handle 0x%X\n",
1353 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001354 }
1355
1356 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001357 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Joe Perches8c4877a2010-12-13 10:05:14 -08001358 netif_info(port, intr, dev,
1359 "associated event interrupt for handle 0x%X freed\n",
1360 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001361}
1362
1363static int ehea_configure_port(struct ehea_port *port)
1364{
1365 int ret, i;
1366 u64 hret, mask;
1367 struct hcp_ehea_port_cb0 *cb0;
1368
1369 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001370 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001371 if (!cb0)
1372 goto out;
1373
1374 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1375 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1376 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1377 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1378 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1379 PXLY_RC_VLAN_FILTER)
1380 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1381
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001382 for (i = 0; i < port->num_mcs; i++)
1383 if (use_mcs)
1384 cb0->default_qpn_arr[i] =
1385 port->port_res[i].qp->init_attr.qp_nr;
1386 else
1387 cb0->default_qpn_arr[i] =
1388 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001389
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001390 if (netif_msg_ifup(port))
1391 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1392
1393 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1394 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1395
1396 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1397 port->logical_port_id,
1398 H_PORT_CB0, mask, cb0);
1399 ret = -EIO;
1400 if (hret != H_SUCCESS)
1401 goto out_free;
1402
1403 ret = 0;
1404
1405out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001406 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001407out:
1408 return ret;
1409}
1410
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00001411static int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001412{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001413 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001414 struct ehea_adapter *adapter = pr->port->adapter;
1415
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001416 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1417 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001418 goto out;
1419
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001420 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1421 if (ret)
1422 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001423
1424 return 0;
1425
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001426out_free:
1427 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001428out:
Joe Perches8c4877a2010-12-13 10:05:14 -08001429 pr_err("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001430 return -EIO;
1431}
1432
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00001433static int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001434{
Joe Perches8e95a202009-12-03 07:58:21 +00001435 if ((ehea_rem_mr(&pr->send_mr)) ||
1436 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001437 return -EIO;
1438 else
1439 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001440}
1441
1442static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1443{
Doug Maxey508d2b52008-01-31 20:20:49 -06001444 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001445
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001446 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001447 if (!q_skba->arr)
1448 return -ENOMEM;
1449
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001450 q_skba->len = max_q_entries;
1451 q_skba->index = 0;
1452 q_skba->os_skbs = 0;
1453
1454 return 0;
1455}
1456
1457static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1458 struct port_res_cfg *pr_cfg, int queue_token)
1459{
1460 struct ehea_adapter *adapter = port->adapter;
1461 enum ehea_eq_type eq_type = EHEA_EQ;
1462 struct ehea_qp_init_attr *init_attr = NULL;
1463 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001464 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1465
1466 tx_bytes = pr->tx_bytes;
1467 tx_packets = pr->tx_packets;
1468 rx_bytes = pr->rx_bytes;
1469 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001470
1471 memset(pr, 0, sizeof(struct ehea_port_res));
1472
Breno Leitaoce45b872010-10-27 08:45:14 +00001473 pr->tx_bytes = rx_bytes;
1474 pr->tx_packets = tx_packets;
1475 pr->rx_bytes = rx_bytes;
1476 pr->rx_packets = rx_packets;
1477
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001478 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001479
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001480 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1481 if (!pr->eq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001482 pr_err("create_eq failed (eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001483 goto out_free;
1484 }
1485
1486 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001487 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001488 port->logical_port_id);
1489 if (!pr->recv_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001490 pr_err("create_cq failed (cq_recv)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001491 goto out_free;
1492 }
1493
1494 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001495 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001496 port->logical_port_id);
1497 if (!pr->send_cq) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001498 pr_err("create_cq failed (cq_send)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001499 goto out_free;
1500 }
1501
1502 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001503 pr_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d\n",
1504 pr->send_cq->attr.act_nr_of_cqes,
1505 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001506
1507 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1508 if (!init_attr) {
1509 ret = -ENOMEM;
Joe Perches8c4877a2010-12-13 10:05:14 -08001510 pr_err("no mem for ehea_qp_init_attr\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001511 goto out_free;
1512 }
1513
1514 init_attr->low_lat_rq1 = 1;
1515 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1516 init_attr->rq_count = 3;
1517 init_attr->qp_token = queue_token;
1518 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1519 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1520 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1521 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1522 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1523 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1524 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1525 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1526 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1527 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1528 init_attr->port_nr = port->logical_port_id;
1529 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1530 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1531 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1532
1533 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1534 if (!pr->qp) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001535 pr_err("create_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001536 ret = -EIO;
1537 goto out_free;
1538 }
1539
1540 if (netif_msg_ifup(port))
Joe Perches8c4877a2010-12-13 10:05:14 -08001541 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",
1542 init_attr->qp_nr,
1543 init_attr->act_nr_send_wqes,
1544 init_attr->act_nr_rwqes_rq1,
1545 init_attr->act_nr_rwqes_rq2,
1546 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001547
Thomas Klein44fb3122008-04-04 15:04:53 +02001548 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1549
1550 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001551 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1552 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1553 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1554 if (ret)
1555 goto out_free;
1556
1557 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1558 if (ehea_gen_smrs(pr) != 0) {
1559 ret = -EIO;
1560 goto out_free;
1561 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001562
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001563 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1564
1565 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001566
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001567 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001568
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001569 ret = 0;
1570 goto out;
1571
1572out_free:
1573 kfree(init_attr);
1574 vfree(pr->sq_skba.arr);
1575 vfree(pr->rq1_skba.arr);
1576 vfree(pr->rq2_skba.arr);
1577 vfree(pr->rq3_skba.arr);
1578 ehea_destroy_qp(pr->qp);
1579 ehea_destroy_cq(pr->send_cq);
1580 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001581 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001582out:
1583 return ret;
1584}
1585
1586static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1587{
1588 int ret, i;
1589
Hannes Hering357eb462009-08-04 11:48:39 -07001590 if (pr->qp)
1591 netif_napi_del(&pr->napi);
1592
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001593 ret = ehea_destroy_qp(pr->qp);
1594
1595 if (!ret) {
1596 ehea_destroy_cq(pr->send_cq);
1597 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001598 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001599
1600 for (i = 0; i < pr->rq1_skba.len; i++)
1601 if (pr->rq1_skba.arr[i])
1602 dev_kfree_skb(pr->rq1_skba.arr[i]);
1603
1604 for (i = 0; i < pr->rq2_skba.len; i++)
1605 if (pr->rq2_skba.arr[i])
1606 dev_kfree_skb(pr->rq2_skba.arr[i]);
1607
1608 for (i = 0; i < pr->rq3_skba.len; i++)
1609 if (pr->rq3_skba.arr[i])
1610 dev_kfree_skb(pr->rq3_skba.arr[i]);
1611
1612 for (i = 0; i < pr->sq_skba.len; i++)
1613 if (pr->sq_skba.arr[i])
1614 dev_kfree_skb(pr->sq_skba.arr[i]);
1615
1616 vfree(pr->rq1_skba.arr);
1617 vfree(pr->rq2_skba.arr);
1618 vfree(pr->rq3_skba.arr);
1619 vfree(pr->sq_skba.arr);
1620 ret = ehea_rem_smrs(pr);
1621 }
1622 return ret;
1623}
1624
Anton Blanchard13946f52011-10-14 05:31:06 +00001625static void write_swqe2_immediate(struct sk_buff *skb, struct ehea_swqe *swqe,
1626 u32 lkey)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001627{
Eric Dumazete743d312010-04-14 15:59:40 -07001628 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001629 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1630 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Anton Blanchard13946f52011-10-14 05:31:06 +00001631 unsigned int immediate_len = SWQE2_MAX_IMM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001632
Anton Blanchard13946f52011-10-14 05:31:06 +00001633 swqe->descriptors = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001634
Anton Blanchard13946f52011-10-14 05:31:06 +00001635 if (skb_is_gso(skb)) {
1636 swqe->tx_control |= EHEA_SWQE_TSO;
1637 swqe->mss = skb_shinfo(skb)->gso_size;
1638 /*
1639 * For TSO packets we only copy the headers into the
1640 * immediate area.
1641 */
1642 immediate_len = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
1643 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001644
Anton Blanchard13946f52011-10-14 05:31:06 +00001645 if (skb_is_gso(skb) || skb_data_size >= SWQE2_MAX_IMM) {
1646 skb_copy_from_linear_data(skb, imm_data, immediate_len);
1647 swqe->immediate_data_length = immediate_len;
1648
1649 if (skb_data_size > immediate_len) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001650 sg1entry->l_key = lkey;
Anton Blanchard13946f52011-10-14 05:31:06 +00001651 sg1entry->len = skb_data_size - immediate_len;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001652 sg1entry->vaddr =
Anton Blanchard13946f52011-10-14 05:31:06 +00001653 ehea_map_vaddr(skb->data + immediate_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001654 swqe->descriptors++;
1655 }
1656 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001657 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001658 swqe->immediate_data_length = skb_data_size;
1659 }
1660}
1661
1662static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1663 struct ehea_swqe *swqe, u32 lkey)
1664{
1665 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1666 skb_frag_t *frag;
1667 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001668
1669 nfrags = skb_shinfo(skb)->nr_frags;
1670 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001671 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001672 sg1entry_contains_frag_data = 0;
1673
Anton Blanchard13946f52011-10-14 05:31:06 +00001674 write_swqe2_immediate(skb, swqe, lkey);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001675
1676 /* write descriptors */
1677 if (nfrags > 0) {
1678 if (swqe->descriptors == 0) {
1679 /* sg1entry not yet used */
1680 frag = &skb_shinfo(skb)->frags[0];
1681
1682 /* copy sg1entry data */
1683 sg1entry->l_key = lkey;
Eric Dumazet9e903e02011-10-18 21:00:24 +00001684 sg1entry->len = skb_frag_size(frag);
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001685 sg1entry->vaddr =
Ian Campbell618c4a02011-10-10 01:11:38 +00001686 ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001687 swqe->descriptors++;
1688 sg1entry_contains_frag_data = 1;
1689 }
1690
1691 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1692
1693 frag = &skb_shinfo(skb)->frags[i];
1694 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1695
1696 sgentry->l_key = lkey;
Eric Dumazet0110bba2011-10-25 16:16:10 +02001697 sgentry->len = skb_frag_size(frag);
Ian Campbell618c4a02011-10-10 01:11:38 +00001698 sgentry->vaddr = ehea_map_vaddr(skb_frag_address(frag));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001699 swqe->descriptors++;
1700 }
1701 }
1702}
1703
1704static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1705{
1706 int ret = 0;
1707 u64 hret;
1708 u8 reg_type;
1709
1710 /* De/Register untagged packets */
1711 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1712 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1713 port->logical_port_id,
1714 reg_type, port->mac_addr, 0, hcallid);
1715 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001716 pr_err("%sregistering bc address failed (tagged)\n",
1717 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001718 ret = -EIO;
1719 goto out_herr;
1720 }
1721
1722 /* De/Register VLAN packets */
1723 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1724 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1725 port->logical_port_id,
1726 reg_type, port->mac_addr, 0, hcallid);
1727 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001728 pr_err("%sregistering bc address failed (vlan)\n",
1729 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001730 ret = -EIO;
1731 }
1732out_herr:
1733 return ret;
1734}
1735
1736static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1737{
1738 struct ehea_port *port = netdev_priv(dev);
1739 struct sockaddr *mac_addr = sa;
1740 struct hcp_ehea_port_cb0 *cb0;
1741 int ret;
1742 u64 hret;
1743
1744 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1745 ret = -EADDRNOTAVAIL;
1746 goto out;
1747 }
1748
Thomas Klein3faf2692009-01-21 14:45:33 -08001749 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001750 if (!cb0) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001751 pr_err("no mem for cb0\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001752 ret = -ENOMEM;
1753 goto out;
1754 }
1755
1756 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1757
1758 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1759
1760 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1761 port->logical_port_id, H_PORT_CB0,
1762 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1763 if (hret != H_SUCCESS) {
1764 ret = -EIO;
1765 goto out_free;
1766 }
1767
1768 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1769
1770 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001771 if (port->state == EHEA_PORT_UP) {
1772 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1773 if (ret)
1774 goto out_upregs;
1775 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001776
1777 port->mac_addr = cb0->port_mac_addr << 16;
1778
1779 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001780 if (port->state == EHEA_PORT_UP) {
1781 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1782 if (ret)
1783 goto out_upregs;
1784 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001785
1786 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001787
1788out_upregs:
1789 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001790out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001791 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001792out:
1793 return ret;
1794}
1795
1796static void ehea_promiscuous_error(u64 hret, int enable)
1797{
Thomas Klein7674a582007-01-22 12:54:20 +01001798 if (hret == H_AUTHORITY)
Joe Perches8c4877a2010-12-13 10:05:14 -08001799 pr_info("Hypervisor denied %sabling promiscuous mode\n",
1800 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001801 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001802 pr_err("failed %sabling promiscuous mode\n",
1803 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001804}
1805
1806static void ehea_promiscuous(struct net_device *dev, int enable)
1807{
1808 struct ehea_port *port = netdev_priv(dev);
1809 struct hcp_ehea_port_cb7 *cb7;
1810 u64 hret;
1811
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001812 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001813 return;
1814
Thomas Klein3faf2692009-01-21 14:45:33 -08001815 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001816 if (!cb7) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001817 pr_err("no mem for cb7\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001818 goto out;
1819 }
1820
1821 /* Modify Pxs_DUCQPN in CB7 */
1822 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1823
1824 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1825 port->logical_port_id,
1826 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1827 if (hret) {
1828 ehea_promiscuous_error(hret, enable);
1829 goto out;
1830 }
1831
1832 port->promisc = enable;
1833out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001834 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001835}
1836
1837static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1838 u32 hcallid)
1839{
1840 u64 hret;
1841 u8 reg_type;
1842
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001843 reg_type = EHEA_BCMC_MULTICAST | EHEA_BCMC_UNTAGGED;
1844 if (mc_mac_addr == 0)
1845 reg_type |= EHEA_BCMC_SCOPE_ALL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001846
1847 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1848 port->logical_port_id,
1849 reg_type, mc_mac_addr, 0, hcallid);
1850 if (hret)
1851 goto out;
1852
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001853 reg_type = EHEA_BCMC_MULTICAST | EHEA_BCMC_VLANID_ALL;
1854 if (mc_mac_addr == 0)
1855 reg_type |= EHEA_BCMC_SCOPE_ALL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001856
1857 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1858 port->logical_port_id,
1859 reg_type, mc_mac_addr, 0, hcallid);
1860out:
1861 return hret;
1862}
1863
1864static int ehea_drop_multicast_list(struct net_device *dev)
1865{
1866 struct ehea_port *port = netdev_priv(dev);
1867 struct ehea_mc_list *mc_entry = port->mc_list;
1868 struct list_head *pos;
1869 struct list_head *temp;
1870 int ret = 0;
1871 u64 hret;
1872
1873 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1874 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1875
1876 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1877 H_DEREG_BCMC);
1878 if (hret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001879 pr_err("failed deregistering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001880 ret = -EIO;
1881 }
1882
1883 list_del(pos);
1884 kfree(mc_entry);
1885 }
1886 return ret;
1887}
1888
1889static void ehea_allmulti(struct net_device *dev, int enable)
1890{
1891 struct ehea_port *port = netdev_priv(dev);
1892 u64 hret;
1893
1894 if (!port->allmulti) {
1895 if (enable) {
1896 /* Enable ALLMULTI */
1897 ehea_drop_multicast_list(dev);
1898 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1899 if (!hret)
1900 port->allmulti = 1;
1901 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001902 netdev_err(dev,
1903 "failed enabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001904 }
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001905 } else {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001906 if (!enable) {
1907 /* Disable ALLMULTI */
1908 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1909 if (!hret)
1910 port->allmulti = 0;
1911 else
Joe Perches8c4877a2010-12-13 10:05:14 -08001912 netdev_err(dev,
1913 "failed disabling IFF_ALLMULTI\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001914 }
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00001915 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001916}
1917
Doug Maxey508d2b52008-01-31 20:20:49 -06001918static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001919{
1920 struct ehea_mc_list *ehea_mcl_entry;
1921 u64 hret;
1922
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001923 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Joe Perchesb2adaca2013-02-03 17:43:58 +00001924 if (!ehea_mcl_entry)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001925 return;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001926
1927 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1928
1929 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1930
1931 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1932 H_REG_BCMC);
1933 if (!hret)
1934 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1935 else {
Joe Perches8c4877a2010-12-13 10:05:14 -08001936 pr_err("failed registering mcast MAC\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001937 kfree(ehea_mcl_entry);
1938 }
1939}
1940
1941static void ehea_set_multicast_list(struct net_device *dev)
1942{
1943 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00001944 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00001945 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001946
Thadeu Lima de Souza Cascardo47d59d02012-04-25 07:32:12 +00001947 ehea_promiscuous(dev, !!(dev->flags & IFF_PROMISC));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001948
1949 if (dev->flags & IFF_ALLMULTI) {
1950 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001951 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001952 }
1953 ehea_allmulti(dev, 0);
1954
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001955 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001956 ret = ehea_drop_multicast_list(dev);
1957 if (ret) {
1958 /* Dropping the current multicast list failed.
1959 * Enabling ALL_MULTI is the best we can do.
1960 */
1961 ehea_allmulti(dev, 1);
1962 }
1963
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001964 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Joe Perches8c4877a2010-12-13 10:05:14 -08001965 pr_info("Mcast registration limit reached (0x%llx). Use ALLMULTI!\n",
1966 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001967 goto out;
1968 }
1969
Jiri Pirko22bedad32010-04-01 21:22:57 +00001970 netdev_for_each_mc_addr(ha, dev)
1971 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06001972
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001973 }
1974out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01001975 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001976}
1977
1978static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1979{
1980 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1981 return -EINVAL;
1982 dev->mtu = new_mtu;
1983 return 0;
1984}
1985
Anton Blanchardd695c332011-10-14 05:31:05 +00001986static void xmit_common(struct sk_buff *skb, struct ehea_swqe *swqe)
1987{
1988 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT | EHEA_SWQE_CRC;
1989
1990 if (skb->protocol != htons(ETH_P_IP))
1991 return;
1992
1993 if (skb->ip_summed == CHECKSUM_PARTIAL)
1994 swqe->tx_control |= EHEA_SWQE_IP_CHECKSUM;
1995
1996 swqe->ip_start = skb_network_offset(skb);
1997 swqe->ip_end = swqe->ip_start + ip_hdrlen(skb) - 1;
1998
1999 switch (ip_hdr(skb)->protocol) {
2000 case IPPROTO_UDP:
2001 if (skb->ip_summed == CHECKSUM_PARTIAL)
2002 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2003
2004 swqe->tcp_offset = swqe->ip_end + 1 +
2005 offsetof(struct udphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002006 break;
2007
2008 case IPPROTO_TCP:
2009 if (skb->ip_summed == CHECKSUM_PARTIAL)
2010 swqe->tx_control |= EHEA_SWQE_TCP_CHECKSUM;
2011
2012 swqe->tcp_offset = swqe->ip_end + 1 +
2013 offsetof(struct tcphdr, check);
Anton Blanchardd695c332011-10-14 05:31:05 +00002014 break;
2015 }
2016}
2017
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002018static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2019 struct ehea_swqe *swqe, u32 lkey)
2020{
Anton Blanchardd695c332011-10-14 05:31:05 +00002021 swqe->tx_control |= EHEA_SWQE_DESCRIPTORS_PRESENT;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002022
Anton Blanchardd695c332011-10-14 05:31:05 +00002023 xmit_common(skb, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002024
2025 write_swqe2_data(skb, dev, swqe, lkey);
2026}
2027
2028static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2029 struct ehea_swqe *swqe)
2030{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002031 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002032
Anton Blanchardd695c332011-10-14 05:31:05 +00002033 xmit_common(skb, swqe);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002034
Anton Blanchard30e2e902011-10-14 05:31:07 +00002035 if (!skb->data_len)
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002036 skb_copy_from_linear_data(skb, imm_data, skb->len);
Anton Blanchard30e2e902011-10-14 05:31:07 +00002037 else
2038 skb_copy_bits(skb, 0, imm_data, skb->len);
Anton Blanchardd695c332011-10-14 05:31:05 +00002039
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002040 swqe->immediate_data_length = skb->len;
2041 dev_kfree_skb(skb);
2042}
2043
2044static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2045{
2046 struct ehea_port *port = netdev_priv(dev);
2047 struct ehea_swqe *swqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002048 u32 lkey;
2049 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002050 struct ehea_port_res *pr;
Anton Blanchardb9564462011-10-14 05:30:59 +00002051 struct netdev_queue *txq;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002052
Anton Blanchardb9564462011-10-14 05:30:59 +00002053 pr = &port->port_res[skb_get_queue_mapping(skb)];
2054 txq = netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002055
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002056 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2057 memset(swqe, 0, SWQE_HEADER_SIZE);
2058 atomic_dec(&pr->swqe_avail);
2059
Eric Dumazete5ccd962010-10-26 19:21:07 +00002060 if (vlan_tx_tag_present(skb)) {
2061 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2062 swqe->vlan_tag = vlan_tx_tag_get(skb);
2063 }
2064
Breno Leitaoce45b872010-10-27 08:45:14 +00002065 pr->tx_packets++;
2066 pr->tx_bytes += skb->len;
2067
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002068 if (skb->len <= SWQE3_MAX_IMM) {
2069 u32 sig_iv = port->sig_comp_iv;
2070 u32 swqe_num = pr->swqe_id_counter;
2071 ehea_xmit3(skb, dev, swqe);
2072 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2073 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2074 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2075 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2076 sig_iv);
2077 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2078 pr->swqe_ll_count = 0;
2079 } else
2080 pr->swqe_ll_count += 1;
2081 } else {
2082 swqe->wr_id =
2083 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2084 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002085 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002086 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2087 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2088
2089 pr->sq_skba.index++;
2090 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2091
2092 lkey = pr->send_mr.lkey;
2093 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002094 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002095 }
2096 pr->swqe_id_counter += 1;
2097
Joe Perches8c4877a2010-12-13 10:05:14 -08002098 netif_info(port, tx_queued, dev,
2099 "post swqe on QP %d\n", pr->qp->init_attr.qp_nr);
2100 if (netif_msg_tx_queued(port))
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002101 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002102
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002103 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002104 netif_tx_stop_queue(txq);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002105 swqe->tx_control |= EHEA_SWQE_PURGE;
2106 }
Thomas Klein44c82152007-07-11 16:32:00 +02002107
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002108 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002109
2110 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Anton Blanchardb9564462011-10-14 05:30:59 +00002111 pr->p_stats.queue_stopped++;
2112 netif_tx_stop_queue(txq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002113 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002114
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002115 return NETDEV_TX_OK;
2116}
2117
Jiri Pirko8e586132011-12-08 19:52:37 -05002118static int ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002119{
2120 struct ehea_port *port = netdev_priv(dev);
2121 struct ehea_adapter *adapter = port->adapter;
2122 struct hcp_ehea_port_cb1 *cb1;
2123 int index;
2124 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002125 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002126
Thomas Klein3faf2692009-01-21 14:45:33 -08002127 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002128 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002129 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002130 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002131 goto out;
2132 }
2133
2134 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2135 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2136 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002137 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002138 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002139 goto out;
2140 }
2141
2142 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002143 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002144
2145 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2146 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002147 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002148 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002149 err = -EINVAL;
2150 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002151out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002152 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002153 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002154}
2155
Jiri Pirko8e586132011-12-08 19:52:37 -05002156static int ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002157{
2158 struct ehea_port *port = netdev_priv(dev);
2159 struct ehea_adapter *adapter = port->adapter;
2160 struct hcp_ehea_port_cb1 *cb1;
2161 int index;
2162 u64 hret;
Jiri Pirko8e586132011-12-08 19:52:37 -05002163 int err = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002164
Thomas Klein3faf2692009-01-21 14:45:33 -08002165 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002166 if (!cb1) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002167 pr_err("no mem for cb1\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002168 err = -ENOMEM;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002169 goto out;
2170 }
2171
2172 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2173 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2174 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002175 pr_err("query_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002176 err = -EINVAL;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002177 goto out;
2178 }
2179
2180 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002181 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002182
2183 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2184 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002185 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002186 pr_err("modify_ehea_port failed\n");
Jiri Pirko8e586132011-12-08 19:52:37 -05002187 err = -EINVAL;
2188 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002189out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002190 free_page((unsigned long)cb1);
Jiri Pirko8e586132011-12-08 19:52:37 -05002191 return err;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002192}
2193
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00002194static int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002195{
2196 int ret = -EIO;
2197 u64 hret;
2198 u16 dummy16 = 0;
2199 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002200 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002201
Thomas Klein3faf2692009-01-21 14:45:33 -08002202 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002203 if (!cb0) {
2204 ret = -ENOMEM;
2205 goto out;
2206 }
2207
2208 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2209 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2210 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002211 pr_err("query_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002212 goto out;
2213 }
2214
2215 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2216 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2217 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2218 &dummy64, &dummy64, &dummy16, &dummy16);
2219 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002220 pr_err("modify_ehea_qp failed (1)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002221 goto out;
2222 }
2223
2224 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2225 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2226 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002227 pr_err("query_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002228 goto out;
2229 }
2230
2231 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2232 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2233 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2234 &dummy64, &dummy64, &dummy16, &dummy16);
2235 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002236 pr_err("modify_ehea_qp failed (2)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002237 goto out;
2238 }
2239
2240 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2241 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2242 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002243 pr_err("query_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002244 goto out;
2245 }
2246
2247 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2248 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2249 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2250 &dummy64, &dummy64, &dummy16, &dummy16);
2251 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002252 pr_err("modify_ehea_qp failed (3)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002253 goto out;
2254 }
2255
2256 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2257 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2258 if (hret != H_SUCCESS) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002259 pr_err("query_ehea_qp failed (4)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002260 goto out;
2261 }
2262
2263 ret = 0;
2264out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002265 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002266 return ret;
2267}
2268
Anton Blanchard723f28e2011-10-14 05:31:01 +00002269static int ehea_port_res_setup(struct ehea_port *port, int def_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002270{
2271 int ret, i;
2272 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2273 enum ehea_eq_type eq_type = EHEA_EQ;
2274
2275 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2276 EHEA_MAX_ENTRIES_EQ, 1);
2277 if (!port->qp_eq) {
2278 ret = -EINVAL;
Joe Perches8c4877a2010-12-13 10:05:14 -08002279 pr_err("ehea_create_eq failed (qp_eq)\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002280 goto out_kill_eq;
2281 }
2282
2283 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002284 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002285 pr_cfg.max_entries_sq = sq_entries;
2286 pr_cfg.max_entries_rq1 = rq1_entries;
2287 pr_cfg.max_entries_rq2 = rq2_entries;
2288 pr_cfg.max_entries_rq3 = rq3_entries;
2289
2290 pr_cfg_small_rx.max_entries_rcq = 1;
2291 pr_cfg_small_rx.max_entries_scq = sq_entries;
2292 pr_cfg_small_rx.max_entries_sq = sq_entries;
2293 pr_cfg_small_rx.max_entries_rq1 = 1;
2294 pr_cfg_small_rx.max_entries_rq2 = 1;
2295 pr_cfg_small_rx.max_entries_rq3 = 1;
2296
2297 for (i = 0; i < def_qps; i++) {
2298 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2299 if (ret)
2300 goto out_clean_pr;
2301 }
Anton Blanchard723f28e2011-10-14 05:31:01 +00002302 for (i = def_qps; i < def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002303 ret = ehea_init_port_res(port, &port->port_res[i],
2304 &pr_cfg_small_rx, i);
2305 if (ret)
2306 goto out_clean_pr;
2307 }
2308
2309 return 0;
2310
2311out_clean_pr:
2312 while (--i >= 0)
2313 ehea_clean_portres(port, &port->port_res[i]);
2314
2315out_kill_eq:
2316 ehea_destroy_eq(port->qp_eq);
2317 return ret;
2318}
2319
2320static int ehea_clean_all_portres(struct ehea_port *port)
2321{
2322 int ret = 0;
2323 int i;
2324
Anton Blanchard723f28e2011-10-14 05:31:01 +00002325 for (i = 0; i < port->num_def_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002326 ret |= ehea_clean_portres(port, &port->port_res[i]);
2327
2328 ret |= ehea_destroy_eq(port->qp_eq);
2329
2330 return ret;
2331}
2332
Thomas Klein35cf2e22007-08-06 13:55:14 +02002333static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002334{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002335 if (adapter->active_ports)
2336 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002337
2338 ehea_rem_mr(&adapter->mr);
2339}
2340
Thomas Klein35cf2e22007-08-06 13:55:14 +02002341static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002342{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002343 if (adapter->active_ports)
2344 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002345
2346 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2347}
2348
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002349static int ehea_up(struct net_device *dev)
2350{
2351 int ret, i;
2352 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002353
2354 if (port->state == EHEA_PORT_UP)
2355 return 0;
2356
Anton Blanchard723f28e2011-10-14 05:31:01 +00002357 ret = ehea_port_res_setup(port, port->num_def_qps);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002358 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002359 netdev_err(dev, "port_res_failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002360 goto out;
2361 }
2362
2363 /* Set default QP for this port */
2364 ret = ehea_configure_port(port);
2365 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002366 netdev_err(dev, "ehea_configure_port failed. ret:%d\n", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002367 goto out_clean_pr;
2368 }
2369
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002370 ret = ehea_reg_interrupts(dev);
2371 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002372 netdev_err(dev, "reg_interrupts failed. ret:%d\n", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002373 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002374 }
2375
Anton Blanchard723f28e2011-10-14 05:31:01 +00002376 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002377 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2378 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002379 netdev_err(dev, "activate_qp failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002380 goto out_free_irqs;
2381 }
2382 }
2383
Doug Maxey508d2b52008-01-31 20:20:49 -06002384 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002385 ret = ehea_fill_port_res(&port->port_res[i]);
2386 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08002387 netdev_err(dev, "out_free_irqs\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002388 goto out_free_irqs;
2389 }
2390 }
2391
Thomas Klein21eee2d2008-02-13 16:18:33 +01002392 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2393 if (ret) {
2394 ret = -EIO;
2395 goto out_free_irqs;
2396 }
2397
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002398 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002399
2400 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002401 goto out;
2402
2403out_free_irqs:
2404 ehea_free_interrupts(dev);
2405
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002406out_clean_pr:
2407 ehea_clean_all_portres(port);
2408out:
Thomas Klein44c82152007-07-11 16:32:00 +02002409 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08002410 netdev_info(dev, "Failed starting. ret=%i\n", ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002411
Thomas Klein21eee2d2008-02-13 16:18:33 +01002412 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002413 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002414
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002415 return ret;
2416}
2417
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002418static void port_napi_disable(struct ehea_port *port)
2419{
2420 int i;
2421
Anton Blanchard723f28e2011-10-14 05:31:01 +00002422 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002423 napi_disable(&port->port_res[i].napi);
2424}
2425
2426static void port_napi_enable(struct ehea_port *port)
2427{
2428 int i;
2429
Anton Blanchard723f28e2011-10-14 05:31:01 +00002430 for (i = 0; i < port->num_def_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002431 napi_enable(&port->port_res[i].napi);
2432}
2433
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002434static int ehea_open(struct net_device *dev)
2435{
2436 int ret;
2437 struct ehea_port *port = netdev_priv(dev);
2438
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002439 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002440
Joe Perches8c4877a2010-12-13 10:05:14 -08002441 netif_info(port, ifup, dev, "enabling port\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002442
2443 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002444 if (!ret) {
2445 port_napi_enable(port);
Anton Blanchardb9564462011-10-14 05:30:59 +00002446 netif_tx_start_all_queues(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002447 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002448
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002449 mutex_unlock(&port->port_lock);
Anton Blanchard67c170a2011-11-23 00:13:54 +00002450 schedule_delayed_work(&port->stats_work,
2451 round_jiffies_relative(msecs_to_jiffies(1000)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002452
2453 return ret;
2454}
2455
2456static int ehea_down(struct net_device *dev)
2457{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002458 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002459 struct ehea_port *port = netdev_priv(dev);
2460
2461 if (port->state == EHEA_PORT_DOWN)
2462 return 0;
2463
2464 ehea_drop_multicast_list(dev);
Thadeu Lima de Souza Cascardo5d384572012-04-25 07:32:11 +00002465 ehea_allmulti(dev, 0);
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
Bill Pemberton0297be02012-12-03 09:23:10 -05002910static void logical_port_release(struct device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002911{
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
Ben Hutchings3865fe12012-11-16 12:46:43 +00003029 | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX;
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
Bill Pemberton0297be02012-12-03 09:23:10 -05003258static int ehea_probe_adapter(struct platform_device *dev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00003259 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;
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003264 int i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003265
Grant Likely61c7a082010-04-13 16:12:29 -07003266 if (!dev || !dev->dev.of_node) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003267 pr_err("Invalid ibmebus device probed\n");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003268 return -EINVAL;
3269 }
3270
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003271 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3272 if (!adapter) {
3273 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003274 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003275 goto out;
3276 }
3277
Thomas Klein44c82152007-07-11 16:32:00 +02003278 list_add(&adapter->list, &adapter_list);
3279
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003280 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003281
Grant Likely61c7a082010-04-13 16:12:29 -07003282 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003283 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003284 if (adapter_handle)
3285 adapter->handle = *adapter_handle;
3286
3287 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003288 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003289 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003290 ret = -ENODEV;
3291 goto out_free_ad;
3292 }
3293
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003294 adapter->pd = EHEA_PD_ID;
3295
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003296 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003297
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003298
3299 /* initialize adapter and ports */
3300 /* get adapter properties */
3301 ret = ehea_sense_adapter_attr(adapter);
3302 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003303 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003304 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003305 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003306
3307 adapter->neq = ehea_create_eq(adapter,
3308 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3309 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003310 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003311 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003312 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003313 }
3314
3315 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3316 (unsigned long)adapter);
3317
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003318 ret = ehea_create_device_sysfs(dev);
3319 if (ret)
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003320 goto out_kill_eq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003321
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003322 ret = ehea_setup_ports(adapter);
3323 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003324 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003325 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003326 }
3327
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003328 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
3329 ehea_interrupt_neq, IRQF_DISABLED,
3330 "ehea_neq", adapter);
3331 if (ret) {
3332 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
3333 goto out_shutdown_ports;
3334 }
3335
Thadeu Lima de Souza Cascardo380ec962012-05-10 04:00:53 +00003336 /* Handle any events that might be pending. */
3337 tasklet_hi_schedule(&adapter->neq_tasklet);
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003338
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003339 ret = 0;
3340 goto out;
3341
Thadeu Lima de Souza Cascardoc2f12442012-04-23 03:46:29 +00003342out_shutdown_ports:
3343 for (i = 0; i < EHEA_MAX_PORTS; i++)
3344 if (adapter->port[i]) {
3345 ehea_shutdown_single_port(adapter->port[i]);
3346 adapter->port[i] = NULL;
3347 }
3348
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003349out_rem_dev_sysfs:
3350 ehea_remove_device_sysfs(dev);
3351
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003352out_kill_eq:
3353 ehea_destroy_eq(adapter->neq);
3354
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003355out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003356 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003357 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003358
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003359out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003360 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003361
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003362 return ret;
3363}
3364
Bill Pemberton0297be02012-12-03 09:23:10 -05003365static int ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003366{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003367 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003368 int i;
3369
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003370 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003371 if (adapter->port[i]) {
3372 ehea_shutdown_single_port(adapter->port[i]);
3373 adapter->port[i] = NULL;
3374 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003375
3376 ehea_remove_device_sysfs(dev);
3377
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003378 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003379 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003380
3381 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003382 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003383 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003384 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003385
Thomas Klein21eee2d2008-02-13 16:18:33 +01003386 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003387
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003388 return 0;
3389}
3390
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003391static void ehea_crash_handler(void)
Thomas Klein21eee2d2008-02-13 16:18:33 +01003392{
3393 int i;
3394
3395 if (ehea_fw_handles.arr)
3396 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3397 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3398 ehea_fw_handles.arr[i].fwh,
3399 FORCE_FREE);
3400
3401 if (ehea_bcmc_regs.arr)
3402 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3403 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3404 ehea_bcmc_regs.arr[i].port_id,
3405 ehea_bcmc_regs.arr[i].reg_type,
3406 ehea_bcmc_regs.arr[i].macaddr,
3407 0, H_DEREG_BCMC);
3408}
3409
Hannes Hering48cfb142008-05-07 14:43:36 +02003410static int ehea_mem_notifier(struct notifier_block *nb,
3411 unsigned long action, void *data)
3412{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003413 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003414 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003415
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003416 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003417
Hannes Hering48cfb142008-05-07 14:43:36 +02003418 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003419 case MEM_CANCEL_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003420 pr_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003421 /* Readd canceled memory block */
3422 case MEM_ONLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003423 pr_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003424 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003425 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003426 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003427 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003428 break;
3429 case MEM_GOING_OFFLINE:
Joe Perches8c4877a2010-12-13 10:05:14 -08003430 pr_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003431 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003432 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003433 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003434 ehea_rereg_mrs();
Hannes Hering48cfb142008-05-07 14:43:36 +02003435 break;
3436 default:
3437 break;
3438 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003439
3440 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003441 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003442
Thomas Kleina7c561f22010-04-20 23:11:31 +00003443out_unlock:
3444 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003445 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003446}
3447
3448static struct notifier_block ehea_mem_nb = {
3449 .notifier_call = ehea_mem_notifier,
3450};
3451
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003452static int ehea_reboot_notifier(struct notifier_block *nb,
3453 unsigned long action, void *unused)
3454{
3455 if (action == SYS_RESTART) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003456 pr_info("Reboot: freeing all eHEA resources\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003457 ibmebus_unregister_driver(&ehea_driver);
3458 }
3459 return NOTIFY_DONE;
3460}
3461
3462static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003463 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003464};
3465
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003466static int check_module_parm(void)
3467{
3468 int ret = 0;
3469
3470 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3471 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003472 pr_info("Bad parameter: rq1_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003473 ret = -EINVAL;
3474 }
3475 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3476 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003477 pr_info("Bad parameter: rq2_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003478 ret = -EINVAL;
3479 }
3480 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3481 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003482 pr_info("Bad parameter: rq3_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003483 ret = -EINVAL;
3484 }
3485 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3486 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003487 pr_info("Bad parameter: sq_entries\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003488 ret = -EINVAL;
3489 }
3490
3491 return ret;
3492}
3493
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003494static ssize_t ehea_show_capabilities(struct device_driver *drv,
3495 char *buf)
3496{
3497 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3498}
3499
3500static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3501 ehea_show_capabilities, NULL);
3502
Thadeu Lima de Souza Cascardo1886e5d2012-01-13 08:06:32 +00003503static int __init ehea_module_init(void)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003504{
3505 int ret;
3506
Joe Perches8c4877a2010-12-13 10:05:14 -08003507 pr_info("IBM eHEA ethernet device driver (Release %s)\n", DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003508
Thomas Klein21eee2d2008-02-13 16:18:33 +01003509 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3510 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3511
Daniel Walker9f71a562008-03-28 14:41:26 -07003512 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003513 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003514
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003515 ret = check_module_parm();
3516 if (ret)
3517 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003518
3519 ret = ehea_create_busmap();
3520 if (ret)
3521 goto out;
3522
Thomas Klein21eee2d2008-02-13 16:18:33 +01003523 ret = register_reboot_notifier(&ehea_reboot_nb);
3524 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003525 pr_info("failed registering reboot notifier\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003526
Hannes Hering48cfb142008-05-07 14:43:36 +02003527 ret = register_memory_notifier(&ehea_mem_nb);
3528 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003529 pr_info("failed registering memory remove notifier\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003530
Joe Perchesc061b182010-08-23 18:20:03 +00003531 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003532 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003533 pr_info("failed registering crash handler\n");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003534
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003535 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003536 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003537 pr_err("failed registering eHEA device driver on ebus\n");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003538 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003539 }
3540
3541 ret = driver_create_file(&ehea_driver.driver,
3542 &driver_attr_capabilities);
3543 if (ret) {
Joe Perches8c4877a2010-12-13 10:05:14 -08003544 pr_err("failed to register capabilities attribute, ret=%d\n",
3545 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003546 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003547 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003548
Thomas Klein21eee2d2008-02-13 16:18:33 +01003549 return ret;
3550
3551out3:
3552 ibmebus_unregister_driver(&ehea_driver);
3553out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003554 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003555 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003556 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003557out:
3558 return ret;
3559}
3560
3561static void __exit ehea_module_exit(void)
3562{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003563 int ret;
3564
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003565 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003566 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003567 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003568 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003569 if (ret)
Joe Perches8c4877a2010-12-13 10:05:14 -08003570 pr_info("failed unregistering crash handler\n");
Hannes Hering48cfb142008-05-07 14:43:36 +02003571 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003572 kfree(ehea_fw_handles.arr);
3573 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003574 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003575}
3576
3577module_init(ehea_module_init);
3578module_exit(ehea_module_exit);