blob: 69f61523fcc8483eed3d1d5b27de515316b824ef [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]) {
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000403 ehea_info("Unable to allocate enough skb in the array\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200404 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200405 break;
406 }
407 }
408 index--;
409 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200410 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200411 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200412
413 if (adder == 0)
414 return;
415
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200416 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200417 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200418}
419
Thomas Kleine2878802009-01-21 14:45:57 -0800420static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200421{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200422 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
423 struct net_device *dev = pr->port->netdev;
424 int i;
425
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000426 if (nr_rq1a > pr->rq1_skba.len) {
427 ehea_error("NR_RQ1A bigger than skb array len\n");
428 return;
429 }
430
431 for (i = 0; i < nr_rq1a; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200432 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000433 if (!skb_arr_rq1[i]) {
434 ehea_info("No enough memory to allocate skb array\n");
Thomas Kleine2878802009-01-21 14:45:57 -0800435 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000436 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200437 }
438 /* Ring doorbell */
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000439 ehea_update_rq1a(pr->qp, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200440}
441
442static int ehea_refill_rq_def(struct ehea_port_res *pr,
443 struct ehea_q_skb_arr *q_skba, int rq_nr,
444 int num_wqes, int wqe_type, int packet_size)
445{
446 struct net_device *dev = pr->port->netdev;
447 struct ehea_qp *qp = pr->qp;
448 struct sk_buff **skb_arr = q_skba->arr;
449 struct ehea_rwqe *rwqe;
450 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200451 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200452 int ret = 0;
453
454 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200455 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200456
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200457 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
458 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200459 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200460 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200461
462 index = q_skba->index;
463 max_index_mask = q_skba->len - 1;
464 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200465 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000466 struct sk_buff *skb;
467
468 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200469 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200470 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800471 if (q_skba->os_skbs == q_skba->len - 2) {
David S. Millercfa969e2010-12-06 20:45:28 -0800472 ehea_info("%s: rq%i ran dry - no mem for skb",
473 pr->port->netdev->name, rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800474 ret = -ENOMEM;
475 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200476 break;
477 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200478
479 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200480 tmp_addr = ehea_map_vaddr(skb->data);
481 if (tmp_addr == -1) {
482 dev_kfree_skb(skb);
483 q_skba->os_skbs = fill_wqes - i;
484 ret = 0;
485 break;
486 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200487
488 rwqe = ehea_get_next_rwqe(qp, rq_nr);
489 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200490 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200491 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200492 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200493 rwqe->sg_list[0].len = packet_size;
494 rwqe->data_segments = 1;
495
496 index++;
497 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200498 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200499 }
Thomas Klein44c82152007-07-11 16:32:00 +0200500
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200501 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200502 if (adder == 0)
503 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200504
505 /* Ring doorbell */
506 iosync();
507 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200508 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200509 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200510 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200511out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200512 return ret;
513}
514
515
516static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
517{
518 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
519 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000520 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200521}
522
523
524static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
525{
526 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
527 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000528 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200529}
530
531static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
532{
533 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
534 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
535 return 0;
536 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
537 (cqe->header_length == 0))
538 return 0;
539 return -EINVAL;
540}
541
542static inline void ehea_fill_skb(struct net_device *dev,
543 struct sk_buff *skb, struct ehea_cqe *cqe)
544{
545 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
546
547 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200548 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000549
550 /* The packet was not an IPV4 packet so a complemented checksum was
551 calculated. The value is found in the Internet Checksum field. */
552 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
553 skb->ip_summed = CHECKSUM_COMPLETE;
554 skb->csum = csum_unfold(~cqe->inet_checksum_value);
555 } else
556 skb->ip_summed = CHECKSUM_UNNECESSARY;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200557}
558
559static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
560 int arr_len,
561 struct ehea_cqe *cqe)
562{
563 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
564 struct sk_buff *skb;
565 void *pref;
566 int x;
567
568 x = skb_index + 1;
569 x &= (arr_len - 1);
570
571 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700572 if (pref) {
573 prefetchw(pref);
574 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200575
Hannes Hering0b2febf2009-05-04 11:06:37 -0700576 pref = (skb_array[x]->data);
577 prefetch(pref);
578 prefetch(pref + EHEA_CACHE_LINE);
579 prefetch(pref + EHEA_CACHE_LINE * 2);
580 prefetch(pref + EHEA_CACHE_LINE * 3);
581 }
582
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200583 skb = skb_array[skb_index];
584 skb_array[skb_index] = NULL;
585 return skb;
586}
587
588static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
589 int arr_len, int wqe_index)
590{
591 struct sk_buff *skb;
592 void *pref;
593 int x;
594
595 x = wqe_index + 1;
596 x &= (arr_len - 1);
597
598 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700599 if (pref) {
600 prefetchw(pref);
601 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200602
Hannes Hering0b2febf2009-05-04 11:06:37 -0700603 pref = (skb_array[x]->data);
604 prefetchw(pref);
605 prefetchw(pref + EHEA_CACHE_LINE);
606 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200607
608 skb = skb_array[wqe_index];
609 skb_array[wqe_index] = NULL;
610 return skb;
611}
612
613static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
614 struct ehea_cqe *cqe, int *processed_rq2,
615 int *processed_rq3)
616{
617 struct sk_buff *skb;
618
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100619 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
620 pr->p_stats.err_tcp_cksum++;
621 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
622 pr->p_stats.err_ip_cksum++;
623 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
624 pr->p_stats.err_frame_crc++;
625
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200626 if (rq == 2) {
627 *processed_rq2 += 1;
628 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
629 dev_kfree_skb(skb);
630 } else if (rq == 3) {
631 *processed_rq3 += 1;
632 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
633 dev_kfree_skb(skb);
634 }
635
636 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100637 if (netif_msg_rx_err(pr->port)) {
David S. Millercfa969e2010-12-06 20:45:28 -0800638 ehea_error("Critical receive error for QP %d. "
639 "Resetting port.", pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100640 ehea_dump(cqe, sizeof(*cqe), "CQE");
641 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100642 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200643 return 1;
644 }
645
646 return 0;
647}
648
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700649static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
650 void **tcph, u64 *hdr_flags, void *priv)
651{
652 struct ehea_cqe *cqe = priv;
653 unsigned int ip_len;
654 struct iphdr *iph;
655
656 /* non tcp/udp packets */
657 if (!cqe->header_length)
658 return -1;
659
660 /* non tcp packet */
661 skb_reset_network_header(skb);
662 iph = ip_hdr(skb);
663 if (iph->protocol != IPPROTO_TCP)
664 return -1;
665
666 ip_len = ip_hdrlen(skb);
667 skb_set_transport_header(skb, ip_len);
668 *tcph = tcp_hdr(skb);
669
670 /* check if ip header and tcp header are complete */
Roland Dreier3ff2cd22008-07-01 10:20:33 -0700671 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700672 return -1;
673
674 *hdr_flags = LRO_IPV4 | LRO_TCP;
675 *iphdr = iph;
676
677 return 0;
678}
679
680static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
681 struct sk_buff *skb)
682{
Joe Perches8e95a202009-12-03 07:58:21 +0000683 int vlan_extracted = ((cqe->status & EHEA_CQE_VLAN_TAG_XTRACT) &&
684 pr->port->vgrp);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700685
Breno Leitaoc7757fd2010-12-08 12:19:14 -0800686 if (skb->dev->features & NETIF_F_LRO) {
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700687 if (vlan_extracted)
688 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
689 pr->port->vgrp,
690 cqe->vlan_tag,
691 cqe);
692 else
693 lro_receive_skb(&pr->lro_mgr, skb, cqe);
694 } else {
695 if (vlan_extracted)
696 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
697 cqe->vlan_tag);
698 else
699 netif_receive_skb(skb);
700 }
701}
702
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700703static int ehea_proc_rwqes(struct net_device *dev,
704 struct ehea_port_res *pr,
705 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200706{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100707 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200708 struct ehea_qp *qp = pr->qp;
709 struct ehea_cqe *cqe;
710 struct sk_buff *skb;
711 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
712 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
713 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
714 int skb_arr_rq1_len = pr->rq1_skba.len;
715 int skb_arr_rq2_len = pr->rq2_skba.len;
716 int skb_arr_rq3_len = pr->rq3_skba.len;
717 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000718 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700719 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200720
721 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
722 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200723
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200724 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700725 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200726 ehea_inc_rq1(qp);
727 processed_rq1++;
728 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200729 if (netif_msg_rx_status(port))
730 ehea_dump(cqe, sizeof(*cqe), "CQE");
731
732 last_wqe_index = wqe_index;
733 rmb();
734 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600735 if (rq == 1) {
736 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200737 skb = get_skb_by_index_ll(skb_arr_rq1,
738 skb_arr_rq1_len,
739 wqe_index);
740 if (unlikely(!skb)) {
David S. Millercfa969e2010-12-06 20:45:28 -0800741 if (netif_msg_rx_err(port))
742 ehea_error("LL rq1: skb=NULL");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100743
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700744 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200745 EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000746 if (!skb) {
747 ehea_info("Not enough memory to allocate skb\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200748 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000749 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200750 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600751 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200752 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700753 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600754 } else if (rq == 2) {
755 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200756 skb = get_skb_by_index(skb_arr_rq2,
757 skb_arr_rq2_len, cqe);
758 if (unlikely(!skb)) {
David S. Millercfa969e2010-12-06 20:45:28 -0800759 if (netif_msg_rx_err(port))
760 ehea_error("rq2: skb=NULL");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200761 break;
762 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700763 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200764 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600765 } else {
766 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200767 skb = get_skb_by_index(skb_arr_rq3,
768 skb_arr_rq3_len, cqe);
769 if (unlikely(!skb)) {
David S. Millercfa969e2010-12-06 20:45:28 -0800770 if (netif_msg_rx_err(port))
771 ehea_error("rq3: skb=NULL");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200772 break;
773 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700774 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200775 processed_rq3++;
776 }
777
Breno Leitaoce45b872010-10-27 08:45:14 +0000778 processed_bytes += skb->len;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700779 ehea_proc_skb(pr, cqe, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100780 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100781 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200782 port_reset = ehea_treat_poll_error(pr, rq, cqe,
783 &processed_rq2,
784 &processed_rq3);
785 if (port_reset)
786 break;
787 }
788 cqe = ehea_poll_rq1(qp, &wqe_index);
789 }
Breno Leitaoc7757fd2010-12-08 12:19:14 -0800790 if (dev->features & NETIF_F_LRO)
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700791 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200792
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200793 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000794 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200795
796 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
797 ehea_refill_rq2(pr, processed_rq2);
798 ehea_refill_rq3(pr, processed_rq3);
799
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700800 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200801}
802
Andre Detsch2928db42010-08-17 05:49:12 +0000803#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
804
805static void reset_sq_restart_flag(struct ehea_port *port)
806{
807 int i;
808
809 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
810 struct ehea_port_res *pr = &port->port_res[i];
811 pr->sq_restart_flag = 0;
812 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000813 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000814}
815
816static void check_sqs(struct ehea_port *port)
817{
818 struct ehea_swqe *swqe;
819 int swqe_index;
820 int i, k;
821
822 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
823 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000824 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000825 k = 0;
826 swqe = ehea_get_swqe(pr->qp, &swqe_index);
827 memset(swqe, 0, SWQE_HEADER_SIZE);
828 atomic_dec(&pr->swqe_avail);
829
830 swqe->tx_control |= EHEA_SWQE_PURGE;
831 swqe->wr_id = SWQE_RESTART_CHECK;
832 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
833 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
834 swqe->immediate_data_length = 80;
835
836 ehea_post_swqe(pr->qp, swqe);
837
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000838 ret = wait_event_timeout(port->restart_wq,
839 pr->sq_restart_flag == 0,
840 msecs_to_jiffies(100));
841
842 if (!ret) {
David S. Millercfa969e2010-12-06 20:45:28 -0800843 ehea_error("HW/SW queues out of sync");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000844 ehea_schedule_port_reset(pr->port);
845 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000846 }
847 }
Andre Detsch2928db42010-08-17 05:49:12 +0000848}
849
850
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100851static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200852{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100853 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200854 struct ehea_cq *send_cq = pr->send_cq;
855 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100856 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200857 int cqe_counter = 0;
858 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100859 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200860 unsigned long flags;
861
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100862 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600863 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100864 ehea_inc_cq(send_cq);
865
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200866 cqe_counter++;
867 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000868
869 if (cqe->wr_id == SWQE_RESTART_CHECK) {
870 pr->sq_restart_flag = 1;
871 swqe_av++;
872 break;
873 }
874
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200875 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
David S. Millercfa969e2010-12-06 20:45:28 -0800876 ehea_error("Bad send completion status=0x%04X",
877 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000878
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200879 if (netif_msg_tx_err(pr->port))
880 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000881
882 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
David S. Millercfa969e2010-12-06 20:45:28 -0800883 ehea_error("Resetting port");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000884 ehea_schedule_port_reset(pr->port);
885 break;
886 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200887 }
888
889 if (netif_msg_tx_done(pr->port))
890 ehea_dump(cqe, sizeof(*cqe), "CQE");
891
892 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100893 == EHEA_SWQE2_TYPE)) {
894
895 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
896 skb = pr->sq_skba.arr[index];
897 dev_kfree_skb(skb);
898 pr->sq_skba.arr[index] = NULL;
899 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200900
901 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
902 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100903
904 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700905 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200906
907 ehea_update_feca(send_cq, cqe_counter);
908 atomic_add(swqe_av, &pr->swqe_avail);
909
910 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100911
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200912 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
913 >= pr->swqe_refill_th)) {
914 netif_wake_queue(pr->port->netdev);
915 pr->queue_stopped = 0;
916 }
917 spin_unlock_irqrestore(&pr->netif_queue, flags);
Breno Leitao5b27d422010-10-05 13:16:22 +0000918 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200919
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100920 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200921}
922
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100923#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700924#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100925
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700926static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200927{
Doug Maxey508d2b52008-01-31 20:20:49 -0600928 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
929 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700930 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100931 struct ehea_cqe *cqe;
932 struct ehea_cqe *cqe_skb = NULL;
933 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700934 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100935
936 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700937 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100938
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700939 if (!force_irq)
940 rx += ehea_proc_rwqes(dev, pr, budget - rx);
941
942 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100943 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700944 force_irq = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -0800945 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100946 ehea_reset_cq_ep(pr->recv_cq);
947 ehea_reset_cq_ep(pr->send_cq);
948 ehea_reset_cq_n1(pr->recv_cq);
949 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000950 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100951 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
952 cqe_skb = ehea_poll_cq(pr->send_cq);
953
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100954 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700955 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100956
Ben Hutchings288379f2009-01-19 16:43:59 -0800957 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700958 return rx;
959
960 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
961 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100962 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100963
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700964 pr->poll_counter++;
965 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200966}
967
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200968#ifdef CONFIG_NET_POLL_CONTROLLER
969static void ehea_netpoll(struct net_device *dev)
970{
971 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700972 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200973
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700974 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800975 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200976}
977#endif
978
David Howells7d12e782006-10-05 14:55:46 +0100979static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200980{
981 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100982
Ben Hutchings288379f2009-01-19 16:43:59 -0800983 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100984
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200985 return IRQ_HANDLED;
986}
987
David Howells7d12e782006-10-05 14:55:46 +0100988static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200989{
990 struct ehea_port *port = param;
991 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100992 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200993 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000994 u64 resource_type, aer, aerr;
995 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200996
997 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100998
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200999 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001000 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
David S. Millercfa969e2010-12-06 20:45:28 -08001001 ehea_error("QP aff_err: entry=0x%llx, token=0x%x",
1002 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001003
1004 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +00001005
1006 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
1007 &aer, &aerr);
1008
1009 if (resource_type == EHEA_AER_RESTYPE_QP) {
1010 if ((aer & EHEA_AER_RESET_MASK) ||
1011 (aerr & EHEA_AERR_RESET_MASK))
1012 reset_port = 1;
1013 } else
1014 reset_port = 1; /* Reset in case of CQ or EQ error */
1015
Thomas Kleinbb3a6442007-01-22 12:54:50 +01001016 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001017 }
1018
Thomas Kleinea96cea2010-04-20 23:10:55 +00001019 if (reset_port) {
David S. Millercfa969e2010-12-06 20:45:28 -08001020 ehea_error("Resetting port");
Thomas Kleinea96cea2010-04-20 23:10:55 +00001021 ehea_schedule_port_reset(port);
1022 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001023
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001024 return IRQ_HANDLED;
1025}
1026
1027static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
1028 int logical_port)
1029{
1030 int i;
1031
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01001032 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +01001033 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001034 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +01001035 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001036 return NULL;
1037}
1038
1039int ehea_sense_port_attr(struct ehea_port *port)
1040{
1041 int ret;
1042 u64 hret;
1043 struct hcp_ehea_port_cb0 *cb0;
1044
Doug Maxey508d2b52008-01-31 20:20:49 -06001045 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -08001046 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -06001047 if (!cb0) {
David S. Millercfa969e2010-12-06 20:45:28 -08001048 ehea_error("no mem for cb0");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001049 ret = -ENOMEM;
1050 goto out;
1051 }
1052
1053 hret = ehea_h_query_ehea_port(port->adapter->handle,
1054 port->logical_port_id, H_PORT_CB0,
1055 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1056 cb0);
1057 if (hret != H_SUCCESS) {
1058 ret = -EIO;
1059 goto out_free;
1060 }
1061
1062 /* MAC address */
1063 port->mac_addr = cb0->port_mac_addr << 16;
1064
Doug Maxey508d2b52008-01-31 20:20:49 -06001065 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001066 ret = -EADDRNOTAVAIL;
1067 goto out_free;
1068 }
1069
1070 /* Port speed */
1071 switch (cb0->port_speed) {
1072 case H_SPEED_10M_H:
1073 port->port_speed = EHEA_SPEED_10M;
1074 port->full_duplex = 0;
1075 break;
1076 case H_SPEED_10M_F:
1077 port->port_speed = EHEA_SPEED_10M;
1078 port->full_duplex = 1;
1079 break;
1080 case H_SPEED_100M_H:
1081 port->port_speed = EHEA_SPEED_100M;
1082 port->full_duplex = 0;
1083 break;
1084 case H_SPEED_100M_F:
1085 port->port_speed = EHEA_SPEED_100M;
1086 port->full_duplex = 1;
1087 break;
1088 case H_SPEED_1G_F:
1089 port->port_speed = EHEA_SPEED_1G;
1090 port->full_duplex = 1;
1091 break;
1092 case H_SPEED_10G_F:
1093 port->port_speed = EHEA_SPEED_10G;
1094 port->full_duplex = 1;
1095 break;
1096 default:
1097 port->port_speed = 0;
1098 port->full_duplex = 0;
1099 break;
1100 }
1101
Thomas Kleine919b592007-01-22 12:53:20 +01001102 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001103 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001104
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001105 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001106 if (use_mcs)
1107 port->num_def_qps = cb0->num_default_qps;
1108 else
1109 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001110
1111 if (!port->num_def_qps) {
1112 ret = -EINVAL;
1113 goto out_free;
1114 }
1115
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001116 port->num_tx_qps = num_tx_qps;
1117
1118 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001119 port->num_add_tx_qps = 0;
1120 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001121 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001122
1123 ret = 0;
1124out_free:
1125 if (ret || netif_msg_probe(port))
1126 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001127 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001128out:
1129 return ret;
1130}
1131
1132int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1133{
1134 struct hcp_ehea_port_cb4 *cb4;
1135 u64 hret;
1136 int ret = 0;
1137
Thomas Klein3faf2692009-01-21 14:45:33 -08001138 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001139 if (!cb4) {
David S. Millercfa969e2010-12-06 20:45:28 -08001140 ehea_error("no mem for cb4");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001141 ret = -ENOMEM;
1142 goto out;
1143 }
1144
1145 cb4->port_speed = port_speed;
1146
1147 netif_carrier_off(port->netdev);
1148
1149 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1150 port->logical_port_id,
1151 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1152 if (hret == H_SUCCESS) {
1153 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1154
1155 hret = ehea_h_query_ehea_port(port->adapter->handle,
1156 port->logical_port_id,
1157 H_PORT_CB4, H_PORT_CB4_SPEED,
1158 cb4);
1159 if (hret == H_SUCCESS) {
1160 switch (cb4->port_speed) {
1161 case H_SPEED_10M_H:
1162 port->port_speed = EHEA_SPEED_10M;
1163 port->full_duplex = 0;
1164 break;
1165 case H_SPEED_10M_F:
1166 port->port_speed = EHEA_SPEED_10M;
1167 port->full_duplex = 1;
1168 break;
1169 case H_SPEED_100M_H:
1170 port->port_speed = EHEA_SPEED_100M;
1171 port->full_duplex = 0;
1172 break;
1173 case H_SPEED_100M_F:
1174 port->port_speed = EHEA_SPEED_100M;
1175 port->full_duplex = 1;
1176 break;
1177 case H_SPEED_1G_F:
1178 port->port_speed = EHEA_SPEED_1G;
1179 port->full_duplex = 1;
1180 break;
1181 case H_SPEED_10G_F:
1182 port->port_speed = EHEA_SPEED_10G;
1183 port->full_duplex = 1;
1184 break;
1185 default:
1186 port->port_speed = 0;
1187 port->full_duplex = 0;
1188 break;
1189 }
1190 } else {
David S. Millercfa969e2010-12-06 20:45:28 -08001191 ehea_error("Failed sensing port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001192 ret = -EIO;
1193 }
1194 } else {
1195 if (hret == H_AUTHORITY) {
David S. Millercfa969e2010-12-06 20:45:28 -08001196 ehea_info("Hypervisor denied setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001197 ret = -EPERM;
1198 } else {
1199 ret = -EIO;
David S. Millercfa969e2010-12-06 20:45:28 -08001200 ehea_error("Failed setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001201 }
1202 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001203 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1204 netif_carrier_on(port->netdev);
1205
Thomas Klein3faf2692009-01-21 14:45:33 -08001206 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001207out:
1208 return ret;
1209}
1210
1211static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1212{
1213 int ret;
1214 u8 ec;
1215 u8 portnum;
1216 struct ehea_port *port;
1217
1218 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1219 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1220 port = ehea_get_port(adapter, portnum);
1221
1222 switch (ec) {
1223 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1224
1225 if (!port) {
David S. Millercfa969e2010-12-06 20:45:28 -08001226 ehea_error("unknown portnum %x", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001227 break;
1228 }
1229
1230 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
David S. Millercfa969e2010-12-06 20:45:28 -08001231 if (!netif_carrier_ok(port->netdev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001232 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001233 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08001234 ehea_error("failed resensing port "
1235 "attributes");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001236 break;
1237 }
1238
David S. Millercfa969e2010-12-06 20:45:28 -08001239 if (netif_msg_link(port))
1240 ehea_info("%s: Logical port up: %dMbps "
1241 "%s Duplex",
1242 port->netdev->name,
1243 port->port_speed,
1244 port->full_duplex ==
1245 1 ? "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001246
David S. Millercfa969e2010-12-06 20:45:28 -08001247 netif_carrier_on(port->netdev);
1248 netif_wake_queue(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001249 }
1250 } else
David S. Millercfa969e2010-12-06 20:45:28 -08001251 if (netif_carrier_ok(port->netdev)) {
1252 if (netif_msg_link(port))
1253 ehea_info("%s: Logical port down",
1254 port->netdev->name);
1255 netif_carrier_off(port->netdev);
1256 netif_stop_queue(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001257 }
1258
1259 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001260 port->phy_link = EHEA_PHY_LINK_UP;
David S. Millercfa969e2010-12-06 20:45:28 -08001261 if (netif_msg_link(port))
1262 ehea_info("%s: Physical port up",
1263 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001264 if (prop_carrier_state)
David S. Millercfa969e2010-12-06 20:45:28 -08001265 netif_carrier_on(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001266 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001267 port->phy_link = EHEA_PHY_LINK_DOWN;
David S. Millercfa969e2010-12-06 20:45:28 -08001268 if (netif_msg_link(port))
1269 ehea_info("%s: Physical port down",
1270 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001271 if (prop_carrier_state)
David S. Millercfa969e2010-12-06 20:45:28 -08001272 netif_carrier_off(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001273 }
1274
1275 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
David S. Millercfa969e2010-12-06 20:45:28 -08001276 ehea_info("External switch port is primary port");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001277 else
David S. Millercfa969e2010-12-06 20:45:28 -08001278 ehea_info("External switch port is backup port");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001279
1280 break;
1281 case EHEA_EC_ADAPTER_MALFUNC:
David S. Millercfa969e2010-12-06 20:45:28 -08001282 ehea_error("Adapter malfunction");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001283 break;
1284 case EHEA_EC_PORT_MALFUNC:
David S. Millercfa969e2010-12-06 20:45:28 -08001285 ehea_info("Port malfunction: Device: %s", port->netdev->name);
1286 netif_carrier_off(port->netdev);
1287 netif_stop_queue(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001288 break;
1289 default:
David S. Millercfa969e2010-12-06 20:45:28 -08001290 ehea_error("unknown event code %x, eqe=0x%llX", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001291 break;
1292 }
1293}
1294
1295static void ehea_neq_tasklet(unsigned long data)
1296{
Doug Maxey508d2b52008-01-31 20:20:49 -06001297 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001298 struct ehea_eqe *eqe;
1299 u64 event_mask;
1300
1301 eqe = ehea_poll_eq(adapter->neq);
David S. Millercfa969e2010-12-06 20:45:28 -08001302 ehea_debug("eqe=%p", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001303
1304 while (eqe) {
David S. Millercfa969e2010-12-06 20:45:28 -08001305 ehea_debug("*eqe=%lx", eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001306 ehea_parse_eqe(adapter, eqe->entry);
1307 eqe = ehea_poll_eq(adapter->neq);
David S. Millercfa969e2010-12-06 20:45:28 -08001308 ehea_debug("next eqe=%p", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001309 }
1310
1311 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1312 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1313 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1314
1315 ehea_h_reset_events(adapter->handle,
1316 adapter->neq->fw_handle, event_mask);
1317}
1318
David Howells7d12e782006-10-05 14:55:46 +01001319static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001320{
1321 struct ehea_adapter *adapter = param;
1322 tasklet_hi_schedule(&adapter->neq_tasklet);
1323 return IRQ_HANDLED;
1324}
1325
1326
1327static int ehea_fill_port_res(struct ehea_port_res *pr)
1328{
1329 int ret;
1330 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1331
Thomas Kleine2878802009-01-21 14:45:57 -08001332 ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1333 - init_attr->act_nr_rwqes_rq2
1334 - init_attr->act_nr_rwqes_rq3 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001335
Thomas Kleine2878802009-01-21 14:45:57 -08001336 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001337
1338 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1339
1340 return ret;
1341}
1342
1343static int ehea_reg_interrupts(struct net_device *dev)
1344{
1345 struct ehea_port *port = netdev_priv(dev);
1346 struct ehea_port_res *pr;
1347 int i, ret;
1348
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001349
1350 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1351 dev->name);
1352
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001353 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001354 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001355 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001356 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08001357 ehea_error("failed registering irq for qp_aff_irq_handler:"
1358 "ist=%X", port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001359 goto out_free_qpeq;
1360 }
1361
David S. Millercfa969e2010-12-06 20:45:28 -08001362 if (netif_msg_ifup(port))
1363 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1364 "registered", port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001365
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001366
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001367 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1368 pr = &port->port_res[i];
1369 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001370 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001371 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001372 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001373 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001374 pr);
1375 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08001376 ehea_error("failed registering irq for ehea_queue "
1377 "port_res_nr:%d, ist=%X", i,
1378 pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001379 goto out_free_req;
1380 }
David S. Millercfa969e2010-12-06 20:45:28 -08001381 if (netif_msg_ifup(port))
1382 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1383 "%d registered", pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001384 }
1385out:
1386 return ret;
1387
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001388
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001389out_free_req:
1390 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001391 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001392 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001393 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001394
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001395out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001396 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001397 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001398
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001399 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001400
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001401}
1402
1403static void ehea_free_interrupts(struct net_device *dev)
1404{
1405 struct ehea_port *port = netdev_priv(dev);
1406 struct ehea_port_res *pr;
1407 int i;
1408
1409 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001410
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001411 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1412 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001413 ibmebus_free_irq(pr->eq->attr.ist1, pr);
David S. Millercfa969e2010-12-06 20:45:28 -08001414 if (netif_msg_intr(port))
1415 ehea_info("free send irq for res %d with handle 0x%X",
1416 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001417 }
1418
1419 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001420 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
David S. Millercfa969e2010-12-06 20:45:28 -08001421 if (netif_msg_intr(port))
1422 ehea_info("associated event interrupt for handle 0x%X freed",
1423 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001424}
1425
1426static int ehea_configure_port(struct ehea_port *port)
1427{
1428 int ret, i;
1429 u64 hret, mask;
1430 struct hcp_ehea_port_cb0 *cb0;
1431
1432 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001433 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001434 if (!cb0)
1435 goto out;
1436
1437 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1438 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1439 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1440 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1441 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1442 PXLY_RC_VLAN_FILTER)
1443 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1444
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001445 for (i = 0; i < port->num_mcs; i++)
1446 if (use_mcs)
1447 cb0->default_qpn_arr[i] =
1448 port->port_res[i].qp->init_attr.qp_nr;
1449 else
1450 cb0->default_qpn_arr[i] =
1451 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001452
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001453 if (netif_msg_ifup(port))
1454 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1455
1456 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1457 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1458
1459 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1460 port->logical_port_id,
1461 H_PORT_CB0, mask, cb0);
1462 ret = -EIO;
1463 if (hret != H_SUCCESS)
1464 goto out_free;
1465
1466 ret = 0;
1467
1468out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001469 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001470out:
1471 return ret;
1472}
1473
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001474int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001475{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001476 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001477 struct ehea_adapter *adapter = pr->port->adapter;
1478
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001479 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1480 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001481 goto out;
1482
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001483 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1484 if (ret)
1485 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001486
1487 return 0;
1488
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001489out_free:
1490 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001491out:
David S. Millercfa969e2010-12-06 20:45:28 -08001492 ehea_error("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001493 return -EIO;
1494}
1495
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001496int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001497{
Joe Perches8e95a202009-12-03 07:58:21 +00001498 if ((ehea_rem_mr(&pr->send_mr)) ||
1499 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001500 return -EIO;
1501 else
1502 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001503}
1504
1505static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1506{
Doug Maxey508d2b52008-01-31 20:20:49 -06001507 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001508
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001509 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001510 if (!q_skba->arr)
1511 return -ENOMEM;
1512
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001513 q_skba->len = max_q_entries;
1514 q_skba->index = 0;
1515 q_skba->os_skbs = 0;
1516
1517 return 0;
1518}
1519
1520static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1521 struct port_res_cfg *pr_cfg, int queue_token)
1522{
1523 struct ehea_adapter *adapter = port->adapter;
1524 enum ehea_eq_type eq_type = EHEA_EQ;
1525 struct ehea_qp_init_attr *init_attr = NULL;
1526 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001527 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1528
1529 tx_bytes = pr->tx_bytes;
1530 tx_packets = pr->tx_packets;
1531 rx_bytes = pr->rx_bytes;
1532 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001533
1534 memset(pr, 0, sizeof(struct ehea_port_res));
1535
Breno Leitaoce45b872010-10-27 08:45:14 +00001536 pr->tx_bytes = rx_bytes;
1537 pr->tx_packets = tx_packets;
1538 pr->rx_bytes = rx_bytes;
1539 pr->rx_packets = rx_packets;
1540
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001541 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001542 spin_lock_init(&pr->xmit_lock);
1543 spin_lock_init(&pr->netif_queue);
1544
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001545 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1546 if (!pr->eq) {
David S. Millercfa969e2010-12-06 20:45:28 -08001547 ehea_error("create_eq failed (eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001548 goto out_free;
1549 }
1550
1551 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001552 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001553 port->logical_port_id);
1554 if (!pr->recv_cq) {
David S. Millercfa969e2010-12-06 20:45:28 -08001555 ehea_error("create_cq failed (cq_recv)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001556 goto out_free;
1557 }
1558
1559 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001560 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001561 port->logical_port_id);
1562 if (!pr->send_cq) {
David S. Millercfa969e2010-12-06 20:45:28 -08001563 ehea_error("create_cq failed (cq_send)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001564 goto out_free;
1565 }
1566
1567 if (netif_msg_ifup(port))
David S. Millercfa969e2010-12-06 20:45:28 -08001568 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1569 pr->send_cq->attr.act_nr_of_cqes,
1570 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001571
1572 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1573 if (!init_attr) {
1574 ret = -ENOMEM;
David S. Millercfa969e2010-12-06 20:45:28 -08001575 ehea_error("no mem for ehea_qp_init_attr");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001576 goto out_free;
1577 }
1578
1579 init_attr->low_lat_rq1 = 1;
1580 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1581 init_attr->rq_count = 3;
1582 init_attr->qp_token = queue_token;
1583 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1584 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1585 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1586 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1587 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1588 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1589 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1590 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1591 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1592 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1593 init_attr->port_nr = port->logical_port_id;
1594 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1595 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1596 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1597
1598 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1599 if (!pr->qp) {
David S. Millercfa969e2010-12-06 20:45:28 -08001600 ehea_error("create_qp failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001601 ret = -EIO;
1602 goto out_free;
1603 }
1604
1605 if (netif_msg_ifup(port))
David S. Millercfa969e2010-12-06 20:45:28 -08001606 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1607 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1608 init_attr->act_nr_send_wqes,
1609 init_attr->act_nr_rwqes_rq1,
1610 init_attr->act_nr_rwqes_rq2,
1611 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001612
Thomas Klein44fb3122008-04-04 15:04:53 +02001613 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1614
1615 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001616 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1617 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1618 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1619 if (ret)
1620 goto out_free;
1621
1622 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1623 if (ehea_gen_smrs(pr) != 0) {
1624 ret = -EIO;
1625 goto out_free;
1626 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001627
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001628 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1629
1630 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001631
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001632 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001633
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001634 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1635 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1636 pr->lro_mgr.lro_arr = pr->lro_desc;
1637 pr->lro_mgr.get_skb_header = get_skb_hdr;
1638 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1639 pr->lro_mgr.dev = port->netdev;
1640 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1641 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1642
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001643 ret = 0;
1644 goto out;
1645
1646out_free:
1647 kfree(init_attr);
1648 vfree(pr->sq_skba.arr);
1649 vfree(pr->rq1_skba.arr);
1650 vfree(pr->rq2_skba.arr);
1651 vfree(pr->rq3_skba.arr);
1652 ehea_destroy_qp(pr->qp);
1653 ehea_destroy_cq(pr->send_cq);
1654 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001655 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001656out:
1657 return ret;
1658}
1659
1660static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1661{
1662 int ret, i;
1663
Hannes Hering357eb462009-08-04 11:48:39 -07001664 if (pr->qp)
1665 netif_napi_del(&pr->napi);
1666
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001667 ret = ehea_destroy_qp(pr->qp);
1668
1669 if (!ret) {
1670 ehea_destroy_cq(pr->send_cq);
1671 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001672 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001673
1674 for (i = 0; i < pr->rq1_skba.len; i++)
1675 if (pr->rq1_skba.arr[i])
1676 dev_kfree_skb(pr->rq1_skba.arr[i]);
1677
1678 for (i = 0; i < pr->rq2_skba.len; i++)
1679 if (pr->rq2_skba.arr[i])
1680 dev_kfree_skb(pr->rq2_skba.arr[i]);
1681
1682 for (i = 0; i < pr->rq3_skba.len; i++)
1683 if (pr->rq3_skba.arr[i])
1684 dev_kfree_skb(pr->rq3_skba.arr[i]);
1685
1686 for (i = 0; i < pr->sq_skba.len; i++)
1687 if (pr->sq_skba.arr[i])
1688 dev_kfree_skb(pr->sq_skba.arr[i]);
1689
1690 vfree(pr->rq1_skba.arr);
1691 vfree(pr->rq2_skba.arr);
1692 vfree(pr->rq3_skba.arr);
1693 vfree(pr->sq_skba.arr);
1694 ret = ehea_rem_smrs(pr);
1695 }
1696 return ret;
1697}
1698
1699/*
1700 * The write_* functions store information in swqe which is used by
1701 * the hardware to calculate the ip/tcp/udp checksum
1702 */
1703
1704static inline void write_ip_start_end(struct ehea_swqe *swqe,
1705 const struct sk_buff *skb)
1706{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001707 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001708 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001709}
1710
1711static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1712 const struct sk_buff *skb)
1713{
1714 swqe->tcp_offset =
1715 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1716
1717 swqe->tcp_end = (u16)skb->len - 1;
1718}
1719
1720static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1721 const struct sk_buff *skb)
1722{
1723 swqe->tcp_offset =
1724 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1725
1726 swqe->tcp_end = (u16)skb->len - 1;
1727}
1728
1729
1730static void write_swqe2_TSO(struct sk_buff *skb,
1731 struct ehea_swqe *swqe, u32 lkey)
1732{
1733 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1734 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001735 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001736 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001737
1738 /* Packet is TCP with TSO enabled */
1739 swqe->tx_control |= EHEA_SWQE_TSO;
1740 swqe->mss = skb_shinfo(skb)->gso_size;
1741 /* copy only eth/ip/tcp headers to immediate data and
1742 * the rest of skb->data to sg1entry
1743 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001744 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001745
Eric Dumazete743d312010-04-14 15:59:40 -07001746 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001747
1748 if (skb_data_size >= headersize) {
1749 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001750 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001751 swqe->immediate_data_length = headersize;
1752
1753 if (skb_data_size > headersize) {
1754 /* set sg1entry data */
1755 sg1entry->l_key = lkey;
1756 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001757 sg1entry->vaddr =
1758 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001759 swqe->descriptors++;
1760 }
1761 } else
David S. Millercfa969e2010-12-06 20:45:28 -08001762 ehea_error("cannot handle fragmented headers");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001763}
1764
1765static void write_swqe2_nonTSO(struct sk_buff *skb,
1766 struct ehea_swqe *swqe, u32 lkey)
1767{
Eric Dumazete743d312010-04-14 15:59:40 -07001768 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001769 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1770 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001771
1772 /* Packet is any nonTSO type
1773 *
1774 * Copy as much as possible skb->data to immediate data and
1775 * the rest to sg1entry
1776 */
1777 if (skb_data_size >= SWQE2_MAX_IMM) {
1778 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001779 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001780
1781 swqe->immediate_data_length = SWQE2_MAX_IMM;
1782
1783 if (skb_data_size > SWQE2_MAX_IMM) {
1784 /* copy sg1entry data */
1785 sg1entry->l_key = lkey;
1786 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001787 sg1entry->vaddr =
1788 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001789 swqe->descriptors++;
1790 }
1791 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001792 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001793 swqe->immediate_data_length = skb_data_size;
1794 }
1795}
1796
1797static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1798 struct ehea_swqe *swqe, u32 lkey)
1799{
1800 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1801 skb_frag_t *frag;
1802 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001803
1804 nfrags = skb_shinfo(skb)->nr_frags;
1805 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001806 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001807 swqe->descriptors = 0;
1808 sg1entry_contains_frag_data = 0;
1809
1810 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1811 write_swqe2_TSO(skb, swqe, lkey);
1812 else
1813 write_swqe2_nonTSO(skb, swqe, lkey);
1814
1815 /* write descriptors */
1816 if (nfrags > 0) {
1817 if (swqe->descriptors == 0) {
1818 /* sg1entry not yet used */
1819 frag = &skb_shinfo(skb)->frags[0];
1820
1821 /* copy sg1entry data */
1822 sg1entry->l_key = lkey;
1823 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001824 sg1entry->vaddr =
1825 ehea_map_vaddr(page_address(frag->page)
1826 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001827 swqe->descriptors++;
1828 sg1entry_contains_frag_data = 1;
1829 }
1830
1831 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1832
1833 frag = &skb_shinfo(skb)->frags[i];
1834 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1835
1836 sgentry->l_key = lkey;
1837 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001838 sgentry->vaddr =
1839 ehea_map_vaddr(page_address(frag->page)
1840 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001841 swqe->descriptors++;
1842 }
1843 }
1844}
1845
1846static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1847{
1848 int ret = 0;
1849 u64 hret;
1850 u8 reg_type;
1851
1852 /* De/Register untagged packets */
1853 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1854 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1855 port->logical_port_id,
1856 reg_type, port->mac_addr, 0, hcallid);
1857 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08001858 ehea_error("%sregistering bc address failed (tagged)",
1859 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001860 ret = -EIO;
1861 goto out_herr;
1862 }
1863
1864 /* De/Register VLAN packets */
1865 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1866 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1867 port->logical_port_id,
1868 reg_type, port->mac_addr, 0, hcallid);
1869 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08001870 ehea_error("%sregistering bc address failed (vlan)",
1871 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001872 ret = -EIO;
1873 }
1874out_herr:
1875 return ret;
1876}
1877
1878static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1879{
1880 struct ehea_port *port = netdev_priv(dev);
1881 struct sockaddr *mac_addr = sa;
1882 struct hcp_ehea_port_cb0 *cb0;
1883 int ret;
1884 u64 hret;
1885
1886 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1887 ret = -EADDRNOTAVAIL;
1888 goto out;
1889 }
1890
Thomas Klein3faf2692009-01-21 14:45:33 -08001891 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001892 if (!cb0) {
David S. Millercfa969e2010-12-06 20:45:28 -08001893 ehea_error("no mem for cb0");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001894 ret = -ENOMEM;
1895 goto out;
1896 }
1897
1898 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1899
1900 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1901
1902 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1903 port->logical_port_id, H_PORT_CB0,
1904 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1905 if (hret != H_SUCCESS) {
1906 ret = -EIO;
1907 goto out_free;
1908 }
1909
1910 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1911
1912 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001913 if (port->state == EHEA_PORT_UP) {
1914 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1915 if (ret)
1916 goto out_upregs;
1917 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001918
1919 port->mac_addr = cb0->port_mac_addr << 16;
1920
1921 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001922 if (port->state == EHEA_PORT_UP) {
1923 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1924 if (ret)
1925 goto out_upregs;
1926 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001927
1928 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001929
1930out_upregs:
1931 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001932out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001933 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001934out:
1935 return ret;
1936}
1937
1938static void ehea_promiscuous_error(u64 hret, int enable)
1939{
Thomas Klein7674a582007-01-22 12:54:20 +01001940 if (hret == H_AUTHORITY)
David S. Millercfa969e2010-12-06 20:45:28 -08001941 ehea_info("Hypervisor denied %sabling promiscuous mode",
1942 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001943 else
David S. Millercfa969e2010-12-06 20:45:28 -08001944 ehea_error("failed %sabling promiscuous mode",
1945 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001946}
1947
1948static void ehea_promiscuous(struct net_device *dev, int enable)
1949{
1950 struct ehea_port *port = netdev_priv(dev);
1951 struct hcp_ehea_port_cb7 *cb7;
1952 u64 hret;
1953
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001954 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001955 return;
1956
Thomas Klein3faf2692009-01-21 14:45:33 -08001957 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001958 if (!cb7) {
David S. Millercfa969e2010-12-06 20:45:28 -08001959 ehea_error("no mem for cb7");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001960 goto out;
1961 }
1962
1963 /* Modify Pxs_DUCQPN in CB7 */
1964 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1965
1966 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1967 port->logical_port_id,
1968 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1969 if (hret) {
1970 ehea_promiscuous_error(hret, enable);
1971 goto out;
1972 }
1973
1974 port->promisc = enable;
1975out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001976 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001977}
1978
1979static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1980 u32 hcallid)
1981{
1982 u64 hret;
1983 u8 reg_type;
1984
1985 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1986 | EHEA_BCMC_UNTAGGED;
1987
1988 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1989 port->logical_port_id,
1990 reg_type, mc_mac_addr, 0, hcallid);
1991 if (hret)
1992 goto out;
1993
1994 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1995 | EHEA_BCMC_VLANID_ALL;
1996
1997 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1998 port->logical_port_id,
1999 reg_type, mc_mac_addr, 0, hcallid);
2000out:
2001 return hret;
2002}
2003
2004static int ehea_drop_multicast_list(struct net_device *dev)
2005{
2006 struct ehea_port *port = netdev_priv(dev);
2007 struct ehea_mc_list *mc_entry = port->mc_list;
2008 struct list_head *pos;
2009 struct list_head *temp;
2010 int ret = 0;
2011 u64 hret;
2012
2013 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
2014 mc_entry = list_entry(pos, struct ehea_mc_list, list);
2015
2016 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
2017 H_DEREG_BCMC);
2018 if (hret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002019 ehea_error("failed deregistering mcast MAC");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002020 ret = -EIO;
2021 }
2022
2023 list_del(pos);
2024 kfree(mc_entry);
2025 }
2026 return ret;
2027}
2028
2029static void ehea_allmulti(struct net_device *dev, int enable)
2030{
2031 struct ehea_port *port = netdev_priv(dev);
2032 u64 hret;
2033
2034 if (!port->allmulti) {
2035 if (enable) {
2036 /* Enable ALLMULTI */
2037 ehea_drop_multicast_list(dev);
2038 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
2039 if (!hret)
2040 port->allmulti = 1;
2041 else
David S. Millercfa969e2010-12-06 20:45:28 -08002042 ehea_error("failed enabling IFF_ALLMULTI");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002043 }
2044 } else
2045 if (!enable) {
2046 /* Disable ALLMULTI */
2047 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
2048 if (!hret)
2049 port->allmulti = 0;
2050 else
David S. Millercfa969e2010-12-06 20:45:28 -08002051 ehea_error("failed disabling IFF_ALLMULTI");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002052 }
2053}
2054
Doug Maxey508d2b52008-01-31 20:20:49 -06002055static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002056{
2057 struct ehea_mc_list *ehea_mcl_entry;
2058 u64 hret;
2059
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02002060 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002061 if (!ehea_mcl_entry) {
David S. Millercfa969e2010-12-06 20:45:28 -08002062 ehea_error("no mem for mcl_entry");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002063 return;
2064 }
2065
2066 INIT_LIST_HEAD(&ehea_mcl_entry->list);
2067
2068 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
2069
2070 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
2071 H_REG_BCMC);
2072 if (!hret)
2073 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
2074 else {
David S. Millercfa969e2010-12-06 20:45:28 -08002075 ehea_error("failed registering mcast MAC");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002076 kfree(ehea_mcl_entry);
2077 }
2078}
2079
2080static void ehea_set_multicast_list(struct net_device *dev)
2081{
2082 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad2010-04-01 21:22:57 +00002083 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002084 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002085
2086 if (dev->flags & IFF_PROMISC) {
2087 ehea_promiscuous(dev, 1);
2088 return;
2089 }
2090 ehea_promiscuous(dev, 0);
2091
2092 if (dev->flags & IFF_ALLMULTI) {
2093 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002094 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002095 }
2096 ehea_allmulti(dev, 0);
2097
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002098 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002099 ret = ehea_drop_multicast_list(dev);
2100 if (ret) {
2101 /* Dropping the current multicast list failed.
2102 * Enabling ALL_MULTI is the best we can do.
2103 */
2104 ehea_allmulti(dev, 1);
2105 }
2106
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002107 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
David S. Millercfa969e2010-12-06 20:45:28 -08002108 ehea_info("Mcast registration limit reached (0x%llx). "
2109 "Use ALLMULTI!",
2110 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002111 goto out;
2112 }
2113
Jiri Pirko22bedad2010-04-01 21:22:57 +00002114 netdev_for_each_mc_addr(ha, dev)
2115 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002116
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002117 }
2118out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002119 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002120}
2121
2122static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2123{
2124 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2125 return -EINVAL;
2126 dev->mtu = new_mtu;
2127 return 0;
2128}
2129
2130static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2131 struct ehea_swqe *swqe, u32 lkey)
2132{
2133 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002134 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002135
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002136 /* IPv4 */
2137 swqe->tx_control |= EHEA_SWQE_CRC
2138 | EHEA_SWQE_IP_CHECKSUM
2139 | EHEA_SWQE_TCP_CHECKSUM
2140 | EHEA_SWQE_IMM_DATA_PRESENT
2141 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2142
2143 write_ip_start_end(swqe, skb);
2144
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002145 if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002146 if ((iph->frag_off & IP_MF) ||
2147 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002148 /* IP fragment, so don't change cs */
2149 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2150 else
2151 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002152 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002153 write_tcp_offset_end(swqe, skb);
2154 }
2155
2156 /* icmp (big data) and ip segmentation packets (all other ip
2157 packets) do not require any special handling */
2158
2159 } else {
2160 /* Other Ethernet Protocol */
2161 swqe->tx_control |= EHEA_SWQE_CRC
2162 | EHEA_SWQE_IMM_DATA_PRESENT
2163 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2164 }
2165
2166 write_swqe2_data(skb, dev, swqe, lkey);
2167}
2168
2169static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2170 struct ehea_swqe *swqe)
2171{
2172 int nfrags = skb_shinfo(skb)->nr_frags;
2173 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2174 skb_frag_t *frag;
2175 int i;
2176
2177 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002178 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002179
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002180 /* IPv4 */
2181 write_ip_start_end(swqe, skb);
2182
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002183 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002184 swqe->tx_control |= EHEA_SWQE_CRC
2185 | EHEA_SWQE_IP_CHECKSUM
2186 | EHEA_SWQE_TCP_CHECKSUM
2187 | EHEA_SWQE_IMM_DATA_PRESENT;
2188
2189 write_tcp_offset_end(swqe, skb);
2190
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002191 } else if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002192 if ((iph->frag_off & IP_MF) ||
2193 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002194 /* IP fragment, so don't change cs */
2195 swqe->tx_control |= EHEA_SWQE_CRC
2196 | EHEA_SWQE_IMM_DATA_PRESENT;
2197 else {
2198 swqe->tx_control |= EHEA_SWQE_CRC
2199 | EHEA_SWQE_IP_CHECKSUM
2200 | EHEA_SWQE_TCP_CHECKSUM
2201 | EHEA_SWQE_IMM_DATA_PRESENT;
2202
2203 write_udp_offset_end(swqe, skb);
2204 }
2205 } else {
2206 /* icmp (big data) and
2207 ip segmentation packets (all other ip packets) */
2208 swqe->tx_control |= EHEA_SWQE_CRC
2209 | EHEA_SWQE_IP_CHECKSUM
2210 | EHEA_SWQE_IMM_DATA_PRESENT;
2211 }
2212 } else {
2213 /* Other Ethernet Protocol */
2214 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2215 }
2216 /* copy (immediate) data */
2217 if (nfrags == 0) {
2218 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002219 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002220 } else {
2221 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002222 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002223 skb_headlen(skb));
2224 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002225
2226 /* ... then copy data from the fragments */
2227 for (i = 0; i < nfrags; i++) {
2228 frag = &skb_shinfo(skb)->frags[i];
2229 memcpy(imm_data,
2230 page_address(frag->page) + frag->page_offset,
2231 frag->size);
2232 imm_data += frag->size;
2233 }
2234 }
2235 swqe->immediate_data_length = skb->len;
2236 dev_kfree_skb(skb);
2237}
2238
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002239static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2240{
2241 struct tcphdr *tcp;
2242 u32 tmp;
2243
2244 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002245 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002246 tcp = (struct tcphdr *)(skb_network_header(skb) +
2247 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002248 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002249 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002250 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002251 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002252 return 0;
2253}
2254
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002255static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2256{
2257 struct ehea_port *port = netdev_priv(dev);
2258 struct ehea_swqe *swqe;
2259 unsigned long flags;
2260 u32 lkey;
2261 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002262 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002263
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002264 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2265
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002266 if (!spin_trylock(&pr->xmit_lock))
2267 return NETDEV_TX_BUSY;
2268
2269 if (pr->queue_stopped) {
2270 spin_unlock(&pr->xmit_lock);
2271 return NETDEV_TX_BUSY;
2272 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002273
2274 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2275 memset(swqe, 0, SWQE_HEADER_SIZE);
2276 atomic_dec(&pr->swqe_avail);
2277
Eric Dumazete5ccd962010-10-26 19:21:07 +00002278 if (vlan_tx_tag_present(skb)) {
2279 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2280 swqe->vlan_tag = vlan_tx_tag_get(skb);
2281 }
2282
Breno Leitaoce45b872010-10-27 08:45:14 +00002283 pr->tx_packets++;
2284 pr->tx_bytes += skb->len;
2285
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002286 if (skb->len <= SWQE3_MAX_IMM) {
2287 u32 sig_iv = port->sig_comp_iv;
2288 u32 swqe_num = pr->swqe_id_counter;
2289 ehea_xmit3(skb, dev, swqe);
2290 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2291 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2292 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2293 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2294 sig_iv);
2295 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2296 pr->swqe_ll_count = 0;
2297 } else
2298 pr->swqe_ll_count += 1;
2299 } else {
2300 swqe->wr_id =
2301 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2302 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002303 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002304 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2305 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2306
2307 pr->sq_skba.index++;
2308 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2309
2310 lkey = pr->send_mr.lkey;
2311 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002312 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002313 }
2314 pr->swqe_id_counter += 1;
2315
David S. Millercfa969e2010-12-06 20:45:28 -08002316 if (netif_msg_tx_queued(port)) {
2317 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002318 ehea_dump(swqe, 512, "swqe");
David S. Millercfa969e2010-12-06 20:45:28 -08002319 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002320
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002321 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2322 netif_stop_queue(dev);
2323 swqe->tx_control |= EHEA_SWQE_PURGE;
2324 }
Thomas Klein44c82152007-07-11 16:32:00 +02002325
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002326 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002327
2328 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2329 spin_lock_irqsave(&pr->netif_queue, flags);
2330 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002331 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002332 netif_stop_queue(dev);
2333 pr->queue_stopped = 1;
2334 }
2335 spin_unlock_irqrestore(&pr->netif_queue, flags);
2336 }
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07002337 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002338 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002339
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002340 return NETDEV_TX_OK;
2341}
2342
2343static void ehea_vlan_rx_register(struct net_device *dev,
2344 struct vlan_group *grp)
2345{
2346 struct ehea_port *port = netdev_priv(dev);
2347 struct ehea_adapter *adapter = port->adapter;
2348 struct hcp_ehea_port_cb1 *cb1;
2349 u64 hret;
2350
2351 port->vgrp = grp;
2352
Thomas Klein3faf2692009-01-21 14:45:33 -08002353 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002354 if (!cb1) {
David S. Millercfa969e2010-12-06 20:45:28 -08002355 ehea_error("no mem for cb1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002356 goto out;
2357 }
2358
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002359 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2360 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2361 if (hret != H_SUCCESS)
David S. Millercfa969e2010-12-06 20:45:28 -08002362 ehea_error("modify_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002363
Thomas Klein3faf2692009-01-21 14:45:33 -08002364 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002365out:
2366 return;
2367}
2368
2369static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2370{
2371 struct ehea_port *port = netdev_priv(dev);
2372 struct ehea_adapter *adapter = port->adapter;
2373 struct hcp_ehea_port_cb1 *cb1;
2374 int index;
2375 u64 hret;
2376
Thomas Klein3faf2692009-01-21 14:45:33 -08002377 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002378 if (!cb1) {
David S. Millercfa969e2010-12-06 20:45:28 -08002379 ehea_error("no mem for cb1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002380 goto out;
2381 }
2382
2383 hret = ehea_h_query_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("query_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002387 goto out;
2388 }
2389
2390 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002391 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002392
2393 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2394 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2395 if (hret != H_SUCCESS)
David S. Millercfa969e2010-12-06 20:45:28 -08002396 ehea_error("modify_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002397out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002398 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002399 return;
2400}
2401
2402static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2403{
2404 struct ehea_port *port = netdev_priv(dev);
2405 struct ehea_adapter *adapter = port->adapter;
2406 struct hcp_ehea_port_cb1 *cb1;
2407 int index;
2408 u64 hret;
2409
Dan Aloni5c15bde2007-03-02 20:44:51 -08002410 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002411
Thomas Klein3faf2692009-01-21 14:45:33 -08002412 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002413 if (!cb1) {
David S. Millercfa969e2010-12-06 20:45:28 -08002414 ehea_error("no mem for cb1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002415 goto out;
2416 }
2417
2418 hret = ehea_h_query_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("query_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002422 goto out;
2423 }
2424
2425 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002426 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002427
2428 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2429 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2430 if (hret != H_SUCCESS)
David S. Millercfa969e2010-12-06 20:45:28 -08002431 ehea_error("modify_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002432out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002433 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002434}
2435
2436int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2437{
2438 int ret = -EIO;
2439 u64 hret;
2440 u16 dummy16 = 0;
2441 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002442 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002443
Thomas Klein3faf2692009-01-21 14:45:33 -08002444 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002445 if (!cb0) {
2446 ret = -ENOMEM;
2447 goto out;
2448 }
2449
2450 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2451 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2452 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002453 ehea_error("query_ehea_qp failed (1)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002454 goto out;
2455 }
2456
2457 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2458 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2459 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2460 &dummy64, &dummy64, &dummy16, &dummy16);
2461 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002462 ehea_error("modify_ehea_qp failed (1)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002463 goto out;
2464 }
2465
2466 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2467 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2468 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002469 ehea_error("query_ehea_qp failed (2)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002470 goto out;
2471 }
2472
2473 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2474 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2475 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2476 &dummy64, &dummy64, &dummy16, &dummy16);
2477 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002478 ehea_error("modify_ehea_qp failed (2)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002479 goto out;
2480 }
2481
2482 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2483 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2484 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002485 ehea_error("query_ehea_qp failed (3)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002486 goto out;
2487 }
2488
2489 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2490 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2491 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2492 &dummy64, &dummy64, &dummy16, &dummy16);
2493 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002494 ehea_error("modify_ehea_qp failed (3)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002495 goto out;
2496 }
2497
2498 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2499 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2500 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002501 ehea_error("query_ehea_qp failed (4)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002502 goto out;
2503 }
2504
2505 ret = 0;
2506out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002507 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002508 return ret;
2509}
2510
2511static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2512 int add_tx_qps)
2513{
2514 int ret, i;
2515 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2516 enum ehea_eq_type eq_type = EHEA_EQ;
2517
2518 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2519 EHEA_MAX_ENTRIES_EQ, 1);
2520 if (!port->qp_eq) {
2521 ret = -EINVAL;
David S. Millercfa969e2010-12-06 20:45:28 -08002522 ehea_error("ehea_create_eq failed (qp_eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002523 goto out_kill_eq;
2524 }
2525
2526 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002527 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002528 pr_cfg.max_entries_sq = sq_entries;
2529 pr_cfg.max_entries_rq1 = rq1_entries;
2530 pr_cfg.max_entries_rq2 = rq2_entries;
2531 pr_cfg.max_entries_rq3 = rq3_entries;
2532
2533 pr_cfg_small_rx.max_entries_rcq = 1;
2534 pr_cfg_small_rx.max_entries_scq = sq_entries;
2535 pr_cfg_small_rx.max_entries_sq = sq_entries;
2536 pr_cfg_small_rx.max_entries_rq1 = 1;
2537 pr_cfg_small_rx.max_entries_rq2 = 1;
2538 pr_cfg_small_rx.max_entries_rq3 = 1;
2539
2540 for (i = 0; i < def_qps; i++) {
2541 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2542 if (ret)
2543 goto out_clean_pr;
2544 }
2545 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2546 ret = ehea_init_port_res(port, &port->port_res[i],
2547 &pr_cfg_small_rx, i);
2548 if (ret)
2549 goto out_clean_pr;
2550 }
2551
2552 return 0;
2553
2554out_clean_pr:
2555 while (--i >= 0)
2556 ehea_clean_portres(port, &port->port_res[i]);
2557
2558out_kill_eq:
2559 ehea_destroy_eq(port->qp_eq);
2560 return ret;
2561}
2562
2563static int ehea_clean_all_portres(struct ehea_port *port)
2564{
2565 int ret = 0;
2566 int i;
2567
Doug Maxey508d2b52008-01-31 20:20:49 -06002568 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002569 ret |= ehea_clean_portres(port, &port->port_res[i]);
2570
2571 ret |= ehea_destroy_eq(port->qp_eq);
2572
2573 return ret;
2574}
2575
Thomas Klein35cf2e22007-08-06 13:55:14 +02002576static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002577{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002578 if (adapter->active_ports)
2579 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002580
2581 ehea_rem_mr(&adapter->mr);
2582}
2583
Thomas Klein35cf2e22007-08-06 13:55:14 +02002584static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002585{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002586 if (adapter->active_ports)
2587 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002588
2589 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2590}
2591
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002592static int ehea_up(struct net_device *dev)
2593{
2594 int ret, i;
2595 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002596
2597 if (port->state == EHEA_PORT_UP)
2598 return 0;
2599
2600 ret = ehea_port_res_setup(port, port->num_def_qps,
2601 port->num_add_tx_qps);
2602 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002603 ehea_error("port_res_failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002604 goto out;
2605 }
2606
2607 /* Set default QP for this port */
2608 ret = ehea_configure_port(port);
2609 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002610 ehea_error("ehea_configure_port failed. ret:%d", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002611 goto out_clean_pr;
2612 }
2613
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002614 ret = ehea_reg_interrupts(dev);
2615 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002616 ehea_error("reg_interrupts failed. ret:%d", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002617 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002618 }
2619
Doug Maxey508d2b52008-01-31 20:20:49 -06002620 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002621 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2622 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002623 ehea_error("activate_qp failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002624 goto out_free_irqs;
2625 }
2626 }
2627
Doug Maxey508d2b52008-01-31 20:20:49 -06002628 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002629 ret = ehea_fill_port_res(&port->port_res[i]);
2630 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002631 ehea_error("out_free_irqs");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002632 goto out_free_irqs;
2633 }
2634 }
2635
Thomas Klein21eee2d2008-02-13 16:18:33 +01002636 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2637 if (ret) {
2638 ret = -EIO;
2639 goto out_free_irqs;
2640 }
2641
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002642 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002643
2644 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002645 goto out;
2646
2647out_free_irqs:
2648 ehea_free_interrupts(dev);
2649
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002650out_clean_pr:
2651 ehea_clean_all_portres(port);
2652out:
Thomas Klein44c82152007-07-11 16:32:00 +02002653 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08002654 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002655
Thomas Klein21eee2d2008-02-13 16:18:33 +01002656 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002657 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002658
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002659 return ret;
2660}
2661
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002662static void port_napi_disable(struct ehea_port *port)
2663{
2664 int i;
2665
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002666 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002667 napi_disable(&port->port_res[i].napi);
2668}
2669
2670static void port_napi_enable(struct ehea_port *port)
2671{
2672 int i;
2673
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002674 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002675 napi_enable(&port->port_res[i].napi);
2676}
2677
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002678static int ehea_open(struct net_device *dev)
2679{
2680 int ret;
2681 struct ehea_port *port = netdev_priv(dev);
2682
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002683 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002684
David S. Millercfa969e2010-12-06 20:45:28 -08002685 if (netif_msg_ifup(port))
2686 ehea_info("enabling port %s", dev->name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002687
2688 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002689 if (!ret) {
2690 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002691 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002692 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002693
Breno Leitao5b27d422010-10-05 13:16:22 +00002694 init_waitqueue_head(&port->swqe_avail_wq);
Breno Leitaoa8bb69f2010-10-05 13:16:23 +00002695 init_waitqueue_head(&port->restart_wq);
Breno Leitao5b27d422010-10-05 13:16:22 +00002696
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002697 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002698
2699 return ret;
2700}
2701
2702static int ehea_down(struct net_device *dev)
2703{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002704 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002705 struct ehea_port *port = netdev_priv(dev);
2706
2707 if (port->state == EHEA_PORT_DOWN)
2708 return 0;
2709
2710 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002711 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2712
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002713 ehea_free_interrupts(dev);
2714
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002715 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002716
Thomas Klein21eee2d2008-02-13 16:18:33 +01002717 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002718
Thomas Klein44c82152007-07-11 16:32:00 +02002719 ret = ehea_clean_all_portres(port);
2720 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08002721 ehea_info("Failed freeing resources for %s. ret=%i",
2722 dev->name, ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002723
Thomas Klein21eee2d2008-02-13 16:18:33 +01002724 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002725
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002726 return ret;
2727}
2728
2729static int ehea_stop(struct net_device *dev)
2730{
2731 int ret;
2732 struct ehea_port *port = netdev_priv(dev);
2733
David S. Millercfa969e2010-12-06 20:45:28 -08002734 if (netif_msg_ifdown(port))
2735 ehea_info("disabling port %s", dev->name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002736
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002737 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002738 cancel_work_sync(&port->reset_task);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002739 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002740 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002741 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002742 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002743 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002744 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002745 return ret;
2746}
2747
Andrew Morton22559c52008-04-18 13:50:39 -07002748static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002749{
2750 struct ehea_qp qp = *orig_qp;
2751 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2752 struct ehea_swqe *swqe;
2753 int wqe_index;
2754 int i;
2755
2756 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2757 swqe = ehea_get_swqe(&qp, &wqe_index);
2758 swqe->tx_control |= EHEA_SWQE_PURGE;
2759 }
2760}
2761
Andrew Morton22559c52008-04-18 13:50:39 -07002762static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002763{
2764 int i;
2765
2766 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2767 struct ehea_port_res *pr = &port->port_res[i];
2768 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002769 int ret;
2770
2771 ret = wait_event_timeout(port->swqe_avail_wq,
2772 atomic_read(&pr->swqe_avail) >= swqe_max,
2773 msecs_to_jiffies(100));
2774
2775 if (!ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002776 ehea_error("WARNING: sq not flushed completely");
Breno Leitao5b27d422010-10-05 13:16:22 +00002777 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002778 }
2779 }
2780}
2781
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002782int ehea_stop_qps(struct net_device *dev)
2783{
2784 struct ehea_port *port = netdev_priv(dev);
2785 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002786 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002787 int ret = -EIO;
2788 int dret;
2789 int i;
2790 u64 hret;
2791 u64 dummy64 = 0;
2792 u16 dummy16 = 0;
2793
Thomas Klein3faf2692009-01-21 14:45:33 -08002794 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002795 if (!cb0) {
2796 ret = -ENOMEM;
2797 goto out;
2798 }
2799
2800 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2801 struct ehea_port_res *pr = &port->port_res[i];
2802 struct ehea_qp *qp = pr->qp;
2803
2804 /* Purge send queue */
2805 ehea_purge_sq(qp);
2806
2807 /* Disable queue pair */
2808 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2809 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2810 cb0);
2811 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002812 ehea_error("query_ehea_qp failed (1)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002813 goto out;
2814 }
2815
2816 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2817 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2818
2819 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2820 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2821 1), cb0, &dummy64,
2822 &dummy64, &dummy16, &dummy16);
2823 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002824 ehea_error("modify_ehea_qp failed (1)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002825 goto out;
2826 }
2827
2828 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2829 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2830 cb0);
2831 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002832 ehea_error("query_ehea_qp failed (2)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002833 goto out;
2834 }
2835
2836 /* deregister shared memory regions */
2837 dret = ehea_rem_smrs(pr);
2838 if (dret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002839 ehea_error("unreg shared memory region failed");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002840 goto out;
2841 }
2842 }
2843
2844 ret = 0;
2845out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002846 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002847
2848 return ret;
2849}
2850
Doug Maxey508d2b52008-01-31 20:20:49 -06002851void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002852{
2853 struct ehea_qp qp = *orig_qp;
2854 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2855 struct ehea_rwqe *rwqe;
2856 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2857 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2858 struct sk_buff *skb;
2859 u32 lkey = pr->recv_mr.lkey;
2860
2861
2862 int i;
2863 int index;
2864
2865 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2866 rwqe = ehea_get_next_rwqe(&qp, 2);
2867 rwqe->sg_list[0].l_key = lkey;
2868 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2869 skb = skba_rq2[index];
2870 if (skb)
2871 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2872 }
2873
2874 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2875 rwqe = ehea_get_next_rwqe(&qp, 3);
2876 rwqe->sg_list[0].l_key = lkey;
2877 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2878 skb = skba_rq3[index];
2879 if (skb)
2880 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2881 }
2882}
2883
2884int ehea_restart_qps(struct net_device *dev)
2885{
2886 struct ehea_port *port = netdev_priv(dev);
2887 struct ehea_adapter *adapter = port->adapter;
2888 int ret = 0;
2889 int i;
2890
Doug Maxey508d2b52008-01-31 20:20:49 -06002891 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002892 u64 hret;
2893 u64 dummy64 = 0;
2894 u16 dummy16 = 0;
2895
Thomas Klein3faf2692009-01-21 14:45:33 -08002896 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002897 if (!cb0) {
2898 ret = -ENOMEM;
2899 goto out;
2900 }
2901
2902 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2903 struct ehea_port_res *pr = &port->port_res[i];
2904 struct ehea_qp *qp = pr->qp;
2905
2906 ret = ehea_gen_smrs(pr);
2907 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002908 ehea_error("creation of shared memory regions failed");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002909 goto out;
2910 }
2911
2912 ehea_update_rqs(qp, pr);
2913
2914 /* Enable queue pair */
2915 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2916 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2917 cb0);
2918 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002919 ehea_error("query_ehea_qp failed (1)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002920 goto out;
2921 }
2922
2923 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2924 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2925
2926 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2927 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2928 1), cb0, &dummy64,
2929 &dummy64, &dummy16, &dummy16);
2930 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002931 ehea_error("modify_ehea_qp failed (1)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002932 goto out;
2933 }
2934
2935 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2936 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2937 cb0);
2938 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002939 ehea_error("query_ehea_qp failed (2)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002940 goto out;
2941 }
2942
2943 /* refill entire queue */
2944 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2945 ehea_refill_rq2(pr, 0);
2946 ehea_refill_rq3(pr, 0);
2947 }
2948out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002949 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002950
2951 return ret;
2952}
2953
David Howellsc4028952006-11-22 14:57:56 +00002954static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002955{
2956 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002957 struct ehea_port *port =
2958 container_of(work, struct ehea_port, reset_task);
2959 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002960
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002961 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002962 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002963 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002964 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002965
2966 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002967
Thomas Klein44c82152007-07-11 16:32:00 +02002968 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002969
2970 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002971 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002972 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002973
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002974 ehea_set_multicast_list(dev);
2975
David S. Millercfa969e2010-12-06 20:45:28 -08002976 if (netif_msg_timer(port))
2977 ehea_info("Device %s resetted successfully", dev->name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002978
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002979 port_napi_enable(port);
2980
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002981 netif_wake_queue(dev);
2982out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002983 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002984 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002985}
2986
Thomas Klein44c82152007-07-11 16:32:00 +02002987static void ehea_rereg_mrs(struct work_struct *work)
2988{
2989 int ret, i;
2990 struct ehea_adapter *adapter;
2991
David S. Millercfa969e2010-12-06 20:45:28 -08002992 ehea_info("LPAR memory changed - re-initializing driver");
Thomas Klein44c82152007-07-11 16:32:00 +02002993
2994 list_for_each_entry(adapter, &adapter_list, list)
2995 if (adapter->active_ports) {
2996 /* Shutdown all ports */
2997 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2998 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002999 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02003000
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003001 if (!port)
3002 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02003003
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003004 dev = port->netdev;
3005
3006 if (dev->flags & IFF_UP) {
3007 mutex_lock(&port->port_lock);
3008 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07003009 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003010 ret = ehea_stop_qps(dev);
3011 if (ret) {
3012 mutex_unlock(&port->port_lock);
3013 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003014 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003015 port_napi_disable(port);
3016 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003017 }
Andre Detsch2928db42010-08-17 05:49:12 +00003018 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02003019 }
3020
3021 /* Unregister old memory region */
3022 ret = ehea_rem_mr(&adapter->mr);
3023 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003024 ehea_error("unregister MR failed - driver"
3025 " inoperable!");
Thomas Klein44c82152007-07-11 16:32:00 +02003026 goto out;
3027 }
3028 }
3029
Thomas Klein44c82152007-07-11 16:32:00 +02003030 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
3031
3032 list_for_each_entry(adapter, &adapter_list, list)
3033 if (adapter->active_ports) {
3034 /* Register new memory region */
3035 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
3036 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003037 ehea_error("register MR failed - driver"
3038 " inoperable!");
Thomas Klein44c82152007-07-11 16:32:00 +02003039 goto out;
3040 }
3041
3042 /* Restart all ports */
3043 for (i = 0; i < EHEA_MAX_PORTS; i++) {
3044 struct ehea_port *port = adapter->port[i];
3045
3046 if (port) {
3047 struct net_device *dev = port->netdev;
3048
3049 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003050 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003051 port_napi_enable(port);
3052 ret = ehea_restart_qps(dev);
Andre Detsch2928db42010-08-17 05:49:12 +00003053 check_sqs(port);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003054 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02003055 netif_wake_queue(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003056 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003057 }
3058 }
3059 }
3060 }
David S. Millercfa969e2010-12-06 20:45:28 -08003061 ehea_info("re-initializing driver complete");
Thomas Klein44c82152007-07-11 16:32:00 +02003062out:
3063 return;
3064}
3065
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003066static void ehea_tx_watchdog(struct net_device *dev)
3067{
3068 struct ehea_port *port = netdev_priv(dev);
3069
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003070 if (netif_carrier_ok(dev) &&
3071 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01003072 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003073}
3074
3075int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
3076{
3077 struct hcp_query_ehea *cb;
3078 u64 hret;
3079 int ret;
3080
Thomas Klein3faf2692009-01-21 14:45:33 -08003081 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003082 if (!cb) {
3083 ret = -ENOMEM;
3084 goto out;
3085 }
3086
3087 hret = ehea_h_query_ehea(adapter->handle, cb);
3088
3089 if (hret != H_SUCCESS) {
3090 ret = -EIO;
3091 goto out_herr;
3092 }
3093
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003094 adapter->max_mc_mac = cb->max_mc_mac - 1;
3095 ret = 0;
3096
3097out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08003098 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003099out:
3100 return ret;
3101}
3102
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003103int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
3104{
3105 struct hcp_ehea_port_cb4 *cb4;
3106 u64 hret;
3107 int ret = 0;
3108
3109 *jumbo = 0;
3110
3111 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08003112 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003113 if (!cb4) {
David S. Millercfa969e2010-12-06 20:45:28 -08003114 ehea_error("no mem for cb4");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003115 ret = -ENOMEM;
3116 goto out;
3117 } else {
3118 hret = ehea_h_query_ehea_port(port->adapter->handle,
3119 port->logical_port_id,
3120 H_PORT_CB4,
3121 H_PORT_CB4_JUMBO, cb4);
3122 if (hret == H_SUCCESS) {
3123 if (cb4->jumbo_frame)
3124 *jumbo = 1;
3125 else {
3126 cb4->jumbo_frame = 1;
3127 hret = ehea_h_modify_ehea_port(port->adapter->
3128 handle,
3129 port->
3130 logical_port_id,
3131 H_PORT_CB4,
3132 H_PORT_CB4_JUMBO,
3133 cb4);
3134 if (hret == H_SUCCESS)
3135 *jumbo = 1;
3136 }
3137 } else
3138 ret = -EINVAL;
3139
Thomas Klein3faf2692009-01-21 14:45:33 -08003140 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003141 }
3142out:
3143 return ret;
3144}
3145
3146static ssize_t ehea_show_port_id(struct device *dev,
3147 struct device_attribute *attr, char *buf)
3148{
3149 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003150 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003151}
3152
3153static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3154 NULL);
3155
3156static void __devinit logical_port_release(struct device *dev)
3157{
3158 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07003159 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003160}
3161
3162static struct device *ehea_register_port(struct ehea_port *port,
3163 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003164{
3165 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003166
Grant Likely61c7a082010-04-13 16:12:29 -07003167 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003168 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003169 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003170
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003171 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003172 port->ofdev.dev.release = logical_port_release;
3173
3174 ret = of_device_register(&port->ofdev);
3175 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003176 ehea_error("failed to register device. ret=%d", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003177 goto out;
3178 }
3179
3180 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003181 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003182 ehea_error("failed to register attributes, ret=%d", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003183 goto out_unreg_of_dev;
3184 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003185
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003186 return &port->ofdev.dev;
3187
3188out_unreg_of_dev:
3189 of_device_unregister(&port->ofdev);
3190out:
3191 return NULL;
3192}
3193
3194static void ehea_unregister_port(struct ehea_port *port)
3195{
3196 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3197 of_device_unregister(&port->ofdev);
3198}
3199
Thomas Klein086c1b22009-01-21 14:43:59 -08003200static const struct net_device_ops ehea_netdev_ops = {
3201 .ndo_open = ehea_open,
3202 .ndo_stop = ehea_stop,
3203 .ndo_start_xmit = ehea_start_xmit,
3204#ifdef CONFIG_NET_POLL_CONTROLLER
3205 .ndo_poll_controller = ehea_netpoll,
3206#endif
3207 .ndo_get_stats = ehea_get_stats,
3208 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003209 .ndo_validate_addr = eth_validate_addr,
Thomas Klein086c1b22009-01-21 14:43:59 -08003210 .ndo_set_multicast_list = ehea_set_multicast_list,
3211 .ndo_change_mtu = ehea_change_mtu,
3212 .ndo_vlan_rx_register = ehea_vlan_rx_register,
3213 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003214 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3215 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003216};
3217
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003218struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3219 u32 logical_port_id,
3220 struct device_node *dn)
3221{
3222 int ret;
3223 struct net_device *dev;
3224 struct ehea_port *port;
3225 struct device *port_dev;
3226 int jumbo;
3227
3228 /* allocate memory for the port structures */
3229 dev = alloc_etherdev(sizeof(struct ehea_port));
3230
3231 if (!dev) {
David S. Millercfa969e2010-12-06 20:45:28 -08003232 ehea_error("no mem for net_device");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003233 ret = -ENOMEM;
3234 goto out_err;
3235 }
3236
3237 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003238
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003239 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003240 port->state = EHEA_PORT_DOWN;
3241 port->sig_comp_iv = sq_entries / 10;
3242
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003243 port->adapter = adapter;
3244 port->netdev = dev;
3245 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003246
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003247 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003248
3249 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3250 if (!port->mc_list) {
3251 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003252 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003253 }
3254
3255 INIT_LIST_HEAD(&port->mc_list->list);
3256
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003257 ret = ehea_sense_port_attr(port);
3258 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003259 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003260
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003261 port_dev = ehea_register_port(port, dn);
3262 if (!port_dev)
3263 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003264
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003265 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003266
3267 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003268 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3269
Thomas Klein086c1b22009-01-21 14:43:59 -08003270 dev->netdev_ops = &ehea_netdev_ops;
3271 ehea_set_ethtool_ops(dev);
3272
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003273 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003274 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003275 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3276 | NETIF_F_LLTX;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003277 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3278
Breno Leitaoc7757fd2010-12-08 12:19:14 -08003279 if (use_lro)
3280 dev->features |= NETIF_F_LRO;
3281
David Howellsc4028952006-11-22 14:57:56 +00003282 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003283
3284 ret = register_netdev(dev);
3285 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003286 ehea_error("register_netdev failed. ret=%d", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003287 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003288 }
3289
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003290 port->lro_max_aggr = lro_max_aggr;
3291
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003292 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003293 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08003294 ehea_error("failed determining jumbo frame status for %s",
3295 port->netdev->name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003296
David S. Millercfa969e2010-12-06 20:45:28 -08003297 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3298 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003299
Thomas Klein44c82152007-07-11 16:32:00 +02003300 adapter->active_ports++;
3301
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003302 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003303
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003304out_unreg_port:
3305 ehea_unregister_port(port);
3306
3307out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003308 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003309
3310out_free_ethdev:
3311 free_netdev(dev);
3312
3313out_err:
David S. Millercfa969e2010-12-06 20:45:28 -08003314 ehea_error("setting up logical port with id=%d failed, ret=%d",
3315 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003316 return NULL;
3317}
3318
3319static void ehea_shutdown_single_port(struct ehea_port *port)
3320{
Brian King7fb1c2a2008-05-14 09:48:25 -05003321 struct ehea_adapter *adapter = port->adapter;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003322 unregister_netdev(port->netdev);
3323 ehea_unregister_port(port);
3324 kfree(port->mc_list);
3325 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003326 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003327}
3328
3329static int ehea_setup_ports(struct ehea_adapter *adapter)
3330{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003331 struct device_node *lhea_dn;
3332 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003333
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003334 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003335 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003336
Grant Likely61c7a082010-04-13 16:12:29 -07003337 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003338 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003339
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003340 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003341 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003342 if (!dn_log_port_id) {
David S. Millercfa969e2010-12-06 20:45:28 -08003343 ehea_error("bad device node: eth_dn name=%s",
3344 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003345 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003346 }
3347
Thomas Klein1211bb62007-04-26 11:56:43 +02003348 if (ehea_add_adapter_mr(adapter)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003349 ehea_error("creating MR failed");
Thomas Klein1211bb62007-04-26 11:56:43 +02003350 of_node_put(eth_dn);
3351 return -EIO;
3352 }
3353
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003354 adapter->port[i] = ehea_setup_single_port(adapter,
3355 *dn_log_port_id,
3356 eth_dn);
3357 if (adapter->port[i])
David S. Millercfa969e2010-12-06 20:45:28 -08003358 ehea_info("%s -> logical port id #%d",
3359 adapter->port[i]->netdev->name,
3360 *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003361 else
3362 ehea_remove_adapter_mr(adapter);
3363
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003364 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003365 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003366 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003367}
3368
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003369static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3370 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003371{
3372 struct device_node *lhea_dn;
3373 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003374 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003375
Grant Likely61c7a082010-04-13 16:12:29 -07003376 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003377 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003378
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003379 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003380 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003381 if (dn_log_port_id)
3382 if (*dn_log_port_id == logical_port_id)
3383 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003384 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003385
3386 return NULL;
3387}
3388
3389static ssize_t ehea_probe_port(struct device *dev,
3390 struct device_attribute *attr,
3391 const char *buf, size_t count)
3392{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003393 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003394 struct ehea_port *port;
3395 struct device_node *eth_dn = NULL;
3396 int i;
3397
3398 u32 logical_port_id;
3399
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003400 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003401
3402 port = ehea_get_port(adapter, logical_port_id);
3403
3404 if (port) {
David S. Millercfa969e2010-12-06 20:45:28 -08003405 ehea_info("adding port with logical port id=%d failed. port "
3406 "already configured as %s.", logical_port_id,
3407 port->netdev->name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003408 return -EINVAL;
3409 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003410
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003411 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3412
3413 if (!eth_dn) {
David S. Millercfa969e2010-12-06 20:45:28 -08003414 ehea_info("no logical port with id %d found", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003415 return -EINVAL;
3416 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003417
Thomas Klein1211bb62007-04-26 11:56:43 +02003418 if (ehea_add_adapter_mr(adapter)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003419 ehea_error("creating MR failed");
Thomas Klein1211bb62007-04-26 11:56:43 +02003420 return -EIO;
3421 }
3422
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003423 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3424
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003425 of_node_put(eth_dn);
3426
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003427 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003428 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003429 if (!adapter->port[i]) {
3430 adapter->port[i] = port;
3431 break;
3432 }
3433
David S. Millercfa969e2010-12-06 20:45:28 -08003434 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3435 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003436 } else {
3437 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003438 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003439 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003440
3441 return (ssize_t) count;
3442}
3443
3444static ssize_t ehea_remove_port(struct device *dev,
3445 struct device_attribute *attr,
3446 const char *buf, size_t count)
3447{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003448 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003449 struct ehea_port *port;
3450 int i;
3451 u32 logical_port_id;
3452
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003453 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003454
3455 port = ehea_get_port(adapter, logical_port_id);
3456
3457 if (port) {
David S. Millercfa969e2010-12-06 20:45:28 -08003458 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3459 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003460
3461 ehea_shutdown_single_port(port);
3462
Doug Maxey508d2b52008-01-31 20:20:49 -06003463 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003464 if (adapter->port[i] == port) {
3465 adapter->port[i] = NULL;
3466 break;
3467 }
3468 } else {
David S. Millercfa969e2010-12-06 20:45:28 -08003469 ehea_error("removing port with logical port id=%d failed. port "
3470 "not configured.", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003471 return -EINVAL;
3472 }
3473
Thomas Klein1211bb62007-04-26 11:56:43 +02003474 ehea_remove_adapter_mr(adapter);
3475
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003476 return (ssize_t) count;
3477}
3478
3479static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3480static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3481
Grant Likely2dc11582010-08-06 09:25:50 -06003482int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003483{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003484 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003485 if (ret)
3486 goto out;
3487
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003488 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003489out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003490 return ret;
3491}
3492
Grant Likely2dc11582010-08-06 09:25:50 -06003493void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003494{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003495 device_remove_file(&dev->dev, &dev_attr_probe_port);
3496 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003497}
3498
Grant Likely2dc11582010-08-06 09:25:50 -06003499static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003500 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003501{
3502 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003503 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003504 int ret;
3505
Grant Likely61c7a082010-04-13 16:12:29 -07003506 if (!dev || !dev->dev.of_node) {
David S. Millercfa969e2010-12-06 20:45:28 -08003507 ehea_error("Invalid ibmebus device probed");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003508 return -EINVAL;
3509 }
3510
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003511 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3512 if (!adapter) {
3513 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003514 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003515 goto out;
3516 }
3517
Thomas Klein44c82152007-07-11 16:32:00 +02003518 list_add(&adapter->list, &adapter_list);
3519
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003520 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003521
Grant Likely61c7a082010-04-13 16:12:29 -07003522 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003523 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003524 if (adapter_handle)
3525 adapter->handle = *adapter_handle;
3526
3527 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003528 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003529 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003530 ret = -ENODEV;
3531 goto out_free_ad;
3532 }
3533
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003534 adapter->pd = EHEA_PD_ID;
3535
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003536 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003537
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003538
3539 /* initialize adapter and ports */
3540 /* get adapter properties */
3541 ret = ehea_sense_adapter_attr(adapter);
3542 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003543 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003544 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003545 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003546
3547 adapter->neq = ehea_create_eq(adapter,
3548 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3549 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003550 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003551 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003552 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003553 }
3554
3555 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3556 (unsigned long)adapter);
3557
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003558 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003559 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003560 "ehea_neq", adapter);
3561 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003562 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003563 goto out_kill_eq;
3564 }
3565
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003566 ret = ehea_create_device_sysfs(dev);
3567 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003568 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003569
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003570 ret = ehea_setup_ports(adapter);
3571 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003572 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003573 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003574 }
3575
3576 ret = 0;
3577 goto out;
3578
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003579out_rem_dev_sysfs:
3580 ehea_remove_device_sysfs(dev);
3581
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003582out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003583 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003584
3585out_kill_eq:
3586 ehea_destroy_eq(adapter->neq);
3587
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003588out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003589 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003590 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003591
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003592out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003593 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003594
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003595 return ret;
3596}
3597
Grant Likely2dc11582010-08-06 09:25:50 -06003598static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003599{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003600 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003601 int i;
3602
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003603 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003604 if (adapter->port[i]) {
3605 ehea_shutdown_single_port(adapter->port[i]);
3606 adapter->port[i] = NULL;
3607 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003608
3609 ehea_remove_device_sysfs(dev);
3610
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003611 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003612
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003613 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003614 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003615
3616 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003617 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003618 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003619 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003620
Thomas Klein21eee2d2008-02-13 16:18:33 +01003621 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003622
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003623 return 0;
3624}
3625
Thomas Klein21eee2d2008-02-13 16:18:33 +01003626void ehea_crash_handler(void)
3627{
3628 int i;
3629
3630 if (ehea_fw_handles.arr)
3631 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3632 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3633 ehea_fw_handles.arr[i].fwh,
3634 FORCE_FREE);
3635
3636 if (ehea_bcmc_regs.arr)
3637 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3638 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3639 ehea_bcmc_regs.arr[i].port_id,
3640 ehea_bcmc_regs.arr[i].reg_type,
3641 ehea_bcmc_regs.arr[i].macaddr,
3642 0, H_DEREG_BCMC);
3643}
3644
Hannes Hering48cfb142008-05-07 14:43:36 +02003645static int ehea_mem_notifier(struct notifier_block *nb,
3646 unsigned long action, void *data)
3647{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003648 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003649 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003650
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003651 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003652
Hannes Hering48cfb142008-05-07 14:43:36 +02003653 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003654 case MEM_CANCEL_OFFLINE:
David S. Millercfa969e2010-12-06 20:45:28 -08003655 ehea_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003656 /* Readd canceled memory block */
3657 case MEM_ONLINE:
David S. Millercfa969e2010-12-06 20:45:28 -08003658 ehea_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003659 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003660 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003661 goto out_unlock;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003662 ehea_rereg_mrs(NULL);
3663 break;
3664 case MEM_GOING_OFFLINE:
David S. Millercfa969e2010-12-06 20:45:28 -08003665 ehea_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003666 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003667 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003668 goto out_unlock;
Hannes Hering48cfb142008-05-07 14:43:36 +02003669 ehea_rereg_mrs(NULL);
3670 break;
3671 default:
3672 break;
3673 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003674
3675 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003676 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003677
Thomas Kleina7c561f22010-04-20 23:11:31 +00003678out_unlock:
3679 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003680 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003681}
3682
3683static struct notifier_block ehea_mem_nb = {
3684 .notifier_call = ehea_mem_notifier,
3685};
3686
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003687static int ehea_reboot_notifier(struct notifier_block *nb,
3688 unsigned long action, void *unused)
3689{
3690 if (action == SYS_RESTART) {
David S. Millercfa969e2010-12-06 20:45:28 -08003691 ehea_info("Reboot: freeing all eHEA resources");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003692 ibmebus_unregister_driver(&ehea_driver);
3693 }
3694 return NOTIFY_DONE;
3695}
3696
3697static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003698 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003699};
3700
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003701static int check_module_parm(void)
3702{
3703 int ret = 0;
3704
3705 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3706 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003707 ehea_info("Bad parameter: rq1_entries");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003708 ret = -EINVAL;
3709 }
3710 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3711 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003712 ehea_info("Bad parameter: rq2_entries");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003713 ret = -EINVAL;
3714 }
3715 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3716 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003717 ehea_info("Bad parameter: rq3_entries");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003718 ret = -EINVAL;
3719 }
3720 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3721 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003722 ehea_info("Bad parameter: sq_entries");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003723 ret = -EINVAL;
3724 }
3725
3726 return ret;
3727}
3728
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003729static ssize_t ehea_show_capabilities(struct device_driver *drv,
3730 char *buf)
3731{
3732 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3733}
3734
3735static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3736 ehea_show_capabilities, NULL);
3737
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003738int __init ehea_module_init(void)
3739{
3740 int ret;
3741
David S. Millercfa969e2010-12-06 20:45:28 -08003742 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3743 DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003744
Thomas Klein44c82152007-07-11 16:32:00 +02003745
3746 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003747 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3748 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3749
Daniel Walker9f71a562008-03-28 14:41:26 -07003750 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003751 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003752
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003753 ret = check_module_parm();
3754 if (ret)
3755 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003756
3757 ret = ehea_create_busmap();
3758 if (ret)
3759 goto out;
3760
Thomas Klein21eee2d2008-02-13 16:18:33 +01003761 ret = register_reboot_notifier(&ehea_reboot_nb);
3762 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08003763 ehea_info("failed registering reboot notifier");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003764
Hannes Hering48cfb142008-05-07 14:43:36 +02003765 ret = register_memory_notifier(&ehea_mem_nb);
3766 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08003767 ehea_info("failed registering memory remove notifier");
Hannes Hering48cfb142008-05-07 14:43:36 +02003768
Joe Perchesc061b182010-08-23 18:20:03 +00003769 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003770 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08003771 ehea_info("failed registering crash handler");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003772
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003773 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003774 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003775 ehea_error("failed registering eHEA device driver on ebus");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003776 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003777 }
3778
3779 ret = driver_create_file(&ehea_driver.driver,
3780 &driver_attr_capabilities);
3781 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003782 ehea_error("failed to register capabilities attribute, ret=%d",
3783 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003784 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003785 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003786
Thomas Klein21eee2d2008-02-13 16:18:33 +01003787 return ret;
3788
3789out3:
3790 ibmebus_unregister_driver(&ehea_driver);
3791out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003792 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003793 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003794 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003795out:
3796 return ret;
3797}
3798
3799static void __exit ehea_module_exit(void)
3800{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003801 int ret;
3802
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003803 flush_scheduled_work();
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003804 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003805 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003806 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003807 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003808 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08003809 ehea_info("failed unregistering crash handler");
Hannes Hering48cfb142008-05-07 14:43:36 +02003810 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003811 kfree(ehea_fw_handles.arr);
3812 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003813 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003814}
3815
3816module_init(ehea_module_init);
3817module_exit(ehea_module_exit);