blob: 81e5b7b49e9ee23072d006cc22d33c8244d2249b [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;
Daniel Walker06f89ed2008-03-28 14:41:26 -0700104static DEFINE_MUTEX(dlpar_mem_lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100105struct ehea_fw_handle_array ehea_fw_handles;
106struct ehea_bcmc_reg_array ehea_bcmc_regs;
107
Thomas Kleind1dea382007-04-26 11:56:13 +0200108
Grant Likely2dc11582010-08-06 09:25:50 -0600109static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200110 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200111
Grant Likely2dc11582010-08-06 09:25:50 -0600112static int __devexit ehea_remove(struct platform_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200113
114static struct of_device_id ehea_device_table[] = {
115 {
116 .name = "lhea",
117 .compatible = "IBM,lhea",
118 },
119 {},
120};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100121MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200122
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000123static struct of_platform_driver ehea_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700124 .driver = {
125 .name = "ehea",
126 .owner = THIS_MODULE,
127 .of_match_table = ehea_device_table,
128 },
Thomas Kleind1dea382007-04-26 11:56:13 +0200129 .probe = ehea_probe_adapter,
130 .remove = ehea_remove,
131};
132
Doug Maxey508d2b52008-01-31 20:20:49 -0600133void ehea_dump(void *adr, int len, char *msg)
134{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200135 int x;
136 unsigned char *deb = adr;
137 for (x = 0; x < len; x += 16) {
David S. Millercfa969e2010-12-06 20:45:28 -0800138 printk(DRV_NAME " %s adr=%p ofs=%04x %016llx %016llx\n", msg,
139 deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200140 deb += 16;
141 }
142}
143
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100144void ehea_schedule_port_reset(struct ehea_port *port)
145{
146 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
147 schedule_work(&port->reset_task);
148}
149
Thomas Klein21eee2d2008-02-13 16:18:33 +0100150static void ehea_update_firmware_handles(void)
151{
152 struct ehea_fw_handle_entry *arr = NULL;
153 struct ehea_adapter *adapter;
154 int num_adapters = 0;
155 int num_ports = 0;
156 int num_portres = 0;
157 int i = 0;
158 int num_fw_handles, k, l;
159
160 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700161 mutex_lock(&ehea_fw_handles.lock);
162
Thomas Klein21eee2d2008-02-13 16:18:33 +0100163 list_for_each_entry(adapter, &adapter_list, list) {
164 num_adapters++;
165
166 for (k = 0; k < EHEA_MAX_PORTS; k++) {
167 struct ehea_port *port = adapter->port[k];
168
169 if (!port || (port->state != EHEA_PORT_UP))
170 continue;
171
172 num_ports++;
173 num_portres += port->num_def_qps + port->num_add_tx_qps;
174 }
175 }
176
177 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
178 num_ports * EHEA_NUM_PORT_FW_HANDLES +
179 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
180
181 if (num_fw_handles) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000182 arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100183 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700184 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100185 } else
186 goto out_update;
187
188 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700189 if (num_adapters == 0)
190 break;
191
Thomas Klein21eee2d2008-02-13 16:18:33 +0100192 for (k = 0; k < EHEA_MAX_PORTS; k++) {
193 struct ehea_port *port = adapter->port[k];
194
Joe Perches8e95a202009-12-03 07:58:21 +0000195 if (!port || (port->state != EHEA_PORT_UP) ||
196 (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100197 continue;
198
199 for (l = 0;
200 l < port->num_def_qps + port->num_add_tx_qps;
201 l++) {
202 struct ehea_port_res *pr = &port->port_res[l];
203
204 arr[i].adh = adapter->handle;
205 arr[i++].fwh = pr->qp->fw_handle;
206 arr[i].adh = adapter->handle;
207 arr[i++].fwh = pr->send_cq->fw_handle;
208 arr[i].adh = adapter->handle;
209 arr[i++].fwh = pr->recv_cq->fw_handle;
210 arr[i].adh = adapter->handle;
211 arr[i++].fwh = pr->eq->fw_handle;
212 arr[i].adh = adapter->handle;
213 arr[i++].fwh = pr->send_mr.handle;
214 arr[i].adh = adapter->handle;
215 arr[i++].fwh = pr->recv_mr.handle;
216 }
217 arr[i].adh = adapter->handle;
218 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700219 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100220 }
221
222 arr[i].adh = adapter->handle;
223 arr[i++].fwh = adapter->neq->fw_handle;
224
225 if (adapter->mr.handle) {
226 arr[i].adh = adapter->handle;
227 arr[i++].fwh = adapter->mr.handle;
228 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700229 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100230 }
231
232out_update:
233 kfree(ehea_fw_handles.arr);
234 ehea_fw_handles.arr = arr;
235 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700236out:
237 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100238}
239
240static void ehea_update_bcmc_registrations(void)
241{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700242 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100243 struct ehea_bcmc_reg_entry *arr = NULL;
244 struct ehea_adapter *adapter;
245 struct ehea_mc_list *mc_entry;
246 int num_registrations = 0;
247 int i = 0;
248 int k;
249
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700250 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
251
Thomas Klein21eee2d2008-02-13 16:18:33 +0100252 /* Determine number of registrations */
253 list_for_each_entry(adapter, &adapter_list, list)
254 for (k = 0; k < EHEA_MAX_PORTS; k++) {
255 struct ehea_port *port = adapter->port[k];
256
257 if (!port || (port->state != EHEA_PORT_UP))
258 continue;
259
260 num_registrations += 2; /* Broadcast registrations */
261
262 list_for_each_entry(mc_entry, &port->mc_list->list,list)
263 num_registrations += 2;
264 }
265
266 if (num_registrations) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000267 arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100268 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700269 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100270 } else
271 goto out_update;
272
273 list_for_each_entry(adapter, &adapter_list, list) {
274 for (k = 0; k < EHEA_MAX_PORTS; k++) {
275 struct ehea_port *port = adapter->port[k];
276
277 if (!port || (port->state != EHEA_PORT_UP))
278 continue;
279
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700280 if (num_registrations == 0)
281 goto out_update;
282
Thomas Klein21eee2d2008-02-13 16:18:33 +0100283 arr[i].adh = adapter->handle;
284 arr[i].port_id = port->logical_port_id;
285 arr[i].reg_type = EHEA_BCMC_BROADCAST |
286 EHEA_BCMC_UNTAGGED;
287 arr[i++].macaddr = port->mac_addr;
288
289 arr[i].adh = adapter->handle;
290 arr[i].port_id = port->logical_port_id;
291 arr[i].reg_type = EHEA_BCMC_BROADCAST |
292 EHEA_BCMC_VLANID_ALL;
293 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700294 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100295
296 list_for_each_entry(mc_entry,
297 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700298 if (num_registrations == 0)
299 goto out_update;
300
Thomas Klein21eee2d2008-02-13 16:18:33 +0100301 arr[i].adh = adapter->handle;
302 arr[i].port_id = port->logical_port_id;
303 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
304 EHEA_BCMC_MULTICAST |
305 EHEA_BCMC_UNTAGGED;
306 arr[i++].macaddr = mc_entry->macaddr;
307
308 arr[i].adh = adapter->handle;
309 arr[i].port_id = port->logical_port_id;
310 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
311 EHEA_BCMC_MULTICAST |
312 EHEA_BCMC_VLANID_ALL;
313 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700314 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100315 }
316 }
317 }
318
319out_update:
320 kfree(ehea_bcmc_regs.arr);
321 ehea_bcmc_regs.arr = arr;
322 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700323out:
324 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100325}
326
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200327static struct net_device_stats *ehea_get_stats(struct net_device *dev)
328{
329 struct ehea_port *port = netdev_priv(dev);
330 struct net_device_stats *stats = &port->stats;
331 struct hcp_ehea_port_cb2 *cb2;
Breno Leitaoce45b872010-10-27 08:45:14 +0000332 u64 hret, rx_packets, tx_packets, rx_bytes = 0, tx_bytes = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200333 int i;
334
335 memset(stats, 0, sizeof(*stats));
336
Brian King3d8009c2010-06-30 11:59:12 +0000337 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200338 if (!cb2) {
David S. Millercfa969e2010-12-06 20:45:28 -0800339 ehea_error("no mem for cb2");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200340 goto out;
341 }
342
343 hret = ehea_h_query_ehea_port(port->adapter->handle,
344 port->logical_port_id,
345 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
346 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -0800347 ehea_error("query_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200348 goto out_herr;
349 }
350
351 if (netif_msg_hw(port))
352 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
353
354 rx_packets = 0;
Breno Leitaoce45b872010-10-27 08:45:14 +0000355 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200356 rx_packets += port->port_res[i].rx_packets;
Breno Leitaoce45b872010-10-27 08:45:14 +0000357 rx_bytes += port->port_res[i].rx_bytes;
358 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200359
Thomas Klein7393b872007-11-21 17:37:58 +0100360 tx_packets = 0;
Breno Leitaoce45b872010-10-27 08:45:14 +0000361 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Thomas Klein7393b872007-11-21 17:37:58 +0100362 tx_packets += port->port_res[i].tx_packets;
Breno Leitaoce45b872010-10-27 08:45:14 +0000363 tx_bytes += port->port_res[i].tx_bytes;
364 }
Thomas Klein7393b872007-11-21 17:37:58 +0100365
366 stats->tx_packets = tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200367 stats->multicast = cb2->rxmcp;
368 stats->rx_errors = cb2->rxuerr;
Breno Leitaoce45b872010-10-27 08:45:14 +0000369 stats->rx_bytes = rx_bytes;
370 stats->tx_bytes = tx_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200371 stats->rx_packets = rx_packets;
372
373out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800374 free_page((unsigned long)cb2);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200375out:
376 return stats;
377}
378
379static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
380{
381 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
382 struct net_device *dev = pr->port->netdev;
383 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200384 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
385 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200386 int i;
387
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200388 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200389
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200390 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200391 if (nr_of_wqes > 0)
392 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200393 pr->rq1_skba.os_skbs = fill_wqes;
394 return;
395 }
396
397 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200398 if (!skb_arr_rq1[index]) {
399 skb_arr_rq1[index] = netdev_alloc_skb(dev,
400 EHEA_L_PKT_SIZE);
401 if (!skb_arr_rq1[index]) {
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000402 ehea_info("Unable to allocate enough skb in the array\n");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200403 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200404 break;
405 }
406 }
407 index--;
408 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200409 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200410 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200411
412 if (adder == 0)
413 return;
414
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200415 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200416 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200417}
418
Thomas Kleine2878802009-01-21 14:45:57 -0800419static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200420{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200421 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
422 struct net_device *dev = pr->port->netdev;
423 int i;
424
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000425 if (nr_rq1a > pr->rq1_skba.len) {
426 ehea_error("NR_RQ1A bigger than skb array len\n");
427 return;
428 }
429
430 for (i = 0; i < nr_rq1a; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200431 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000432 if (!skb_arr_rq1[i]) {
433 ehea_info("No enough memory to allocate skb array\n");
Thomas Kleine2878802009-01-21 14:45:57 -0800434 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000435 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200436 }
437 /* Ring doorbell */
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000438 ehea_update_rq1a(pr->qp, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200439}
440
441static int ehea_refill_rq_def(struct ehea_port_res *pr,
442 struct ehea_q_skb_arr *q_skba, int rq_nr,
443 int num_wqes, int wqe_type, int packet_size)
444{
445 struct net_device *dev = pr->port->netdev;
446 struct ehea_qp *qp = pr->qp;
447 struct sk_buff **skb_arr = q_skba->arr;
448 struct ehea_rwqe *rwqe;
449 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200450 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200451 int ret = 0;
452
453 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200454 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200455
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200456 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
457 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200458 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200459 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200460
461 index = q_skba->index;
462 max_index_mask = q_skba->len - 1;
463 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200464 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000465 struct sk_buff *skb;
466
467 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200468 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200469 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800470 if (q_skba->os_skbs == q_skba->len - 2) {
David S. Millercfa969e2010-12-06 20:45:28 -0800471 ehea_info("%s: rq%i ran dry - no mem for skb",
472 pr->port->netdev->name, rq_nr);
Thomas Kleine2878802009-01-21 14:45:57 -0800473 ret = -ENOMEM;
474 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200475 break;
476 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200477
478 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200479 tmp_addr = ehea_map_vaddr(skb->data);
480 if (tmp_addr == -1) {
481 dev_kfree_skb(skb);
482 q_skba->os_skbs = fill_wqes - i;
483 ret = 0;
484 break;
485 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200486
487 rwqe = ehea_get_next_rwqe(qp, rq_nr);
488 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200489 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200490 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200491 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200492 rwqe->sg_list[0].len = packet_size;
493 rwqe->data_segments = 1;
494
495 index++;
496 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200497 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200498 }
Thomas Klein44c82152007-07-11 16:32:00 +0200499
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200500 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200501 if (adder == 0)
502 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200503
504 /* Ring doorbell */
505 iosync();
506 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200507 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200508 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200509 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200510out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200511 return ret;
512}
513
514
515static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
516{
517 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
518 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000519 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200520}
521
522
523static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
524{
525 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
526 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000527 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200528}
529
530static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
531{
532 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
533 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
534 return 0;
535 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
536 (cqe->header_length == 0))
537 return 0;
538 return -EINVAL;
539}
540
541static inline void ehea_fill_skb(struct net_device *dev,
542 struct sk_buff *skb, struct ehea_cqe *cqe)
543{
544 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
545
546 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200547 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000548
549 /* The packet was not an IPV4 packet so a complemented checksum was
550 calculated. The value is found in the Internet Checksum field. */
551 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
552 skb->ip_summed = CHECKSUM_COMPLETE;
553 skb->csum = csum_unfold(~cqe->inet_checksum_value);
554 } else
555 skb->ip_summed = CHECKSUM_UNNECESSARY;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200556}
557
558static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
559 int arr_len,
560 struct ehea_cqe *cqe)
561{
562 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
563 struct sk_buff *skb;
564 void *pref;
565 int x;
566
567 x = skb_index + 1;
568 x &= (arr_len - 1);
569
570 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700571 if (pref) {
572 prefetchw(pref);
573 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200574
Hannes Hering0b2febf2009-05-04 11:06:37 -0700575 pref = (skb_array[x]->data);
576 prefetch(pref);
577 prefetch(pref + EHEA_CACHE_LINE);
578 prefetch(pref + EHEA_CACHE_LINE * 2);
579 prefetch(pref + EHEA_CACHE_LINE * 3);
580 }
581
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200582 skb = skb_array[skb_index];
583 skb_array[skb_index] = NULL;
584 return skb;
585}
586
587static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
588 int arr_len, int wqe_index)
589{
590 struct sk_buff *skb;
591 void *pref;
592 int x;
593
594 x = wqe_index + 1;
595 x &= (arr_len - 1);
596
597 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700598 if (pref) {
599 prefetchw(pref);
600 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200601
Hannes Hering0b2febf2009-05-04 11:06:37 -0700602 pref = (skb_array[x]->data);
603 prefetchw(pref);
604 prefetchw(pref + EHEA_CACHE_LINE);
605 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200606
607 skb = skb_array[wqe_index];
608 skb_array[wqe_index] = NULL;
609 return skb;
610}
611
612static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
613 struct ehea_cqe *cqe, int *processed_rq2,
614 int *processed_rq3)
615{
616 struct sk_buff *skb;
617
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100618 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
619 pr->p_stats.err_tcp_cksum++;
620 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
621 pr->p_stats.err_ip_cksum++;
622 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
623 pr->p_stats.err_frame_crc++;
624
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200625 if (rq == 2) {
626 *processed_rq2 += 1;
627 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
628 dev_kfree_skb(skb);
629 } else if (rq == 3) {
630 *processed_rq3 += 1;
631 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
632 dev_kfree_skb(skb);
633 }
634
635 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100636 if (netif_msg_rx_err(pr->port)) {
David S. Millercfa969e2010-12-06 20:45:28 -0800637 ehea_error("Critical receive error for QP %d. "
638 "Resetting port.", pr->qp->init_attr.qp_nr);
Thomas Klein58dd8252007-11-21 17:42:27 +0100639 ehea_dump(cqe, sizeof(*cqe), "CQE");
640 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100641 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200642 return 1;
643 }
644
645 return 0;
646}
647
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700648static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
649 void **tcph, u64 *hdr_flags, void *priv)
650{
651 struct ehea_cqe *cqe = priv;
652 unsigned int ip_len;
653 struct iphdr *iph;
654
655 /* non tcp/udp packets */
656 if (!cqe->header_length)
657 return -1;
658
659 /* non tcp packet */
660 skb_reset_network_header(skb);
661 iph = ip_hdr(skb);
662 if (iph->protocol != IPPROTO_TCP)
663 return -1;
664
665 ip_len = ip_hdrlen(skb);
666 skb_set_transport_header(skb, ip_len);
667 *tcph = tcp_hdr(skb);
668
669 /* check if ip header and tcp header are complete */
Roland Dreier3ff2cd22008-07-01 10:20:33 -0700670 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700671 return -1;
672
673 *hdr_flags = LRO_IPV4 | LRO_TCP;
674 *iphdr = iph;
675
676 return 0;
677}
678
679static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
680 struct sk_buff *skb)
681{
Joe Perches8e95a202009-12-03 07:58:21 +0000682 int vlan_extracted = ((cqe->status & EHEA_CQE_VLAN_TAG_XTRACT) &&
683 pr->port->vgrp);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700684
Breno Leitaoc7757fd2010-12-08 12:19:14 -0800685 if (skb->dev->features & NETIF_F_LRO) {
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700686 if (vlan_extracted)
687 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
688 pr->port->vgrp,
689 cqe->vlan_tag,
690 cqe);
691 else
692 lro_receive_skb(&pr->lro_mgr, skb, cqe);
693 } else {
694 if (vlan_extracted)
695 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
696 cqe->vlan_tag);
697 else
698 netif_receive_skb(skb);
699 }
700}
701
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700702static int ehea_proc_rwqes(struct net_device *dev,
703 struct ehea_port_res *pr,
704 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200705{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100706 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200707 struct ehea_qp *qp = pr->qp;
708 struct ehea_cqe *cqe;
709 struct sk_buff *skb;
710 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
711 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
712 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
713 int skb_arr_rq1_len = pr->rq1_skba.len;
714 int skb_arr_rq2_len = pr->rq2_skba.len;
715 int skb_arr_rq3_len = pr->rq3_skba.len;
716 int processed, processed_rq1, processed_rq2, processed_rq3;
Breno Leitaoce45b872010-10-27 08:45:14 +0000717 u64 processed_bytes = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700718 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200719
720 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
721 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200722
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200723 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700724 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200725 ehea_inc_rq1(qp);
726 processed_rq1++;
727 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200728 if (netif_msg_rx_status(port))
729 ehea_dump(cqe, sizeof(*cqe), "CQE");
730
731 last_wqe_index = wqe_index;
732 rmb();
733 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600734 if (rq == 1) {
735 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200736 skb = get_skb_by_index_ll(skb_arr_rq1,
737 skb_arr_rq1_len,
738 wqe_index);
739 if (unlikely(!skb)) {
David S. Millercfa969e2010-12-06 20:45:28 -0800740 if (netif_msg_rx_err(port))
741 ehea_error("LL rq1: skb=NULL");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100742
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700743 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200744 EHEA_L_PKT_SIZE);
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000745 if (!skb) {
746 ehea_info("Not enough memory to allocate skb\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200747 break;
Breno Leitao5c7e57f2010-11-26 07:26:27 +0000748 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200749 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600750 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200751 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700752 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600753 } else if (rq == 2) {
754 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200755 skb = get_skb_by_index(skb_arr_rq2,
756 skb_arr_rq2_len, cqe);
757 if (unlikely(!skb)) {
David S. Millercfa969e2010-12-06 20:45:28 -0800758 if (netif_msg_rx_err(port))
759 ehea_error("rq2: skb=NULL");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200760 break;
761 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700762 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200763 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600764 } else {
765 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200766 skb = get_skb_by_index(skb_arr_rq3,
767 skb_arr_rq3_len, cqe);
768 if (unlikely(!skb)) {
David S. Millercfa969e2010-12-06 20:45:28 -0800769 if (netif_msg_rx_err(port))
770 ehea_error("rq3: skb=NULL");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200771 break;
772 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700773 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200774 processed_rq3++;
775 }
776
Breno Leitaoce45b872010-10-27 08:45:14 +0000777 processed_bytes += skb->len;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700778 ehea_proc_skb(pr, cqe, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100779 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100780 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200781 port_reset = ehea_treat_poll_error(pr, rq, cqe,
782 &processed_rq2,
783 &processed_rq3);
784 if (port_reset)
785 break;
786 }
787 cqe = ehea_poll_rq1(qp, &wqe_index);
788 }
Breno Leitaoc7757fd2010-12-08 12:19:14 -0800789 if (dev->features & NETIF_F_LRO)
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700790 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200791
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200792 pr->rx_packets += processed;
Breno Leitaoce45b872010-10-27 08:45:14 +0000793 pr->rx_bytes += processed_bytes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200794
795 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
796 ehea_refill_rq2(pr, processed_rq2);
797 ehea_refill_rq3(pr, processed_rq3);
798
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700799 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200800}
801
Andre Detsch2928db42010-08-17 05:49:12 +0000802#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
803
804static void reset_sq_restart_flag(struct ehea_port *port)
805{
806 int i;
807
808 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
809 struct ehea_port_res *pr = &port->port_res[i];
810 pr->sq_restart_flag = 0;
811 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000812 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000813}
814
815static void check_sqs(struct ehea_port *port)
816{
817 struct ehea_swqe *swqe;
818 int swqe_index;
819 int i, k;
820
821 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
822 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000823 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000824 k = 0;
825 swqe = ehea_get_swqe(pr->qp, &swqe_index);
826 memset(swqe, 0, SWQE_HEADER_SIZE);
827 atomic_dec(&pr->swqe_avail);
828
829 swqe->tx_control |= EHEA_SWQE_PURGE;
830 swqe->wr_id = SWQE_RESTART_CHECK;
831 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
832 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
833 swqe->immediate_data_length = 80;
834
835 ehea_post_swqe(pr->qp, swqe);
836
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000837 ret = wait_event_timeout(port->restart_wq,
838 pr->sq_restart_flag == 0,
839 msecs_to_jiffies(100));
840
841 if (!ret) {
David S. Millercfa969e2010-12-06 20:45:28 -0800842 ehea_error("HW/SW queues out of sync");
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000843 ehea_schedule_port_reset(pr->port);
844 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000845 }
846 }
Andre Detsch2928db42010-08-17 05:49:12 +0000847}
848
849
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100850static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200851{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100852 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200853 struct ehea_cq *send_cq = pr->send_cq;
854 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100855 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200856 int cqe_counter = 0;
857 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100858 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200859 unsigned long flags;
860
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100861 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600862 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100863 ehea_inc_cq(send_cq);
864
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200865 cqe_counter++;
866 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000867
868 if (cqe->wr_id == SWQE_RESTART_CHECK) {
869 pr->sq_restart_flag = 1;
870 swqe_av++;
871 break;
872 }
873
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200874 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
David S. Millercfa969e2010-12-06 20:45:28 -0800875 ehea_error("Bad send completion status=0x%04X",
876 cqe->status);
Thomas Kleinea96cea2010-04-20 23:10:55 +0000877
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200878 if (netif_msg_tx_err(pr->port))
879 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000880
881 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
David S. Millercfa969e2010-12-06 20:45:28 -0800882 ehea_error("Resetting port");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000883 ehea_schedule_port_reset(pr->port);
884 break;
885 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200886 }
887
888 if (netif_msg_tx_done(pr->port))
889 ehea_dump(cqe, sizeof(*cqe), "CQE");
890
891 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100892 == EHEA_SWQE2_TYPE)) {
893
894 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
895 skb = pr->sq_skba.arr[index];
896 dev_kfree_skb(skb);
897 pr->sq_skba.arr[index] = NULL;
898 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200899
900 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
901 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100902
903 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700904 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200905
906 ehea_update_feca(send_cq, cqe_counter);
907 atomic_add(swqe_av, &pr->swqe_avail);
908
909 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100910
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200911 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
912 >= pr->swqe_refill_th)) {
913 netif_wake_queue(pr->port->netdev);
914 pr->queue_stopped = 0;
915 }
916 spin_unlock_irqrestore(&pr->netif_queue, flags);
Breno Leitao5b27d422010-10-05 13:16:22 +0000917 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200918
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100919 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200920}
921
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100922#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700923#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100924
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700925static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200926{
Doug Maxey508d2b52008-01-31 20:20:49 -0600927 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
928 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700929 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100930 struct ehea_cqe *cqe;
931 struct ehea_cqe *cqe_skb = NULL;
932 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700933 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100934
935 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700936 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100937
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700938 if (!force_irq)
939 rx += ehea_proc_rwqes(dev, pr, budget - rx);
940
941 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100942 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700943 force_irq = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -0800944 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100945 ehea_reset_cq_ep(pr->recv_cq);
946 ehea_reset_cq_ep(pr->send_cq);
947 ehea_reset_cq_n1(pr->recv_cq);
948 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000949 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100950 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
951 cqe_skb = ehea_poll_cq(pr->send_cq);
952
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100953 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700954 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100955
Ben Hutchings288379f2009-01-19 16:43:59 -0800956 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700957 return rx;
958
959 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
960 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100961 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100962
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700963 pr->poll_counter++;
964 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200965}
966
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200967#ifdef CONFIG_NET_POLL_CONTROLLER
968static void ehea_netpoll(struct net_device *dev)
969{
970 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700971 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200972
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700973 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800974 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200975}
976#endif
977
David Howells7d12e782006-10-05 14:55:46 +0100978static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200979{
980 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100981
Ben Hutchings288379f2009-01-19 16:43:59 -0800982 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100983
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200984 return IRQ_HANDLED;
985}
986
David Howells7d12e782006-10-05 14:55:46 +0100987static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200988{
989 struct ehea_port *port = param;
990 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100991 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200992 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000993 u64 resource_type, aer, aerr;
994 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200995
996 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100997
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200998 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200999 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
David S. Millercfa969e2010-12-06 20:45:28 -08001000 ehea_error("QP aff_err: entry=0x%llx, token=0x%x",
1001 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001002
1003 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +00001004
1005 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
1006 &aer, &aerr);
1007
1008 if (resource_type == EHEA_AER_RESTYPE_QP) {
1009 if ((aer & EHEA_AER_RESET_MASK) ||
1010 (aerr & EHEA_AERR_RESET_MASK))
1011 reset_port = 1;
1012 } else
1013 reset_port = 1; /* Reset in case of CQ or EQ error */
1014
Thomas Kleinbb3a6442007-01-22 12:54:50 +01001015 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001016 }
1017
Thomas Kleinea96cea2010-04-20 23:10:55 +00001018 if (reset_port) {
David S. Millercfa969e2010-12-06 20:45:28 -08001019 ehea_error("Resetting port");
Thomas Kleinea96cea2010-04-20 23:10:55 +00001020 ehea_schedule_port_reset(port);
1021 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001022
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001023 return IRQ_HANDLED;
1024}
1025
1026static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
1027 int logical_port)
1028{
1029 int i;
1030
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01001031 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +01001032 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001033 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +01001034 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001035 return NULL;
1036}
1037
1038int ehea_sense_port_attr(struct ehea_port *port)
1039{
1040 int ret;
1041 u64 hret;
1042 struct hcp_ehea_port_cb0 *cb0;
1043
Doug Maxey508d2b52008-01-31 20:20:49 -06001044 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -08001045 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -06001046 if (!cb0) {
David S. Millercfa969e2010-12-06 20:45:28 -08001047 ehea_error("no mem for cb0");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001048 ret = -ENOMEM;
1049 goto out;
1050 }
1051
1052 hret = ehea_h_query_ehea_port(port->adapter->handle,
1053 port->logical_port_id, H_PORT_CB0,
1054 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1055 cb0);
1056 if (hret != H_SUCCESS) {
1057 ret = -EIO;
1058 goto out_free;
1059 }
1060
1061 /* MAC address */
1062 port->mac_addr = cb0->port_mac_addr << 16;
1063
Doug Maxey508d2b52008-01-31 20:20:49 -06001064 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001065 ret = -EADDRNOTAVAIL;
1066 goto out_free;
1067 }
1068
1069 /* Port speed */
1070 switch (cb0->port_speed) {
1071 case H_SPEED_10M_H:
1072 port->port_speed = EHEA_SPEED_10M;
1073 port->full_duplex = 0;
1074 break;
1075 case H_SPEED_10M_F:
1076 port->port_speed = EHEA_SPEED_10M;
1077 port->full_duplex = 1;
1078 break;
1079 case H_SPEED_100M_H:
1080 port->port_speed = EHEA_SPEED_100M;
1081 port->full_duplex = 0;
1082 break;
1083 case H_SPEED_100M_F:
1084 port->port_speed = EHEA_SPEED_100M;
1085 port->full_duplex = 1;
1086 break;
1087 case H_SPEED_1G_F:
1088 port->port_speed = EHEA_SPEED_1G;
1089 port->full_duplex = 1;
1090 break;
1091 case H_SPEED_10G_F:
1092 port->port_speed = EHEA_SPEED_10G;
1093 port->full_duplex = 1;
1094 break;
1095 default:
1096 port->port_speed = 0;
1097 port->full_duplex = 0;
1098 break;
1099 }
1100
Thomas Kleine919b592007-01-22 12:53:20 +01001101 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001102 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001103
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001104 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001105 if (use_mcs)
1106 port->num_def_qps = cb0->num_default_qps;
1107 else
1108 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001109
1110 if (!port->num_def_qps) {
1111 ret = -EINVAL;
1112 goto out_free;
1113 }
1114
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001115 port->num_tx_qps = num_tx_qps;
1116
1117 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001118 port->num_add_tx_qps = 0;
1119 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001120 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001121
1122 ret = 0;
1123out_free:
1124 if (ret || netif_msg_probe(port))
1125 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001126 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001127out:
1128 return ret;
1129}
1130
1131int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1132{
1133 struct hcp_ehea_port_cb4 *cb4;
1134 u64 hret;
1135 int ret = 0;
1136
Thomas Klein3faf2692009-01-21 14:45:33 -08001137 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001138 if (!cb4) {
David S. Millercfa969e2010-12-06 20:45:28 -08001139 ehea_error("no mem for cb4");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001140 ret = -ENOMEM;
1141 goto out;
1142 }
1143
1144 cb4->port_speed = port_speed;
1145
1146 netif_carrier_off(port->netdev);
1147
1148 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1149 port->logical_port_id,
1150 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1151 if (hret == H_SUCCESS) {
1152 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1153
1154 hret = ehea_h_query_ehea_port(port->adapter->handle,
1155 port->logical_port_id,
1156 H_PORT_CB4, H_PORT_CB4_SPEED,
1157 cb4);
1158 if (hret == H_SUCCESS) {
1159 switch (cb4->port_speed) {
1160 case H_SPEED_10M_H:
1161 port->port_speed = EHEA_SPEED_10M;
1162 port->full_duplex = 0;
1163 break;
1164 case H_SPEED_10M_F:
1165 port->port_speed = EHEA_SPEED_10M;
1166 port->full_duplex = 1;
1167 break;
1168 case H_SPEED_100M_H:
1169 port->port_speed = EHEA_SPEED_100M;
1170 port->full_duplex = 0;
1171 break;
1172 case H_SPEED_100M_F:
1173 port->port_speed = EHEA_SPEED_100M;
1174 port->full_duplex = 1;
1175 break;
1176 case H_SPEED_1G_F:
1177 port->port_speed = EHEA_SPEED_1G;
1178 port->full_duplex = 1;
1179 break;
1180 case H_SPEED_10G_F:
1181 port->port_speed = EHEA_SPEED_10G;
1182 port->full_duplex = 1;
1183 break;
1184 default:
1185 port->port_speed = 0;
1186 port->full_duplex = 0;
1187 break;
1188 }
1189 } else {
David S. Millercfa969e2010-12-06 20:45:28 -08001190 ehea_error("Failed sensing port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001191 ret = -EIO;
1192 }
1193 } else {
1194 if (hret == H_AUTHORITY) {
David S. Millercfa969e2010-12-06 20:45:28 -08001195 ehea_info("Hypervisor denied setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001196 ret = -EPERM;
1197 } else {
1198 ret = -EIO;
David S. Millercfa969e2010-12-06 20:45:28 -08001199 ehea_error("Failed setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001200 }
1201 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001202 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1203 netif_carrier_on(port->netdev);
1204
Thomas Klein3faf2692009-01-21 14:45:33 -08001205 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001206out:
1207 return ret;
1208}
1209
1210static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1211{
1212 int ret;
1213 u8 ec;
1214 u8 portnum;
1215 struct ehea_port *port;
1216
1217 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1218 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1219 port = ehea_get_port(adapter, portnum);
1220
1221 switch (ec) {
1222 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1223
1224 if (!port) {
David S. Millercfa969e2010-12-06 20:45:28 -08001225 ehea_error("unknown portnum %x", portnum);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001226 break;
1227 }
1228
1229 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
David S. Millercfa969e2010-12-06 20:45:28 -08001230 if (!netif_carrier_ok(port->netdev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001231 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001232 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08001233 ehea_error("failed resensing port "
1234 "attributes");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001235 break;
1236 }
1237
David S. Millercfa969e2010-12-06 20:45:28 -08001238 if (netif_msg_link(port))
1239 ehea_info("%s: Logical port up: %dMbps "
1240 "%s Duplex",
1241 port->netdev->name,
1242 port->port_speed,
1243 port->full_duplex ==
1244 1 ? "Full" : "Half");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001245
David S. Millercfa969e2010-12-06 20:45:28 -08001246 netif_carrier_on(port->netdev);
1247 netif_wake_queue(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001248 }
1249 } else
David S. Millercfa969e2010-12-06 20:45:28 -08001250 if (netif_carrier_ok(port->netdev)) {
1251 if (netif_msg_link(port))
1252 ehea_info("%s: Logical port down",
1253 port->netdev->name);
1254 netif_carrier_off(port->netdev);
1255 netif_stop_queue(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001256 }
1257
1258 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001259 port->phy_link = EHEA_PHY_LINK_UP;
David S. Millercfa969e2010-12-06 20:45:28 -08001260 if (netif_msg_link(port))
1261 ehea_info("%s: Physical port up",
1262 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001263 if (prop_carrier_state)
David S. Millercfa969e2010-12-06 20:45:28 -08001264 netif_carrier_on(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001265 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001266 port->phy_link = EHEA_PHY_LINK_DOWN;
David S. Millercfa969e2010-12-06 20:45:28 -08001267 if (netif_msg_link(port))
1268 ehea_info("%s: Physical port down",
1269 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001270 if (prop_carrier_state)
David S. Millercfa969e2010-12-06 20:45:28 -08001271 netif_carrier_off(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001272 }
1273
1274 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
David S. Millercfa969e2010-12-06 20:45:28 -08001275 ehea_info("External switch port is primary port");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001276 else
David S. Millercfa969e2010-12-06 20:45:28 -08001277 ehea_info("External switch port is backup port");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001278
1279 break;
1280 case EHEA_EC_ADAPTER_MALFUNC:
David S. Millercfa969e2010-12-06 20:45:28 -08001281 ehea_error("Adapter malfunction");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001282 break;
1283 case EHEA_EC_PORT_MALFUNC:
David S. Millercfa969e2010-12-06 20:45:28 -08001284 ehea_info("Port malfunction: Device: %s", port->netdev->name);
1285 netif_carrier_off(port->netdev);
1286 netif_stop_queue(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001287 break;
1288 default:
David S. Millercfa969e2010-12-06 20:45:28 -08001289 ehea_error("unknown event code %x, eqe=0x%llX", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001290 break;
1291 }
1292}
1293
1294static void ehea_neq_tasklet(unsigned long data)
1295{
Doug Maxey508d2b52008-01-31 20:20:49 -06001296 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001297 struct ehea_eqe *eqe;
1298 u64 event_mask;
1299
1300 eqe = ehea_poll_eq(adapter->neq);
David S. Millercfa969e2010-12-06 20:45:28 -08001301 ehea_debug("eqe=%p", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001302
1303 while (eqe) {
David S. Millercfa969e2010-12-06 20:45:28 -08001304 ehea_debug("*eqe=%lx", eqe->entry);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001305 ehea_parse_eqe(adapter, eqe->entry);
1306 eqe = ehea_poll_eq(adapter->neq);
David S. Millercfa969e2010-12-06 20:45:28 -08001307 ehea_debug("next eqe=%p", eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001308 }
1309
1310 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1311 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1312 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1313
1314 ehea_h_reset_events(adapter->handle,
1315 adapter->neq->fw_handle, event_mask);
1316}
1317
David Howells7d12e782006-10-05 14:55:46 +01001318static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001319{
1320 struct ehea_adapter *adapter = param;
1321 tasklet_hi_schedule(&adapter->neq_tasklet);
1322 return IRQ_HANDLED;
1323}
1324
1325
1326static int ehea_fill_port_res(struct ehea_port_res *pr)
1327{
1328 int ret;
1329 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1330
Thomas Kleine2878802009-01-21 14:45:57 -08001331 ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1332 - init_attr->act_nr_rwqes_rq2
1333 - init_attr->act_nr_rwqes_rq3 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001334
Thomas Kleine2878802009-01-21 14:45:57 -08001335 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001336
1337 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1338
1339 return ret;
1340}
1341
1342static int ehea_reg_interrupts(struct net_device *dev)
1343{
1344 struct ehea_port *port = netdev_priv(dev);
1345 struct ehea_port_res *pr;
1346 int i, ret;
1347
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001348
1349 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1350 dev->name);
1351
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001352 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001353 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001354 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001355 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08001356 ehea_error("failed registering irq for qp_aff_irq_handler:"
1357 "ist=%X", port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001358 goto out_free_qpeq;
1359 }
1360
David S. Millercfa969e2010-12-06 20:45:28 -08001361 if (netif_msg_ifup(port))
1362 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1363 "registered", port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001364
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001365
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001366 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1367 pr = &port->port_res[i];
1368 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001369 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001370 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001371 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001372 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001373 pr);
1374 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08001375 ehea_error("failed registering irq for ehea_queue "
1376 "port_res_nr:%d, ist=%X", i,
1377 pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001378 goto out_free_req;
1379 }
David S. Millercfa969e2010-12-06 20:45:28 -08001380 if (netif_msg_ifup(port))
1381 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1382 "%d registered", pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001383 }
1384out:
1385 return ret;
1386
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001387
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001388out_free_req:
1389 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001390 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001391 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001392 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001393
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001394out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001395 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001396 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001397
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001398 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001399
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001400}
1401
1402static void ehea_free_interrupts(struct net_device *dev)
1403{
1404 struct ehea_port *port = netdev_priv(dev);
1405 struct ehea_port_res *pr;
1406 int i;
1407
1408 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001409
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001410 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1411 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001412 ibmebus_free_irq(pr->eq->attr.ist1, pr);
David S. Millercfa969e2010-12-06 20:45:28 -08001413 if (netif_msg_intr(port))
1414 ehea_info("free send irq for res %d with handle 0x%X",
1415 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001416 }
1417
1418 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001419 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
David S. Millercfa969e2010-12-06 20:45:28 -08001420 if (netif_msg_intr(port))
1421 ehea_info("associated event interrupt for handle 0x%X freed",
1422 port->qp_eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001423}
1424
1425static int ehea_configure_port(struct ehea_port *port)
1426{
1427 int ret, i;
1428 u64 hret, mask;
1429 struct hcp_ehea_port_cb0 *cb0;
1430
1431 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001432 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001433 if (!cb0)
1434 goto out;
1435
1436 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1437 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1438 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1439 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1440 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1441 PXLY_RC_VLAN_FILTER)
1442 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1443
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001444 for (i = 0; i < port->num_mcs; i++)
1445 if (use_mcs)
1446 cb0->default_qpn_arr[i] =
1447 port->port_res[i].qp->init_attr.qp_nr;
1448 else
1449 cb0->default_qpn_arr[i] =
1450 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001451
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001452 if (netif_msg_ifup(port))
1453 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1454
1455 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1456 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1457
1458 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1459 port->logical_port_id,
1460 H_PORT_CB0, mask, cb0);
1461 ret = -EIO;
1462 if (hret != H_SUCCESS)
1463 goto out_free;
1464
1465 ret = 0;
1466
1467out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001468 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001469out:
1470 return ret;
1471}
1472
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001473int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001474{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001475 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001476 struct ehea_adapter *adapter = pr->port->adapter;
1477
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001478 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1479 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001480 goto out;
1481
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001482 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1483 if (ret)
1484 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001485
1486 return 0;
1487
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001488out_free:
1489 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001490out:
David S. Millercfa969e2010-12-06 20:45:28 -08001491 ehea_error("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001492 return -EIO;
1493}
1494
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001495int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001496{
Joe Perches8e95a202009-12-03 07:58:21 +00001497 if ((ehea_rem_mr(&pr->send_mr)) ||
1498 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001499 return -EIO;
1500 else
1501 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001502}
1503
1504static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1505{
Doug Maxey508d2b52008-01-31 20:20:49 -06001506 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001507
Eric Dumazet89bf67f2010-11-22 00:15:06 +00001508 q_skba->arr = vzalloc(arr_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001509 if (!q_skba->arr)
1510 return -ENOMEM;
1511
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001512 q_skba->len = max_q_entries;
1513 q_skba->index = 0;
1514 q_skba->os_skbs = 0;
1515
1516 return 0;
1517}
1518
1519static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1520 struct port_res_cfg *pr_cfg, int queue_token)
1521{
1522 struct ehea_adapter *adapter = port->adapter;
1523 enum ehea_eq_type eq_type = EHEA_EQ;
1524 struct ehea_qp_init_attr *init_attr = NULL;
1525 int ret = -EIO;
Breno Leitaoce45b872010-10-27 08:45:14 +00001526 u64 tx_bytes, rx_bytes, tx_packets, rx_packets;
1527
1528 tx_bytes = pr->tx_bytes;
1529 tx_packets = pr->tx_packets;
1530 rx_bytes = pr->rx_bytes;
1531 rx_packets = pr->rx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001532
1533 memset(pr, 0, sizeof(struct ehea_port_res));
1534
Breno Leitaoce45b872010-10-27 08:45:14 +00001535 pr->tx_bytes = rx_bytes;
1536 pr->tx_packets = tx_packets;
1537 pr->rx_bytes = rx_bytes;
1538 pr->rx_packets = rx_packets;
1539
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001540 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001541 spin_lock_init(&pr->xmit_lock);
1542 spin_lock_init(&pr->netif_queue);
1543
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001544 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1545 if (!pr->eq) {
David S. Millercfa969e2010-12-06 20:45:28 -08001546 ehea_error("create_eq failed (eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001547 goto out_free;
1548 }
1549
1550 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001551 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001552 port->logical_port_id);
1553 if (!pr->recv_cq) {
David S. Millercfa969e2010-12-06 20:45:28 -08001554 ehea_error("create_cq failed (cq_recv)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001555 goto out_free;
1556 }
1557
1558 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001559 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001560 port->logical_port_id);
1561 if (!pr->send_cq) {
David S. Millercfa969e2010-12-06 20:45:28 -08001562 ehea_error("create_cq failed (cq_send)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001563 goto out_free;
1564 }
1565
1566 if (netif_msg_ifup(port))
David S. Millercfa969e2010-12-06 20:45:28 -08001567 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1568 pr->send_cq->attr.act_nr_of_cqes,
1569 pr->recv_cq->attr.act_nr_of_cqes);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001570
1571 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1572 if (!init_attr) {
1573 ret = -ENOMEM;
David S. Millercfa969e2010-12-06 20:45:28 -08001574 ehea_error("no mem for ehea_qp_init_attr");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001575 goto out_free;
1576 }
1577
1578 init_attr->low_lat_rq1 = 1;
1579 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1580 init_attr->rq_count = 3;
1581 init_attr->qp_token = queue_token;
1582 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1583 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1584 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1585 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1586 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1587 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1588 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1589 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1590 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1591 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1592 init_attr->port_nr = port->logical_port_id;
1593 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1594 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1595 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1596
1597 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1598 if (!pr->qp) {
David S. Millercfa969e2010-12-06 20:45:28 -08001599 ehea_error("create_qp failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001600 ret = -EIO;
1601 goto out_free;
1602 }
1603
1604 if (netif_msg_ifup(port))
David S. Millercfa969e2010-12-06 20:45:28 -08001605 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1606 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1607 init_attr->act_nr_send_wqes,
1608 init_attr->act_nr_rwqes_rq1,
1609 init_attr->act_nr_rwqes_rq2,
1610 init_attr->act_nr_rwqes_rq3);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001611
Thomas Klein44fb3122008-04-04 15:04:53 +02001612 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1613
1614 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001615 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1616 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1617 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1618 if (ret)
1619 goto out_free;
1620
1621 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1622 if (ehea_gen_smrs(pr) != 0) {
1623 ret = -EIO;
1624 goto out_free;
1625 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001626
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001627 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1628
1629 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001630
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001631 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001632
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001633 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1634 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1635 pr->lro_mgr.lro_arr = pr->lro_desc;
1636 pr->lro_mgr.get_skb_header = get_skb_hdr;
1637 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1638 pr->lro_mgr.dev = port->netdev;
1639 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1640 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1641
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001642 ret = 0;
1643 goto out;
1644
1645out_free:
1646 kfree(init_attr);
1647 vfree(pr->sq_skba.arr);
1648 vfree(pr->rq1_skba.arr);
1649 vfree(pr->rq2_skba.arr);
1650 vfree(pr->rq3_skba.arr);
1651 ehea_destroy_qp(pr->qp);
1652 ehea_destroy_cq(pr->send_cq);
1653 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001654 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001655out:
1656 return ret;
1657}
1658
1659static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1660{
1661 int ret, i;
1662
Hannes Hering357eb462009-08-04 11:48:39 -07001663 if (pr->qp)
1664 netif_napi_del(&pr->napi);
1665
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001666 ret = ehea_destroy_qp(pr->qp);
1667
1668 if (!ret) {
1669 ehea_destroy_cq(pr->send_cq);
1670 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001671 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001672
1673 for (i = 0; i < pr->rq1_skba.len; i++)
1674 if (pr->rq1_skba.arr[i])
1675 dev_kfree_skb(pr->rq1_skba.arr[i]);
1676
1677 for (i = 0; i < pr->rq2_skba.len; i++)
1678 if (pr->rq2_skba.arr[i])
1679 dev_kfree_skb(pr->rq2_skba.arr[i]);
1680
1681 for (i = 0; i < pr->rq3_skba.len; i++)
1682 if (pr->rq3_skba.arr[i])
1683 dev_kfree_skb(pr->rq3_skba.arr[i]);
1684
1685 for (i = 0; i < pr->sq_skba.len; i++)
1686 if (pr->sq_skba.arr[i])
1687 dev_kfree_skb(pr->sq_skba.arr[i]);
1688
1689 vfree(pr->rq1_skba.arr);
1690 vfree(pr->rq2_skba.arr);
1691 vfree(pr->rq3_skba.arr);
1692 vfree(pr->sq_skba.arr);
1693 ret = ehea_rem_smrs(pr);
1694 }
1695 return ret;
1696}
1697
1698/*
1699 * The write_* functions store information in swqe which is used by
1700 * the hardware to calculate the ip/tcp/udp checksum
1701 */
1702
1703static inline void write_ip_start_end(struct ehea_swqe *swqe,
1704 const struct sk_buff *skb)
1705{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001706 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001707 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001708}
1709
1710static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1711 const struct sk_buff *skb)
1712{
1713 swqe->tcp_offset =
1714 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1715
1716 swqe->tcp_end = (u16)skb->len - 1;
1717}
1718
1719static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1720 const struct sk_buff *skb)
1721{
1722 swqe->tcp_offset =
1723 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1724
1725 swqe->tcp_end = (u16)skb->len - 1;
1726}
1727
1728
1729static void write_swqe2_TSO(struct sk_buff *skb,
1730 struct ehea_swqe *swqe, u32 lkey)
1731{
1732 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1733 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001734 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001735 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001736
1737 /* Packet is TCP with TSO enabled */
1738 swqe->tx_control |= EHEA_SWQE_TSO;
1739 swqe->mss = skb_shinfo(skb)->gso_size;
1740 /* copy only eth/ip/tcp headers to immediate data and
1741 * the rest of skb->data to sg1entry
1742 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001743 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001744
Eric Dumazete743d312010-04-14 15:59:40 -07001745 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001746
1747 if (skb_data_size >= headersize) {
1748 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001749 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001750 swqe->immediate_data_length = headersize;
1751
1752 if (skb_data_size > headersize) {
1753 /* set sg1entry data */
1754 sg1entry->l_key = lkey;
1755 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001756 sg1entry->vaddr =
1757 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001758 swqe->descriptors++;
1759 }
1760 } else
David S. Millercfa969e2010-12-06 20:45:28 -08001761 ehea_error("cannot handle fragmented headers");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001762}
1763
1764static void write_swqe2_nonTSO(struct sk_buff *skb,
1765 struct ehea_swqe *swqe, u32 lkey)
1766{
Eric Dumazete743d312010-04-14 15:59:40 -07001767 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001768 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1769 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001770
1771 /* Packet is any nonTSO type
1772 *
1773 * Copy as much as possible skb->data to immediate data and
1774 * the rest to sg1entry
1775 */
1776 if (skb_data_size >= SWQE2_MAX_IMM) {
1777 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001778 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001779
1780 swqe->immediate_data_length = SWQE2_MAX_IMM;
1781
1782 if (skb_data_size > SWQE2_MAX_IMM) {
1783 /* copy sg1entry data */
1784 sg1entry->l_key = lkey;
1785 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001786 sg1entry->vaddr =
1787 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001788 swqe->descriptors++;
1789 }
1790 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001791 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001792 swqe->immediate_data_length = skb_data_size;
1793 }
1794}
1795
1796static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1797 struct ehea_swqe *swqe, u32 lkey)
1798{
1799 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1800 skb_frag_t *frag;
1801 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001802
1803 nfrags = skb_shinfo(skb)->nr_frags;
1804 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001805 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001806 swqe->descriptors = 0;
1807 sg1entry_contains_frag_data = 0;
1808
1809 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1810 write_swqe2_TSO(skb, swqe, lkey);
1811 else
1812 write_swqe2_nonTSO(skb, swqe, lkey);
1813
1814 /* write descriptors */
1815 if (nfrags > 0) {
1816 if (swqe->descriptors == 0) {
1817 /* sg1entry not yet used */
1818 frag = &skb_shinfo(skb)->frags[0];
1819
1820 /* copy sg1entry data */
1821 sg1entry->l_key = lkey;
1822 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001823 sg1entry->vaddr =
1824 ehea_map_vaddr(page_address(frag->page)
1825 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001826 swqe->descriptors++;
1827 sg1entry_contains_frag_data = 1;
1828 }
1829
1830 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1831
1832 frag = &skb_shinfo(skb)->frags[i];
1833 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1834
1835 sgentry->l_key = lkey;
1836 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001837 sgentry->vaddr =
1838 ehea_map_vaddr(page_address(frag->page)
1839 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001840 swqe->descriptors++;
1841 }
1842 }
1843}
1844
1845static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1846{
1847 int ret = 0;
1848 u64 hret;
1849 u8 reg_type;
1850
1851 /* De/Register untagged packets */
1852 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1853 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1854 port->logical_port_id,
1855 reg_type, port->mac_addr, 0, hcallid);
1856 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08001857 ehea_error("%sregistering bc address failed (tagged)",
1858 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001859 ret = -EIO;
1860 goto out_herr;
1861 }
1862
1863 /* De/Register VLAN packets */
1864 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1865 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1866 port->logical_port_id,
1867 reg_type, port->mac_addr, 0, hcallid);
1868 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08001869 ehea_error("%sregistering bc address failed (vlan)",
1870 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001871 ret = -EIO;
1872 }
1873out_herr:
1874 return ret;
1875}
1876
1877static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1878{
1879 struct ehea_port *port = netdev_priv(dev);
1880 struct sockaddr *mac_addr = sa;
1881 struct hcp_ehea_port_cb0 *cb0;
1882 int ret;
1883 u64 hret;
1884
1885 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1886 ret = -EADDRNOTAVAIL;
1887 goto out;
1888 }
1889
Thomas Klein3faf2692009-01-21 14:45:33 -08001890 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001891 if (!cb0) {
David S. Millercfa969e2010-12-06 20:45:28 -08001892 ehea_error("no mem for cb0");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001893 ret = -ENOMEM;
1894 goto out;
1895 }
1896
1897 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1898
1899 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1900
1901 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1902 port->logical_port_id, H_PORT_CB0,
1903 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1904 if (hret != H_SUCCESS) {
1905 ret = -EIO;
1906 goto out_free;
1907 }
1908
1909 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1910
1911 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001912 if (port->state == EHEA_PORT_UP) {
1913 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1914 if (ret)
1915 goto out_upregs;
1916 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001917
1918 port->mac_addr = cb0->port_mac_addr << 16;
1919
1920 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001921 if (port->state == EHEA_PORT_UP) {
1922 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1923 if (ret)
1924 goto out_upregs;
1925 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001926
1927 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001928
1929out_upregs:
1930 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001931out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001932 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001933out:
1934 return ret;
1935}
1936
1937static void ehea_promiscuous_error(u64 hret, int enable)
1938{
Thomas Klein7674a582007-01-22 12:54:20 +01001939 if (hret == H_AUTHORITY)
David S. Millercfa969e2010-12-06 20:45:28 -08001940 ehea_info("Hypervisor denied %sabling promiscuous mode",
1941 enable == 1 ? "en" : "dis");
Thomas Klein7674a582007-01-22 12:54:20 +01001942 else
David S. Millercfa969e2010-12-06 20:45:28 -08001943 ehea_error("failed %sabling promiscuous mode",
1944 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001945}
1946
1947static void ehea_promiscuous(struct net_device *dev, int enable)
1948{
1949 struct ehea_port *port = netdev_priv(dev);
1950 struct hcp_ehea_port_cb7 *cb7;
1951 u64 hret;
1952
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001953 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001954 return;
1955
Thomas Klein3faf2692009-01-21 14:45:33 -08001956 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001957 if (!cb7) {
David S. Millercfa969e2010-12-06 20:45:28 -08001958 ehea_error("no mem for cb7");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001959 goto out;
1960 }
1961
1962 /* Modify Pxs_DUCQPN in CB7 */
1963 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1964
1965 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1966 port->logical_port_id,
1967 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1968 if (hret) {
1969 ehea_promiscuous_error(hret, enable);
1970 goto out;
1971 }
1972
1973 port->promisc = enable;
1974out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001975 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001976}
1977
1978static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1979 u32 hcallid)
1980{
1981 u64 hret;
1982 u8 reg_type;
1983
1984 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1985 | EHEA_BCMC_UNTAGGED;
1986
1987 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1988 port->logical_port_id,
1989 reg_type, mc_mac_addr, 0, hcallid);
1990 if (hret)
1991 goto out;
1992
1993 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1994 | EHEA_BCMC_VLANID_ALL;
1995
1996 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1997 port->logical_port_id,
1998 reg_type, mc_mac_addr, 0, hcallid);
1999out:
2000 return hret;
2001}
2002
2003static int ehea_drop_multicast_list(struct net_device *dev)
2004{
2005 struct ehea_port *port = netdev_priv(dev);
2006 struct ehea_mc_list *mc_entry = port->mc_list;
2007 struct list_head *pos;
2008 struct list_head *temp;
2009 int ret = 0;
2010 u64 hret;
2011
2012 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
2013 mc_entry = list_entry(pos, struct ehea_mc_list, list);
2014
2015 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
2016 H_DEREG_BCMC);
2017 if (hret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002018 ehea_error("failed deregistering mcast MAC");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002019 ret = -EIO;
2020 }
2021
2022 list_del(pos);
2023 kfree(mc_entry);
2024 }
2025 return ret;
2026}
2027
2028static void ehea_allmulti(struct net_device *dev, int enable)
2029{
2030 struct ehea_port *port = netdev_priv(dev);
2031 u64 hret;
2032
2033 if (!port->allmulti) {
2034 if (enable) {
2035 /* Enable ALLMULTI */
2036 ehea_drop_multicast_list(dev);
2037 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
2038 if (!hret)
2039 port->allmulti = 1;
2040 else
David S. Millercfa969e2010-12-06 20:45:28 -08002041 ehea_error("failed enabling IFF_ALLMULTI");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002042 }
2043 } else
2044 if (!enable) {
2045 /* Disable ALLMULTI */
2046 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
2047 if (!hret)
2048 port->allmulti = 0;
2049 else
David S. Millercfa969e2010-12-06 20:45:28 -08002050 ehea_error("failed disabling IFF_ALLMULTI");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002051 }
2052}
2053
Doug Maxey508d2b52008-01-31 20:20:49 -06002054static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002055{
2056 struct ehea_mc_list *ehea_mcl_entry;
2057 u64 hret;
2058
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02002059 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002060 if (!ehea_mcl_entry) {
David S. Millercfa969e2010-12-06 20:45:28 -08002061 ehea_error("no mem for mcl_entry");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002062 return;
2063 }
2064
2065 INIT_LIST_HEAD(&ehea_mcl_entry->list);
2066
2067 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
2068
2069 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
2070 H_REG_BCMC);
2071 if (!hret)
2072 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
2073 else {
David S. Millercfa969e2010-12-06 20:45:28 -08002074 ehea_error("failed registering mcast MAC");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002075 kfree(ehea_mcl_entry);
2076 }
2077}
2078
2079static void ehea_set_multicast_list(struct net_device *dev)
2080{
2081 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00002082 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002083 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002084
2085 if (dev->flags & IFF_PROMISC) {
2086 ehea_promiscuous(dev, 1);
2087 return;
2088 }
2089 ehea_promiscuous(dev, 0);
2090
2091 if (dev->flags & IFF_ALLMULTI) {
2092 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002093 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002094 }
2095 ehea_allmulti(dev, 0);
2096
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002097 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002098 ret = ehea_drop_multicast_list(dev);
2099 if (ret) {
2100 /* Dropping the current multicast list failed.
2101 * Enabling ALL_MULTI is the best we can do.
2102 */
2103 ehea_allmulti(dev, 1);
2104 }
2105
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002106 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
David S. Millercfa969e2010-12-06 20:45:28 -08002107 ehea_info("Mcast registration limit reached (0x%llx). "
2108 "Use ALLMULTI!",
2109 port->adapter->max_mc_mac);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002110 goto out;
2111 }
2112
Jiri Pirko22bedad32010-04-01 21:22:57 +00002113 netdev_for_each_mc_addr(ha, dev)
2114 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002115
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002116 }
2117out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002118 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002119}
2120
2121static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2122{
2123 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2124 return -EINVAL;
2125 dev->mtu = new_mtu;
2126 return 0;
2127}
2128
2129static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2130 struct ehea_swqe *swqe, u32 lkey)
2131{
2132 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002133 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002134
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002135 /* IPv4 */
2136 swqe->tx_control |= EHEA_SWQE_CRC
2137 | EHEA_SWQE_IP_CHECKSUM
2138 | EHEA_SWQE_TCP_CHECKSUM
2139 | EHEA_SWQE_IMM_DATA_PRESENT
2140 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2141
2142 write_ip_start_end(swqe, skb);
2143
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002144 if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002145 if ((iph->frag_off & IP_MF) ||
2146 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002147 /* IP fragment, so don't change cs */
2148 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2149 else
2150 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002151 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002152 write_tcp_offset_end(swqe, skb);
2153 }
2154
2155 /* icmp (big data) and ip segmentation packets (all other ip
2156 packets) do not require any special handling */
2157
2158 } else {
2159 /* Other Ethernet Protocol */
2160 swqe->tx_control |= EHEA_SWQE_CRC
2161 | EHEA_SWQE_IMM_DATA_PRESENT
2162 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2163 }
2164
2165 write_swqe2_data(skb, dev, swqe, lkey);
2166}
2167
2168static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2169 struct ehea_swqe *swqe)
2170{
2171 int nfrags = skb_shinfo(skb)->nr_frags;
2172 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2173 skb_frag_t *frag;
2174 int i;
2175
2176 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002177 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002178
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002179 /* IPv4 */
2180 write_ip_start_end(swqe, skb);
2181
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002182 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002183 swqe->tx_control |= EHEA_SWQE_CRC
2184 | EHEA_SWQE_IP_CHECKSUM
2185 | EHEA_SWQE_TCP_CHECKSUM
2186 | EHEA_SWQE_IMM_DATA_PRESENT;
2187
2188 write_tcp_offset_end(swqe, skb);
2189
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002190 } else if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002191 if ((iph->frag_off & IP_MF) ||
2192 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002193 /* IP fragment, so don't change cs */
2194 swqe->tx_control |= EHEA_SWQE_CRC
2195 | EHEA_SWQE_IMM_DATA_PRESENT;
2196 else {
2197 swqe->tx_control |= EHEA_SWQE_CRC
2198 | EHEA_SWQE_IP_CHECKSUM
2199 | EHEA_SWQE_TCP_CHECKSUM
2200 | EHEA_SWQE_IMM_DATA_PRESENT;
2201
2202 write_udp_offset_end(swqe, skb);
2203 }
2204 } else {
2205 /* icmp (big data) and
2206 ip segmentation packets (all other ip packets) */
2207 swqe->tx_control |= EHEA_SWQE_CRC
2208 | EHEA_SWQE_IP_CHECKSUM
2209 | EHEA_SWQE_IMM_DATA_PRESENT;
2210 }
2211 } else {
2212 /* Other Ethernet Protocol */
2213 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2214 }
2215 /* copy (immediate) data */
2216 if (nfrags == 0) {
2217 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002218 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002219 } else {
2220 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002221 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002222 skb_headlen(skb));
2223 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002224
2225 /* ... then copy data from the fragments */
2226 for (i = 0; i < nfrags; i++) {
2227 frag = &skb_shinfo(skb)->frags[i];
2228 memcpy(imm_data,
2229 page_address(frag->page) + frag->page_offset,
2230 frag->size);
2231 imm_data += frag->size;
2232 }
2233 }
2234 swqe->immediate_data_length = skb->len;
2235 dev_kfree_skb(skb);
2236}
2237
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002238static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2239{
2240 struct tcphdr *tcp;
2241 u32 tmp;
2242
2243 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002244 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002245 tcp = (struct tcphdr *)(skb_network_header(skb) +
2246 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002247 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002248 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002249 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002250 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002251 return 0;
2252}
2253
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002254static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2255{
2256 struct ehea_port *port = netdev_priv(dev);
2257 struct ehea_swqe *swqe;
2258 unsigned long flags;
2259 u32 lkey;
2260 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002261 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002262
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002263 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2264
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002265 if (!spin_trylock(&pr->xmit_lock))
2266 return NETDEV_TX_BUSY;
2267
2268 if (pr->queue_stopped) {
2269 spin_unlock(&pr->xmit_lock);
2270 return NETDEV_TX_BUSY;
2271 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002272
2273 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2274 memset(swqe, 0, SWQE_HEADER_SIZE);
2275 atomic_dec(&pr->swqe_avail);
2276
Eric Dumazete5ccd962010-10-26 19:21:07 +00002277 if (vlan_tx_tag_present(skb)) {
2278 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2279 swqe->vlan_tag = vlan_tx_tag_get(skb);
2280 }
2281
Breno Leitaoce45b872010-10-27 08:45:14 +00002282 pr->tx_packets++;
2283 pr->tx_bytes += skb->len;
2284
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002285 if (skb->len <= SWQE3_MAX_IMM) {
2286 u32 sig_iv = port->sig_comp_iv;
2287 u32 swqe_num = pr->swqe_id_counter;
2288 ehea_xmit3(skb, dev, swqe);
2289 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2290 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2291 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2292 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2293 sig_iv);
2294 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2295 pr->swqe_ll_count = 0;
2296 } else
2297 pr->swqe_ll_count += 1;
2298 } else {
2299 swqe->wr_id =
2300 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2301 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002302 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002303 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2304 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2305
2306 pr->sq_skba.index++;
2307 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2308
2309 lkey = pr->send_mr.lkey;
2310 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002311 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002312 }
2313 pr->swqe_id_counter += 1;
2314
David S. Millercfa969e2010-12-06 20:45:28 -08002315 if (netif_msg_tx_queued(port)) {
2316 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002317 ehea_dump(swqe, 512, "swqe");
David S. Millercfa969e2010-12-06 20:45:28 -08002318 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002319
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002320 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2321 netif_stop_queue(dev);
2322 swqe->tx_control |= EHEA_SWQE_PURGE;
2323 }
Thomas Klein44c82152007-07-11 16:32:00 +02002324
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002325 ehea_post_swqe(pr->qp, swqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002326
2327 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2328 spin_lock_irqsave(&pr->netif_queue, flags);
2329 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002330 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002331 netif_stop_queue(dev);
2332 pr->queue_stopped = 1;
2333 }
2334 spin_unlock_irqrestore(&pr->netif_queue, flags);
2335 }
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07002336 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002337 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002338
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002339 return NETDEV_TX_OK;
2340}
2341
2342static void ehea_vlan_rx_register(struct net_device *dev,
2343 struct vlan_group *grp)
2344{
2345 struct ehea_port *port = netdev_priv(dev);
2346 struct ehea_adapter *adapter = port->adapter;
2347 struct hcp_ehea_port_cb1 *cb1;
2348 u64 hret;
2349
2350 port->vgrp = grp;
2351
Thomas Klein3faf2692009-01-21 14:45:33 -08002352 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002353 if (!cb1) {
David S. Millercfa969e2010-12-06 20:45:28 -08002354 ehea_error("no mem for cb1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002355 goto out;
2356 }
2357
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002358 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2359 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2360 if (hret != H_SUCCESS)
David S. Millercfa969e2010-12-06 20:45:28 -08002361 ehea_error("modify_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002362
Thomas Klein3faf2692009-01-21 14:45:33 -08002363 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002364out:
2365 return;
2366}
2367
2368static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2369{
2370 struct ehea_port *port = netdev_priv(dev);
2371 struct ehea_adapter *adapter = port->adapter;
2372 struct hcp_ehea_port_cb1 *cb1;
2373 int index;
2374 u64 hret;
2375
Thomas Klein3faf2692009-01-21 14:45:33 -08002376 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002377 if (!cb1) {
David S. Millercfa969e2010-12-06 20:45:28 -08002378 ehea_error("no mem for cb1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002379 goto out;
2380 }
2381
2382 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2383 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2384 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002385 ehea_error("query_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002386 goto out;
2387 }
2388
2389 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002390 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002391
2392 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2393 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2394 if (hret != H_SUCCESS)
David S. Millercfa969e2010-12-06 20:45:28 -08002395 ehea_error("modify_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002396out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002397 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002398 return;
2399}
2400
2401static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2402{
2403 struct ehea_port *port = netdev_priv(dev);
2404 struct ehea_adapter *adapter = port->adapter;
2405 struct hcp_ehea_port_cb1 *cb1;
2406 int index;
2407 u64 hret;
2408
Dan Aloni5c15bde2007-03-02 20:44:51 -08002409 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002410
Thomas Klein3faf2692009-01-21 14:45:33 -08002411 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002412 if (!cb1) {
David S. Millercfa969e2010-12-06 20:45:28 -08002413 ehea_error("no mem for cb1");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002414 goto out;
2415 }
2416
2417 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2418 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2419 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002420 ehea_error("query_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002421 goto out;
2422 }
2423
2424 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002425 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002426
2427 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2428 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2429 if (hret != H_SUCCESS)
David S. Millercfa969e2010-12-06 20:45:28 -08002430 ehea_error("modify_ehea_port failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002431out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002432 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002433}
2434
2435int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2436{
2437 int ret = -EIO;
2438 u64 hret;
2439 u16 dummy16 = 0;
2440 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002441 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002442
Thomas Klein3faf2692009-01-21 14:45:33 -08002443 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002444 if (!cb0) {
2445 ret = -ENOMEM;
2446 goto out;
2447 }
2448
2449 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2450 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2451 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002452 ehea_error("query_ehea_qp failed (1)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002453 goto out;
2454 }
2455
2456 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2457 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2458 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2459 &dummy64, &dummy64, &dummy16, &dummy16);
2460 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002461 ehea_error("modify_ehea_qp failed (1)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002462 goto out;
2463 }
2464
2465 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2466 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2467 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002468 ehea_error("query_ehea_qp failed (2)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002469 goto out;
2470 }
2471
2472 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2473 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2474 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2475 &dummy64, &dummy64, &dummy16, &dummy16);
2476 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002477 ehea_error("modify_ehea_qp failed (2)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002478 goto out;
2479 }
2480
2481 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2482 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2483 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002484 ehea_error("query_ehea_qp failed (3)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002485 goto out;
2486 }
2487
2488 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2489 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2490 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2491 &dummy64, &dummy64, &dummy16, &dummy16);
2492 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002493 ehea_error("modify_ehea_qp failed (3)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002494 goto out;
2495 }
2496
2497 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2498 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2499 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002500 ehea_error("query_ehea_qp failed (4)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002501 goto out;
2502 }
2503
2504 ret = 0;
2505out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002506 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002507 return ret;
2508}
2509
2510static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2511 int add_tx_qps)
2512{
2513 int ret, i;
2514 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2515 enum ehea_eq_type eq_type = EHEA_EQ;
2516
2517 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2518 EHEA_MAX_ENTRIES_EQ, 1);
2519 if (!port->qp_eq) {
2520 ret = -EINVAL;
David S. Millercfa969e2010-12-06 20:45:28 -08002521 ehea_error("ehea_create_eq failed (qp_eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002522 goto out_kill_eq;
2523 }
2524
2525 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002526 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002527 pr_cfg.max_entries_sq = sq_entries;
2528 pr_cfg.max_entries_rq1 = rq1_entries;
2529 pr_cfg.max_entries_rq2 = rq2_entries;
2530 pr_cfg.max_entries_rq3 = rq3_entries;
2531
2532 pr_cfg_small_rx.max_entries_rcq = 1;
2533 pr_cfg_small_rx.max_entries_scq = sq_entries;
2534 pr_cfg_small_rx.max_entries_sq = sq_entries;
2535 pr_cfg_small_rx.max_entries_rq1 = 1;
2536 pr_cfg_small_rx.max_entries_rq2 = 1;
2537 pr_cfg_small_rx.max_entries_rq3 = 1;
2538
2539 for (i = 0; i < def_qps; i++) {
2540 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2541 if (ret)
2542 goto out_clean_pr;
2543 }
2544 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2545 ret = ehea_init_port_res(port, &port->port_res[i],
2546 &pr_cfg_small_rx, i);
2547 if (ret)
2548 goto out_clean_pr;
2549 }
2550
2551 return 0;
2552
2553out_clean_pr:
2554 while (--i >= 0)
2555 ehea_clean_portres(port, &port->port_res[i]);
2556
2557out_kill_eq:
2558 ehea_destroy_eq(port->qp_eq);
2559 return ret;
2560}
2561
2562static int ehea_clean_all_portres(struct ehea_port *port)
2563{
2564 int ret = 0;
2565 int i;
2566
Doug Maxey508d2b52008-01-31 20:20:49 -06002567 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002568 ret |= ehea_clean_portres(port, &port->port_res[i]);
2569
2570 ret |= ehea_destroy_eq(port->qp_eq);
2571
2572 return ret;
2573}
2574
Thomas Klein35cf2e22007-08-06 13:55:14 +02002575static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002576{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002577 if (adapter->active_ports)
2578 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002579
2580 ehea_rem_mr(&adapter->mr);
2581}
2582
Thomas Klein35cf2e22007-08-06 13:55:14 +02002583static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002584{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002585 if (adapter->active_ports)
2586 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002587
2588 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2589}
2590
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002591static int ehea_up(struct net_device *dev)
2592{
2593 int ret, i;
2594 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002595
2596 if (port->state == EHEA_PORT_UP)
2597 return 0;
2598
2599 ret = ehea_port_res_setup(port, port->num_def_qps,
2600 port->num_add_tx_qps);
2601 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002602 ehea_error("port_res_failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002603 goto out;
2604 }
2605
2606 /* Set default QP for this port */
2607 ret = ehea_configure_port(port);
2608 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002609 ehea_error("ehea_configure_port failed. ret:%d", ret);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002610 goto out_clean_pr;
2611 }
2612
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002613 ret = ehea_reg_interrupts(dev);
2614 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002615 ehea_error("reg_interrupts failed. ret:%d", ret);
Thomas Kleinf9e29222007-07-18 17:34:09 +02002616 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002617 }
2618
Doug Maxey508d2b52008-01-31 20:20:49 -06002619 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002620 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2621 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002622 ehea_error("activate_qp failed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002623 goto out_free_irqs;
2624 }
2625 }
2626
Doug Maxey508d2b52008-01-31 20:20:49 -06002627 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002628 ret = ehea_fill_port_res(&port->port_res[i]);
2629 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002630 ehea_error("out_free_irqs");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002631 goto out_free_irqs;
2632 }
2633 }
2634
Thomas Klein21eee2d2008-02-13 16:18:33 +01002635 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2636 if (ret) {
2637 ret = -EIO;
2638 goto out_free_irqs;
2639 }
2640
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002641 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002642
2643 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002644 goto out;
2645
2646out_free_irqs:
2647 ehea_free_interrupts(dev);
2648
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002649out_clean_pr:
2650 ehea_clean_all_portres(port);
2651out:
Thomas Klein44c82152007-07-11 16:32:00 +02002652 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08002653 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002654
Thomas Klein21eee2d2008-02-13 16:18:33 +01002655 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002656 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002657
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002658 return ret;
2659}
2660
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002661static void port_napi_disable(struct ehea_port *port)
2662{
2663 int i;
2664
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002665 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002666 napi_disable(&port->port_res[i].napi);
2667}
2668
2669static void port_napi_enable(struct ehea_port *port)
2670{
2671 int i;
2672
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002673 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002674 napi_enable(&port->port_res[i].napi);
2675}
2676
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002677static int ehea_open(struct net_device *dev)
2678{
2679 int ret;
2680 struct ehea_port *port = netdev_priv(dev);
2681
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002682 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002683
David S. Millercfa969e2010-12-06 20:45:28 -08002684 if (netif_msg_ifup(port))
2685 ehea_info("enabling port %s", dev->name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002686
2687 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002688 if (!ret) {
2689 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002690 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002691 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002692
Breno Leitao5b27d422010-10-05 13:16:22 +00002693 init_waitqueue_head(&port->swqe_avail_wq);
Breno Leitaoa8bb69f2010-10-05 13:16:23 +00002694 init_waitqueue_head(&port->restart_wq);
Breno Leitao5b27d422010-10-05 13:16:22 +00002695
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002696 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002697
2698 return ret;
2699}
2700
2701static int ehea_down(struct net_device *dev)
2702{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002703 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002704 struct ehea_port *port = netdev_priv(dev);
2705
2706 if (port->state == EHEA_PORT_DOWN)
2707 return 0;
2708
2709 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002710 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2711
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002712 ehea_free_interrupts(dev);
2713
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002714 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002715
Thomas Klein21eee2d2008-02-13 16:18:33 +01002716 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002717
Thomas Klein44c82152007-07-11 16:32:00 +02002718 ret = ehea_clean_all_portres(port);
2719 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08002720 ehea_info("Failed freeing resources for %s. ret=%i",
2721 dev->name, ret);
Thomas Klein44c82152007-07-11 16:32:00 +02002722
Thomas Klein21eee2d2008-02-13 16:18:33 +01002723 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002724
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002725 return ret;
2726}
2727
2728static int ehea_stop(struct net_device *dev)
2729{
2730 int ret;
2731 struct ehea_port *port = netdev_priv(dev);
2732
David S. Millercfa969e2010-12-06 20:45:28 -08002733 if (netif_msg_ifdown(port))
2734 ehea_info("disabling port %s", dev->name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002735
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002736 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002737 cancel_work_sync(&port->reset_task);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002738 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002739 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002740 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002741 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002742 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002743 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002744 return ret;
2745}
2746
Andrew Morton22559c52008-04-18 13:50:39 -07002747static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002748{
2749 struct ehea_qp qp = *orig_qp;
2750 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2751 struct ehea_swqe *swqe;
2752 int wqe_index;
2753 int i;
2754
2755 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2756 swqe = ehea_get_swqe(&qp, &wqe_index);
2757 swqe->tx_control |= EHEA_SWQE_PURGE;
2758 }
2759}
2760
Andrew Morton22559c52008-04-18 13:50:39 -07002761static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002762{
2763 int i;
2764
2765 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2766 struct ehea_port_res *pr = &port->port_res[i];
2767 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002768 int ret;
2769
2770 ret = wait_event_timeout(port->swqe_avail_wq,
2771 atomic_read(&pr->swqe_avail) >= swqe_max,
2772 msecs_to_jiffies(100));
2773
2774 if (!ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002775 ehea_error("WARNING: sq not flushed completely");
Breno Leitao5b27d422010-10-05 13:16:22 +00002776 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002777 }
2778 }
2779}
2780
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002781int ehea_stop_qps(struct net_device *dev)
2782{
2783 struct ehea_port *port = netdev_priv(dev);
2784 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002785 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002786 int ret = -EIO;
2787 int dret;
2788 int i;
2789 u64 hret;
2790 u64 dummy64 = 0;
2791 u16 dummy16 = 0;
2792
Thomas Klein3faf2692009-01-21 14:45:33 -08002793 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002794 if (!cb0) {
2795 ret = -ENOMEM;
2796 goto out;
2797 }
2798
2799 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2800 struct ehea_port_res *pr = &port->port_res[i];
2801 struct ehea_qp *qp = pr->qp;
2802
2803 /* Purge send queue */
2804 ehea_purge_sq(qp);
2805
2806 /* Disable queue pair */
2807 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2808 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2809 cb0);
2810 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002811 ehea_error("query_ehea_qp failed (1)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002812 goto out;
2813 }
2814
2815 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2816 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2817
2818 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2819 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2820 1), cb0, &dummy64,
2821 &dummy64, &dummy16, &dummy16);
2822 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002823 ehea_error("modify_ehea_qp failed (1)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002824 goto out;
2825 }
2826
2827 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2828 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2829 cb0);
2830 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002831 ehea_error("query_ehea_qp failed (2)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002832 goto out;
2833 }
2834
2835 /* deregister shared memory regions */
2836 dret = ehea_rem_smrs(pr);
2837 if (dret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002838 ehea_error("unreg shared memory region failed");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002839 goto out;
2840 }
2841 }
2842
2843 ret = 0;
2844out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002845 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002846
2847 return ret;
2848}
2849
Doug Maxey508d2b52008-01-31 20:20:49 -06002850void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002851{
2852 struct ehea_qp qp = *orig_qp;
2853 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2854 struct ehea_rwqe *rwqe;
2855 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2856 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2857 struct sk_buff *skb;
2858 u32 lkey = pr->recv_mr.lkey;
2859
2860
2861 int i;
2862 int index;
2863
2864 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2865 rwqe = ehea_get_next_rwqe(&qp, 2);
2866 rwqe->sg_list[0].l_key = lkey;
2867 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2868 skb = skba_rq2[index];
2869 if (skb)
2870 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2871 }
2872
2873 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2874 rwqe = ehea_get_next_rwqe(&qp, 3);
2875 rwqe->sg_list[0].l_key = lkey;
2876 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2877 skb = skba_rq3[index];
2878 if (skb)
2879 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2880 }
2881}
2882
2883int ehea_restart_qps(struct net_device *dev)
2884{
2885 struct ehea_port *port = netdev_priv(dev);
2886 struct ehea_adapter *adapter = port->adapter;
2887 int ret = 0;
2888 int i;
2889
Doug Maxey508d2b52008-01-31 20:20:49 -06002890 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002891 u64 hret;
2892 u64 dummy64 = 0;
2893 u16 dummy16 = 0;
2894
Thomas Klein3faf2692009-01-21 14:45:33 -08002895 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002896 if (!cb0) {
2897 ret = -ENOMEM;
2898 goto out;
2899 }
2900
2901 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2902 struct ehea_port_res *pr = &port->port_res[i];
2903 struct ehea_qp *qp = pr->qp;
2904
2905 ret = ehea_gen_smrs(pr);
2906 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08002907 ehea_error("creation of shared memory regions failed");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002908 goto out;
2909 }
2910
2911 ehea_update_rqs(qp, pr);
2912
2913 /* Enable queue pair */
2914 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2915 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2916 cb0);
2917 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002918 ehea_error("query_ehea_qp failed (1)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002919 goto out;
2920 }
2921
2922 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2923 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2924
2925 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2926 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2927 1), cb0, &dummy64,
2928 &dummy64, &dummy16, &dummy16);
2929 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002930 ehea_error("modify_ehea_qp failed (1)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002931 goto out;
2932 }
2933
2934 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2935 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2936 cb0);
2937 if (hret != H_SUCCESS) {
David S. Millercfa969e2010-12-06 20:45:28 -08002938 ehea_error("query_ehea_qp failed (2)");
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002939 goto out;
2940 }
2941
2942 /* refill entire queue */
2943 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2944 ehea_refill_rq2(pr, 0);
2945 ehea_refill_rq3(pr, 0);
2946 }
2947out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002948 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002949
2950 return ret;
2951}
2952
David Howellsc4028952006-11-22 14:57:56 +00002953static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002954{
2955 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002956 struct ehea_port *port =
2957 container_of(work, struct ehea_port, reset_task);
2958 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002959
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002960 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002961 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002962 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002963 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002964
2965 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002966
Thomas Klein44c82152007-07-11 16:32:00 +02002967 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002968
2969 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002970 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002971 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002972
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002973 ehea_set_multicast_list(dev);
2974
David S. Millercfa969e2010-12-06 20:45:28 -08002975 if (netif_msg_timer(port))
2976 ehea_info("Device %s resetted successfully", dev->name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002977
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002978 port_napi_enable(port);
2979
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002980 netif_wake_queue(dev);
2981out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002982 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002983 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002984}
2985
Tejun Heo3d6b8922010-12-12 16:45:14 +01002986static void ehea_rereg_mrs(void)
Thomas Klein44c82152007-07-11 16:32:00 +02002987{
2988 int ret, i;
2989 struct ehea_adapter *adapter;
2990
David S. Millercfa969e2010-12-06 20:45:28 -08002991 ehea_info("LPAR memory changed - re-initializing driver");
Thomas Klein44c82152007-07-11 16:32:00 +02002992
2993 list_for_each_entry(adapter, &adapter_list, list)
2994 if (adapter->active_ports) {
2995 /* Shutdown all ports */
2996 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2997 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002998 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002999
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003000 if (!port)
3001 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02003002
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003003 dev = port->netdev;
3004
3005 if (dev->flags & IFF_UP) {
3006 mutex_lock(&port->port_lock);
3007 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07003008 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003009 ret = ehea_stop_qps(dev);
3010 if (ret) {
3011 mutex_unlock(&port->port_lock);
3012 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003013 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003014 port_napi_disable(port);
3015 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003016 }
Andre Detsch2928db42010-08-17 05:49:12 +00003017 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02003018 }
3019
3020 /* Unregister old memory region */
3021 ret = ehea_rem_mr(&adapter->mr);
3022 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003023 ehea_error("unregister MR failed - driver"
3024 " inoperable!");
Thomas Klein44c82152007-07-11 16:32:00 +02003025 goto out;
3026 }
3027 }
3028
Thomas Klein44c82152007-07-11 16:32:00 +02003029 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
3030
3031 list_for_each_entry(adapter, &adapter_list, list)
3032 if (adapter->active_ports) {
3033 /* Register new memory region */
3034 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
3035 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003036 ehea_error("register MR failed - driver"
3037 " inoperable!");
Thomas Klein44c82152007-07-11 16:32:00 +02003038 goto out;
3039 }
3040
3041 /* Restart all ports */
3042 for (i = 0; i < EHEA_MAX_PORTS; i++) {
3043 struct ehea_port *port = adapter->port[i];
3044
3045 if (port) {
3046 struct net_device *dev = port->netdev;
3047
3048 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003049 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003050 port_napi_enable(port);
3051 ret = ehea_restart_qps(dev);
Andre Detsch2928db42010-08-17 05:49:12 +00003052 check_sqs(port);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003053 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02003054 netif_wake_queue(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003055 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003056 }
3057 }
3058 }
3059 }
David S. Millercfa969e2010-12-06 20:45:28 -08003060 ehea_info("re-initializing driver complete");
Thomas Klein44c82152007-07-11 16:32:00 +02003061out:
3062 return;
3063}
3064
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003065static void ehea_tx_watchdog(struct net_device *dev)
3066{
3067 struct ehea_port *port = netdev_priv(dev);
3068
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003069 if (netif_carrier_ok(dev) &&
3070 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01003071 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003072}
3073
3074int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
3075{
3076 struct hcp_query_ehea *cb;
3077 u64 hret;
3078 int ret;
3079
Thomas Klein3faf2692009-01-21 14:45:33 -08003080 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003081 if (!cb) {
3082 ret = -ENOMEM;
3083 goto out;
3084 }
3085
3086 hret = ehea_h_query_ehea(adapter->handle, cb);
3087
3088 if (hret != H_SUCCESS) {
3089 ret = -EIO;
3090 goto out_herr;
3091 }
3092
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003093 adapter->max_mc_mac = cb->max_mc_mac - 1;
3094 ret = 0;
3095
3096out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08003097 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003098out:
3099 return ret;
3100}
3101
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003102int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
3103{
3104 struct hcp_ehea_port_cb4 *cb4;
3105 u64 hret;
3106 int ret = 0;
3107
3108 *jumbo = 0;
3109
3110 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08003111 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003112 if (!cb4) {
David S. Millercfa969e2010-12-06 20:45:28 -08003113 ehea_error("no mem for cb4");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003114 ret = -ENOMEM;
3115 goto out;
3116 } else {
3117 hret = ehea_h_query_ehea_port(port->adapter->handle,
3118 port->logical_port_id,
3119 H_PORT_CB4,
3120 H_PORT_CB4_JUMBO, cb4);
3121 if (hret == H_SUCCESS) {
3122 if (cb4->jumbo_frame)
3123 *jumbo = 1;
3124 else {
3125 cb4->jumbo_frame = 1;
3126 hret = ehea_h_modify_ehea_port(port->adapter->
3127 handle,
3128 port->
3129 logical_port_id,
3130 H_PORT_CB4,
3131 H_PORT_CB4_JUMBO,
3132 cb4);
3133 if (hret == H_SUCCESS)
3134 *jumbo = 1;
3135 }
3136 } else
3137 ret = -EINVAL;
3138
Thomas Klein3faf2692009-01-21 14:45:33 -08003139 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003140 }
3141out:
3142 return ret;
3143}
3144
3145static ssize_t ehea_show_port_id(struct device *dev,
3146 struct device_attribute *attr, char *buf)
3147{
3148 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003149 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003150}
3151
3152static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3153 NULL);
3154
3155static void __devinit logical_port_release(struct device *dev)
3156{
3157 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07003158 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003159}
3160
3161static struct device *ehea_register_port(struct ehea_port *port,
3162 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003163{
3164 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003165
Grant Likely61c7a082010-04-13 16:12:29 -07003166 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003167 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003168 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003169
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003170 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003171 port->ofdev.dev.release = logical_port_release;
3172
3173 ret = of_device_register(&port->ofdev);
3174 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003175 ehea_error("failed to register device. ret=%d", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003176 goto out;
3177 }
3178
3179 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003180 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003181 ehea_error("failed to register attributes, ret=%d", ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003182 goto out_unreg_of_dev;
3183 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003184
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003185 return &port->ofdev.dev;
3186
3187out_unreg_of_dev:
3188 of_device_unregister(&port->ofdev);
3189out:
3190 return NULL;
3191}
3192
3193static void ehea_unregister_port(struct ehea_port *port)
3194{
3195 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3196 of_device_unregister(&port->ofdev);
3197}
3198
Thomas Klein086c1b22009-01-21 14:43:59 -08003199static const struct net_device_ops ehea_netdev_ops = {
3200 .ndo_open = ehea_open,
3201 .ndo_stop = ehea_stop,
3202 .ndo_start_xmit = ehea_start_xmit,
3203#ifdef CONFIG_NET_POLL_CONTROLLER
3204 .ndo_poll_controller = ehea_netpoll,
3205#endif
3206 .ndo_get_stats = ehea_get_stats,
3207 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003208 .ndo_validate_addr = eth_validate_addr,
Thomas Klein086c1b22009-01-21 14:43:59 -08003209 .ndo_set_multicast_list = ehea_set_multicast_list,
3210 .ndo_change_mtu = ehea_change_mtu,
3211 .ndo_vlan_rx_register = ehea_vlan_rx_register,
3212 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003213 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3214 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003215};
3216
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003217struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3218 u32 logical_port_id,
3219 struct device_node *dn)
3220{
3221 int ret;
3222 struct net_device *dev;
3223 struct ehea_port *port;
3224 struct device *port_dev;
3225 int jumbo;
3226
3227 /* allocate memory for the port structures */
3228 dev = alloc_etherdev(sizeof(struct ehea_port));
3229
3230 if (!dev) {
David S. Millercfa969e2010-12-06 20:45:28 -08003231 ehea_error("no mem for net_device");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003232 ret = -ENOMEM;
3233 goto out_err;
3234 }
3235
3236 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003237
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003238 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003239 port->state = EHEA_PORT_DOWN;
3240 port->sig_comp_iv = sq_entries / 10;
3241
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003242 port->adapter = adapter;
3243 port->netdev = dev;
3244 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003245
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003246 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003247
3248 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3249 if (!port->mc_list) {
3250 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003251 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003252 }
3253
3254 INIT_LIST_HEAD(&port->mc_list->list);
3255
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003256 ret = ehea_sense_port_attr(port);
3257 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003258 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003259
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003260 port_dev = ehea_register_port(port, dn);
3261 if (!port_dev)
3262 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003263
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003264 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003265
3266 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003267 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3268
Thomas Klein086c1b22009-01-21 14:43:59 -08003269 dev->netdev_ops = &ehea_netdev_ops;
3270 ehea_set_ethtool_ops(dev);
3271
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003272 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003273 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003274 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3275 | NETIF_F_LLTX;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003276 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3277
Breno Leitaoc7757fd2010-12-08 12:19:14 -08003278 if (use_lro)
3279 dev->features |= NETIF_F_LRO;
3280
David Howellsc4028952006-11-22 14:57:56 +00003281 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003282
3283 ret = register_netdev(dev);
3284 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003285 ehea_error("register_netdev failed. ret=%d", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003286 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003287 }
3288
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003289 port->lro_max_aggr = lro_max_aggr;
3290
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003291 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003292 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08003293 ehea_error("failed determining jumbo frame status for %s",
3294 port->netdev->name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003295
David S. Millercfa969e2010-12-06 20:45:28 -08003296 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3297 jumbo == 1 ? "en" : "dis");
Thomas Klein9c750b72007-01-29 18:44:01 +01003298
Thomas Klein44c82152007-07-11 16:32:00 +02003299 adapter->active_ports++;
3300
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003301 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003302
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003303out_unreg_port:
3304 ehea_unregister_port(port);
3305
3306out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003307 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003308
3309out_free_ethdev:
3310 free_netdev(dev);
3311
3312out_err:
David S. Millercfa969e2010-12-06 20:45:28 -08003313 ehea_error("setting up logical port with id=%d failed, ret=%d",
3314 logical_port_id, ret);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003315 return NULL;
3316}
3317
3318static void ehea_shutdown_single_port(struct ehea_port *port)
3319{
Brian King7fb1c2a2008-05-14 09:48:25 -05003320 struct ehea_adapter *adapter = port->adapter;
Tejun Heof5c35cc2010-12-12 16:45:14 +01003321
3322 cancel_work_sync(&port->reset_task);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003323 unregister_netdev(port->netdev);
3324 ehea_unregister_port(port);
3325 kfree(port->mc_list);
3326 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003327 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003328}
3329
3330static int ehea_setup_ports(struct ehea_adapter *adapter)
3331{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003332 struct device_node *lhea_dn;
3333 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003334
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003335 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003336 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003337
Grant Likely61c7a082010-04-13 16:12:29 -07003338 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003339 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003340
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003341 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003342 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003343 if (!dn_log_port_id) {
David S. Millercfa969e2010-12-06 20:45:28 -08003344 ehea_error("bad device node: eth_dn name=%s",
3345 eth_dn->full_name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003346 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003347 }
3348
Thomas Klein1211bb62007-04-26 11:56:43 +02003349 if (ehea_add_adapter_mr(adapter)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003350 ehea_error("creating MR failed");
Thomas Klein1211bb62007-04-26 11:56:43 +02003351 of_node_put(eth_dn);
3352 return -EIO;
3353 }
3354
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003355 adapter->port[i] = ehea_setup_single_port(adapter,
3356 *dn_log_port_id,
3357 eth_dn);
3358 if (adapter->port[i])
David S. Millercfa969e2010-12-06 20:45:28 -08003359 ehea_info("%s -> logical port id #%d",
3360 adapter->port[i]->netdev->name,
3361 *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003362 else
3363 ehea_remove_adapter_mr(adapter);
3364
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003365 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003366 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003367 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003368}
3369
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003370static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3371 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003372{
3373 struct device_node *lhea_dn;
3374 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003375 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003376
Grant Likely61c7a082010-04-13 16:12:29 -07003377 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003378 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003379
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003380 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003381 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003382 if (dn_log_port_id)
3383 if (*dn_log_port_id == logical_port_id)
3384 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003385 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003386
3387 return NULL;
3388}
3389
3390static ssize_t ehea_probe_port(struct device *dev,
3391 struct device_attribute *attr,
3392 const char *buf, size_t count)
3393{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003394 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003395 struct ehea_port *port;
3396 struct device_node *eth_dn = NULL;
3397 int i;
3398
3399 u32 logical_port_id;
3400
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003401 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003402
3403 port = ehea_get_port(adapter, logical_port_id);
3404
3405 if (port) {
David S. Millercfa969e2010-12-06 20:45:28 -08003406 ehea_info("adding port with logical port id=%d failed. port "
3407 "already configured as %s.", logical_port_id,
3408 port->netdev->name);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003409 return -EINVAL;
3410 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003411
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003412 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3413
3414 if (!eth_dn) {
David S. Millercfa969e2010-12-06 20:45:28 -08003415 ehea_info("no logical port with id %d found", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003416 return -EINVAL;
3417 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003418
Thomas Klein1211bb62007-04-26 11:56:43 +02003419 if (ehea_add_adapter_mr(adapter)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003420 ehea_error("creating MR failed");
Thomas Klein1211bb62007-04-26 11:56:43 +02003421 return -EIO;
3422 }
3423
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003424 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3425
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003426 of_node_put(eth_dn);
3427
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003428 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003429 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003430 if (!adapter->port[i]) {
3431 adapter->port[i] = port;
3432 break;
3433 }
3434
David S. Millercfa969e2010-12-06 20:45:28 -08003435 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3436 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003437 } else {
3438 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003439 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003440 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003441
3442 return (ssize_t) count;
3443}
3444
3445static ssize_t ehea_remove_port(struct device *dev,
3446 struct device_attribute *attr,
3447 const char *buf, size_t count)
3448{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003449 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003450 struct ehea_port *port;
3451 int i;
3452 u32 logical_port_id;
3453
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003454 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003455
3456 port = ehea_get_port(adapter, logical_port_id);
3457
3458 if (port) {
David S. Millercfa969e2010-12-06 20:45:28 -08003459 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3460 logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003461
3462 ehea_shutdown_single_port(port);
3463
Doug Maxey508d2b52008-01-31 20:20:49 -06003464 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003465 if (adapter->port[i] == port) {
3466 adapter->port[i] = NULL;
3467 break;
3468 }
3469 } else {
David S. Millercfa969e2010-12-06 20:45:28 -08003470 ehea_error("removing port with logical port id=%d failed. port "
3471 "not configured.", logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003472 return -EINVAL;
3473 }
3474
Thomas Klein1211bb62007-04-26 11:56:43 +02003475 ehea_remove_adapter_mr(adapter);
3476
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003477 return (ssize_t) count;
3478}
3479
3480static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3481static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3482
Grant Likely2dc11582010-08-06 09:25:50 -06003483int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003484{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003485 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003486 if (ret)
3487 goto out;
3488
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003489 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003490out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003491 return ret;
3492}
3493
Grant Likely2dc11582010-08-06 09:25:50 -06003494void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003495{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003496 device_remove_file(&dev->dev, &dev_attr_probe_port);
3497 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003498}
3499
Grant Likely2dc11582010-08-06 09:25:50 -06003500static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003501 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003502{
3503 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003504 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003505 int ret;
3506
Grant Likely61c7a082010-04-13 16:12:29 -07003507 if (!dev || !dev->dev.of_node) {
David S. Millercfa969e2010-12-06 20:45:28 -08003508 ehea_error("Invalid ibmebus device probed");
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003509 return -EINVAL;
3510 }
3511
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003512 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3513 if (!adapter) {
3514 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003515 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003516 goto out;
3517 }
3518
Thomas Klein44c82152007-07-11 16:32:00 +02003519 list_add(&adapter->list, &adapter_list);
3520
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003521 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003522
Grant Likely61c7a082010-04-13 16:12:29 -07003523 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003524 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003525 if (adapter_handle)
3526 adapter->handle = *adapter_handle;
3527
3528 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003529 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003530 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003531 ret = -ENODEV;
3532 goto out_free_ad;
3533 }
3534
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003535 adapter->pd = EHEA_PD_ID;
3536
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003537 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003538
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003539
3540 /* initialize adapter and ports */
3541 /* get adapter properties */
3542 ret = ehea_sense_adapter_attr(adapter);
3543 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003544 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003545 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003546 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003547
3548 adapter->neq = ehea_create_eq(adapter,
3549 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3550 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003551 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003552 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003553 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003554 }
3555
3556 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3557 (unsigned long)adapter);
3558
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003559 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003560 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003561 "ehea_neq", adapter);
3562 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003563 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003564 goto out_kill_eq;
3565 }
3566
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003567 ret = ehea_create_device_sysfs(dev);
3568 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003569 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003570
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003571 ret = ehea_setup_ports(adapter);
3572 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003573 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003574 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003575 }
3576
3577 ret = 0;
3578 goto out;
3579
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003580out_rem_dev_sysfs:
3581 ehea_remove_device_sysfs(dev);
3582
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003583out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003584 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003585
3586out_kill_eq:
3587 ehea_destroy_eq(adapter->neq);
3588
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003589out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003590 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003591 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003592
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003593out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003594 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003595
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003596 return ret;
3597}
3598
Grant Likely2dc11582010-08-06 09:25:50 -06003599static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003600{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003601 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003602 int i;
3603
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003604 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003605 if (adapter->port[i]) {
3606 ehea_shutdown_single_port(adapter->port[i]);
3607 adapter->port[i] = NULL;
3608 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003609
3610 ehea_remove_device_sysfs(dev);
3611
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003612 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003613 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003614
3615 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003616 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003617 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003618 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003619
Thomas Klein21eee2d2008-02-13 16:18:33 +01003620 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003621
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003622 return 0;
3623}
3624
Thomas Klein21eee2d2008-02-13 16:18:33 +01003625void ehea_crash_handler(void)
3626{
3627 int i;
3628
3629 if (ehea_fw_handles.arr)
3630 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3631 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3632 ehea_fw_handles.arr[i].fwh,
3633 FORCE_FREE);
3634
3635 if (ehea_bcmc_regs.arr)
3636 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3637 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3638 ehea_bcmc_regs.arr[i].port_id,
3639 ehea_bcmc_regs.arr[i].reg_type,
3640 ehea_bcmc_regs.arr[i].macaddr,
3641 0, H_DEREG_BCMC);
3642}
3643
Hannes Hering48cfb142008-05-07 14:43:36 +02003644static int ehea_mem_notifier(struct notifier_block *nb,
3645 unsigned long action, void *data)
3646{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003647 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003648 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003649
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003650 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003651
Hannes Hering48cfb142008-05-07 14:43:36 +02003652 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003653 case MEM_CANCEL_OFFLINE:
David S. Millercfa969e2010-12-06 20:45:28 -08003654 ehea_info("memory offlining canceled");
Hannes Heringd4f12da2008-10-16 11:36:42 +02003655 /* Readd canceled memory block */
3656 case MEM_ONLINE:
David S. Millercfa969e2010-12-06 20:45:28 -08003657 ehea_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003658 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003659 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003660 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003661 ehea_rereg_mrs();
Hannes Heringd4f12da2008-10-16 11:36:42 +02003662 break;
3663 case MEM_GOING_OFFLINE:
David S. Millercfa969e2010-12-06 20:45:28 -08003664 ehea_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003665 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003666 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003667 goto out_unlock;
Tejun Heo3d6b8922010-12-12 16:45:14 +01003668 ehea_rereg_mrs();
Hannes Hering48cfb142008-05-07 14:43:36 +02003669 break;
3670 default:
3671 break;
3672 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003673
3674 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003675 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003676
Thomas Kleina7c561f22010-04-20 23:11:31 +00003677out_unlock:
3678 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003679 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003680}
3681
3682static struct notifier_block ehea_mem_nb = {
3683 .notifier_call = ehea_mem_notifier,
3684};
3685
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003686static int ehea_reboot_notifier(struct notifier_block *nb,
3687 unsigned long action, void *unused)
3688{
3689 if (action == SYS_RESTART) {
David S. Millercfa969e2010-12-06 20:45:28 -08003690 ehea_info("Reboot: freeing all eHEA resources");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003691 ibmebus_unregister_driver(&ehea_driver);
3692 }
3693 return NOTIFY_DONE;
3694}
3695
3696static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003697 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003698};
3699
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003700static int check_module_parm(void)
3701{
3702 int ret = 0;
3703
3704 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3705 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003706 ehea_info("Bad parameter: rq1_entries");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003707 ret = -EINVAL;
3708 }
3709 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3710 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003711 ehea_info("Bad parameter: rq2_entries");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003712 ret = -EINVAL;
3713 }
3714 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3715 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003716 ehea_info("Bad parameter: rq3_entries");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003717 ret = -EINVAL;
3718 }
3719 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3720 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
David S. Millercfa969e2010-12-06 20:45:28 -08003721 ehea_info("Bad parameter: sq_entries");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003722 ret = -EINVAL;
3723 }
3724
3725 return ret;
3726}
3727
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003728static ssize_t ehea_show_capabilities(struct device_driver *drv,
3729 char *buf)
3730{
3731 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3732}
3733
3734static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3735 ehea_show_capabilities, NULL);
3736
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003737int __init ehea_module_init(void)
3738{
3739 int ret;
3740
David S. Millercfa969e2010-12-06 20:45:28 -08003741 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3742 DRV_VERSION);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003743
Thomas Klein21eee2d2008-02-13 16:18:33 +01003744 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3745 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3746
Daniel Walker9f71a562008-03-28 14:41:26 -07003747 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003748 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003749
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003750 ret = check_module_parm();
3751 if (ret)
3752 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003753
3754 ret = ehea_create_busmap();
3755 if (ret)
3756 goto out;
3757
Thomas Klein21eee2d2008-02-13 16:18:33 +01003758 ret = register_reboot_notifier(&ehea_reboot_nb);
3759 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08003760 ehea_info("failed registering reboot notifier");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003761
Hannes Hering48cfb142008-05-07 14:43:36 +02003762 ret = register_memory_notifier(&ehea_mem_nb);
3763 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08003764 ehea_info("failed registering memory remove notifier");
Hannes Hering48cfb142008-05-07 14:43:36 +02003765
Joe Perchesc061b182010-08-23 18:20:03 +00003766 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003767 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08003768 ehea_info("failed registering crash handler");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003769
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003770 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003771 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003772 ehea_error("failed registering eHEA device driver on ebus");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003773 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003774 }
3775
3776 ret = driver_create_file(&ehea_driver.driver,
3777 &driver_attr_capabilities);
3778 if (ret) {
David S. Millercfa969e2010-12-06 20:45:28 -08003779 ehea_error("failed to register capabilities attribute, ret=%d",
3780 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003781 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003782 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003783
Thomas Klein21eee2d2008-02-13 16:18:33 +01003784 return ret;
3785
3786out3:
3787 ibmebus_unregister_driver(&ehea_driver);
3788out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003789 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003790 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003791 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003792out:
3793 return ret;
3794}
3795
3796static void __exit ehea_module_exit(void)
3797{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003798 int ret;
3799
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003800 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003801 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003802 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003803 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003804 if (ret)
David S. Millercfa969e2010-12-06 20:45:28 -08003805 ehea_info("failed unregistering crash handler");
Hannes Hering48cfb142008-05-07 14:43:36 +02003806 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003807 kfree(ehea_fw_handles.arr);
3808 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003809 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003810}
3811
3812module_init(ehea_module_init);
3813module_exit(ehea_module_exit);