blob: b95f087cd5a9c4a51525718e90ba65b56cf81b99 [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) {
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000139 printk(DRV_NAME " %s adr=%p ofs=%04x %016llx %016llx\n", msg,
Doug Maxey508d2b52008-01-31 20:20:49 -0600140 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) {
340 ehea_error("no mem for cb2");
341 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) {
348 ehea_error("query_ehea_port failed");
349 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) {
472 ehea_info("%s: rq%i ran dry - no mem for skb",
473 pr->port->netdev->name, rq_nr);
474 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)) {
638 ehea_error("Critical receive error for QP %d. "
639 "Resetting port.", pr->qp->init_attr.qp_nr);
640 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)) {
741 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)) {
759 if (netif_msg_rx_err(port))
760 ehea_error("rq2: skb=NULL");
761 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)) {
770 if (netif_msg_rx_err(port))
771 ehea_error("rq3: skb=NULL");
772 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) {
843 ehea_error("HW/SW queues out of sync");
844 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) {
Thomas Kleinea96cea2010-04-20 23:10:55 +0000876 ehea_error("Bad send completion status=0x%04X",
877 cqe->status);
878
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) {
883 ehea_error("Resetting port");
884 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);
Stephen Rothwella1c5a892009-01-06 14:40:06 +00001001 ehea_error("QP aff_err: entry=0x%llx, token=0x%x",
Thomas Kleinbb3a6442007-01-22 12:54:50 +01001002 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) {
1020 ehea_error("Resetting port");
1021 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) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001048 ehea_error("no mem for cb0");
1049 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) {
1140 ehea_error("no mem for cb4");
1141 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 {
1191 ehea_error("Failed sensing port speed");
1192 ret = -EIO;
1193 }
1194 } else {
1195 if (hret == H_AUTHORITY) {
Thomas Klein7674a582007-01-22 12:54:20 +01001196 ehea_info("Hypervisor denied setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001197 ret = -EPERM;
1198 } else {
1199 ret = -EIO;
1200 ehea_error("Failed setting port speed");
1201 }
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) {
1226 ehea_error("unknown portnum %x", portnum);
1227 break;
1228 }
1229
1230 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
1231 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) {
1234 ehea_error("failed resensing port "
1235 "attributes");
1236 break;
1237 }
1238
1239 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");
1246
1247 netif_carrier_on(port->netdev);
1248 netif_wake_queue(port->netdev);
1249 }
1250 } else
1251 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);
1257 }
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;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001261 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)
1265 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;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001268 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)
1272 netif_carrier_off(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001273 }
1274
1275 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
1276 ehea_info("External switch port is primary port");
1277 else
1278 ehea_info("External switch port is backup port");
1279
1280 break;
1281 case EHEA_EC_ADAPTER_MALFUNC:
1282 ehea_error("Adapter malfunction");
1283 break;
1284 case EHEA_EC_PORT_MALFUNC:
1285 ehea_info("Port malfunction: Device: %s", port->netdev->name);
1286 netif_carrier_off(port->netdev);
1287 netif_stop_queue(port->netdev);
1288 break;
1289 default:
Stephen Rothwella1c5a892009-01-06 14:40:06 +00001290 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);
1302 ehea_debug("eqe=%p", eqe);
1303
1304 while (eqe) {
1305 ehea_debug("*eqe=%lx", eqe->entry);
1306 ehea_parse_eqe(adapter, eqe->entry);
1307 eqe = ehea_poll_eq(adapter->neq);
1308 ehea_debug("next eqe=%p", eqe);
1309 }
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) {
1357 ehea_error("failed registering irq for qp_aff_irq_handler:"
1358 "ist=%X", port->qp_eq->attr.ist1);
1359 goto out_free_qpeq;
1360 }
1361
1362 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);
1365
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) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001376 ehea_error("failed registering irq for ehea_queue "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001377 "port_res_nr:%d, ist=%X", i,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001378 pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001379 goto out_free_req;
1380 }
1381 if (netif_msg_ifup(port))
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001382 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);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001414 if (netif_msg_intr(port))
1415 ehea_info("free send irq for res %d with handle 0x%X",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001416 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);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001421 if (netif_msg_intr(port))
1422 ehea_info("associated event interrupt for handle 0x%X freed",
1423 port->qp_eq->attr.ist1);
1424}
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:
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001492 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
1509 q_skba->arr = vmalloc(arr_size);
1510 if (!q_skba->arr)
1511 return -ENOMEM;
1512
1513 memset(q_skba->arr, 0, arr_size);
1514
1515 q_skba->len = max_q_entries;
1516 q_skba->index = 0;
1517 q_skba->os_skbs = 0;
1518
1519 return 0;
1520}
1521
1522static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1523 struct port_res_cfg *pr_cfg, int queue_token)
1524{
1525 struct ehea_adapter *adapter = port->adapter;
1526 enum ehea_eq_type eq_type = EHEA_EQ;
1527 struct ehea_qp_init_attr *init_attr = NULL;
1528 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001529 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1530
1531 tx_bytes = pr->tx_bytes;
1532 tx_packets = pr->tx_packets;
1533 rx_bytes = pr->rx_bytes;
1534 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001535
1536 memset(pr, 0, sizeof(struct ehea_port_res));
1537
Breno Leitaoce45b872010-10-27 08:45:14 +00001538 pr->tx_bytes = rx_bytes;
1539 pr->tx_packets = tx_packets;
1540 pr->rx_bytes = rx_bytes;
1541 pr->rx_packets = rx_packets;
1542
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001543 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001544 spin_lock_init(&pr->xmit_lock);
1545 spin_lock_init(&pr->netif_queue);
1546
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001547 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1548 if (!pr->eq) {
1549 ehea_error("create_eq failed (eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001550 goto out_free;
1551 }
1552
1553 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001554 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001555 port->logical_port_id);
1556 if (!pr->recv_cq) {
1557 ehea_error("create_cq failed (cq_recv)");
1558 goto out_free;
1559 }
1560
1561 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001562 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001563 port->logical_port_id);
1564 if (!pr->send_cq) {
1565 ehea_error("create_cq failed (cq_send)");
1566 goto out_free;
1567 }
1568
1569 if (netif_msg_ifup(port))
1570 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1571 pr->send_cq->attr.act_nr_of_cqes,
1572 pr->recv_cq->attr.act_nr_of_cqes);
1573
1574 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1575 if (!init_attr) {
1576 ret = -ENOMEM;
1577 ehea_error("no mem for ehea_qp_init_attr");
1578 goto out_free;
1579 }
1580
1581 init_attr->low_lat_rq1 = 1;
1582 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1583 init_attr->rq_count = 3;
1584 init_attr->qp_token = queue_token;
1585 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1586 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1587 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1588 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1589 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1590 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1591 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1592 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1593 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1594 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1595 init_attr->port_nr = port->logical_port_id;
1596 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1597 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1598 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1599
1600 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1601 if (!pr->qp) {
1602 ehea_error("create_qp failed");
1603 ret = -EIO;
1604 goto out_free;
1605 }
1606
1607 if (netif_msg_ifup(port))
1608 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1609 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1610 init_attr->act_nr_send_wqes,
1611 init_attr->act_nr_rwqes_rq1,
1612 init_attr->act_nr_rwqes_rq2,
1613 init_attr->act_nr_rwqes_rq3);
1614
Thomas Klein44fb3122008-04-04 15:04:53 +02001615 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1616
1617 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001618 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1619 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1620 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1621 if (ret)
1622 goto out_free;
1623
1624 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1625 if (ehea_gen_smrs(pr) != 0) {
1626 ret = -EIO;
1627 goto out_free;
1628 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001629
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001630 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1631
1632 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001633
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001634 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001635
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001636 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1637 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1638 pr->lro_mgr.lro_arr = pr->lro_desc;
1639 pr->lro_mgr.get_skb_header = get_skb_hdr;
1640 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1641 pr->lro_mgr.dev = port->netdev;
1642 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1643 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1644
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001645 ret = 0;
1646 goto out;
1647
1648out_free:
1649 kfree(init_attr);
1650 vfree(pr->sq_skba.arr);
1651 vfree(pr->rq1_skba.arr);
1652 vfree(pr->rq2_skba.arr);
1653 vfree(pr->rq3_skba.arr);
1654 ehea_destroy_qp(pr->qp);
1655 ehea_destroy_cq(pr->send_cq);
1656 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001657 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001658out:
1659 return ret;
1660}
1661
1662static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1663{
1664 int ret, i;
1665
Hannes Hering357eb462009-08-04 11:48:39 -07001666 if (pr->qp)
1667 netif_napi_del(&pr->napi);
1668
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001669 ret = ehea_destroy_qp(pr->qp);
1670
1671 if (!ret) {
1672 ehea_destroy_cq(pr->send_cq);
1673 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001674 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001675
1676 for (i = 0; i < pr->rq1_skba.len; i++)
1677 if (pr->rq1_skba.arr[i])
1678 dev_kfree_skb(pr->rq1_skba.arr[i]);
1679
1680 for (i = 0; i < pr->rq2_skba.len; i++)
1681 if (pr->rq2_skba.arr[i])
1682 dev_kfree_skb(pr->rq2_skba.arr[i]);
1683
1684 for (i = 0; i < pr->rq3_skba.len; i++)
1685 if (pr->rq3_skba.arr[i])
1686 dev_kfree_skb(pr->rq3_skba.arr[i]);
1687
1688 for (i = 0; i < pr->sq_skba.len; i++)
1689 if (pr->sq_skba.arr[i])
1690 dev_kfree_skb(pr->sq_skba.arr[i]);
1691
1692 vfree(pr->rq1_skba.arr);
1693 vfree(pr->rq2_skba.arr);
1694 vfree(pr->rq3_skba.arr);
1695 vfree(pr->sq_skba.arr);
1696 ret = ehea_rem_smrs(pr);
1697 }
1698 return ret;
1699}
1700
1701/*
1702 * The write_* functions store information in swqe which is used by
1703 * the hardware to calculate the ip/tcp/udp checksum
1704 */
1705
1706static inline void write_ip_start_end(struct ehea_swqe *swqe,
1707 const struct sk_buff *skb)
1708{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001709 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001710 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001711}
1712
1713static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1714 const struct sk_buff *skb)
1715{
1716 swqe->tcp_offset =
1717 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1718
1719 swqe->tcp_end = (u16)skb->len - 1;
1720}
1721
1722static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1723 const struct sk_buff *skb)
1724{
1725 swqe->tcp_offset =
1726 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1727
1728 swqe->tcp_end = (u16)skb->len - 1;
1729}
1730
1731
1732static void write_swqe2_TSO(struct sk_buff *skb,
1733 struct ehea_swqe *swqe, u32 lkey)
1734{
1735 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1736 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001737 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001738 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001739
1740 /* Packet is TCP with TSO enabled */
1741 swqe->tx_control |= EHEA_SWQE_TSO;
1742 swqe->mss = skb_shinfo(skb)->gso_size;
1743 /* copy only eth/ip/tcp headers to immediate data and
1744 * the rest of skb->data to sg1entry
1745 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001746 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001747
Eric Dumazete743d312010-04-14 15:59:40 -07001748 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001749
1750 if (skb_data_size >= headersize) {
1751 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001752 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001753 swqe->immediate_data_length = headersize;
1754
1755 if (skb_data_size > headersize) {
1756 /* set sg1entry data */
1757 sg1entry->l_key = lkey;
1758 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001759 sg1entry->vaddr =
1760 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001761 swqe->descriptors++;
1762 }
1763 } else
1764 ehea_error("cannot handle fragmented headers");
1765}
1766
1767static void write_swqe2_nonTSO(struct sk_buff *skb,
1768 struct ehea_swqe *swqe, u32 lkey)
1769{
Eric Dumazete743d312010-04-14 15:59:40 -07001770 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001771 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1772 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001773
1774 /* Packet is any nonTSO type
1775 *
1776 * Copy as much as possible skb->data to immediate data and
1777 * the rest to sg1entry
1778 */
1779 if (skb_data_size >= SWQE2_MAX_IMM) {
1780 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001781 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001782
1783 swqe->immediate_data_length = SWQE2_MAX_IMM;
1784
1785 if (skb_data_size > SWQE2_MAX_IMM) {
1786 /* copy sg1entry data */
1787 sg1entry->l_key = lkey;
1788 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001789 sg1entry->vaddr =
1790 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001791 swqe->descriptors++;
1792 }
1793 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001794 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001795 swqe->immediate_data_length = skb_data_size;
1796 }
1797}
1798
1799static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1800 struct ehea_swqe *swqe, u32 lkey)
1801{
1802 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1803 skb_frag_t *frag;
1804 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001805
1806 nfrags = skb_shinfo(skb)->nr_frags;
1807 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001808 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001809 swqe->descriptors = 0;
1810 sg1entry_contains_frag_data = 0;
1811
1812 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1813 write_swqe2_TSO(skb, swqe, lkey);
1814 else
1815 write_swqe2_nonTSO(skb, swqe, lkey);
1816
1817 /* write descriptors */
1818 if (nfrags > 0) {
1819 if (swqe->descriptors == 0) {
1820 /* sg1entry not yet used */
1821 frag = &skb_shinfo(skb)->frags[0];
1822
1823 /* copy sg1entry data */
1824 sg1entry->l_key = lkey;
1825 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001826 sg1entry->vaddr =
1827 ehea_map_vaddr(page_address(frag->page)
1828 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001829 swqe->descriptors++;
1830 sg1entry_contains_frag_data = 1;
1831 }
1832
1833 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1834
1835 frag = &skb_shinfo(skb)->frags[i];
1836 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1837
1838 sgentry->l_key = lkey;
1839 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001840 sgentry->vaddr =
1841 ehea_map_vaddr(page_address(frag->page)
1842 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001843 swqe->descriptors++;
1844 }
1845 }
1846}
1847
1848static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1849{
1850 int ret = 0;
1851 u64 hret;
1852 u8 reg_type;
1853
1854 /* De/Register untagged packets */
1855 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1856 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1857 port->logical_port_id,
1858 reg_type, port->mac_addr, 0, hcallid);
1859 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001860 ehea_error("%sregistering bc address failed (tagged)",
Doug Maxey508d2b52008-01-31 20:20:49 -06001861 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001862 ret = -EIO;
1863 goto out_herr;
1864 }
1865
1866 /* De/Register VLAN packets */
1867 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1868 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1869 port->logical_port_id,
1870 reg_type, port->mac_addr, 0, hcallid);
1871 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001872 ehea_error("%sregistering bc address failed (vlan)",
1873 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001874 ret = -EIO;
1875 }
1876out_herr:
1877 return ret;
1878}
1879
1880static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1881{
1882 struct ehea_port *port = netdev_priv(dev);
1883 struct sockaddr *mac_addr = sa;
1884 struct hcp_ehea_port_cb0 *cb0;
1885 int ret;
1886 u64 hret;
1887
1888 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1889 ret = -EADDRNOTAVAIL;
1890 goto out;
1891 }
1892
Thomas Klein3faf2692009-01-21 14:45:33 -08001893 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001894 if (!cb0) {
1895 ehea_error("no mem for cb0");
1896 ret = -ENOMEM;
1897 goto out;
1898 }
1899
1900 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1901
1902 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1903
1904 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1905 port->logical_port_id, H_PORT_CB0,
1906 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1907 if (hret != H_SUCCESS) {
1908 ret = -EIO;
1909 goto out_free;
1910 }
1911
1912 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1913
1914 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001915 if (port->state == EHEA_PORT_UP) {
1916 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1917 if (ret)
1918 goto out_upregs;
1919 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001920
1921 port->mac_addr = cb0->port_mac_addr << 16;
1922
1923 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001924 if (port->state == EHEA_PORT_UP) {
1925 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1926 if (ret)
1927 goto out_upregs;
1928 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001929
1930 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001931
1932out_upregs:
1933 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001934out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001935 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001936out:
1937 return ret;
1938}
1939
1940static void ehea_promiscuous_error(u64 hret, int enable)
1941{
Thomas Klein7674a582007-01-22 12:54:20 +01001942 if (hret == H_AUTHORITY)
1943 ehea_info("Hypervisor denied %sabling promiscuous mode",
1944 enable == 1 ? "en" : "dis");
1945 else
1946 ehea_error("failed %sabling promiscuous mode",
1947 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001948}
1949
1950static void ehea_promiscuous(struct net_device *dev, int enable)
1951{
1952 struct ehea_port *port = netdev_priv(dev);
1953 struct hcp_ehea_port_cb7 *cb7;
1954 u64 hret;
1955
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001956 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001957 return;
1958
Thomas Klein3faf2692009-01-21 14:45:33 -08001959 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001960 if (!cb7) {
1961 ehea_error("no mem for cb7");
1962 goto out;
1963 }
1964
1965 /* Modify Pxs_DUCQPN in CB7 */
1966 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1967
1968 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1969 port->logical_port_id,
1970 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1971 if (hret) {
1972 ehea_promiscuous_error(hret, enable);
1973 goto out;
1974 }
1975
1976 port->promisc = enable;
1977out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001978 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001979}
1980
1981static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1982 u32 hcallid)
1983{
1984 u64 hret;
1985 u8 reg_type;
1986
1987 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1988 | EHEA_BCMC_UNTAGGED;
1989
1990 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1991 port->logical_port_id,
1992 reg_type, mc_mac_addr, 0, hcallid);
1993 if (hret)
1994 goto out;
1995
1996 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1997 | EHEA_BCMC_VLANID_ALL;
1998
1999 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
2000 port->logical_port_id,
2001 reg_type, mc_mac_addr, 0, hcallid);
2002out:
2003 return hret;
2004}
2005
2006static int ehea_drop_multicast_list(struct net_device *dev)
2007{
2008 struct ehea_port *port = netdev_priv(dev);
2009 struct ehea_mc_list *mc_entry = port->mc_list;
2010 struct list_head *pos;
2011 struct list_head *temp;
2012 int ret = 0;
2013 u64 hret;
2014
2015 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
2016 mc_entry = list_entry(pos, struct ehea_mc_list, list);
2017
2018 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
2019 H_DEREG_BCMC);
2020 if (hret) {
2021 ehea_error("failed deregistering mcast MAC");
2022 ret = -EIO;
2023 }
2024
2025 list_del(pos);
2026 kfree(mc_entry);
2027 }
2028 return ret;
2029}
2030
2031static void ehea_allmulti(struct net_device *dev, int enable)
2032{
2033 struct ehea_port *port = netdev_priv(dev);
2034 u64 hret;
2035
2036 if (!port->allmulti) {
2037 if (enable) {
2038 /* Enable ALLMULTI */
2039 ehea_drop_multicast_list(dev);
2040 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
2041 if (!hret)
2042 port->allmulti = 1;
2043 else
2044 ehea_error("failed enabling IFF_ALLMULTI");
2045 }
2046 } else
2047 if (!enable) {
2048 /* Disable ALLMULTI */
2049 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
2050 if (!hret)
2051 port->allmulti = 0;
2052 else
2053 ehea_error("failed disabling IFF_ALLMULTI");
2054 }
2055}
2056
Doug Maxey508d2b52008-01-31 20:20:49 -06002057static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002058{
2059 struct ehea_mc_list *ehea_mcl_entry;
2060 u64 hret;
2061
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02002062 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002063 if (!ehea_mcl_entry) {
2064 ehea_error("no mem for mcl_entry");
2065 return;
2066 }
2067
2068 INIT_LIST_HEAD(&ehea_mcl_entry->list);
2069
2070 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
2071
2072 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
2073 H_REG_BCMC);
2074 if (!hret)
2075 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
2076 else {
2077 ehea_error("failed registering mcast MAC");
2078 kfree(ehea_mcl_entry);
2079 }
2080}
2081
2082static void ehea_set_multicast_list(struct net_device *dev)
2083{
2084 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00002085 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002086 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002087
2088 if (dev->flags & IFF_PROMISC) {
2089 ehea_promiscuous(dev, 1);
2090 return;
2091 }
2092 ehea_promiscuous(dev, 0);
2093
2094 if (dev->flags & IFF_ALLMULTI) {
2095 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002096 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002097 }
2098 ehea_allmulti(dev, 0);
2099
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002100 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002101 ret = ehea_drop_multicast_list(dev);
2102 if (ret) {
2103 /* Dropping the current multicast list failed.
2104 * Enabling ALL_MULTI is the best we can do.
2105 */
2106 ehea_allmulti(dev, 1);
2107 }
2108
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002109 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Stephen Rothwella1c5a892009-01-06 14:40:06 +00002110 ehea_info("Mcast registration limit reached (0x%llx). "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002111 "Use ALLMULTI!",
2112 port->adapter->max_mc_mac);
2113 goto out;
2114 }
2115
Jiri Pirko22bedad32010-04-01 21:22:57 +00002116 netdev_for_each_mc_addr(ha, dev)
2117 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002118
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002119 }
2120out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002121 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002122}
2123
2124static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2125{
2126 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2127 return -EINVAL;
2128 dev->mtu = new_mtu;
2129 return 0;
2130}
2131
2132static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2133 struct ehea_swqe *swqe, u32 lkey)
2134{
2135 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002136 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002137
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002138 /* IPv4 */
2139 swqe->tx_control |= EHEA_SWQE_CRC
2140 | EHEA_SWQE_IP_CHECKSUM
2141 | EHEA_SWQE_TCP_CHECKSUM
2142 | EHEA_SWQE_IMM_DATA_PRESENT
2143 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2144
2145 write_ip_start_end(swqe, skb);
2146
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002147 if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002148 if ((iph->frag_off & IP_MF) ||
2149 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002150 /* IP fragment, so don't change cs */
2151 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2152 else
2153 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002154 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002155 write_tcp_offset_end(swqe, skb);
2156 }
2157
2158 /* icmp (big data) and ip segmentation packets (all other ip
2159 packets) do not require any special handling */
2160
2161 } else {
2162 /* Other Ethernet Protocol */
2163 swqe->tx_control |= EHEA_SWQE_CRC
2164 | EHEA_SWQE_IMM_DATA_PRESENT
2165 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2166 }
2167
2168 write_swqe2_data(skb, dev, swqe, lkey);
2169}
2170
2171static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2172 struct ehea_swqe *swqe)
2173{
2174 int nfrags = skb_shinfo(skb)->nr_frags;
2175 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2176 skb_frag_t *frag;
2177 int i;
2178
2179 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002180 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002181
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002182 /* IPv4 */
2183 write_ip_start_end(swqe, skb);
2184
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002185 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002186 swqe->tx_control |= EHEA_SWQE_CRC
2187 | EHEA_SWQE_IP_CHECKSUM
2188 | EHEA_SWQE_TCP_CHECKSUM
2189 | EHEA_SWQE_IMM_DATA_PRESENT;
2190
2191 write_tcp_offset_end(swqe, skb);
2192
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002193 } else if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002194 if ((iph->frag_off & IP_MF) ||
2195 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002196 /* IP fragment, so don't change cs */
2197 swqe->tx_control |= EHEA_SWQE_CRC
2198 | EHEA_SWQE_IMM_DATA_PRESENT;
2199 else {
2200 swqe->tx_control |= EHEA_SWQE_CRC
2201 | EHEA_SWQE_IP_CHECKSUM
2202 | EHEA_SWQE_TCP_CHECKSUM
2203 | EHEA_SWQE_IMM_DATA_PRESENT;
2204
2205 write_udp_offset_end(swqe, skb);
2206 }
2207 } else {
2208 /* icmp (big data) and
2209 ip segmentation packets (all other ip packets) */
2210 swqe->tx_control |= EHEA_SWQE_CRC
2211 | EHEA_SWQE_IP_CHECKSUM
2212 | EHEA_SWQE_IMM_DATA_PRESENT;
2213 }
2214 } else {
2215 /* Other Ethernet Protocol */
2216 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2217 }
2218 /* copy (immediate) data */
2219 if (nfrags == 0) {
2220 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002221 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002222 } else {
2223 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002224 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002225 skb_headlen(skb));
2226 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002227
2228 /* ... then copy data from the fragments */
2229 for (i = 0; i < nfrags; i++) {
2230 frag = &skb_shinfo(skb)->frags[i];
2231 memcpy(imm_data,
2232 page_address(frag->page) + frag->page_offset,
2233 frag->size);
2234 imm_data += frag->size;
2235 }
2236 }
2237 swqe->immediate_data_length = skb->len;
2238 dev_kfree_skb(skb);
2239}
2240
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002241static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2242{
2243 struct tcphdr *tcp;
2244 u32 tmp;
2245
2246 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002247 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002248 tcp = (struct tcphdr *)(skb_network_header(skb) +
2249 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002250 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002251 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002252 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002253 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002254 return 0;
2255}
2256
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002257static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2258{
2259 struct ehea_port *port = netdev_priv(dev);
2260 struct ehea_swqe *swqe;
2261 unsigned long flags;
2262 u32 lkey;
2263 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002264 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002265
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002266 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2267
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002268 if (!spin_trylock(&pr->xmit_lock))
2269 return NETDEV_TX_BUSY;
2270
2271 if (pr->queue_stopped) {
2272 spin_unlock(&pr->xmit_lock);
2273 return NETDEV_TX_BUSY;
2274 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002275
2276 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2277 memset(swqe, 0, SWQE_HEADER_SIZE);
2278 atomic_dec(&pr->swqe_avail);
2279
Eric Dumazete5ccd962010-10-26 19:21:07 +00002280 if (vlan_tx_tag_present(skb)) {
2281 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2282 swqe->vlan_tag = vlan_tx_tag_get(skb);
2283 }
2284
Breno Leitaoce45b872010-10-27 08:45:14 +00002285 pr->tx_packets++;
2286 pr->tx_bytes += skb->len;
2287
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002288 if (skb->len <= SWQE3_MAX_IMM) {
2289 u32 sig_iv = port->sig_comp_iv;
2290 u32 swqe_num = pr->swqe_id_counter;
2291 ehea_xmit3(skb, dev, swqe);
2292 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2293 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2294 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2295 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2296 sig_iv);
2297 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2298 pr->swqe_ll_count = 0;
2299 } else
2300 pr->swqe_ll_count += 1;
2301 } else {
2302 swqe->wr_id =
2303 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2304 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002305 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002306 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2307 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2308
2309 pr->sq_skba.index++;
2310 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2311
2312 lkey = pr->send_mr.lkey;
2313 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002314 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002315 }
2316 pr->swqe_id_counter += 1;
2317
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002318 if (netif_msg_tx_queued(port)) {
2319 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002320 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002321 }
2322
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002323 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2324 netif_stop_queue(dev);
2325 swqe->tx_control |= EHEA_SWQE_PURGE;
2326 }
Thomas Klein44c82152007-07-11 16:32:00 +02002327
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002328 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002329
2330 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2331 spin_lock_irqsave(&pr->netif_queue, flags);
2332 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002333 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002334 netif_stop_queue(dev);
2335 pr->queue_stopped = 1;
2336 }
2337 spin_unlock_irqrestore(&pr->netif_queue, flags);
2338 }
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07002339 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002340 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002341
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002342 return NETDEV_TX_OK;
2343}
2344
2345static void ehea_vlan_rx_register(struct net_device *dev,
2346 struct vlan_group *grp)
2347{
2348 struct ehea_port *port = netdev_priv(dev);
2349 struct ehea_adapter *adapter = port->adapter;
2350 struct hcp_ehea_port_cb1 *cb1;
2351 u64 hret;
2352
2353 port->vgrp = grp;
2354
Thomas Klein3faf2692009-01-21 14:45:33 -08002355 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002356 if (!cb1) {
2357 ehea_error("no mem for cb1");
2358 goto out;
2359 }
2360
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002361 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2362 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2363 if (hret != H_SUCCESS)
2364 ehea_error("modify_ehea_port failed");
2365
Thomas Klein3faf2692009-01-21 14:45:33 -08002366 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002367out:
2368 return;
2369}
2370
2371static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2372{
2373 struct ehea_port *port = netdev_priv(dev);
2374 struct ehea_adapter *adapter = port->adapter;
2375 struct hcp_ehea_port_cb1 *cb1;
2376 int index;
2377 u64 hret;
2378
Thomas Klein3faf2692009-01-21 14:45:33 -08002379 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002380 if (!cb1) {
2381 ehea_error("no mem for cb1");
2382 goto out;
2383 }
2384
2385 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2386 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2387 if (hret != H_SUCCESS) {
2388 ehea_error("query_ehea_port failed");
2389 goto out;
2390 }
2391
2392 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002393 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002394
2395 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2396 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2397 if (hret != H_SUCCESS)
2398 ehea_error("modify_ehea_port failed");
2399out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002400 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002401 return;
2402}
2403
2404static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2405{
2406 struct ehea_port *port = netdev_priv(dev);
2407 struct ehea_adapter *adapter = port->adapter;
2408 struct hcp_ehea_port_cb1 *cb1;
2409 int index;
2410 u64 hret;
2411
Dan Aloni5c15bde2007-03-02 20:44:51 -08002412 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002413
Thomas Klein3faf2692009-01-21 14:45:33 -08002414 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002415 if (!cb1) {
2416 ehea_error("no mem for cb1");
2417 goto out;
2418 }
2419
2420 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2421 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2422 if (hret != H_SUCCESS) {
2423 ehea_error("query_ehea_port failed");
2424 goto out;
2425 }
2426
2427 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002428 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002429
2430 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2431 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2432 if (hret != H_SUCCESS)
2433 ehea_error("modify_ehea_port failed");
2434out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002435 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002436}
2437
2438int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2439{
2440 int ret = -EIO;
2441 u64 hret;
2442 u16 dummy16 = 0;
2443 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002444 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002445
Thomas Klein3faf2692009-01-21 14:45:33 -08002446 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002447 if (!cb0) {
2448 ret = -ENOMEM;
2449 goto out;
2450 }
2451
2452 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2453 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2454 if (hret != H_SUCCESS) {
2455 ehea_error("query_ehea_qp failed (1)");
2456 goto out;
2457 }
2458
2459 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2460 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2461 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2462 &dummy64, &dummy64, &dummy16, &dummy16);
2463 if (hret != H_SUCCESS) {
2464 ehea_error("modify_ehea_qp failed (1)");
2465 goto out;
2466 }
2467
2468 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2469 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2470 if (hret != H_SUCCESS) {
2471 ehea_error("query_ehea_qp failed (2)");
2472 goto out;
2473 }
2474
2475 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2476 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2477 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2478 &dummy64, &dummy64, &dummy16, &dummy16);
2479 if (hret != H_SUCCESS) {
2480 ehea_error("modify_ehea_qp failed (2)");
2481 goto out;
2482 }
2483
2484 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2485 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2486 if (hret != H_SUCCESS) {
2487 ehea_error("query_ehea_qp failed (3)");
2488 goto out;
2489 }
2490
2491 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2492 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2493 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2494 &dummy64, &dummy64, &dummy16, &dummy16);
2495 if (hret != H_SUCCESS) {
2496 ehea_error("modify_ehea_qp failed (3)");
2497 goto out;
2498 }
2499
2500 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2501 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2502 if (hret != H_SUCCESS) {
2503 ehea_error("query_ehea_qp failed (4)");
2504 goto out;
2505 }
2506
2507 ret = 0;
2508out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002509 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002510 return ret;
2511}
2512
2513static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2514 int add_tx_qps)
2515{
2516 int ret, i;
2517 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2518 enum ehea_eq_type eq_type = EHEA_EQ;
2519
2520 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2521 EHEA_MAX_ENTRIES_EQ, 1);
2522 if (!port->qp_eq) {
2523 ret = -EINVAL;
2524 ehea_error("ehea_create_eq failed (qp_eq)");
2525 goto out_kill_eq;
2526 }
2527
2528 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002529 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002530 pr_cfg.max_entries_sq = sq_entries;
2531 pr_cfg.max_entries_rq1 = rq1_entries;
2532 pr_cfg.max_entries_rq2 = rq2_entries;
2533 pr_cfg.max_entries_rq3 = rq3_entries;
2534
2535 pr_cfg_small_rx.max_entries_rcq = 1;
2536 pr_cfg_small_rx.max_entries_scq = sq_entries;
2537 pr_cfg_small_rx.max_entries_sq = sq_entries;
2538 pr_cfg_small_rx.max_entries_rq1 = 1;
2539 pr_cfg_small_rx.max_entries_rq2 = 1;
2540 pr_cfg_small_rx.max_entries_rq3 = 1;
2541
2542 for (i = 0; i < def_qps; i++) {
2543 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2544 if (ret)
2545 goto out_clean_pr;
2546 }
2547 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2548 ret = ehea_init_port_res(port, &port->port_res[i],
2549 &pr_cfg_small_rx, i);
2550 if (ret)
2551 goto out_clean_pr;
2552 }
2553
2554 return 0;
2555
2556out_clean_pr:
2557 while (--i >= 0)
2558 ehea_clean_portres(port, &port->port_res[i]);
2559
2560out_kill_eq:
2561 ehea_destroy_eq(port->qp_eq);
2562 return ret;
2563}
2564
2565static int ehea_clean_all_portres(struct ehea_port *port)
2566{
2567 int ret = 0;
2568 int i;
2569
Doug Maxey508d2b52008-01-31 20:20:49 -06002570 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002571 ret |= ehea_clean_portres(port, &port->port_res[i]);
2572
2573 ret |= ehea_destroy_eq(port->qp_eq);
2574
2575 return ret;
2576}
2577
Thomas Klein35cf2e22007-08-06 13:55:14 +02002578static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002579{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002580 if (adapter->active_ports)
2581 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002582
2583 ehea_rem_mr(&adapter->mr);
2584}
2585
Thomas Klein35cf2e22007-08-06 13:55:14 +02002586static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002587{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002588 if (adapter->active_ports)
2589 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002590
2591 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2592}
2593
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002594static int ehea_up(struct net_device *dev)
2595{
2596 int ret, i;
2597 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002598
2599 if (port->state == EHEA_PORT_UP)
2600 return 0;
2601
2602 ret = ehea_port_res_setup(port, port->num_def_qps,
2603 port->num_add_tx_qps);
2604 if (ret) {
2605 ehea_error("port_res_failed");
2606 goto out;
2607 }
2608
2609 /* Set default QP for this port */
2610 ret = ehea_configure_port(port);
2611 if (ret) {
2612 ehea_error("ehea_configure_port failed. ret:%d", ret);
2613 goto out_clean_pr;
2614 }
2615
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002616 ret = ehea_reg_interrupts(dev);
2617 if (ret) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02002618 ehea_error("reg_interrupts failed. ret:%d", ret);
2619 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002620 }
2621
Doug Maxey508d2b52008-01-31 20:20:49 -06002622 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002623 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2624 if (ret) {
2625 ehea_error("activate_qp failed");
2626 goto out_free_irqs;
2627 }
2628 }
2629
Doug Maxey508d2b52008-01-31 20:20:49 -06002630 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002631 ret = ehea_fill_port_res(&port->port_res[i]);
2632 if (ret) {
2633 ehea_error("out_free_irqs");
2634 goto out_free_irqs;
2635 }
2636 }
2637
Thomas Klein21eee2d2008-02-13 16:18:33 +01002638 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2639 if (ret) {
2640 ret = -EIO;
2641 goto out_free_irqs;
2642 }
2643
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002644 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002645
2646 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002647 goto out;
2648
2649out_free_irqs:
2650 ehea_free_interrupts(dev);
2651
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002652out_clean_pr:
2653 ehea_clean_all_portres(port);
2654out:
Thomas Klein44c82152007-07-11 16:32:00 +02002655 if (ret)
2656 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
2657
Thomas Klein21eee2d2008-02-13 16:18:33 +01002658 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002659 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002660
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002661 return ret;
2662}
2663
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002664static void port_napi_disable(struct ehea_port *port)
2665{
2666 int i;
2667
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002668 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002669 napi_disable(&port->port_res[i].napi);
2670}
2671
2672static void port_napi_enable(struct ehea_port *port)
2673{
2674 int i;
2675
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002676 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002677 napi_enable(&port->port_res[i].napi);
2678}
2679
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002680static int ehea_open(struct net_device *dev)
2681{
2682 int ret;
2683 struct ehea_port *port = netdev_priv(dev);
2684
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002685 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002686
2687 if (netif_msg_ifup(port))
2688 ehea_info("enabling port %s", dev->name);
2689
2690 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002691 if (!ret) {
2692 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002693 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002694 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002695
Breno Leitao5b27d422010-10-05 13:16:22 +00002696 init_waitqueue_head(&port->swqe_avail_wq);
Breno Leitaoa8bb69f2010-10-05 13:16:23 +00002697 init_waitqueue_head(&port->restart_wq);
Breno Leitao5b27d422010-10-05 13:16:22 +00002698
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002699 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002700
2701 return ret;
2702}
2703
2704static int ehea_down(struct net_device *dev)
2705{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002706 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002707 struct ehea_port *port = netdev_priv(dev);
2708
2709 if (port->state == EHEA_PORT_DOWN)
2710 return 0;
2711
2712 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002713 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2714
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002715 ehea_free_interrupts(dev);
2716
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002717 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002718
Thomas Klein21eee2d2008-02-13 16:18:33 +01002719 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002720
Thomas Klein44c82152007-07-11 16:32:00 +02002721 ret = ehea_clean_all_portres(port);
2722 if (ret)
2723 ehea_info("Failed freeing resources for %s. ret=%i",
2724 dev->name, ret);
2725
Thomas Klein21eee2d2008-02-13 16:18:33 +01002726 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002727
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002728 return ret;
2729}
2730
2731static int ehea_stop(struct net_device *dev)
2732{
2733 int ret;
2734 struct ehea_port *port = netdev_priv(dev);
2735
2736 if (netif_msg_ifdown(port))
2737 ehea_info("disabling port %s", dev->name);
2738
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002739 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002740 cancel_work_sync(&port->reset_task);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002741 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002742 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002743 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002744 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002745 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002746 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002747 return ret;
2748}
2749
Andrew Morton22559c52008-04-18 13:50:39 -07002750static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002751{
2752 struct ehea_qp qp = *orig_qp;
2753 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2754 struct ehea_swqe *swqe;
2755 int wqe_index;
2756 int i;
2757
2758 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2759 swqe = ehea_get_swqe(&qp, &wqe_index);
2760 swqe->tx_control |= EHEA_SWQE_PURGE;
2761 }
2762}
2763
Andrew Morton22559c52008-04-18 13:50:39 -07002764static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002765{
2766 int i;
2767
2768 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2769 struct ehea_port_res *pr = &port->port_res[i];
2770 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002771 int ret;
2772
2773 ret = wait_event_timeout(port->swqe_avail_wq,
2774 atomic_read(&pr->swqe_avail) >= swqe_max,
2775 msecs_to_jiffies(100));
2776
2777 if (!ret) {
2778 ehea_error("WARNING: sq not flushed completely");
2779 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002780 }
2781 }
2782}
2783
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002784int ehea_stop_qps(struct net_device *dev)
2785{
2786 struct ehea_port *port = netdev_priv(dev);
2787 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002788 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002789 int ret = -EIO;
2790 int dret;
2791 int i;
2792 u64 hret;
2793 u64 dummy64 = 0;
2794 u16 dummy16 = 0;
2795
Thomas Klein3faf2692009-01-21 14:45:33 -08002796 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002797 if (!cb0) {
2798 ret = -ENOMEM;
2799 goto out;
2800 }
2801
2802 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2803 struct ehea_port_res *pr = &port->port_res[i];
2804 struct ehea_qp *qp = pr->qp;
2805
2806 /* Purge send queue */
2807 ehea_purge_sq(qp);
2808
2809 /* Disable queue pair */
2810 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2811 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2812 cb0);
2813 if (hret != H_SUCCESS) {
2814 ehea_error("query_ehea_qp failed (1)");
2815 goto out;
2816 }
2817
2818 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2819 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2820
2821 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2822 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2823 1), cb0, &dummy64,
2824 &dummy64, &dummy16, &dummy16);
2825 if (hret != H_SUCCESS) {
2826 ehea_error("modify_ehea_qp failed (1)");
2827 goto out;
2828 }
2829
2830 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2831 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2832 cb0);
2833 if (hret != H_SUCCESS) {
2834 ehea_error("query_ehea_qp failed (2)");
2835 goto out;
2836 }
2837
2838 /* deregister shared memory regions */
2839 dret = ehea_rem_smrs(pr);
2840 if (dret) {
2841 ehea_error("unreg shared memory region failed");
2842 goto out;
2843 }
2844 }
2845
2846 ret = 0;
2847out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002848 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002849
2850 return ret;
2851}
2852
Doug Maxey508d2b52008-01-31 20:20:49 -06002853void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002854{
2855 struct ehea_qp qp = *orig_qp;
2856 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2857 struct ehea_rwqe *rwqe;
2858 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2859 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2860 struct sk_buff *skb;
2861 u32 lkey = pr->recv_mr.lkey;
2862
2863
2864 int i;
2865 int index;
2866
2867 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2868 rwqe = ehea_get_next_rwqe(&qp, 2);
2869 rwqe->sg_list[0].l_key = lkey;
2870 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2871 skb = skba_rq2[index];
2872 if (skb)
2873 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2874 }
2875
2876 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2877 rwqe = ehea_get_next_rwqe(&qp, 3);
2878 rwqe->sg_list[0].l_key = lkey;
2879 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2880 skb = skba_rq3[index];
2881 if (skb)
2882 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2883 }
2884}
2885
2886int ehea_restart_qps(struct net_device *dev)
2887{
2888 struct ehea_port *port = netdev_priv(dev);
2889 struct ehea_adapter *adapter = port->adapter;
2890 int ret = 0;
2891 int i;
2892
Doug Maxey508d2b52008-01-31 20:20:49 -06002893 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002894 u64 hret;
2895 u64 dummy64 = 0;
2896 u16 dummy16 = 0;
2897
Thomas Klein3faf2692009-01-21 14:45:33 -08002898 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002899 if (!cb0) {
2900 ret = -ENOMEM;
2901 goto out;
2902 }
2903
2904 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2905 struct ehea_port_res *pr = &port->port_res[i];
2906 struct ehea_qp *qp = pr->qp;
2907
2908 ret = ehea_gen_smrs(pr);
2909 if (ret) {
2910 ehea_error("creation of shared memory regions failed");
2911 goto out;
2912 }
2913
2914 ehea_update_rqs(qp, pr);
2915
2916 /* Enable queue pair */
2917 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2918 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2919 cb0);
2920 if (hret != H_SUCCESS) {
2921 ehea_error("query_ehea_qp failed (1)");
2922 goto out;
2923 }
2924
2925 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2926 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2927
2928 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2929 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2930 1), cb0, &dummy64,
2931 &dummy64, &dummy16, &dummy16);
2932 if (hret != H_SUCCESS) {
2933 ehea_error("modify_ehea_qp failed (1)");
2934 goto out;
2935 }
2936
2937 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2938 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2939 cb0);
2940 if (hret != H_SUCCESS) {
2941 ehea_error("query_ehea_qp failed (2)");
2942 goto out;
2943 }
2944
2945 /* refill entire queue */
2946 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2947 ehea_refill_rq2(pr, 0);
2948 ehea_refill_rq3(pr, 0);
2949 }
2950out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002951 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002952
2953 return ret;
2954}
2955
David Howellsc4028952006-11-22 14:57:56 +00002956static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002957{
2958 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002959 struct ehea_port *port =
2960 container_of(work, struct ehea_port, reset_task);
2961 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002962
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002963 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002964 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002965 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002966 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002967
2968 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002969
Thomas Klein44c82152007-07-11 16:32:00 +02002970 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002971
2972 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002973 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002974 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002975
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002976 ehea_set_multicast_list(dev);
2977
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002978 if (netif_msg_timer(port))
2979 ehea_info("Device %s resetted successfully", dev->name);
2980
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002981 port_napi_enable(port);
2982
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002983 netif_wake_queue(dev);
2984out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002985 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002986 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002987}
2988
Thomas Klein44c82152007-07-11 16:32:00 +02002989static void ehea_rereg_mrs(struct work_struct *work)
2990{
2991 int ret, i;
2992 struct ehea_adapter *adapter;
2993
Hannes Heringd4f12da2008-10-16 11:36:42 +02002994 ehea_info("LPAR memory changed - re-initializing driver");
Thomas Klein44c82152007-07-11 16:32:00 +02002995
2996 list_for_each_entry(adapter, &adapter_list, list)
2997 if (adapter->active_ports) {
2998 /* Shutdown all ports */
2999 for (i = 0; i < EHEA_MAX_PORTS; i++) {
3000 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003001 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02003002
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003003 if (!port)
3004 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02003005
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003006 dev = port->netdev;
3007
3008 if (dev->flags & IFF_UP) {
3009 mutex_lock(&port->port_lock);
3010 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07003011 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003012 ret = ehea_stop_qps(dev);
3013 if (ret) {
3014 mutex_unlock(&port->port_lock);
3015 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003016 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003017 port_napi_disable(port);
3018 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003019 }
Andre Detsch2928db42010-08-17 05:49:12 +00003020 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02003021 }
3022
3023 /* Unregister old memory region */
3024 ret = ehea_rem_mr(&adapter->mr);
3025 if (ret) {
3026 ehea_error("unregister MR failed - driver"
3027 " inoperable!");
3028 goto out;
3029 }
3030 }
3031
Thomas Klein44c82152007-07-11 16:32:00 +02003032 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
3033
3034 list_for_each_entry(adapter, &adapter_list, list)
3035 if (adapter->active_ports) {
3036 /* Register new memory region */
3037 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
3038 if (ret) {
3039 ehea_error("register MR failed - driver"
3040 " inoperable!");
3041 goto out;
3042 }
3043
3044 /* Restart all ports */
3045 for (i = 0; i < EHEA_MAX_PORTS; i++) {
3046 struct ehea_port *port = adapter->port[i];
3047
3048 if (port) {
3049 struct net_device *dev = port->netdev;
3050
3051 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003052 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003053 port_napi_enable(port);
3054 ret = ehea_restart_qps(dev);
Andre Detsch2928db42010-08-17 05:49:12 +00003055 check_sqs(port);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003056 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02003057 netif_wake_queue(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003058 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003059 }
3060 }
3061 }
3062 }
Julia Lawall68905eb2008-07-21 09:57:26 +02003063 ehea_info("re-initializing driver complete");
Thomas Klein44c82152007-07-11 16:32:00 +02003064out:
3065 return;
3066}
3067
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003068static void ehea_tx_watchdog(struct net_device *dev)
3069{
3070 struct ehea_port *port = netdev_priv(dev);
3071
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003072 if (netif_carrier_ok(dev) &&
3073 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01003074 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003075}
3076
3077int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
3078{
3079 struct hcp_query_ehea *cb;
3080 u64 hret;
3081 int ret;
3082
Thomas Klein3faf2692009-01-21 14:45:33 -08003083 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003084 if (!cb) {
3085 ret = -ENOMEM;
3086 goto out;
3087 }
3088
3089 hret = ehea_h_query_ehea(adapter->handle, cb);
3090
3091 if (hret != H_SUCCESS) {
3092 ret = -EIO;
3093 goto out_herr;
3094 }
3095
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003096 adapter->max_mc_mac = cb->max_mc_mac - 1;
3097 ret = 0;
3098
3099out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08003100 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003101out:
3102 return ret;
3103}
3104
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003105int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
3106{
3107 struct hcp_ehea_port_cb4 *cb4;
3108 u64 hret;
3109 int ret = 0;
3110
3111 *jumbo = 0;
3112
3113 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08003114 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003115 if (!cb4) {
3116 ehea_error("no mem for cb4");
3117 ret = -ENOMEM;
3118 goto out;
3119 } else {
3120 hret = ehea_h_query_ehea_port(port->adapter->handle,
3121 port->logical_port_id,
3122 H_PORT_CB4,
3123 H_PORT_CB4_JUMBO, cb4);
3124 if (hret == H_SUCCESS) {
3125 if (cb4->jumbo_frame)
3126 *jumbo = 1;
3127 else {
3128 cb4->jumbo_frame = 1;
3129 hret = ehea_h_modify_ehea_port(port->adapter->
3130 handle,
3131 port->
3132 logical_port_id,
3133 H_PORT_CB4,
3134 H_PORT_CB4_JUMBO,
3135 cb4);
3136 if (hret == H_SUCCESS)
3137 *jumbo = 1;
3138 }
3139 } else
3140 ret = -EINVAL;
3141
Thomas Klein3faf2692009-01-21 14:45:33 -08003142 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003143 }
3144out:
3145 return ret;
3146}
3147
3148static ssize_t ehea_show_port_id(struct device *dev,
3149 struct device_attribute *attr, char *buf)
3150{
3151 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003152 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003153}
3154
3155static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3156 NULL);
3157
3158static void __devinit logical_port_release(struct device *dev)
3159{
3160 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07003161 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003162}
3163
3164static struct device *ehea_register_port(struct ehea_port *port,
3165 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003166{
3167 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003168
Grant Likely61c7a082010-04-13 16:12:29 -07003169 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003170 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003171 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003172
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003173 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003174 port->ofdev.dev.release = logical_port_release;
3175
3176 ret = of_device_register(&port->ofdev);
3177 if (ret) {
3178 ehea_error("failed to register device. ret=%d", ret);
3179 goto out;
3180 }
3181
3182 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003183 if (ret) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003184 ehea_error("failed to register attributes, ret=%d", ret);
3185 goto out_unreg_of_dev;
3186 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003187
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003188 return &port->ofdev.dev;
3189
3190out_unreg_of_dev:
3191 of_device_unregister(&port->ofdev);
3192out:
3193 return NULL;
3194}
3195
3196static void ehea_unregister_port(struct ehea_port *port)
3197{
3198 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3199 of_device_unregister(&port->ofdev);
3200}
3201
Thomas Klein086c1b22009-01-21 14:43:59 -08003202static const struct net_device_ops ehea_netdev_ops = {
3203 .ndo_open = ehea_open,
3204 .ndo_stop = ehea_stop,
3205 .ndo_start_xmit = ehea_start_xmit,
3206#ifdef CONFIG_NET_POLL_CONTROLLER
3207 .ndo_poll_controller = ehea_netpoll,
3208#endif
3209 .ndo_get_stats = ehea_get_stats,
3210 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003211 .ndo_validate_addr = eth_validate_addr,
Thomas Klein086c1b22009-01-21 14:43:59 -08003212 .ndo_set_multicast_list = ehea_set_multicast_list,
3213 .ndo_change_mtu = ehea_change_mtu,
3214 .ndo_vlan_rx_register = ehea_vlan_rx_register,
3215 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003216 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3217 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003218};
3219
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003220struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3221 u32 logical_port_id,
3222 struct device_node *dn)
3223{
3224 int ret;
3225 struct net_device *dev;
3226 struct ehea_port *port;
3227 struct device *port_dev;
3228 int jumbo;
3229
3230 /* allocate memory for the port structures */
3231 dev = alloc_etherdev(sizeof(struct ehea_port));
3232
3233 if (!dev) {
3234 ehea_error("no mem for net_device");
3235 ret = -ENOMEM;
3236 goto out_err;
3237 }
3238
3239 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003240
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003241 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003242 port->state = EHEA_PORT_DOWN;
3243 port->sig_comp_iv = sq_entries / 10;
3244
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003245 port->adapter = adapter;
3246 port->netdev = dev;
3247 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003248
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003249 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003250
3251 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3252 if (!port->mc_list) {
3253 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003254 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003255 }
3256
3257 INIT_LIST_HEAD(&port->mc_list->list);
3258
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003259 ret = ehea_sense_port_attr(port);
3260 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003261 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003262
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003263 port_dev = ehea_register_port(port, dn);
3264 if (!port_dev)
3265 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003266
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003267 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003268
3269 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003270 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3271
Thomas Klein086c1b22009-01-21 14:43:59 -08003272 dev->netdev_ops = &ehea_netdev_ops;
3273 ehea_set_ethtool_ops(dev);
3274
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003275 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003276 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003277 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3278 | NETIF_F_LLTX;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003279 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3280
Breno Leitaoc7757fd2010-12-08 12:19:14 -08003281 if (use_lro)
3282 dev->features |= NETIF_F_LRO;
3283
David Howellsc4028952006-11-22 14:57:56 +00003284 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003285
3286 ret = register_netdev(dev);
3287 if (ret) {
3288 ehea_error("register_netdev failed. ret=%d", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003289 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003290 }
3291
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003292 port->lro_max_aggr = lro_max_aggr;
3293
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003294 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003295 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003296 ehea_error("failed determining jumbo frame status for %s",
3297 port->netdev->name);
3298
Thomas Klein9c750b72007-01-29 18:44:01 +01003299 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3300 jumbo == 1 ? "en" : "dis");
3301
Thomas Klein44c82152007-07-11 16:32:00 +02003302 adapter->active_ports++;
3303
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003304 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003305
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003306out_unreg_port:
3307 ehea_unregister_port(port);
3308
3309out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003310 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003311
3312out_free_ethdev:
3313 free_netdev(dev);
3314
3315out_err:
3316 ehea_error("setting up logical port with id=%d failed, ret=%d",
3317 logical_port_id, ret);
3318 return NULL;
3319}
3320
3321static void ehea_shutdown_single_port(struct ehea_port *port)
3322{
Brian King7fb1c2a2008-05-14 09:48:25 -05003323 struct ehea_adapter *adapter = port->adapter;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003324 unregister_netdev(port->netdev);
3325 ehea_unregister_port(port);
3326 kfree(port->mc_list);
3327 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003328 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003329}
3330
3331static int ehea_setup_ports(struct ehea_adapter *adapter)
3332{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003333 struct device_node *lhea_dn;
3334 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003335
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003336 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003337 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003338
Grant Likely61c7a082010-04-13 16:12:29 -07003339 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003340 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003341
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003342 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003343 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003344 if (!dn_log_port_id) {
3345 ehea_error("bad device node: eth_dn name=%s",
3346 eth_dn->full_name);
3347 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003348 }
3349
Thomas Klein1211bb62007-04-26 11:56:43 +02003350 if (ehea_add_adapter_mr(adapter)) {
3351 ehea_error("creating MR failed");
3352 of_node_put(eth_dn);
3353 return -EIO;
3354 }
3355
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003356 adapter->port[i] = ehea_setup_single_port(adapter,
3357 *dn_log_port_id,
3358 eth_dn);
3359 if (adapter->port[i])
3360 ehea_info("%s -> logical port id #%d",
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003361 adapter->port[i]->netdev->name,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003362 *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003363 else
3364 ehea_remove_adapter_mr(adapter);
3365
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003366 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003367 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003368 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003369}
3370
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003371static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3372 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003373{
3374 struct device_node *lhea_dn;
3375 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003376 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003377
Grant Likely61c7a082010-04-13 16:12:29 -07003378 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003379 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003380
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003381 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003382 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003383 if (dn_log_port_id)
3384 if (*dn_log_port_id == logical_port_id)
3385 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003386 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003387
3388 return NULL;
3389}
3390
3391static ssize_t ehea_probe_port(struct device *dev,
3392 struct device_attribute *attr,
3393 const char *buf, size_t count)
3394{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003395 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003396 struct ehea_port *port;
3397 struct device_node *eth_dn = NULL;
3398 int i;
3399
3400 u32 logical_port_id;
3401
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003402 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003403
3404 port = ehea_get_port(adapter, logical_port_id);
3405
3406 if (port) {
3407 ehea_info("adding port with logical port id=%d failed. port "
3408 "already configured as %s.", logical_port_id,
3409 port->netdev->name);
3410 return -EINVAL;
3411 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003412
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003413 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3414
3415 if (!eth_dn) {
3416 ehea_info("no logical port with id %d found", logical_port_id);
3417 return -EINVAL;
3418 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003419
Thomas Klein1211bb62007-04-26 11:56:43 +02003420 if (ehea_add_adapter_mr(adapter)) {
3421 ehea_error("creating MR failed");
3422 return -EIO;
3423 }
3424
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003425 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3426
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003427 of_node_put(eth_dn);
3428
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003429 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003430 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003431 if (!adapter->port[i]) {
3432 adapter->port[i] = port;
3433 break;
3434 }
3435
3436 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3437 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003438 } else {
3439 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003440 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003441 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003442
3443 return (ssize_t) count;
3444}
3445
3446static ssize_t ehea_remove_port(struct device *dev,
3447 struct device_attribute *attr,
3448 const char *buf, size_t count)
3449{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003450 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003451 struct ehea_port *port;
3452 int i;
3453 u32 logical_port_id;
3454
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003455 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003456
3457 port = ehea_get_port(adapter, logical_port_id);
3458
3459 if (port) {
3460 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3461 logical_port_id);
3462
3463 ehea_shutdown_single_port(port);
3464
Doug Maxey508d2b52008-01-31 20:20:49 -06003465 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003466 if (adapter->port[i] == port) {
3467 adapter->port[i] = NULL;
3468 break;
3469 }
3470 } else {
3471 ehea_error("removing port with logical port id=%d failed. port "
3472 "not configured.", logical_port_id);
3473 return -EINVAL;
3474 }
3475
Thomas Klein1211bb62007-04-26 11:56:43 +02003476 ehea_remove_adapter_mr(adapter);
3477
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003478 return (ssize_t) count;
3479}
3480
3481static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3482static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3483
Grant Likely2dc11582010-08-06 09:25:50 -06003484int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003485{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003486 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003487 if (ret)
3488 goto out;
3489
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003490 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003491out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003492 return ret;
3493}
3494
Grant Likely2dc11582010-08-06 09:25:50 -06003495void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003496{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003497 device_remove_file(&dev->dev, &dev_attr_probe_port);
3498 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003499}
3500
Grant Likely2dc11582010-08-06 09:25:50 -06003501static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003502 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003503{
3504 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003505 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003506 int ret;
3507
Grant Likely61c7a082010-04-13 16:12:29 -07003508 if (!dev || !dev->dev.of_node) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003509 ehea_error("Invalid ibmebus device probed");
3510 return -EINVAL;
3511 }
3512
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003513 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3514 if (!adapter) {
3515 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003516 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003517 goto out;
3518 }
3519
Thomas Klein44c82152007-07-11 16:32:00 +02003520 list_add(&adapter->list, &adapter_list);
3521
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003522 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003523
Grant Likely61c7a082010-04-13 16:12:29 -07003524 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003525 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003526 if (adapter_handle)
3527 adapter->handle = *adapter_handle;
3528
3529 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003530 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003531 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003532 ret = -ENODEV;
3533 goto out_free_ad;
3534 }
3535
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003536 adapter->pd = EHEA_PD_ID;
3537
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003538 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003539
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003540
3541 /* initialize adapter and ports */
3542 /* get adapter properties */
3543 ret = ehea_sense_adapter_attr(adapter);
3544 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003545 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003546 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003547 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003548
3549 adapter->neq = ehea_create_eq(adapter,
3550 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3551 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003552 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003553 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003554 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003555 }
3556
3557 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3558 (unsigned long)adapter);
3559
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003560 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003561 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003562 "ehea_neq", adapter);
3563 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003564 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003565 goto out_kill_eq;
3566 }
3567
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003568 ret = ehea_create_device_sysfs(dev);
3569 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003570 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003571
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003572 ret = ehea_setup_ports(adapter);
3573 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003574 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003575 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003576 }
3577
3578 ret = 0;
3579 goto out;
3580
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003581out_rem_dev_sysfs:
3582 ehea_remove_device_sysfs(dev);
3583
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003584out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003585 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003586
3587out_kill_eq:
3588 ehea_destroy_eq(adapter->neq);
3589
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003590out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003591 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003592 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003593
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003594out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003595 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003596
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003597 return ret;
3598}
3599
Grant Likely2dc11582010-08-06 09:25:50 -06003600static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003601{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003602 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003603 int i;
3604
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003605 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003606 if (adapter->port[i]) {
3607 ehea_shutdown_single_port(adapter->port[i]);
3608 adapter->port[i] = NULL;
3609 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003610
3611 ehea_remove_device_sysfs(dev);
3612
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003613 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003614
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003615 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003616 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003617
3618 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003619 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003620 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003621 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003622
Thomas Klein21eee2d2008-02-13 16:18:33 +01003623 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003624
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003625 return 0;
3626}
3627
Thomas Klein21eee2d2008-02-13 16:18:33 +01003628void ehea_crash_handler(void)
3629{
3630 int i;
3631
3632 if (ehea_fw_handles.arr)
3633 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3634 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3635 ehea_fw_handles.arr[i].fwh,
3636 FORCE_FREE);
3637
3638 if (ehea_bcmc_regs.arr)
3639 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3640 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3641 ehea_bcmc_regs.arr[i].port_id,
3642 ehea_bcmc_regs.arr[i].reg_type,
3643 ehea_bcmc_regs.arr[i].macaddr,
3644 0, H_DEREG_BCMC);
3645}
3646
Hannes Hering48cfb142008-05-07 14:43:36 +02003647static int ehea_mem_notifier(struct notifier_block *nb,
3648 unsigned long action, void *data)
3649{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003650 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003651 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003652
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003653 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003654
Hannes Hering48cfb142008-05-07 14:43:36 +02003655 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003656 case MEM_CANCEL_OFFLINE:
3657 ehea_info("memory offlining canceled");
3658 /* Readd canceled memory block */
3659 case MEM_ONLINE:
3660 ehea_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003661 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003662 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003663 goto out_unlock;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003664 ehea_rereg_mrs(NULL);
3665 break;
3666 case MEM_GOING_OFFLINE:
3667 ehea_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003668 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003669 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003670 goto out_unlock;
Hannes Hering48cfb142008-05-07 14:43:36 +02003671 ehea_rereg_mrs(NULL);
3672 break;
3673 default:
3674 break;
3675 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003676
3677 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003678 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003679
Thomas Kleina7c561f22010-04-20 23:11:31 +00003680out_unlock:
3681 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003682 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003683}
3684
3685static struct notifier_block ehea_mem_nb = {
3686 .notifier_call = ehea_mem_notifier,
3687};
3688
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003689static int ehea_reboot_notifier(struct notifier_block *nb,
3690 unsigned long action, void *unused)
3691{
3692 if (action == SYS_RESTART) {
3693 ehea_info("Reboot: freeing all eHEA resources");
3694 ibmebus_unregister_driver(&ehea_driver);
3695 }
3696 return NOTIFY_DONE;
3697}
3698
3699static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003700 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003701};
3702
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003703static int check_module_parm(void)
3704{
3705 int ret = 0;
3706
3707 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3708 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
3709 ehea_info("Bad parameter: rq1_entries");
3710 ret = -EINVAL;
3711 }
3712 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3713 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
3714 ehea_info("Bad parameter: rq2_entries");
3715 ret = -EINVAL;
3716 }
3717 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3718 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
3719 ehea_info("Bad parameter: rq3_entries");
3720 ret = -EINVAL;
3721 }
3722 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3723 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
3724 ehea_info("Bad parameter: sq_entries");
3725 ret = -EINVAL;
3726 }
3727
3728 return ret;
3729}
3730
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003731static ssize_t ehea_show_capabilities(struct device_driver *drv,
3732 char *buf)
3733{
3734 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3735}
3736
3737static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3738 ehea_show_capabilities, NULL);
3739
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003740int __init ehea_module_init(void)
3741{
3742 int ret;
3743
3744 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3745 DRV_VERSION);
3746
Thomas Klein44c82152007-07-11 16:32:00 +02003747
3748 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003749 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3750 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3751
Daniel Walker9f71a562008-03-28 14:41:26 -07003752 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003753 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003754
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003755 ret = check_module_parm();
3756 if (ret)
3757 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003758
3759 ret = ehea_create_busmap();
3760 if (ret)
3761 goto out;
3762
Thomas Klein21eee2d2008-02-13 16:18:33 +01003763 ret = register_reboot_notifier(&ehea_reboot_nb);
3764 if (ret)
3765 ehea_info("failed registering reboot notifier");
3766
Hannes Hering48cfb142008-05-07 14:43:36 +02003767 ret = register_memory_notifier(&ehea_mem_nb);
3768 if (ret)
3769 ehea_info("failed registering memory remove notifier");
3770
Joe Perchesc061b182010-08-23 18:20:03 +00003771 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003772 if (ret)
3773 ehea_info("failed registering crash handler");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003774
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003775 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003776 if (ret) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003777 ehea_error("failed registering eHEA device driver on ebus");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003778 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003779 }
3780
3781 ret = driver_create_file(&ehea_driver.driver,
3782 &driver_attr_capabilities);
3783 if (ret) {
3784 ehea_error("failed to register capabilities attribute, ret=%d",
3785 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003786 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003787 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003788
Thomas Klein21eee2d2008-02-13 16:18:33 +01003789 return ret;
3790
3791out3:
3792 ibmebus_unregister_driver(&ehea_driver);
3793out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003794 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003795 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003796 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003797out:
3798 return ret;
3799}
3800
3801static void __exit ehea_module_exit(void)
3802{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003803 int ret;
3804
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003805 flush_scheduled_work();
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003806 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003807 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003808 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003809 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003810 if (ret)
3811 ehea_info("failed unregistering crash handler");
Hannes Hering48cfb142008-05-07 14:43:36 +02003812 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003813 kfree(ehea_fw_handles.arr);
3814 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003815 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003816}
3817
3818module_init(ehea_module_init);
3819module_exit(ehea_module_exit);