blob: a84c389d3db71a78d47d2a3b0c54a0f15736c53c [file] [log] [blame]
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001/*
2 * linux/drivers/net/ehea/ehea_main.c
3 *
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
29#include <linux/in.h>
30#include <linux/ip.h>
31#include <linux/tcp.h>
32#include <linux/udp.h>
33#include <linux/if.h>
34#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020036#include <linux/if_ether.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020037#include <linux/notifier.h>
38#include <linux/reboot.h>
Hannes Hering48cfb142008-05-07 14:43:36 +020039#include <linux/memory.h>
Thomas Klein21eee2d2008-02-13 16:18:33 +010040#include <asm/kexec.h>
Daniel Walker06f89ed2008-03-28 14:41:26 -070041#include <linux/mutex.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020042
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020043#include <net/ip.h>
44
45#include "ehea.h"
46#include "ehea_qmr.h"
47#include "ehea_phyp.h"
48
49
50MODULE_LICENSE("GPL");
51MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
52MODULE_DESCRIPTION("IBM eServer HEA Driver");
53MODULE_VERSION(DRV_VERSION);
54
55
56static int msg_level = -1;
57static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
58static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
59static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
60static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Doug Maxey508d2b52008-01-31 20:20:49 -060061static int use_mcs;
62static int use_lro;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070063static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010064static int num_tx_qps = EHEA_NUM_TX_QP;
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 Themannd4dc4ec2007-09-25 16:16:34 -070074module_param(use_lro, int, 0);
75module_param(lro_max_aggr, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010076module_param(num_tx_qps, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020077
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010078MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020079MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020080MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
81 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020082MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
83 "[2^x - 1], x = [6..14]. Default = "
84 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
85MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
86 "[2^x - 1], x = [6..14]. Default = "
87 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
88MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
89 "[2^x - 1], x = [6..14]. Default = "
90 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
91MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
92 "[2^x - 1], x = [6..14]. Default = "
93 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Jan-Bernd Themann18072a52007-08-22 16:21:24 +020094MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020095
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070096MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
97 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
98MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
99 "Default = 0");
100
Doug Maxey508d2b52008-01-31 20:20:49 -0600101static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +0200102static LIST_HEAD(adapter_list);
Stephen Rothwell48e4cc72009-01-05 16:06:02 -0800103static unsigned long ehea_driver_flags;
Thomas Klein44c82152007-07-11 16:32:00 +0200104struct work_struct ehea_rereg_mr_task;
Daniel Walker06f89ed2008-03-28 14:41:26 -0700105static DEFINE_MUTEX(dlpar_mem_lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100106struct ehea_fw_handle_array ehea_fw_handles;
107struct ehea_bcmc_reg_array ehea_bcmc_regs;
108
Thomas Kleind1dea382007-04-26 11:56:13 +0200109
Grant Likely2dc11582010-08-06 09:25:50 -0600110static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200111 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200112
Grant Likely2dc11582010-08-06 09:25:50 -0600113static int __devexit ehea_remove(struct platform_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200114
115static struct of_device_id ehea_device_table[] = {
116 {
117 .name = "lhea",
118 .compatible = "IBM,lhea",
119 },
120 {},
121};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100122MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200123
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000124static struct of_platform_driver ehea_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700125 .driver = {
126 .name = "ehea",
127 .owner = THIS_MODULE,
128 .of_match_table = ehea_device_table,
129 },
Thomas Kleind1dea382007-04-26 11:56:13 +0200130 .probe = ehea_probe_adapter,
131 .remove = ehea_remove,
132};
133
Doug Maxey508d2b52008-01-31 20:20:49 -0600134void ehea_dump(void *adr, int len, char *msg)
135{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200136 int x;
137 unsigned char *deb = adr;
138 for (x = 0; x < len; x += 16) {
David S. Millercfa969e2010-12-06 20:45:28 -0800139 printk(DRV_NAME " %s adr=%p ofs=%04x %016llx %016llx\n", msg,
140 deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200141 deb += 16;
142 }
143}
144
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100145void ehea_schedule_port_reset(struct ehea_port *port)
146{
147 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
148 schedule_work(&port->reset_task);
149}
150
Thomas Klein21eee2d2008-02-13 16:18:33 +0100151static void ehea_update_firmware_handles(void)
152{
153 struct ehea_fw_handle_entry *arr = NULL;
154 struct ehea_adapter *adapter;
155 int num_adapters = 0;
156 int num_ports = 0;
157 int num_portres = 0;
158 int i = 0;
159 int num_fw_handles, k, l;
160
161 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700162 mutex_lock(&ehea_fw_handles.lock);
163
Thomas Klein21eee2d2008-02-13 16:18:33 +0100164 list_for_each_entry(adapter, &adapter_list, list) {
165 num_adapters++;
166
167 for (k = 0; k < EHEA_MAX_PORTS; k++) {
168 struct ehea_port *port = adapter->port[k];
169
170 if (!port || (port->state != EHEA_PORT_UP))
171 continue;
172
173 num_ports++;
174 num_portres += port->num_def_qps + port->num_add_tx_qps;
175 }
176 }
177
178 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
179 num_ports * EHEA_NUM_PORT_FW_HANDLES +
180 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
181
182 if (num_fw_handles) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000183 arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100184 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700185 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100186 } else
187 goto out_update;
188
189 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700190 if (num_adapters == 0)
191 break;
192
Thomas Klein21eee2d2008-02-13 16:18:33 +0100193 for (k = 0; k < EHEA_MAX_PORTS; k++) {
194 struct ehea_port *port = adapter->port[k];
195
Joe Perches8e95a202009-12-03 07:58:21 +0000196 if (!port || (port->state != EHEA_PORT_UP) ||
197 (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100198 continue;
199
200 for (l = 0;
201 l < port->num_def_qps + port->num_add_tx_qps;
202 l++) {
203 struct ehea_port_res *pr = &port->port_res[l];
204
205 arr[i].adh = adapter->handle;
206 arr[i++].fwh = pr->qp->fw_handle;
207 arr[i].adh = adapter->handle;
208 arr[i++].fwh = pr->send_cq->fw_handle;
209 arr[i].adh = adapter->handle;
210 arr[i++].fwh = pr->recv_cq->fw_handle;
211 arr[i].adh = adapter->handle;
212 arr[i++].fwh = pr->eq->fw_handle;
213 arr[i].adh = adapter->handle;
214 arr[i++].fwh = pr->send_mr.handle;
215 arr[i].adh = adapter->handle;
216 arr[i++].fwh = pr->recv_mr.handle;
217 }
218 arr[i].adh = adapter->handle;
219 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700220 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100221 }
222
223 arr[i].adh = adapter->handle;
224 arr[i++].fwh = adapter->neq->fw_handle;
225
226 if (adapter->mr.handle) {
227 arr[i].adh = adapter->handle;
228 arr[i++].fwh = adapter->mr.handle;
229 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700230 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100231 }
232
233out_update:
234 kfree(ehea_fw_handles.arr);
235 ehea_fw_handles.arr = arr;
236 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700237out:
238 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100239}
240
241static void ehea_update_bcmc_registrations(void)
242{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700243 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100244 struct ehea_bcmc_reg_entry *arr = NULL;
245 struct ehea_adapter *adapter;
246 struct ehea_mc_list *mc_entry;
247 int num_registrations = 0;
248 int i = 0;
249 int k;
250
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700251 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
252
Thomas Klein21eee2d2008-02-13 16:18:33 +0100253 /* Determine number of registrations */
254 list_for_each_entry(adapter, &adapter_list, list)
255 for (k = 0; k < EHEA_MAX_PORTS; k++) {
256 struct ehea_port *port = adapter->port[k];
257
258 if (!port || (port->state != EHEA_PORT_UP))
259 continue;
260
261 num_registrations += 2; /* Broadcast registrations */
262
263 list_for_each_entry(mc_entry, &port->mc_list->list,list)
264 num_registrations += 2;
265 }
266
267 if (num_registrations) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000268 arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100269 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700270 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100271 } else
272 goto out_update;
273
274 list_for_each_entry(adapter, &adapter_list, list) {
275 for (k = 0; k < EHEA_MAX_PORTS; k++) {
276 struct ehea_port *port = adapter->port[k];
277
278 if (!port || (port->state != EHEA_PORT_UP))
279 continue;
280
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700281 if (num_registrations == 0)
282 goto out_update;
283
Thomas Klein21eee2d2008-02-13 16:18:33 +0100284 arr[i].adh = adapter->handle;
285 arr[i].port_id = port->logical_port_id;
286 arr[i].reg_type = EHEA_BCMC_BROADCAST |
287 EHEA_BCMC_UNTAGGED;
288 arr[i++].macaddr = port->mac_addr;
289
290 arr[i].adh = adapter->handle;
291 arr[i].port_id = port->logical_port_id;
292 arr[i].reg_type = EHEA_BCMC_BROADCAST |
293 EHEA_BCMC_VLANID_ALL;
294 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700295 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100296
297 list_for_each_entry(mc_entry,
298 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700299 if (num_registrations == 0)
300 goto out_update;
301
Thomas Klein21eee2d2008-02-13 16:18:33 +0100302 arr[i].adh = adapter->handle;
303 arr[i].port_id = port->logical_port_id;
304 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
305 EHEA_BCMC_MULTICAST |
306 EHEA_BCMC_UNTAGGED;
307 arr[i++].macaddr = mc_entry->macaddr;
308
309 arr[i].adh = adapter->handle;
310 arr[i].port_id = port->logical_port_id;
311 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
312 EHEA_BCMC_MULTICAST |
313 EHEA_BCMC_VLANID_ALL;
314 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700315 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100316 }
317 }
318 }
319
320out_update:
321 kfree(ehea_bcmc_regs.arr);
322 ehea_bcmc_regs.arr = arr;
323 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700324out:
325 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100326}
327
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200328static struct net_device_stats *ehea_get_stats(struct net_device *dev)
329{
330 struct ehea_port *port = netdev_priv(dev);
331 struct net_device_stats *stats = &port->stats;
332 struct hcp_ehea_port_cb2 *cb2;
Breno Leitaoce45b872010-10-27 08:45:14 +0000333 u64 hret, rx_packets, tx_packets, rx_bytes = 0, tx_bytes = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200334 int i;
335
336 memset(stats, 0, sizeof(*stats));
337
Brian King3d8009c2010-06-30 11:59:12 +0000338 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200339 if (!cb2) {
David S. Millercfa969e2010-12-06 20:45:28 -0800340 ehea_error("no mem for cb2");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200341 goto out;
342 }
343
344 hret = ehea_h_query_ehea_port(port->adapter->handle,
345 port->logical_port_id,
346 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
347 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -0800348 ehea_error("query_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200349 goto out_herr;
350 }
351
352 if (netif_msg_hw(port))
353 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
354
355 rx_packets = 0;
Breno Leitaoce45b872010-10-27 08:45:14 +0000356 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200357 rx_packets += port->port_res[i].rx_packets;
Breno Leitaoce45b872010-10-27 08:45:14 +0000358 rx_bytes += port->port_res[i].rx_bytes;
359 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200360
Thomas Klein7393b872007-11-21 17:37:58 +0100361 tx_packets = 0;
Breno Leitaoce45b872010-10-27 08:45:14 +0000362 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Thomas Klein7393b872007-11-21 17:37:58 +0100363 tx_packets += port->port_res[i].tx_packets;
Breno Leitaoce45b872010-10-27 08:45:14 +0000364 tx_bytes += port->port_res[i].tx_bytes;
365 }
Thomas Klein7393b872007-11-21 17:37:58 +0100366
367 stats->tx_packets = tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200368 stats->multicast = cb2->rxmcp;
369 stats->rx_errors = cb2->rxuerr;
Breno Leitaoce45b872010-10-27 08:45:14 +0000370 stats->rx_bytes = rx_bytes;
371 stats->tx_bytes = tx_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200372 stats->rx_packets = rx_packets;
373
374out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800375 free_page((unsigned long)cb2);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200376out:
377 return stats;
378}
379
380static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
381{
382 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
383 struct net_device *dev = pr->port->netdev;
384 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200385 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
386 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200387 int i;
388
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200389 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200390
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200391 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200392 if (nr_of_wqes > 0)
393 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200394 pr->rq1_skba.os_skbs = fill_wqes;
395 return;
396 }
397
398 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200399 if (!skb_arr_rq1[index]) {
400 skb_arr_rq1[index] = netdev_alloc_skb(dev,
401 EHEA_L_PKT_SIZE);
402 if (!skb_arr_rq1[index]) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200403 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200404 break;
405 }
406 }
407 index--;
408 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200409 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200410 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200411
412 if (adder == 0)
413 return;
414
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200415 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200416 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200417}
418
Thomas Kleine2878802009-01-21 14:45:57 -0800419static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200420{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200421 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
422 struct net_device *dev = pr->port->netdev;
423 int i;
424
425 for (i = 0; i < pr->rq1_skba.len; i++) {
426 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Thomas Kleine2878802009-01-21 14:45:57 -0800427 if (!skb_arr_rq1[i])
428 break;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200429 }
430 /* Ring doorbell */
431 ehea_update_rq1a(pr->qp, nr_rq1a);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200432}
433
434static int ehea_refill_rq_def(struct ehea_port_res *pr,
435 struct ehea_q_skb_arr *q_skba, int rq_nr,
436 int num_wqes, int wqe_type, int packet_size)
437{
438 struct net_device *dev = pr->port->netdev;
439 struct ehea_qp *qp = pr->qp;
440 struct sk_buff **skb_arr = q_skba->arr;
441 struct ehea_rwqe *rwqe;
442 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200443 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200444 int ret = 0;
445
446 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200447 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200448
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200449 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
450 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200451 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200452 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200453
454 index = q_skba->index;
455 max_index_mask = q_skba->len - 1;
456 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200457 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000458 struct sk_buff *skb;
459
460 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200461 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200462 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800463 if (q_skba->os_skbs == q_skba->len - 2) {
David S. Millercfa969e2010-12-06 20:45:28 -0800464 ehea_info("%s: rq%i ran dry - no mem for skb",
465 pr->port->netdev->name, rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800466 ret = -ENOMEM;
467 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200468 break;
469 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200470
471 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200472 tmp_addr = ehea_map_vaddr(skb->data);
473 if (tmp_addr == -1) {
474 dev_kfree_skb(skb);
475 q_skba->os_skbs = fill_wqes - i;
476 ret = 0;
477 break;
478 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200479
480 rwqe = ehea_get_next_rwqe(qp, rq_nr);
481 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200482 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200483 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200484 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200485 rwqe->sg_list[0].len = packet_size;
486 rwqe->data_segments = 1;
487
488 index++;
489 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200490 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200491 }
Thomas Klein44c82152007-07-11 16:32:00 +0200492
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200493 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200494 if (adder == 0)
495 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200496
497 /* Ring doorbell */
498 iosync();
499 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200500 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200501 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200502 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200503out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200504 return ret;
505}
506
507
508static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
509{
510 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
511 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000512 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200513}
514
515
516static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
517{
518 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
519 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000520 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200521}
522
523static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
524{
525 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
526 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
527 return 0;
528 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
529 (cqe->header_length == 0))
530 return 0;
531 return -EINVAL;
532}
533
534static inline void ehea_fill_skb(struct net_device *dev,
535 struct sk_buff *skb, struct ehea_cqe *cqe)
536{
537 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
538
539 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200540 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000541
542 /* The packet was not an IPV4 packet so a complemented checksum was
543 calculated. The value is found in the Internet Checksum field. */
544 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
545 skb->ip_summed = CHECKSUM_COMPLETE;
546 skb->csum = csum_unfold(~cqe->inet_checksum_value);
547 } else
548 skb->ip_summed = CHECKSUM_UNNECESSARY;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200549}
550
551static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
552 int arr_len,
553 struct ehea_cqe *cqe)
554{
555 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
556 struct sk_buff *skb;
557 void *pref;
558 int x;
559
560 x = skb_index + 1;
561 x &= (arr_len - 1);
562
563 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700564 if (pref) {
565 prefetchw(pref);
566 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200567
Hannes Hering0b2febf2009-05-04 11:06:37 -0700568 pref = (skb_array[x]->data);
569 prefetch(pref);
570 prefetch(pref + EHEA_CACHE_LINE);
571 prefetch(pref + EHEA_CACHE_LINE * 2);
572 prefetch(pref + EHEA_CACHE_LINE * 3);
573 }
574
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200575 skb = skb_array[skb_index];
576 skb_array[skb_index] = NULL;
577 return skb;
578}
579
580static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
581 int arr_len, int wqe_index)
582{
583 struct sk_buff *skb;
584 void *pref;
585 int x;
586
587 x = wqe_index + 1;
588 x &= (arr_len - 1);
589
590 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700591 if (pref) {
592 prefetchw(pref);
593 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200594
Hannes Hering0b2febf2009-05-04 11:06:37 -0700595 pref = (skb_array[x]->data);
596 prefetchw(pref);
597 prefetchw(pref + EHEA_CACHE_LINE);
598 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200599
600 skb = skb_array[wqe_index];
601 skb_array[wqe_index] = NULL;
602 return skb;
603}
604
605static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
606 struct ehea_cqe *cqe, int *processed_rq2,
607 int *processed_rq3)
608{
609 struct sk_buff *skb;
610
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100611 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
612 pr->p_stats.err_tcp_cksum++;
613 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
614 pr->p_stats.err_ip_cksum++;
615 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
616 pr->p_stats.err_frame_crc++;
617
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200618 if (rq == 2) {
619 *processed_rq2 += 1;
620 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
621 dev_kfree_skb(skb);
622 } else if (rq == 3) {
623 *processed_rq3 += 1;
624 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
625 dev_kfree_skb(skb);
626 }
627
628 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100629 if (netif_msg_rx_err(pr->port)) {
David S. Millercfa969e2010-12-06 20:45:28 -0800630 ehea_error("Critical receive error for QP %d. "
631 "Resetting port.", pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100632 ehea_dump(cqe, sizeof(*cqe), "CQE");
633 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100634 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200635 return 1;
636 }
637
638 return 0;
639}
640
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700641static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
642 void **tcph, u64 *hdr_flags, void *priv)
643{
644 struct ehea_cqe *cqe = priv;
645 unsigned int ip_len;
646 struct iphdr *iph;
647
648 /* non tcp/udp packets */
649 if (!cqe->header_length)
650 return -1;
651
652 /* non tcp packet */
653 skb_reset_network_header(skb);
654 iph = ip_hdr(skb);
655 if (iph->protocol != IPPROTO_TCP)
656 return -1;
657
658 ip_len = ip_hdrlen(skb);
659 skb_set_transport_header(skb, ip_len);
660 *tcph = tcp_hdr(skb);
661
662 /* check if ip header and tcp header are complete */
Roland Dreier3ff2cd22008-07-01 10:20:33 -0700663 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700664 return -1;
665
666 *hdr_flags = LRO_IPV4 | LRO_TCP;
667 *iphdr = iph;
668
669 return 0;
670}
671
672static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
673 struct sk_buff *skb)
674{
Joe Perches8e95a202009-12-03 07:58:21 +0000675 int vlan_extracted = ((cqe->status & EHEA_CQE_VLAN_TAG_XTRACT) &&
676 pr->port->vgrp);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700677
678 if (use_lro) {
679 if (vlan_extracted)
680 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
681 pr->port->vgrp,
682 cqe->vlan_tag,
683 cqe);
684 else
685 lro_receive_skb(&pr->lro_mgr, skb, cqe);
686 } else {
687 if (vlan_extracted)
688 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
689 cqe->vlan_tag);
690 else
691 netif_receive_skb(skb);
692 }
693}
694
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700695static int ehea_proc_rwqes(struct net_device *dev,
696 struct ehea_port_res *pr,
697 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200698{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100699 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200700 struct ehea_qp *qp = pr->qp;
701 struct ehea_cqe *cqe;
702 struct sk_buff *skb;
703 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
704 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
705 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
706 int skb_arr_rq1_len = pr->rq1_skba.len;
707 int skb_arr_rq2_len = pr->rq2_skba.len;
708 int skb_arr_rq3_len = pr->rq3_skba.len;
709 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000710 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700711 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200712
713 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
714 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200715
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200716 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700717 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200718 ehea_inc_rq1(qp);
719 processed_rq1++;
720 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200721 if (netif_msg_rx_status(port))
722 ehea_dump(cqe, sizeof(*cqe), "CQE");
723
724 last_wqe_index = wqe_index;
725 rmb();
726 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600727 if (rq == 1) {
728 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200729 skb = get_skb_by_index_ll(skb_arr_rq1,
730 skb_arr_rq1_len,
731 wqe_index);
732 if (unlikely(!skb)) {
David S. Millercfa969e2010-12-06 20:45:28 -0800733 if (netif_msg_rx_err(port))
734 ehea_error("LL rq1: skb=NULL");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100735
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700736 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200737 EHEA_L_PKT_SIZE);
738 if (!skb)
739 break;
740 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600741 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200742 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700743 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600744 } else if (rq == 2) {
745 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200746 skb = get_skb_by_index(skb_arr_rq2,
747 skb_arr_rq2_len, cqe);
748 if (unlikely(!skb)) {
David S. Millercfa969e2010-12-06 20:45:28 -0800749 if (netif_msg_rx_err(port))
750 ehea_error("rq2: skb=NULL");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200751 break;
752 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700753 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200754 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600755 } else {
756 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200757 skb = get_skb_by_index(skb_arr_rq3,
758 skb_arr_rq3_len, cqe);
759 if (unlikely(!skb)) {
David S. Millercfa969e2010-12-06 20:45:28 -0800760 if (netif_msg_rx_err(port))
761 ehea_error("rq3: skb=NULL");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200762 break;
763 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700764 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200765 processed_rq3++;
766 }
767
Breno Leitaoce45b872010-10-27 08:45:14 +0000768 processed_bytes += skb->len;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700769 ehea_proc_skb(pr, cqe, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100770 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100771 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200772 port_reset = ehea_treat_poll_error(pr, rq, cqe,
773 &processed_rq2,
774 &processed_rq3);
775 if (port_reset)
776 break;
777 }
778 cqe = ehea_poll_rq1(qp, &wqe_index);
779 }
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700780 if (use_lro)
781 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200782
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200783 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000784 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200785
786 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
787 ehea_refill_rq2(pr, processed_rq2);
788 ehea_refill_rq3(pr, processed_rq3);
789
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700790 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200791}
792
Andre Detsch2928db42010-08-17 05:49:12 +0000793#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
794
795static void reset_sq_restart_flag(struct ehea_port *port)
796{
797 int i;
798
799 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
800 struct ehea_port_res *pr = &port->port_res[i];
801 pr->sq_restart_flag = 0;
802 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000803 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000804}
805
806static void check_sqs(struct ehea_port *port)
807{
808 struct ehea_swqe *swqe;
809 int swqe_index;
810 int i, k;
811
812 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
813 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000814 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000815 k = 0;
816 swqe = ehea_get_swqe(pr->qp, &swqe_index);
817 memset(swqe, 0, SWQE_HEADER_SIZE);
818 atomic_dec(&pr->swqe_avail);
819
820 swqe->tx_control |= EHEA_SWQE_PURGE;
821 swqe->wr_id = SWQE_RESTART_CHECK;
822 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
823 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
824 swqe->immediate_data_length = 80;
825
826 ehea_post_swqe(pr->qp, swqe);
827
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000828 ret = wait_event_timeout(port->restart_wq,
829 pr->sq_restart_flag == 0,
830 msecs_to_jiffies(100));
831
832 if (!ret) {
David S. Millercfa969e2010-12-06 20:45:28 -0800833 ehea_error("HW/SW queues out of sync");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000834 ehea_schedule_port_reset(pr->port);
835 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000836 }
837 }
Andre Detsch2928db42010-08-17 05:49:12 +0000838}
839
840
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100841static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200842{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100843 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200844 struct ehea_cq *send_cq = pr->send_cq;
845 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100846 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200847 int cqe_counter = 0;
848 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100849 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200850 unsigned long flags;
851
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100852 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600853 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100854 ehea_inc_cq(send_cq);
855
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200856 cqe_counter++;
857 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000858
859 if (cqe->wr_id == SWQE_RESTART_CHECK) {
860 pr->sq_restart_flag = 1;
861 swqe_av++;
862 break;
863 }
864
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200865 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
David S. Millercfa969e2010-12-06 20:45:28 -0800866 ehea_error("Bad send completion status=0x%04X",
867 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000868
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200869 if (netif_msg_tx_err(pr->port))
870 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000871
872 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
David S. Millercfa969e2010-12-06 20:45:28 -0800873 ehea_error("Resetting port");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000874 ehea_schedule_port_reset(pr->port);
875 break;
876 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200877 }
878
879 if (netif_msg_tx_done(pr->port))
880 ehea_dump(cqe, sizeof(*cqe), "CQE");
881
882 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100883 == EHEA_SWQE2_TYPE)) {
884
885 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
886 skb = pr->sq_skba.arr[index];
887 dev_kfree_skb(skb);
888 pr->sq_skba.arr[index] = NULL;
889 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200890
891 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
892 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100893
894 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700895 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200896
897 ehea_update_feca(send_cq, cqe_counter);
898 atomic_add(swqe_av, &pr->swqe_avail);
899
900 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100901
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200902 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
903 >= pr->swqe_refill_th)) {
904 netif_wake_queue(pr->port->netdev);
905 pr->queue_stopped = 0;
906 }
907 spin_unlock_irqrestore(&pr->netif_queue, flags);
Breno Leitao5b27d422010-10-05 13:16:22 +0000908 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200909
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100910 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200911}
912
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100913#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700914#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100915
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700916static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200917{
Doug Maxey508d2b52008-01-31 20:20:49 -0600918 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
919 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700920 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100921 struct ehea_cqe *cqe;
922 struct ehea_cqe *cqe_skb = NULL;
923 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700924 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100925
926 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700927 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100928
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700929 if (!force_irq)
930 rx += ehea_proc_rwqes(dev, pr, budget - rx);
931
932 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100933 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700934 force_irq = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -0800935 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100936 ehea_reset_cq_ep(pr->recv_cq);
937 ehea_reset_cq_ep(pr->send_cq);
938 ehea_reset_cq_n1(pr->recv_cq);
939 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000940 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100941 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
942 cqe_skb = ehea_poll_cq(pr->send_cq);
943
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100944 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700945 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100946
Ben Hutchings288379f2009-01-19 16:43:59 -0800947 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700948 return rx;
949
950 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
951 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100952 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100953
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700954 pr->poll_counter++;
955 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200956}
957
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200958#ifdef CONFIG_NET_POLL_CONTROLLER
959static void ehea_netpoll(struct net_device *dev)
960{
961 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700962 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200963
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700964 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800965 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200966}
967#endif
968
David Howells7d12e782006-10-05 14:55:46 +0100969static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200970{
971 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100972
Ben Hutchings288379f2009-01-19 16:43:59 -0800973 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100974
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200975 return IRQ_HANDLED;
976}
977
David Howells7d12e782006-10-05 14:55:46 +0100978static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200979{
980 struct ehea_port *port = param;
981 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100982 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200983 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000984 u64 resource_type, aer, aerr;
985 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200986
987 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100988
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200989 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200990 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
David S. Millercfa969e2010-12-06 20:45:28 -0800991 ehea_error("QP aff_err: entry=0x%llx, token=0x%x",
992 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100993
994 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000995
996 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
997 &aer, &aerr);
998
999 if (resource_type == EHEA_AER_RESTYPE_QP) {
1000 if ((aer & EHEA_AER_RESET_MASK) ||
1001 (aerr & EHEA_AERR_RESET_MASK))
1002 reset_port = 1;
1003 } else
1004 reset_port = 1; /* Reset in case of CQ or EQ error */
1005
Thomas Kleinbb3a6442007-01-22 12:54:50 +01001006 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001007 }
1008
Thomas Kleinea96cea2010-04-20 23:10:55 +00001009 if (reset_port) {
David S. Millercfa969e2010-12-06 20:45:28 -08001010 ehea_error("Resetting port");
Thomas Kleinea96cea2010-04-20 23:10:55 +00001011 ehea_schedule_port_reset(port);
1012 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001013
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001014 return IRQ_HANDLED;
1015}
1016
1017static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
1018 int logical_port)
1019{
1020 int i;
1021
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01001022 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +01001023 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001024 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +01001025 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001026 return NULL;
1027}
1028
1029int ehea_sense_port_attr(struct ehea_port *port)
1030{
1031 int ret;
1032 u64 hret;
1033 struct hcp_ehea_port_cb0 *cb0;
1034
Doug Maxey508d2b52008-01-31 20:20:49 -06001035 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -08001036 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -06001037 if (!cb0) {
David S. Millercfa969e2010-12-06 20:45:28 -08001038 ehea_error("no mem for cb0");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001039 ret = -ENOMEM;
1040 goto out;
1041 }
1042
1043 hret = ehea_h_query_ehea_port(port->adapter->handle,
1044 port->logical_port_id, H_PORT_CB0,
1045 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1046 cb0);
1047 if (hret != H_SUCCESS) {
1048 ret = -EIO;
1049 goto out_free;
1050 }
1051
1052 /* MAC address */
1053 port->mac_addr = cb0->port_mac_addr << 16;
1054
Doug Maxey508d2b52008-01-31 20:20:49 -06001055 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001056 ret = -EADDRNOTAVAIL;
1057 goto out_free;
1058 }
1059
1060 /* Port speed */
1061 switch (cb0->port_speed) {
1062 case H_SPEED_10M_H:
1063 port->port_speed = EHEA_SPEED_10M;
1064 port->full_duplex = 0;
1065 break;
1066 case H_SPEED_10M_F:
1067 port->port_speed = EHEA_SPEED_10M;
1068 port->full_duplex = 1;
1069 break;
1070 case H_SPEED_100M_H:
1071 port->port_speed = EHEA_SPEED_100M;
1072 port->full_duplex = 0;
1073 break;
1074 case H_SPEED_100M_F:
1075 port->port_speed = EHEA_SPEED_100M;
1076 port->full_duplex = 1;
1077 break;
1078 case H_SPEED_1G_F:
1079 port->port_speed = EHEA_SPEED_1G;
1080 port->full_duplex = 1;
1081 break;
1082 case H_SPEED_10G_F:
1083 port->port_speed = EHEA_SPEED_10G;
1084 port->full_duplex = 1;
1085 break;
1086 default:
1087 port->port_speed = 0;
1088 port->full_duplex = 0;
1089 break;
1090 }
1091
Thomas Kleine919b592007-01-22 12:53:20 +01001092 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001093 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001094
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001095 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001096 if (use_mcs)
1097 port->num_def_qps = cb0->num_default_qps;
1098 else
1099 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001100
1101 if (!port->num_def_qps) {
1102 ret = -EINVAL;
1103 goto out_free;
1104 }
1105
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001106 port->num_tx_qps = num_tx_qps;
1107
1108 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001109 port->num_add_tx_qps = 0;
1110 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001111 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001112
1113 ret = 0;
1114out_free:
1115 if (ret || netif_msg_probe(port))
1116 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001117 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001118out:
1119 return ret;
1120}
1121
1122int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1123{
1124 struct hcp_ehea_port_cb4 *cb4;
1125 u64 hret;
1126 int ret = 0;
1127
Thomas Klein3faf2692009-01-21 14:45:33 -08001128 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001129 if (!cb4) {
David S. Millercfa969e2010-12-06 20:45:28 -08001130 ehea_error("no mem for cb4");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001131 ret = -ENOMEM;
1132 goto out;
1133 }
1134
1135 cb4->port_speed = port_speed;
1136
1137 netif_carrier_off(port->netdev);
1138
1139 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1140 port->logical_port_id,
1141 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1142 if (hret == H_SUCCESS) {
1143 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1144
1145 hret = ehea_h_query_ehea_port(port->adapter->handle,
1146 port->logical_port_id,
1147 H_PORT_CB4, H_PORT_CB4_SPEED,
1148 cb4);
1149 if (hret == H_SUCCESS) {
1150 switch (cb4->port_speed) {
1151 case H_SPEED_10M_H:
1152 port->port_speed = EHEA_SPEED_10M;
1153 port->full_duplex = 0;
1154 break;
1155 case H_SPEED_10M_F:
1156 port->port_speed = EHEA_SPEED_10M;
1157 port->full_duplex = 1;
1158 break;
1159 case H_SPEED_100M_H:
1160 port->port_speed = EHEA_SPEED_100M;
1161 port->full_duplex = 0;
1162 break;
1163 case H_SPEED_100M_F:
1164 port->port_speed = EHEA_SPEED_100M;
1165 port->full_duplex = 1;
1166 break;
1167 case H_SPEED_1G_F:
1168 port->port_speed = EHEA_SPEED_1G;
1169 port->full_duplex = 1;
1170 break;
1171 case H_SPEED_10G_F:
1172 port->port_speed = EHEA_SPEED_10G;
1173 port->full_duplex = 1;
1174 break;
1175 default:
1176 port->port_speed = 0;
1177 port->full_duplex = 0;
1178 break;
1179 }
1180 } else {
David S. Millercfa969e2010-12-06 20:45:28 -08001181 ehea_error("Failed sensing port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001182 ret = -EIO;
1183 }
1184 } else {
1185 if (hret == H_AUTHORITY) {
David S. Millercfa969e2010-12-06 20:45:28 -08001186 ehea_info("Hypervisor denied setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001187 ret = -EPERM;
1188 } else {
1189 ret = -EIO;
David S. Millercfa969e2010-12-06 20:45:28 -08001190 ehea_error("Failed setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001191 }
1192 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001193 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1194 netif_carrier_on(port->netdev);
1195
Thomas Klein3faf2692009-01-21 14:45:33 -08001196 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001197out:
1198 return ret;
1199}
1200
1201static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1202{
1203 int ret;
1204 u8 ec;
1205 u8 portnum;
1206 struct ehea_port *port;
1207
1208 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1209 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1210 port = ehea_get_port(adapter, portnum);
1211
1212 switch (ec) {
1213 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1214
1215 if (!port) {
David S. Millercfa969e2010-12-06 20:45:28 -08001216 ehea_error("unknown portnum %x", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001217 break;
1218 }
1219
1220 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
David S. Millercfa969e2010-12-06 20:45:28 -08001221 if (!netif_carrier_ok(port->netdev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001222 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001223 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08001224 ehea_error("failed resensing port "
1225 "attributes");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001226 break;
1227 }
1228
David S. Millercfa969e2010-12-06 20:45:28 -08001229 if (netif_msg_link(port))
1230 ehea_info("%s: Logical port up: %dMbps "
1231 "%s Duplex",
1232 port->netdev->name,
1233 port->port_speed,
1234 port->full_duplex ==
1235 1 ? "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001236
David S. Millercfa969e2010-12-06 20:45:28 -08001237 netif_carrier_on(port->netdev);
1238 netif_wake_queue(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001239 }
1240 } else
David S. Millercfa969e2010-12-06 20:45:28 -08001241 if (netif_carrier_ok(port->netdev)) {
1242 if (netif_msg_link(port))
1243 ehea_info("%s: Logical port down",
1244 port->netdev->name);
1245 netif_carrier_off(port->netdev);
1246 netif_stop_queue(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001247 }
1248
1249 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001250 port->phy_link = EHEA_PHY_LINK_UP;
David S. Millercfa969e2010-12-06 20:45:28 -08001251 if (netif_msg_link(port))
1252 ehea_info("%s: Physical port up",
1253 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001254 if (prop_carrier_state)
David S. Millercfa969e2010-12-06 20:45:28 -08001255 netif_carrier_on(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001256 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001257 port->phy_link = EHEA_PHY_LINK_DOWN;
David S. Millercfa969e2010-12-06 20:45:28 -08001258 if (netif_msg_link(port))
1259 ehea_info("%s: Physical port down",
1260 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001261 if (prop_carrier_state)
David S. Millercfa969e2010-12-06 20:45:28 -08001262 netif_carrier_off(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001263 }
1264
1265 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
David S. Millercfa969e2010-12-06 20:45:28 -08001266 ehea_info("External switch port is primary port");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001267 else
David S. Millercfa969e2010-12-06 20:45:28 -08001268 ehea_info("External switch port is backup port");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001269
1270 break;
1271 case EHEA_EC_ADAPTER_MALFUNC:
David S. Millercfa969e2010-12-06 20:45:28 -08001272 ehea_error("Adapter malfunction");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001273 break;
1274 case EHEA_EC_PORT_MALFUNC:
David S. Millercfa969e2010-12-06 20:45:28 -08001275 ehea_info("Port malfunction: Device: %s", port->netdev->name);
1276 netif_carrier_off(port->netdev);
1277 netif_stop_queue(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001278 break;
1279 default:
David S. Millercfa969e2010-12-06 20:45:28 -08001280 ehea_error("unknown event code %x, eqe=0x%llX", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001281 break;
1282 }
1283}
1284
1285static void ehea_neq_tasklet(unsigned long data)
1286{
Doug Maxey508d2b52008-01-31 20:20:49 -06001287 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001288 struct ehea_eqe *eqe;
1289 u64 event_mask;
1290
1291 eqe = ehea_poll_eq(adapter->neq);
David S. Millercfa969e2010-12-06 20:45:28 -08001292 ehea_debug("eqe=%p", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001293
1294 while (eqe) {
David S. Millercfa969e2010-12-06 20:45:28 -08001295 ehea_debug("*eqe=%lx", eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001296 ehea_parse_eqe(adapter, eqe->entry);
1297 eqe = ehea_poll_eq(adapter->neq);
David S. Millercfa969e2010-12-06 20:45:28 -08001298 ehea_debug("next eqe=%p", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001299 }
1300
1301 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1302 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1303 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1304
1305 ehea_h_reset_events(adapter->handle,
1306 adapter->neq->fw_handle, event_mask);
1307}
1308
David Howells7d12e782006-10-05 14:55:46 +01001309static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001310{
1311 struct ehea_adapter *adapter = param;
1312 tasklet_hi_schedule(&adapter->neq_tasklet);
1313 return IRQ_HANDLED;
1314}
1315
1316
1317static int ehea_fill_port_res(struct ehea_port_res *pr)
1318{
1319 int ret;
1320 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1321
Thomas Kleine2878802009-01-21 14:45:57 -08001322 ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1323 - init_attr->act_nr_rwqes_rq2
1324 - init_attr->act_nr_rwqes_rq3 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001325
Thomas Kleine2878802009-01-21 14:45:57 -08001326 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001327
1328 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1329
1330 return ret;
1331}
1332
1333static int ehea_reg_interrupts(struct net_device *dev)
1334{
1335 struct ehea_port *port = netdev_priv(dev);
1336 struct ehea_port_res *pr;
1337 int i, ret;
1338
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001339
1340 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1341 dev->name);
1342
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001343 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001344 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001345 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001346 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08001347 ehea_error("failed registering irq for qp_aff_irq_handler:"
1348 "ist=%X", port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001349 goto out_free_qpeq;
1350 }
1351
David S. Millercfa969e2010-12-06 20:45:28 -08001352 if (netif_msg_ifup(port))
1353 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1354 "registered", port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001355
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001356
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001357 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1358 pr = &port->port_res[i];
1359 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001360 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001361 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001362 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001363 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001364 pr);
1365 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08001366 ehea_error("failed registering irq for ehea_queue "
1367 "port_res_nr:%d, ist=%X", i,
1368 pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001369 goto out_free_req;
1370 }
David S. Millercfa969e2010-12-06 20:45:28 -08001371 if (netif_msg_ifup(port))
1372 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1373 "%d registered", pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001374 }
1375out:
1376 return ret;
1377
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001378
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001379out_free_req:
1380 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001381 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001382 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001383 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001384
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001385out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001386 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001387 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001388
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001389 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001390
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001391}
1392
1393static void ehea_free_interrupts(struct net_device *dev)
1394{
1395 struct ehea_port *port = netdev_priv(dev);
1396 struct ehea_port_res *pr;
1397 int i;
1398
1399 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001400
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001401 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1402 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001403 ibmebus_free_irq(pr->eq->attr.ist1, pr);
David S. Millercfa969e2010-12-06 20:45:28 -08001404 if (netif_msg_intr(port))
1405 ehea_info("free send irq for res %d with handle 0x%X",
1406 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001407 }
1408
1409 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001410 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
David S. Millercfa969e2010-12-06 20:45:28 -08001411 if (netif_msg_intr(port))
1412 ehea_info("associated event interrupt for handle 0x%X freed",
1413 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001414}
1415
1416static int ehea_configure_port(struct ehea_port *port)
1417{
1418 int ret, i;
1419 u64 hret, mask;
1420 struct hcp_ehea_port_cb0 *cb0;
1421
1422 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001423 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001424 if (!cb0)
1425 goto out;
1426
1427 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1428 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1429 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1430 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1431 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1432 PXLY_RC_VLAN_FILTER)
1433 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1434
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001435 for (i = 0; i < port->num_mcs; i++)
1436 if (use_mcs)
1437 cb0->default_qpn_arr[i] =
1438 port->port_res[i].qp->init_attr.qp_nr;
1439 else
1440 cb0->default_qpn_arr[i] =
1441 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001442
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001443 if (netif_msg_ifup(port))
1444 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1445
1446 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1447 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1448
1449 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1450 port->logical_port_id,
1451 H_PORT_CB0, mask, cb0);
1452 ret = -EIO;
1453 if (hret != H_SUCCESS)
1454 goto out_free;
1455
1456 ret = 0;
1457
1458out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001459 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001460out:
1461 return ret;
1462}
1463
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001464int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001465{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001466 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001467 struct ehea_adapter *adapter = pr->port->adapter;
1468
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001469 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1470 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001471 goto out;
1472
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001473 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1474 if (ret)
1475 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001476
1477 return 0;
1478
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001479out_free:
1480 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001481out:
David S. Millercfa969e2010-12-06 20:45:28 -08001482 ehea_error("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001483 return -EIO;
1484}
1485
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001486int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001487{
Joe Perches8e95a202009-12-03 07:58:21 +00001488 if ((ehea_rem_mr(&pr->send_mr)) ||
1489 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001490 return -EIO;
1491 else
1492 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001493}
1494
1495static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1496{
Doug Maxey508d2b52008-01-31 20:20:49 -06001497 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001498
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001499 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001500 if (!q_skba->arr)
1501 return -ENOMEM;
1502
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001503 q_skba->len = max_q_entries;
1504 q_skba->index = 0;
1505 q_skba->os_skbs = 0;
1506
1507 return 0;
1508}
1509
1510static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1511 struct port_res_cfg *pr_cfg, int queue_token)
1512{
1513 struct ehea_adapter *adapter = port->adapter;
1514 enum ehea_eq_type eq_type = EHEA_EQ;
1515 struct ehea_qp_init_attr *init_attr = NULL;
1516 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001517 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1518
1519 tx_bytes = pr->tx_bytes;
1520 tx_packets = pr->tx_packets;
1521 rx_bytes = pr->rx_bytes;
1522 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001523
1524 memset(pr, 0, sizeof(struct ehea_port_res));
1525
Breno Leitaoce45b872010-10-27 08:45:14 +00001526 pr->tx_bytes = rx_bytes;
1527 pr->tx_packets = tx_packets;
1528 pr->rx_bytes = rx_bytes;
1529 pr->rx_packets = rx_packets;
1530
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001531 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001532 spin_lock_init(&pr->xmit_lock);
1533 spin_lock_init(&pr->netif_queue);
1534
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001535 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1536 if (!pr->eq) {
David S. Millercfa969e2010-12-06 20:45:28 -08001537 ehea_error("create_eq failed (eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001538 goto out_free;
1539 }
1540
1541 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001542 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001543 port->logical_port_id);
1544 if (!pr->recv_cq) {
David S. Millercfa969e2010-12-06 20:45:28 -08001545 ehea_error("create_cq failed (cq_recv)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001546 goto out_free;
1547 }
1548
1549 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001550 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001551 port->logical_port_id);
1552 if (!pr->send_cq) {
David S. Millercfa969e2010-12-06 20:45:28 -08001553 ehea_error("create_cq failed (cq_send)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001554 goto out_free;
1555 }
1556
1557 if (netif_msg_ifup(port))
David S. Millercfa969e2010-12-06 20:45:28 -08001558 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1559 pr->send_cq->attr.act_nr_of_cqes,
1560 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001561
1562 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1563 if (!init_attr) {
1564 ret = -ENOMEM;
David S. Millercfa969e2010-12-06 20:45:28 -08001565 ehea_error("no mem for ehea_qp_init_attr");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001566 goto out_free;
1567 }
1568
1569 init_attr->low_lat_rq1 = 1;
1570 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1571 init_attr->rq_count = 3;
1572 init_attr->qp_token = queue_token;
1573 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1574 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1575 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1576 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1577 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1578 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1579 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1580 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1581 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1582 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1583 init_attr->port_nr = port->logical_port_id;
1584 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1585 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1586 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1587
1588 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1589 if (!pr->qp) {
David S. Millercfa969e2010-12-06 20:45:28 -08001590 ehea_error("create_qp failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001591 ret = -EIO;
1592 goto out_free;
1593 }
1594
1595 if (netif_msg_ifup(port))
David S. Millercfa969e2010-12-06 20:45:28 -08001596 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1597 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1598 init_attr->act_nr_send_wqes,
1599 init_attr->act_nr_rwqes_rq1,
1600 init_attr->act_nr_rwqes_rq2,
1601 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001602
Thomas Klein44fb3122008-04-04 15:04:53 +02001603 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1604
1605 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001606 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1607 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1608 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1609 if (ret)
1610 goto out_free;
1611
1612 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1613 if (ehea_gen_smrs(pr) != 0) {
1614 ret = -EIO;
1615 goto out_free;
1616 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001617
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001618 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1619
1620 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001621
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001622 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001623
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001624 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1625 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1626 pr->lro_mgr.lro_arr = pr->lro_desc;
1627 pr->lro_mgr.get_skb_header = get_skb_hdr;
1628 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1629 pr->lro_mgr.dev = port->netdev;
1630 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1631 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1632
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001633 ret = 0;
1634 goto out;
1635
1636out_free:
1637 kfree(init_attr);
1638 vfree(pr->sq_skba.arr);
1639 vfree(pr->rq1_skba.arr);
1640 vfree(pr->rq2_skba.arr);
1641 vfree(pr->rq3_skba.arr);
1642 ehea_destroy_qp(pr->qp);
1643 ehea_destroy_cq(pr->send_cq);
1644 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001645 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001646out:
1647 return ret;
1648}
1649
1650static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1651{
1652 int ret, i;
1653
Hannes Hering357eb462009-08-04 11:48:39 -07001654 if (pr->qp)
1655 netif_napi_del(&pr->napi);
1656
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001657 ret = ehea_destroy_qp(pr->qp);
1658
1659 if (!ret) {
1660 ehea_destroy_cq(pr->send_cq);
1661 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001662 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001663
1664 for (i = 0; i < pr->rq1_skba.len; i++)
1665 if (pr->rq1_skba.arr[i])
1666 dev_kfree_skb(pr->rq1_skba.arr[i]);
1667
1668 for (i = 0; i < pr->rq2_skba.len; i++)
1669 if (pr->rq2_skba.arr[i])
1670 dev_kfree_skb(pr->rq2_skba.arr[i]);
1671
1672 for (i = 0; i < pr->rq3_skba.len; i++)
1673 if (pr->rq3_skba.arr[i])
1674 dev_kfree_skb(pr->rq3_skba.arr[i]);
1675
1676 for (i = 0; i < pr->sq_skba.len; i++)
1677 if (pr->sq_skba.arr[i])
1678 dev_kfree_skb(pr->sq_skba.arr[i]);
1679
1680 vfree(pr->rq1_skba.arr);
1681 vfree(pr->rq2_skba.arr);
1682 vfree(pr->rq3_skba.arr);
1683 vfree(pr->sq_skba.arr);
1684 ret = ehea_rem_smrs(pr);
1685 }
1686 return ret;
1687}
1688
1689/*
1690 * The write_* functions store information in swqe which is used by
1691 * the hardware to calculate the ip/tcp/udp checksum
1692 */
1693
1694static inline void write_ip_start_end(struct ehea_swqe *swqe,
1695 const struct sk_buff *skb)
1696{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001697 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001698 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001699}
1700
1701static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1702 const struct sk_buff *skb)
1703{
1704 swqe->tcp_offset =
1705 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1706
1707 swqe->tcp_end = (u16)skb->len - 1;
1708}
1709
1710static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1711 const struct sk_buff *skb)
1712{
1713 swqe->tcp_offset =
1714 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1715
1716 swqe->tcp_end = (u16)skb->len - 1;
1717}
1718
1719
1720static void write_swqe2_TSO(struct sk_buff *skb,
1721 struct ehea_swqe *swqe, u32 lkey)
1722{
1723 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1724 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001725 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001726 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001727
1728 /* Packet is TCP with TSO enabled */
1729 swqe->tx_control |= EHEA_SWQE_TSO;
1730 swqe->mss = skb_shinfo(skb)->gso_size;
1731 /* copy only eth/ip/tcp headers to immediate data and
1732 * the rest of skb->data to sg1entry
1733 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001734 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001735
Eric Dumazete743d312010-04-14 15:59:40 -07001736 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001737
1738 if (skb_data_size >= headersize) {
1739 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001740 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001741 swqe->immediate_data_length = headersize;
1742
1743 if (skb_data_size > headersize) {
1744 /* set sg1entry data */
1745 sg1entry->l_key = lkey;
1746 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001747 sg1entry->vaddr =
1748 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001749 swqe->descriptors++;
1750 }
1751 } else
David S. Millercfa969e2010-12-06 20:45:28 -08001752 ehea_error("cannot handle fragmented headers");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001753}
1754
1755static void write_swqe2_nonTSO(struct sk_buff *skb,
1756 struct ehea_swqe *swqe, u32 lkey)
1757{
Eric Dumazete743d312010-04-14 15:59:40 -07001758 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001759 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1760 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001761
1762 /* Packet is any nonTSO type
1763 *
1764 * Copy as much as possible skb->data to immediate data and
1765 * the rest to sg1entry
1766 */
1767 if (skb_data_size >= SWQE2_MAX_IMM) {
1768 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001769 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001770
1771 swqe->immediate_data_length = SWQE2_MAX_IMM;
1772
1773 if (skb_data_size > SWQE2_MAX_IMM) {
1774 /* copy sg1entry data */
1775 sg1entry->l_key = lkey;
1776 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001777 sg1entry->vaddr =
1778 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001779 swqe->descriptors++;
1780 }
1781 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001782 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001783 swqe->immediate_data_length = skb_data_size;
1784 }
1785}
1786
1787static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1788 struct ehea_swqe *swqe, u32 lkey)
1789{
1790 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1791 skb_frag_t *frag;
1792 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001793
1794 nfrags = skb_shinfo(skb)->nr_frags;
1795 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001796 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001797 swqe->descriptors = 0;
1798 sg1entry_contains_frag_data = 0;
1799
1800 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1801 write_swqe2_TSO(skb, swqe, lkey);
1802 else
1803 write_swqe2_nonTSO(skb, swqe, lkey);
1804
1805 /* write descriptors */
1806 if (nfrags > 0) {
1807 if (swqe->descriptors == 0) {
1808 /* sg1entry not yet used */
1809 frag = &skb_shinfo(skb)->frags[0];
1810
1811 /* copy sg1entry data */
1812 sg1entry->l_key = lkey;
1813 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001814 sg1entry->vaddr =
1815 ehea_map_vaddr(page_address(frag->page)
1816 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001817 swqe->descriptors++;
1818 sg1entry_contains_frag_data = 1;
1819 }
1820
1821 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1822
1823 frag = &skb_shinfo(skb)->frags[i];
1824 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1825
1826 sgentry->l_key = lkey;
1827 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001828 sgentry->vaddr =
1829 ehea_map_vaddr(page_address(frag->page)
1830 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001831 swqe->descriptors++;
1832 }
1833 }
1834}
1835
1836static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1837{
1838 int ret = 0;
1839 u64 hret;
1840 u8 reg_type;
1841
1842 /* De/Register untagged packets */
1843 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1844 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1845 port->logical_port_id,
1846 reg_type, port->mac_addr, 0, hcallid);
1847 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08001848 ehea_error("%sregistering bc address failed (tagged)",
1849 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001850 ret = -EIO;
1851 goto out_herr;
1852 }
1853
1854 /* De/Register VLAN packets */
1855 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1856 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1857 port->logical_port_id,
1858 reg_type, port->mac_addr, 0, hcallid);
1859 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08001860 ehea_error("%sregistering bc address failed (vlan)",
1861 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001862 ret = -EIO;
1863 }
1864out_herr:
1865 return ret;
1866}
1867
1868static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1869{
1870 struct ehea_port *port = netdev_priv(dev);
1871 struct sockaddr *mac_addr = sa;
1872 struct hcp_ehea_port_cb0 *cb0;
1873 int ret;
1874 u64 hret;
1875
1876 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1877 ret = -EADDRNOTAVAIL;
1878 goto out;
1879 }
1880
Thomas Klein3faf2692009-01-21 14:45:33 -08001881 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001882 if (!cb0) {
David S. Millercfa969e2010-12-06 20:45:28 -08001883 ehea_error("no mem for cb0");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001884 ret = -ENOMEM;
1885 goto out;
1886 }
1887
1888 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1889
1890 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1891
1892 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1893 port->logical_port_id, H_PORT_CB0,
1894 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1895 if (hret != H_SUCCESS) {
1896 ret = -EIO;
1897 goto out_free;
1898 }
1899
1900 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1901
1902 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001903 if (port->state == EHEA_PORT_UP) {
1904 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1905 if (ret)
1906 goto out_upregs;
1907 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001908
1909 port->mac_addr = cb0->port_mac_addr << 16;
1910
1911 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001912 if (port->state == EHEA_PORT_UP) {
1913 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1914 if (ret)
1915 goto out_upregs;
1916 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001917
1918 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001919
1920out_upregs:
1921 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001922out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001923 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001924out:
1925 return ret;
1926}
1927
1928static void ehea_promiscuous_error(u64 hret, int enable)
1929{
Thomas Klein7674a582007-01-22 12:54:20 +01001930 if (hret == H_AUTHORITY)
David S. Millercfa969e2010-12-06 20:45:28 -08001931 ehea_info("Hypervisor denied %sabling promiscuous mode",
1932 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001933 else
David S. Millercfa969e2010-12-06 20:45:28 -08001934 ehea_error("failed %sabling promiscuous mode",
1935 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001936}
1937
1938static void ehea_promiscuous(struct net_device *dev, int enable)
1939{
1940 struct ehea_port *port = netdev_priv(dev);
1941 struct hcp_ehea_port_cb7 *cb7;
1942 u64 hret;
1943
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001944 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001945 return;
1946
Thomas Klein3faf2692009-01-21 14:45:33 -08001947 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001948 if (!cb7) {
David S. Millercfa969e2010-12-06 20:45:28 -08001949 ehea_error("no mem for cb7");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001950 goto out;
1951 }
1952
1953 /* Modify Pxs_DUCQPN in CB7 */
1954 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1955
1956 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1957 port->logical_port_id,
1958 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1959 if (hret) {
1960 ehea_promiscuous_error(hret, enable);
1961 goto out;
1962 }
1963
1964 port->promisc = enable;
1965out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001966 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001967}
1968
1969static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1970 u32 hcallid)
1971{
1972 u64 hret;
1973 u8 reg_type;
1974
1975 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1976 | EHEA_BCMC_UNTAGGED;
1977
1978 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1979 port->logical_port_id,
1980 reg_type, mc_mac_addr, 0, hcallid);
1981 if (hret)
1982 goto out;
1983
1984 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1985 | EHEA_BCMC_VLANID_ALL;
1986
1987 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1988 port->logical_port_id,
1989 reg_type, mc_mac_addr, 0, hcallid);
1990out:
1991 return hret;
1992}
1993
1994static int ehea_drop_multicast_list(struct net_device *dev)
1995{
1996 struct ehea_port *port = netdev_priv(dev);
1997 struct ehea_mc_list *mc_entry = port->mc_list;
1998 struct list_head *pos;
1999 struct list_head *temp;
2000 int ret = 0;
2001 u64 hret;
2002
2003 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
2004 mc_entry = list_entry(pos, struct ehea_mc_list, list);
2005
2006 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
2007 H_DEREG_BCMC);
2008 if (hret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002009 ehea_error("failed deregistering mcast MAC");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002010 ret = -EIO;
2011 }
2012
2013 list_del(pos);
2014 kfree(mc_entry);
2015 }
2016 return ret;
2017}
2018
2019static void ehea_allmulti(struct net_device *dev, int enable)
2020{
2021 struct ehea_port *port = netdev_priv(dev);
2022 u64 hret;
2023
2024 if (!port->allmulti) {
2025 if (enable) {
2026 /* Enable ALLMULTI */
2027 ehea_drop_multicast_list(dev);
2028 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
2029 if (!hret)
2030 port->allmulti = 1;
2031 else
David S. Millercfa969e2010-12-06 20:45:28 -08002032 ehea_error("failed enabling IFF_ALLMULTI");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002033 }
2034 } else
2035 if (!enable) {
2036 /* Disable ALLMULTI */
2037 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
2038 if (!hret)
2039 port->allmulti = 0;
2040 else
David S. Millercfa969e2010-12-06 20:45:28 -08002041 ehea_error("failed disabling IFF_ALLMULTI");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002042 }
2043}
2044
Doug Maxey508d2b52008-01-31 20:20:49 -06002045static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002046{
2047 struct ehea_mc_list *ehea_mcl_entry;
2048 u64 hret;
2049
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02002050 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002051 if (!ehea_mcl_entry) {
David S. Millercfa969e2010-12-06 20:45:28 -08002052 ehea_error("no mem for mcl_entry");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002053 return;
2054 }
2055
2056 INIT_LIST_HEAD(&ehea_mcl_entry->list);
2057
2058 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
2059
2060 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
2061 H_REG_BCMC);
2062 if (!hret)
2063 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
2064 else {
David S. Millercfa969e2010-12-06 20:45:28 -08002065 ehea_error("failed registering mcast MAC");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002066 kfree(ehea_mcl_entry);
2067 }
2068}
2069
2070static void ehea_set_multicast_list(struct net_device *dev)
2071{
2072 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00002073 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002074 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002075
2076 if (dev->flags & IFF_PROMISC) {
2077 ehea_promiscuous(dev, 1);
2078 return;
2079 }
2080 ehea_promiscuous(dev, 0);
2081
2082 if (dev->flags & IFF_ALLMULTI) {
2083 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002084 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002085 }
2086 ehea_allmulti(dev, 0);
2087
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002088 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002089 ret = ehea_drop_multicast_list(dev);
2090 if (ret) {
2091 /* Dropping the current multicast list failed.
2092 * Enabling ALL_MULTI is the best we can do.
2093 */
2094 ehea_allmulti(dev, 1);
2095 }
2096
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002097 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
David S. Millercfa969e2010-12-06 20:45:28 -08002098 ehea_info("Mcast registration limit reached (0x%llx). "
2099 "Use ALLMULTI!",
2100 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002101 goto out;
2102 }
2103
Jiri Pirko22bedad32010-04-01 21:22:57 +00002104 netdev_for_each_mc_addr(ha, dev)
2105 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002106
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002107 }
2108out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002109 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002110}
2111
2112static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2113{
2114 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2115 return -EINVAL;
2116 dev->mtu = new_mtu;
2117 return 0;
2118}
2119
2120static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2121 struct ehea_swqe *swqe, u32 lkey)
2122{
2123 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002124 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002125
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002126 /* IPv4 */
2127 swqe->tx_control |= EHEA_SWQE_CRC
2128 | EHEA_SWQE_IP_CHECKSUM
2129 | EHEA_SWQE_TCP_CHECKSUM
2130 | EHEA_SWQE_IMM_DATA_PRESENT
2131 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2132
2133 write_ip_start_end(swqe, skb);
2134
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002135 if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002136 if ((iph->frag_off & IP_MF) ||
2137 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002138 /* IP fragment, so don't change cs */
2139 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2140 else
2141 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002142 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002143 write_tcp_offset_end(swqe, skb);
2144 }
2145
2146 /* icmp (big data) and ip segmentation packets (all other ip
2147 packets) do not require any special handling */
2148
2149 } else {
2150 /* Other Ethernet Protocol */
2151 swqe->tx_control |= EHEA_SWQE_CRC
2152 | EHEA_SWQE_IMM_DATA_PRESENT
2153 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2154 }
2155
2156 write_swqe2_data(skb, dev, swqe, lkey);
2157}
2158
2159static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2160 struct ehea_swqe *swqe)
2161{
2162 int nfrags = skb_shinfo(skb)->nr_frags;
2163 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2164 skb_frag_t *frag;
2165 int i;
2166
2167 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002168 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002169
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002170 /* IPv4 */
2171 write_ip_start_end(swqe, skb);
2172
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002173 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002174 swqe->tx_control |= EHEA_SWQE_CRC
2175 | EHEA_SWQE_IP_CHECKSUM
2176 | EHEA_SWQE_TCP_CHECKSUM
2177 | EHEA_SWQE_IMM_DATA_PRESENT;
2178
2179 write_tcp_offset_end(swqe, skb);
2180
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002181 } else if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002182 if ((iph->frag_off & IP_MF) ||
2183 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002184 /* IP fragment, so don't change cs */
2185 swqe->tx_control |= EHEA_SWQE_CRC
2186 | EHEA_SWQE_IMM_DATA_PRESENT;
2187 else {
2188 swqe->tx_control |= EHEA_SWQE_CRC
2189 | EHEA_SWQE_IP_CHECKSUM
2190 | EHEA_SWQE_TCP_CHECKSUM
2191 | EHEA_SWQE_IMM_DATA_PRESENT;
2192
2193 write_udp_offset_end(swqe, skb);
2194 }
2195 } else {
2196 /* icmp (big data) and
2197 ip segmentation packets (all other ip packets) */
2198 swqe->tx_control |= EHEA_SWQE_CRC
2199 | EHEA_SWQE_IP_CHECKSUM
2200 | EHEA_SWQE_IMM_DATA_PRESENT;
2201 }
2202 } else {
2203 /* Other Ethernet Protocol */
2204 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2205 }
2206 /* copy (immediate) data */
2207 if (nfrags == 0) {
2208 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002209 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002210 } else {
2211 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002212 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002213 skb_headlen(skb));
2214 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002215
2216 /* ... then copy data from the fragments */
2217 for (i = 0; i < nfrags; i++) {
2218 frag = &skb_shinfo(skb)->frags[i];
2219 memcpy(imm_data,
2220 page_address(frag->page) + frag->page_offset,
2221 frag->size);
2222 imm_data += frag->size;
2223 }
2224 }
2225 swqe->immediate_data_length = skb->len;
2226 dev_kfree_skb(skb);
2227}
2228
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002229static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2230{
2231 struct tcphdr *tcp;
2232 u32 tmp;
2233
2234 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002235 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002236 tcp = (struct tcphdr *)(skb_network_header(skb) +
2237 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002238 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002239 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002240 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002241 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002242 return 0;
2243}
2244
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002245static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2246{
2247 struct ehea_port *port = netdev_priv(dev);
2248 struct ehea_swqe *swqe;
2249 unsigned long flags;
2250 u32 lkey;
2251 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002252 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002253
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002254 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2255
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002256 if (!spin_trylock(&pr->xmit_lock))
2257 return NETDEV_TX_BUSY;
2258
2259 if (pr->queue_stopped) {
2260 spin_unlock(&pr->xmit_lock);
2261 return NETDEV_TX_BUSY;
2262 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002263
2264 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2265 memset(swqe, 0, SWQE_HEADER_SIZE);
2266 atomic_dec(&pr->swqe_avail);
2267
Eric Dumazete5ccd962010-10-26 19:21:07 +00002268 if (vlan_tx_tag_present(skb)) {
2269 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2270 swqe->vlan_tag = vlan_tx_tag_get(skb);
2271 }
2272
Breno Leitaoce45b872010-10-27 08:45:14 +00002273 pr->tx_packets++;
2274 pr->tx_bytes += skb->len;
2275
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002276 if (skb->len <= SWQE3_MAX_IMM) {
2277 u32 sig_iv = port->sig_comp_iv;
2278 u32 swqe_num = pr->swqe_id_counter;
2279 ehea_xmit3(skb, dev, swqe);
2280 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2281 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2282 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2283 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2284 sig_iv);
2285 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2286 pr->swqe_ll_count = 0;
2287 } else
2288 pr->swqe_ll_count += 1;
2289 } else {
2290 swqe->wr_id =
2291 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2292 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002293 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002294 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2295 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2296
2297 pr->sq_skba.index++;
2298 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2299
2300 lkey = pr->send_mr.lkey;
2301 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002302 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002303 }
2304 pr->swqe_id_counter += 1;
2305
David S. Millercfa969e2010-12-06 20:45:28 -08002306 if (netif_msg_tx_queued(port)) {
2307 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002308 ehea_dump(swqe, 512, "swqe");
David S. Millercfa969e2010-12-06 20:45:28 -08002309 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002310
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002311 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2312 netif_stop_queue(dev);
2313 swqe->tx_control |= EHEA_SWQE_PURGE;
2314 }
Thomas Klein44c82152007-07-11 16:32:00 +02002315
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002316 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002317
2318 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2319 spin_lock_irqsave(&pr->netif_queue, flags);
2320 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002321 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002322 netif_stop_queue(dev);
2323 pr->queue_stopped = 1;
2324 }
2325 spin_unlock_irqrestore(&pr->netif_queue, flags);
2326 }
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07002327 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002328 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002329
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002330 return NETDEV_TX_OK;
2331}
2332
2333static void ehea_vlan_rx_register(struct net_device *dev,
2334 struct vlan_group *grp)
2335{
2336 struct ehea_port *port = netdev_priv(dev);
2337 struct ehea_adapter *adapter = port->adapter;
2338 struct hcp_ehea_port_cb1 *cb1;
2339 u64 hret;
2340
2341 port->vgrp = grp;
2342
Thomas Klein3faf2692009-01-21 14:45:33 -08002343 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002344 if (!cb1) {
David S. Millercfa969e2010-12-06 20:45:28 -08002345 ehea_error("no mem for cb1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002346 goto out;
2347 }
2348
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002349 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2350 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2351 if (hret != H_SUCCESS)
David S. Millercfa969e2010-12-06 20:45:28 -08002352 ehea_error("modify_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002353
Thomas Klein3faf2692009-01-21 14:45:33 -08002354 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002355out:
2356 return;
2357}
2358
2359static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2360{
2361 struct ehea_port *port = netdev_priv(dev);
2362 struct ehea_adapter *adapter = port->adapter;
2363 struct hcp_ehea_port_cb1 *cb1;
2364 int index;
2365 u64 hret;
2366
Thomas Klein3faf2692009-01-21 14:45:33 -08002367 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002368 if (!cb1) {
David S. Millercfa969e2010-12-06 20:45:28 -08002369 ehea_error("no mem for cb1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002370 goto out;
2371 }
2372
2373 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2374 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2375 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002376 ehea_error("query_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002377 goto out;
2378 }
2379
2380 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002381 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002382
2383 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2384 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2385 if (hret != H_SUCCESS)
David S. Millercfa969e2010-12-06 20:45:28 -08002386 ehea_error("modify_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002387out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002388 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002389 return;
2390}
2391
2392static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2393{
2394 struct ehea_port *port = netdev_priv(dev);
2395 struct ehea_adapter *adapter = port->adapter;
2396 struct hcp_ehea_port_cb1 *cb1;
2397 int index;
2398 u64 hret;
2399
Dan Aloni5c15bde2007-03-02 20:44:51 -08002400 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002401
Thomas Klein3faf2692009-01-21 14:45:33 -08002402 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002403 if (!cb1) {
David S. Millercfa969e2010-12-06 20:45:28 -08002404 ehea_error("no mem for cb1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002405 goto out;
2406 }
2407
2408 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2409 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2410 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002411 ehea_error("query_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002412 goto out;
2413 }
2414
2415 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002416 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002417
2418 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2419 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2420 if (hret != H_SUCCESS)
David S. Millercfa969e2010-12-06 20:45:28 -08002421 ehea_error("modify_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002422out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002423 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002424}
2425
2426int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2427{
2428 int ret = -EIO;
2429 u64 hret;
2430 u16 dummy16 = 0;
2431 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002432 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002433
Thomas Klein3faf2692009-01-21 14:45:33 -08002434 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002435 if (!cb0) {
2436 ret = -ENOMEM;
2437 goto out;
2438 }
2439
2440 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2441 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2442 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002443 ehea_error("query_ehea_qp failed (1)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002444 goto out;
2445 }
2446
2447 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2448 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2449 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2450 &dummy64, &dummy64, &dummy16, &dummy16);
2451 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002452 ehea_error("modify_ehea_qp failed (1)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002453 goto out;
2454 }
2455
2456 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2457 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2458 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002459 ehea_error("query_ehea_qp failed (2)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002460 goto out;
2461 }
2462
2463 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2464 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2465 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2466 &dummy64, &dummy64, &dummy16, &dummy16);
2467 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002468 ehea_error("modify_ehea_qp failed (2)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002469 goto out;
2470 }
2471
2472 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2473 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2474 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002475 ehea_error("query_ehea_qp failed (3)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002476 goto out;
2477 }
2478
2479 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2480 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2481 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2482 &dummy64, &dummy64, &dummy16, &dummy16);
2483 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002484 ehea_error("modify_ehea_qp failed (3)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002485 goto out;
2486 }
2487
2488 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2489 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2490 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002491 ehea_error("query_ehea_qp failed (4)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002492 goto out;
2493 }
2494
2495 ret = 0;
2496out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002497 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002498 return ret;
2499}
2500
2501static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2502 int add_tx_qps)
2503{
2504 int ret, i;
2505 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2506 enum ehea_eq_type eq_type = EHEA_EQ;
2507
2508 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2509 EHEA_MAX_ENTRIES_EQ, 1);
2510 if (!port->qp_eq) {
2511 ret = -EINVAL;
David S. Millercfa969e2010-12-06 20:45:28 -08002512 ehea_error("ehea_create_eq failed (qp_eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002513 goto out_kill_eq;
2514 }
2515
2516 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002517 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002518 pr_cfg.max_entries_sq = sq_entries;
2519 pr_cfg.max_entries_rq1 = rq1_entries;
2520 pr_cfg.max_entries_rq2 = rq2_entries;
2521 pr_cfg.max_entries_rq3 = rq3_entries;
2522
2523 pr_cfg_small_rx.max_entries_rcq = 1;
2524 pr_cfg_small_rx.max_entries_scq = sq_entries;
2525 pr_cfg_small_rx.max_entries_sq = sq_entries;
2526 pr_cfg_small_rx.max_entries_rq1 = 1;
2527 pr_cfg_small_rx.max_entries_rq2 = 1;
2528 pr_cfg_small_rx.max_entries_rq3 = 1;
2529
2530 for (i = 0; i < def_qps; i++) {
2531 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2532 if (ret)
2533 goto out_clean_pr;
2534 }
2535 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2536 ret = ehea_init_port_res(port, &port->port_res[i],
2537 &pr_cfg_small_rx, i);
2538 if (ret)
2539 goto out_clean_pr;
2540 }
2541
2542 return 0;
2543
2544out_clean_pr:
2545 while (--i >= 0)
2546 ehea_clean_portres(port, &port->port_res[i]);
2547
2548out_kill_eq:
2549 ehea_destroy_eq(port->qp_eq);
2550 return ret;
2551}
2552
2553static int ehea_clean_all_portres(struct ehea_port *port)
2554{
2555 int ret = 0;
2556 int i;
2557
Doug Maxey508d2b52008-01-31 20:20:49 -06002558 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002559 ret |= ehea_clean_portres(port, &port->port_res[i]);
2560
2561 ret |= ehea_destroy_eq(port->qp_eq);
2562
2563 return ret;
2564}
2565
Thomas Klein35cf2e22007-08-06 13:55:14 +02002566static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002567{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002568 if (adapter->active_ports)
2569 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002570
2571 ehea_rem_mr(&adapter->mr);
2572}
2573
Thomas Klein35cf2e22007-08-06 13:55:14 +02002574static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002575{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002576 if (adapter->active_ports)
2577 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002578
2579 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2580}
2581
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002582static int ehea_up(struct net_device *dev)
2583{
2584 int ret, i;
2585 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002586
2587 if (port->state == EHEA_PORT_UP)
2588 return 0;
2589
2590 ret = ehea_port_res_setup(port, port->num_def_qps,
2591 port->num_add_tx_qps);
2592 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002593 ehea_error("port_res_failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002594 goto out;
2595 }
2596
2597 /* Set default QP for this port */
2598 ret = ehea_configure_port(port);
2599 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002600 ehea_error("ehea_configure_port failed. ret:%d", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002601 goto out_clean_pr;
2602 }
2603
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002604 ret = ehea_reg_interrupts(dev);
2605 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002606 ehea_error("reg_interrupts failed. ret:%d", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002607 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002608 }
2609
Doug Maxey508d2b52008-01-31 20:20:49 -06002610 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002611 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2612 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002613 ehea_error("activate_qp failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002614 goto out_free_irqs;
2615 }
2616 }
2617
Doug Maxey508d2b52008-01-31 20:20:49 -06002618 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002619 ret = ehea_fill_port_res(&port->port_res[i]);
2620 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002621 ehea_error("out_free_irqs");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002622 goto out_free_irqs;
2623 }
2624 }
2625
Thomas Klein21eee2d2008-02-13 16:18:33 +01002626 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2627 if (ret) {
2628 ret = -EIO;
2629 goto out_free_irqs;
2630 }
2631
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002632 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002633
2634 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002635 goto out;
2636
2637out_free_irqs:
2638 ehea_free_interrupts(dev);
2639
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002640out_clean_pr:
2641 ehea_clean_all_portres(port);
2642out:
Thomas Klein44c82152007-07-11 16:32:00 +02002643 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08002644 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002645
Thomas Klein21eee2d2008-02-13 16:18:33 +01002646 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002647 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002648
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002649 return ret;
2650}
2651
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002652static void port_napi_disable(struct ehea_port *port)
2653{
2654 int i;
2655
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002656 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002657 napi_disable(&port->port_res[i].napi);
2658}
2659
2660static void port_napi_enable(struct ehea_port *port)
2661{
2662 int i;
2663
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002664 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002665 napi_enable(&port->port_res[i].napi);
2666}
2667
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002668static int ehea_open(struct net_device *dev)
2669{
2670 int ret;
2671 struct ehea_port *port = netdev_priv(dev);
2672
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002673 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002674
David S. Millercfa969e2010-12-06 20:45:28 -08002675 if (netif_msg_ifup(port))
2676 ehea_info("enabling port %s", dev->name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002677
2678 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002679 if (!ret) {
2680 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002681 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002682 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002683
Breno Leitao5b27d422010-10-05 13:16:22 +00002684 init_waitqueue_head(&port->swqe_avail_wq);
Breno Leitaoa8bb69f2010-10-05 13:16:23 +00002685 init_waitqueue_head(&port->restart_wq);
Breno Leitao5b27d422010-10-05 13:16:22 +00002686
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002687 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002688
2689 return ret;
2690}
2691
2692static int ehea_down(struct net_device *dev)
2693{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002694 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002695 struct ehea_port *port = netdev_priv(dev);
2696
2697 if (port->state == EHEA_PORT_DOWN)
2698 return 0;
2699
2700 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002701 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2702
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002703 ehea_free_interrupts(dev);
2704
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002705 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002706
Thomas Klein21eee2d2008-02-13 16:18:33 +01002707 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002708
Thomas Klein44c82152007-07-11 16:32:00 +02002709 ret = ehea_clean_all_portres(port);
2710 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08002711 ehea_info("Failed freeing resources for %s. ret=%i",
2712 dev->name, ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002713
Thomas Klein21eee2d2008-02-13 16:18:33 +01002714 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002715
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002716 return ret;
2717}
2718
2719static int ehea_stop(struct net_device *dev)
2720{
2721 int ret;
2722 struct ehea_port *port = netdev_priv(dev);
2723
David S. Millercfa969e2010-12-06 20:45:28 -08002724 if (netif_msg_ifdown(port))
2725 ehea_info("disabling port %s", dev->name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002726
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002727 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002728 cancel_work_sync(&port->reset_task);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002729 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002730 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002731 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002732 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002733 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002734 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002735 return ret;
2736}
2737
Andrew Morton22559c52008-04-18 13:50:39 -07002738static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002739{
2740 struct ehea_qp qp = *orig_qp;
2741 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2742 struct ehea_swqe *swqe;
2743 int wqe_index;
2744 int i;
2745
2746 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2747 swqe = ehea_get_swqe(&qp, &wqe_index);
2748 swqe->tx_control |= EHEA_SWQE_PURGE;
2749 }
2750}
2751
Andrew Morton22559c52008-04-18 13:50:39 -07002752static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002753{
2754 int i;
2755
2756 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2757 struct ehea_port_res *pr = &port->port_res[i];
2758 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002759 int ret;
2760
2761 ret = wait_event_timeout(port->swqe_avail_wq,
2762 atomic_read(&pr->swqe_avail) >= swqe_max,
2763 msecs_to_jiffies(100));
2764
2765 if (!ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002766 ehea_error("WARNING: sq not flushed completely");
Breno Leitao5b27d422010-10-05 13:16:22 +00002767 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002768 }
2769 }
2770}
2771
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002772int ehea_stop_qps(struct net_device *dev)
2773{
2774 struct ehea_port *port = netdev_priv(dev);
2775 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002776 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002777 int ret = -EIO;
2778 int dret;
2779 int i;
2780 u64 hret;
2781 u64 dummy64 = 0;
2782 u16 dummy16 = 0;
2783
Thomas Klein3faf2692009-01-21 14:45:33 -08002784 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002785 if (!cb0) {
2786 ret = -ENOMEM;
2787 goto out;
2788 }
2789
2790 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2791 struct ehea_port_res *pr = &port->port_res[i];
2792 struct ehea_qp *qp = pr->qp;
2793
2794 /* Purge send queue */
2795 ehea_purge_sq(qp);
2796
2797 /* Disable queue pair */
2798 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2799 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2800 cb0);
2801 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002802 ehea_error("query_ehea_qp failed (1)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002803 goto out;
2804 }
2805
2806 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2807 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2808
2809 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2810 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2811 1), cb0, &dummy64,
2812 &dummy64, &dummy16, &dummy16);
2813 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002814 ehea_error("modify_ehea_qp failed (1)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002815 goto out;
2816 }
2817
2818 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2819 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2820 cb0);
2821 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002822 ehea_error("query_ehea_qp failed (2)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002823 goto out;
2824 }
2825
2826 /* deregister shared memory regions */
2827 dret = ehea_rem_smrs(pr);
2828 if (dret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002829 ehea_error("unreg shared memory region failed");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002830 goto out;
2831 }
2832 }
2833
2834 ret = 0;
2835out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002836 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002837
2838 return ret;
2839}
2840
Doug Maxey508d2b52008-01-31 20:20:49 -06002841void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002842{
2843 struct ehea_qp qp = *orig_qp;
2844 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2845 struct ehea_rwqe *rwqe;
2846 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2847 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2848 struct sk_buff *skb;
2849 u32 lkey = pr->recv_mr.lkey;
2850
2851
2852 int i;
2853 int index;
2854
2855 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2856 rwqe = ehea_get_next_rwqe(&qp, 2);
2857 rwqe->sg_list[0].l_key = lkey;
2858 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2859 skb = skba_rq2[index];
2860 if (skb)
2861 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2862 }
2863
2864 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2865 rwqe = ehea_get_next_rwqe(&qp, 3);
2866 rwqe->sg_list[0].l_key = lkey;
2867 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2868 skb = skba_rq3[index];
2869 if (skb)
2870 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2871 }
2872}
2873
2874int ehea_restart_qps(struct net_device *dev)
2875{
2876 struct ehea_port *port = netdev_priv(dev);
2877 struct ehea_adapter *adapter = port->adapter;
2878 int ret = 0;
2879 int i;
2880
Doug Maxey508d2b52008-01-31 20:20:49 -06002881 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002882 u64 hret;
2883 u64 dummy64 = 0;
2884 u16 dummy16 = 0;
2885
Thomas Klein3faf2692009-01-21 14:45:33 -08002886 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002887 if (!cb0) {
2888 ret = -ENOMEM;
2889 goto out;
2890 }
2891
2892 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2893 struct ehea_port_res *pr = &port->port_res[i];
2894 struct ehea_qp *qp = pr->qp;
2895
2896 ret = ehea_gen_smrs(pr);
2897 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002898 ehea_error("creation of shared memory regions failed");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002899 goto out;
2900 }
2901
2902 ehea_update_rqs(qp, pr);
2903
2904 /* Enable queue pair */
2905 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2906 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2907 cb0);
2908 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002909 ehea_error("query_ehea_qp failed (1)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002910 goto out;
2911 }
2912
2913 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2914 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2915
2916 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2917 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2918 1), cb0, &dummy64,
2919 &dummy64, &dummy16, &dummy16);
2920 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002921 ehea_error("modify_ehea_qp failed (1)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002922 goto out;
2923 }
2924
2925 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2926 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2927 cb0);
2928 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002929 ehea_error("query_ehea_qp failed (2)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002930 goto out;
2931 }
2932
2933 /* refill entire queue */
2934 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2935 ehea_refill_rq2(pr, 0);
2936 ehea_refill_rq3(pr, 0);
2937 }
2938out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002939 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002940
2941 return ret;
2942}
2943
David Howellsc4028952006-11-22 14:57:56 +00002944static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002945{
2946 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002947 struct ehea_port *port =
2948 container_of(work, struct ehea_port, reset_task);
2949 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002950
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002951 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002952 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002953 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002954 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002955
2956 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002957
Thomas Klein44c82152007-07-11 16:32:00 +02002958 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002959
2960 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002961 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002962 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002963
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002964 ehea_set_multicast_list(dev);
2965
David S. Millercfa969e2010-12-06 20:45:28 -08002966 if (netif_msg_timer(port))
2967 ehea_info("Device %s resetted successfully", dev->name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002968
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002969 port_napi_enable(port);
2970
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002971 netif_wake_queue(dev);
2972out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002973 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002974 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002975}
2976
Thomas Klein44c82152007-07-11 16:32:00 +02002977static void ehea_rereg_mrs(struct work_struct *work)
2978{
2979 int ret, i;
2980 struct ehea_adapter *adapter;
2981
David S. Millercfa969e2010-12-06 20:45:28 -08002982 ehea_info("LPAR memory changed - re-initializing driver");
Thomas Klein44c82152007-07-11 16:32:00 +02002983
2984 list_for_each_entry(adapter, &adapter_list, list)
2985 if (adapter->active_ports) {
2986 /* Shutdown all ports */
2987 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2988 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002989 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002990
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002991 if (!port)
2992 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002993
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002994 dev = port->netdev;
2995
2996 if (dev->flags & IFF_UP) {
2997 mutex_lock(&port->port_lock);
2998 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002999 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003000 ret = ehea_stop_qps(dev);
3001 if (ret) {
3002 mutex_unlock(&port->port_lock);
3003 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003004 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003005 port_napi_disable(port);
3006 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003007 }
Andre Detsch2928db42010-08-17 05:49:12 +00003008 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02003009 }
3010
3011 /* Unregister old memory region */
3012 ret = ehea_rem_mr(&adapter->mr);
3013 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003014 ehea_error("unregister MR failed - driver"
3015 " inoperable!");
Thomas Klein44c82152007-07-11 16:32:00 +02003016 goto out;
3017 }
3018 }
3019
Thomas Klein44c82152007-07-11 16:32:00 +02003020 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
3021
3022 list_for_each_entry(adapter, &adapter_list, list)
3023 if (adapter->active_ports) {
3024 /* Register new memory region */
3025 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
3026 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003027 ehea_error("register MR failed - driver"
3028 " inoperable!");
Thomas Klein44c82152007-07-11 16:32:00 +02003029 goto out;
3030 }
3031
3032 /* Restart all ports */
3033 for (i = 0; i < EHEA_MAX_PORTS; i++) {
3034 struct ehea_port *port = adapter->port[i];
3035
3036 if (port) {
3037 struct net_device *dev = port->netdev;
3038
3039 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003040 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003041 port_napi_enable(port);
3042 ret = ehea_restart_qps(dev);
Andre Detsch2928db42010-08-17 05:49:12 +00003043 check_sqs(port);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003044 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02003045 netif_wake_queue(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003046 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003047 }
3048 }
3049 }
3050 }
David S. Millercfa969e2010-12-06 20:45:28 -08003051 ehea_info("re-initializing driver complete");
Thomas Klein44c82152007-07-11 16:32:00 +02003052out:
3053 return;
3054}
3055
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003056static void ehea_tx_watchdog(struct net_device *dev)
3057{
3058 struct ehea_port *port = netdev_priv(dev);
3059
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003060 if (netif_carrier_ok(dev) &&
3061 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01003062 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003063}
3064
3065int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
3066{
3067 struct hcp_query_ehea *cb;
3068 u64 hret;
3069 int ret;
3070
Thomas Klein3faf2692009-01-21 14:45:33 -08003071 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003072 if (!cb) {
3073 ret = -ENOMEM;
3074 goto out;
3075 }
3076
3077 hret = ehea_h_query_ehea(adapter->handle, cb);
3078
3079 if (hret != H_SUCCESS) {
3080 ret = -EIO;
3081 goto out_herr;
3082 }
3083
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003084 adapter->max_mc_mac = cb->max_mc_mac - 1;
3085 ret = 0;
3086
3087out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08003088 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003089out:
3090 return ret;
3091}
3092
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003093int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
3094{
3095 struct hcp_ehea_port_cb4 *cb4;
3096 u64 hret;
3097 int ret = 0;
3098
3099 *jumbo = 0;
3100
3101 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08003102 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003103 if (!cb4) {
David S. Millercfa969e2010-12-06 20:45:28 -08003104 ehea_error("no mem for cb4");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003105 ret = -ENOMEM;
3106 goto out;
3107 } else {
3108 hret = ehea_h_query_ehea_port(port->adapter->handle,
3109 port->logical_port_id,
3110 H_PORT_CB4,
3111 H_PORT_CB4_JUMBO, cb4);
3112 if (hret == H_SUCCESS) {
3113 if (cb4->jumbo_frame)
3114 *jumbo = 1;
3115 else {
3116 cb4->jumbo_frame = 1;
3117 hret = ehea_h_modify_ehea_port(port->adapter->
3118 handle,
3119 port->
3120 logical_port_id,
3121 H_PORT_CB4,
3122 H_PORT_CB4_JUMBO,
3123 cb4);
3124 if (hret == H_SUCCESS)
3125 *jumbo = 1;
3126 }
3127 } else
3128 ret = -EINVAL;
3129
Thomas Klein3faf2692009-01-21 14:45:33 -08003130 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003131 }
3132out:
3133 return ret;
3134}
3135
3136static ssize_t ehea_show_port_id(struct device *dev,
3137 struct device_attribute *attr, char *buf)
3138{
3139 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003140 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003141}
3142
3143static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3144 NULL);
3145
3146static void __devinit logical_port_release(struct device *dev)
3147{
3148 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07003149 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003150}
3151
3152static struct device *ehea_register_port(struct ehea_port *port,
3153 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003154{
3155 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003156
Grant Likely61c7a082010-04-13 16:12:29 -07003157 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003158 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003159 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003160
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003161 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003162 port->ofdev.dev.release = logical_port_release;
3163
3164 ret = of_device_register(&port->ofdev);
3165 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003166 ehea_error("failed to register device. ret=%d", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003167 goto out;
3168 }
3169
3170 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003171 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003172 ehea_error("failed to register attributes, ret=%d", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003173 goto out_unreg_of_dev;
3174 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003175
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003176 return &port->ofdev.dev;
3177
3178out_unreg_of_dev:
3179 of_device_unregister(&port->ofdev);
3180out:
3181 return NULL;
3182}
3183
3184static void ehea_unregister_port(struct ehea_port *port)
3185{
3186 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3187 of_device_unregister(&port->ofdev);
3188}
3189
Thomas Klein086c1b22009-01-21 14:43:59 -08003190static const struct net_device_ops ehea_netdev_ops = {
3191 .ndo_open = ehea_open,
3192 .ndo_stop = ehea_stop,
3193 .ndo_start_xmit = ehea_start_xmit,
3194#ifdef CONFIG_NET_POLL_CONTROLLER
3195 .ndo_poll_controller = ehea_netpoll,
3196#endif
3197 .ndo_get_stats = ehea_get_stats,
3198 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003199 .ndo_validate_addr = eth_validate_addr,
Thomas Klein086c1b22009-01-21 14:43:59 -08003200 .ndo_set_multicast_list = ehea_set_multicast_list,
3201 .ndo_change_mtu = ehea_change_mtu,
3202 .ndo_vlan_rx_register = ehea_vlan_rx_register,
3203 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003204 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3205 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003206};
3207
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003208struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3209 u32 logical_port_id,
3210 struct device_node *dn)
3211{
3212 int ret;
3213 struct net_device *dev;
3214 struct ehea_port *port;
3215 struct device *port_dev;
3216 int jumbo;
3217
3218 /* allocate memory for the port structures */
3219 dev = alloc_etherdev(sizeof(struct ehea_port));
3220
3221 if (!dev) {
David S. Millercfa969e2010-12-06 20:45:28 -08003222 ehea_error("no mem for net_device");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003223 ret = -ENOMEM;
3224 goto out_err;
3225 }
3226
3227 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003228
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003229 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003230 port->state = EHEA_PORT_DOWN;
3231 port->sig_comp_iv = sq_entries / 10;
3232
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003233 port->adapter = adapter;
3234 port->netdev = dev;
3235 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003236
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003237 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003238
3239 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3240 if (!port->mc_list) {
3241 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003242 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003243 }
3244
3245 INIT_LIST_HEAD(&port->mc_list->list);
3246
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003247 ret = ehea_sense_port_attr(port);
3248 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003249 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003250
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003251 port_dev = ehea_register_port(port, dn);
3252 if (!port_dev)
3253 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003254
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003255 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003256
3257 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003258 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3259
Thomas Klein086c1b22009-01-21 14:43:59 -08003260 dev->netdev_ops = &ehea_netdev_ops;
3261 ehea_set_ethtool_ops(dev);
3262
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003263 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003264 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003265 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3266 | NETIF_F_LLTX;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003267 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3268
David Howellsc4028952006-11-22 14:57:56 +00003269 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003270
3271 ret = register_netdev(dev);
3272 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003273 ehea_error("register_netdev failed. ret=%d", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003274 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003275 }
3276
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003277 port->lro_max_aggr = lro_max_aggr;
3278
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003279 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003280 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08003281 ehea_error("failed determining jumbo frame status for %s",
3282 port->netdev->name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003283
David S. Millercfa969e2010-12-06 20:45:28 -08003284 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3285 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003286
Thomas Klein44c82152007-07-11 16:32:00 +02003287 adapter->active_ports++;
3288
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003289 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003290
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003291out_unreg_port:
3292 ehea_unregister_port(port);
3293
3294out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003295 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003296
3297out_free_ethdev:
3298 free_netdev(dev);
3299
3300out_err:
David S. Millercfa969e2010-12-06 20:45:28 -08003301 ehea_error("setting up logical port with id=%d failed, ret=%d",
3302 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003303 return NULL;
3304}
3305
3306static void ehea_shutdown_single_port(struct ehea_port *port)
3307{
Brian King7fb1c2a2008-05-14 09:48:25 -05003308 struct ehea_adapter *adapter = port->adapter;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003309 unregister_netdev(port->netdev);
3310 ehea_unregister_port(port);
3311 kfree(port->mc_list);
3312 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003313 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003314}
3315
3316static int ehea_setup_ports(struct ehea_adapter *adapter)
3317{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003318 struct device_node *lhea_dn;
3319 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003320
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003321 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003322 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003323
Grant Likely61c7a082010-04-13 16:12:29 -07003324 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003325 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003326
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003327 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003328 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003329 if (!dn_log_port_id) {
David S. Millercfa969e2010-12-06 20:45:28 -08003330 ehea_error("bad device node: eth_dn name=%s",
3331 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003332 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003333 }
3334
Thomas Klein1211bb62007-04-26 11:56:43 +02003335 if (ehea_add_adapter_mr(adapter)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003336 ehea_error("creating MR failed");
Thomas Klein1211bb62007-04-26 11:56:43 +02003337 of_node_put(eth_dn);
3338 return -EIO;
3339 }
3340
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003341 adapter->port[i] = ehea_setup_single_port(adapter,
3342 *dn_log_port_id,
3343 eth_dn);
3344 if (adapter->port[i])
David S. Millercfa969e2010-12-06 20:45:28 -08003345 ehea_info("%s -> logical port id #%d",
3346 adapter->port[i]->netdev->name,
3347 *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003348 else
3349 ehea_remove_adapter_mr(adapter);
3350
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003351 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003352 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003353 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003354}
3355
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003356static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3357 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003358{
3359 struct device_node *lhea_dn;
3360 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003361 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003362
Grant Likely61c7a082010-04-13 16:12:29 -07003363 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003364 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003365
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003366 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003367 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003368 if (dn_log_port_id)
3369 if (*dn_log_port_id == logical_port_id)
3370 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003371 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003372
3373 return NULL;
3374}
3375
3376static ssize_t ehea_probe_port(struct device *dev,
3377 struct device_attribute *attr,
3378 const char *buf, size_t count)
3379{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003380 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003381 struct ehea_port *port;
3382 struct device_node *eth_dn = NULL;
3383 int i;
3384
3385 u32 logical_port_id;
3386
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003387 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003388
3389 port = ehea_get_port(adapter, logical_port_id);
3390
3391 if (port) {
David S. Millercfa969e2010-12-06 20:45:28 -08003392 ehea_info("adding port with logical port id=%d failed. port "
3393 "already configured as %s.", logical_port_id,
3394 port->netdev->name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003395 return -EINVAL;
3396 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003397
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003398 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3399
3400 if (!eth_dn) {
David S. Millercfa969e2010-12-06 20:45:28 -08003401 ehea_info("no logical port with id %d found", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003402 return -EINVAL;
3403 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003404
Thomas Klein1211bb62007-04-26 11:56:43 +02003405 if (ehea_add_adapter_mr(adapter)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003406 ehea_error("creating MR failed");
Thomas Klein1211bb62007-04-26 11:56:43 +02003407 return -EIO;
3408 }
3409
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003410 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3411
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003412 of_node_put(eth_dn);
3413
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003414 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003415 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003416 if (!adapter->port[i]) {
3417 adapter->port[i] = port;
3418 break;
3419 }
3420
David S. Millercfa969e2010-12-06 20:45:28 -08003421 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3422 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003423 } else {
3424 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003425 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003426 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003427
3428 return (ssize_t) count;
3429}
3430
3431static ssize_t ehea_remove_port(struct device *dev,
3432 struct device_attribute *attr,
3433 const char *buf, size_t count)
3434{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003435 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003436 struct ehea_port *port;
3437 int i;
3438 u32 logical_port_id;
3439
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003440 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003441
3442 port = ehea_get_port(adapter, logical_port_id);
3443
3444 if (port) {
David S. Millercfa969e2010-12-06 20:45:28 -08003445 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3446 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003447
3448 ehea_shutdown_single_port(port);
3449
Doug Maxey508d2b52008-01-31 20:20:49 -06003450 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003451 if (adapter->port[i] == port) {
3452 adapter->port[i] = NULL;
3453 break;
3454 }
3455 } else {
David S. Millercfa969e2010-12-06 20:45:28 -08003456 ehea_error("removing port with logical port id=%d failed. port "
3457 "not configured.", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003458 return -EINVAL;
3459 }
3460
Thomas Klein1211bb62007-04-26 11:56:43 +02003461 ehea_remove_adapter_mr(adapter);
3462
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003463 return (ssize_t) count;
3464}
3465
3466static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3467static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3468
Grant Likely2dc11582010-08-06 09:25:50 -06003469int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003470{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003471 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003472 if (ret)
3473 goto out;
3474
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003475 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003476out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003477 return ret;
3478}
3479
Grant Likely2dc11582010-08-06 09:25:50 -06003480void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003481{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003482 device_remove_file(&dev->dev, &dev_attr_probe_port);
3483 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003484}
3485
Grant Likely2dc11582010-08-06 09:25:50 -06003486static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003487 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003488{
3489 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003490 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003491 int ret;
3492
Grant Likely61c7a082010-04-13 16:12:29 -07003493 if (!dev || !dev->dev.of_node) {
David S. Millercfa969e2010-12-06 20:45:28 -08003494 ehea_error("Invalid ibmebus device probed");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003495 return -EINVAL;
3496 }
3497
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003498 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3499 if (!adapter) {
3500 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003501 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003502 goto out;
3503 }
3504
Thomas Klein44c82152007-07-11 16:32:00 +02003505 list_add(&adapter->list, &adapter_list);
3506
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003507 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003508
Grant Likely61c7a082010-04-13 16:12:29 -07003509 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003510 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003511 if (adapter_handle)
3512 adapter->handle = *adapter_handle;
3513
3514 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003515 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003516 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003517 ret = -ENODEV;
3518 goto out_free_ad;
3519 }
3520
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003521 adapter->pd = EHEA_PD_ID;
3522
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003523 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003524
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003525
3526 /* initialize adapter and ports */
3527 /* get adapter properties */
3528 ret = ehea_sense_adapter_attr(adapter);
3529 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003530 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003531 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003532 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003533
3534 adapter->neq = ehea_create_eq(adapter,
3535 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3536 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003537 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003538 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003539 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003540 }
3541
3542 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3543 (unsigned long)adapter);
3544
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003545 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003546 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003547 "ehea_neq", adapter);
3548 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003549 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003550 goto out_kill_eq;
3551 }
3552
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003553 ret = ehea_create_device_sysfs(dev);
3554 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003555 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003556
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003557 ret = ehea_setup_ports(adapter);
3558 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003559 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003560 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003561 }
3562
3563 ret = 0;
3564 goto out;
3565
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003566out_rem_dev_sysfs:
3567 ehea_remove_device_sysfs(dev);
3568
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003569out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003570 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003571
3572out_kill_eq:
3573 ehea_destroy_eq(adapter->neq);
3574
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003575out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003576 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003577 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003578
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003579out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003580 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003581
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003582 return ret;
3583}
3584
Grant Likely2dc11582010-08-06 09:25:50 -06003585static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003586{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003587 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003588 int i;
3589
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003590 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003591 if (adapter->port[i]) {
3592 ehea_shutdown_single_port(adapter->port[i]);
3593 adapter->port[i] = NULL;
3594 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003595
3596 ehea_remove_device_sysfs(dev);
3597
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003598 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003599
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003600 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003601 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003602
3603 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003604 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003605 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003606 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003607
Thomas Klein21eee2d2008-02-13 16:18:33 +01003608 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003609
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003610 return 0;
3611}
3612
Thomas Klein21eee2d2008-02-13 16:18:33 +01003613void ehea_crash_handler(void)
3614{
3615 int i;
3616
3617 if (ehea_fw_handles.arr)
3618 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3619 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3620 ehea_fw_handles.arr[i].fwh,
3621 FORCE_FREE);
3622
3623 if (ehea_bcmc_regs.arr)
3624 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3625 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3626 ehea_bcmc_regs.arr[i].port_id,
3627 ehea_bcmc_regs.arr[i].reg_type,
3628 ehea_bcmc_regs.arr[i].macaddr,
3629 0, H_DEREG_BCMC);
3630}
3631
Hannes Hering48cfb142008-05-07 14:43:36 +02003632static int ehea_mem_notifier(struct notifier_block *nb,
3633 unsigned long action, void *data)
3634{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003635 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003636 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003637
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003638 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003639
Hannes Hering48cfb142008-05-07 14:43:36 +02003640 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003641 case MEM_CANCEL_OFFLINE:
David S. Millercfa969e2010-12-06 20:45:28 -08003642 ehea_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003643 /* Readd canceled memory block */
3644 case MEM_ONLINE:
David S. Millercfa969e2010-12-06 20:45:28 -08003645 ehea_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003646 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003647 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003648 goto out_unlock;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003649 ehea_rereg_mrs(NULL);
3650 break;
3651 case MEM_GOING_OFFLINE:
David S. Millercfa969e2010-12-06 20:45:28 -08003652 ehea_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003653 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003654 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003655 goto out_unlock;
Hannes Hering48cfb142008-05-07 14:43:36 +02003656 ehea_rereg_mrs(NULL);
3657 break;
3658 default:
3659 break;
3660 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003661
3662 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003663 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003664
Thomas Kleina7c561f22010-04-20 23:11:31 +00003665out_unlock:
3666 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003667 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003668}
3669
3670static struct notifier_block ehea_mem_nb = {
3671 .notifier_call = ehea_mem_notifier,
3672};
3673
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003674static int ehea_reboot_notifier(struct notifier_block *nb,
3675 unsigned long action, void *unused)
3676{
3677 if (action == SYS_RESTART) {
David S. Millercfa969e2010-12-06 20:45:28 -08003678 ehea_info("Reboot: freeing all eHEA resources");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003679 ibmebus_unregister_driver(&ehea_driver);
3680 }
3681 return NOTIFY_DONE;
3682}
3683
3684static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003685 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003686};
3687
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003688static int check_module_parm(void)
3689{
3690 int ret = 0;
3691
3692 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3693 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003694 ehea_info("Bad parameter: rq1_entries");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003695 ret = -EINVAL;
3696 }
3697 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3698 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003699 ehea_info("Bad parameter: rq2_entries");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003700 ret = -EINVAL;
3701 }
3702 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3703 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003704 ehea_info("Bad parameter: rq3_entries");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003705 ret = -EINVAL;
3706 }
3707 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3708 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003709 ehea_info("Bad parameter: sq_entries");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003710 ret = -EINVAL;
3711 }
3712
3713 return ret;
3714}
3715
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003716static ssize_t ehea_show_capabilities(struct device_driver *drv,
3717 char *buf)
3718{
3719 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3720}
3721
3722static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3723 ehea_show_capabilities, NULL);
3724
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003725int __init ehea_module_init(void)
3726{
3727 int ret;
3728
David S. Millercfa969e2010-12-06 20:45:28 -08003729 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3730 DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003731
Thomas Klein44c82152007-07-11 16:32:00 +02003732
3733 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003734 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3735 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3736
Daniel Walker9f71a562008-03-28 14:41:26 -07003737 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003738 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003739
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003740 ret = check_module_parm();
3741 if (ret)
3742 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003743
3744 ret = ehea_create_busmap();
3745 if (ret)
3746 goto out;
3747
Thomas Klein21eee2d2008-02-13 16:18:33 +01003748 ret = register_reboot_notifier(&ehea_reboot_nb);
3749 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08003750 ehea_info("failed registering reboot notifier");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003751
Hannes Hering48cfb142008-05-07 14:43:36 +02003752 ret = register_memory_notifier(&ehea_mem_nb);
3753 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08003754 ehea_info("failed registering memory remove notifier");
Hannes Hering48cfb142008-05-07 14:43:36 +02003755
Joe Perchesc061b182010-08-23 18:20:03 +00003756 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003757 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08003758 ehea_info("failed registering crash handler");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003759
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003760 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003761 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003762 ehea_error("failed registering eHEA device driver on ebus");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003763 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003764 }
3765
3766 ret = driver_create_file(&ehea_driver.driver,
3767 &driver_attr_capabilities);
3768 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003769 ehea_error("failed to register capabilities attribute, ret=%d",
3770 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003771 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003772 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003773
Thomas Klein21eee2d2008-02-13 16:18:33 +01003774 return ret;
3775
3776out3:
3777 ibmebus_unregister_driver(&ehea_driver);
3778out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003779 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003780 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003781 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003782out:
3783 return ret;
3784}
3785
3786static void __exit ehea_module_exit(void)
3787{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003788 int ret;
3789
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003790 flush_scheduled_work();
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003791 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003792 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003793 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003794 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003795 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08003796 ehea_info("failed unregistering crash handler");
Hannes Hering48cfb142008-05-07 14:43:36 +02003797 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003798 kfree(ehea_fw_handles.arr);
3799 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003800 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003801}
3802
3803module_init(ehea_module_init);
3804module_exit(ehea_module_exit);