blob: e59d38629099eefef531faa571a4ec604b9bb12d [file] [log] [blame]
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001/*
2 * linux/drivers/net/ehea/ehea_main.c
3 *
4 * eHEA ethernet device driver for IBM eServer System p
5 *
6 * (C) Copyright IBM Corp. 2006
7 *
8 * Authors:
Doug Maxey508d2b52008-01-31 20:20:49 -06009 * Christoph Raisch <raisch@de.ibm.com>
10 * Jan-Bernd Themann <themann@de.ibm.com>
11 * Thomas Klein <tklein@de.ibm.com>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020012 *
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
28
29#include <linux/in.h>
30#include <linux/ip.h>
31#include <linux/tcp.h>
32#include <linux/udp.h>
33#include <linux/if.h>
34#include <linux/list.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020036#include <linux/if_ether.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020037#include <linux/notifier.h>
38#include <linux/reboot.h>
Hannes Hering48cfb142008-05-07 14:43:36 +020039#include <linux/memory.h>
Thomas Klein21eee2d2008-02-13 16:18:33 +010040#include <asm/kexec.h>
Daniel Walker06f89ed2008-03-28 14:41:26 -070041#include <linux/mutex.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020042
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020043#include <net/ip.h>
44
45#include "ehea.h"
46#include "ehea_qmr.h"
47#include "ehea_phyp.h"
48
49
50MODULE_LICENSE("GPL");
51MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
52MODULE_DESCRIPTION("IBM eServer HEA Driver");
53MODULE_VERSION(DRV_VERSION);
54
55
56static int msg_level = -1;
57static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
58static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
59static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
60static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Doug Maxey508d2b52008-01-31 20:20:49 -060061static int use_mcs;
62static int use_lro;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070063static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010064static int num_tx_qps = EHEA_NUM_TX_QP;
Doug Maxey508d2b52008-01-31 20:20:49 -060065static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020066
67module_param(msg_level, int, 0);
68module_param(rq1_entries, int, 0);
69module_param(rq2_entries, int, 0);
70module_param(rq3_entries, int, 0);
71module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020072module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010073module_param(use_mcs, int, 0);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070074module_param(use_lro, int, 0);
75module_param(lro_max_aggr, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010076module_param(num_tx_qps, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020077
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010078MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020079MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020080MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
81 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020082MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
83 "[2^x - 1], x = [6..14]. Default = "
84 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
85MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
86 "[2^x - 1], x = [6..14]. Default = "
87 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
88MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
89 "[2^x - 1], x = [6..14]. Default = "
90 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
91MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
92 "[2^x - 1], x = [6..14]. Default = "
93 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Jan-Bernd Themann18072a52007-08-22 16:21:24 +020094MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020095
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070096MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
97 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
98MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
99 "Default = 0");
100
Doug Maxey508d2b52008-01-31 20:20:49 -0600101static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +0200102static LIST_HEAD(adapter_list);
Stephen Rothwell48e4cc72009-01-05 16:06:02 -0800103static unsigned long ehea_driver_flags;
Thomas Klein44c82152007-07-11 16:32:00 +0200104struct work_struct ehea_rereg_mr_task;
Daniel Walker06f89ed2008-03-28 14:41:26 -0700105static DEFINE_MUTEX(dlpar_mem_lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100106struct ehea_fw_handle_array ehea_fw_handles;
107struct ehea_bcmc_reg_array ehea_bcmc_regs;
108
Thomas Kleind1dea382007-04-26 11:56:13 +0200109
Grant Likely2dc11582010-08-06 09:25:50 -0600110static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200111 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200112
Grant Likely2dc11582010-08-06 09:25:50 -0600113static int __devexit ehea_remove(struct platform_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200114
115static struct of_device_id ehea_device_table[] = {
116 {
117 .name = "lhea",
118 .compatible = "IBM,lhea",
119 },
120 {},
121};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100122MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200123
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000124static struct of_platform_driver ehea_driver = {
Grant Likely40182942010-04-13 16:13:02 -0700125 .driver = {
126 .name = "ehea",
127 .owner = THIS_MODULE,
128 .of_match_table = ehea_device_table,
129 },
Thomas Kleind1dea382007-04-26 11:56:13 +0200130 .probe = ehea_probe_adapter,
131 .remove = ehea_remove,
132};
133
Doug Maxey508d2b52008-01-31 20:20:49 -0600134void ehea_dump(void *adr, int len, char *msg)
135{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200136 int x;
137 unsigned char *deb = adr;
138 for (x = 0; x < len; x += 16) {
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000139 printk(DRV_NAME " %s adr=%p ofs=%04x %016llx %016llx\n", msg,
Doug Maxey508d2b52008-01-31 20:20:49 -0600140 deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200141 deb += 16;
142 }
143}
144
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100145void ehea_schedule_port_reset(struct ehea_port *port)
146{
147 if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
148 schedule_work(&port->reset_task);
149}
150
Thomas Klein21eee2d2008-02-13 16:18:33 +0100151static void ehea_update_firmware_handles(void)
152{
153 struct ehea_fw_handle_entry *arr = NULL;
154 struct ehea_adapter *adapter;
155 int num_adapters = 0;
156 int num_ports = 0;
157 int num_portres = 0;
158 int i = 0;
159 int num_fw_handles, k, l;
160
161 /* Determine number of handles */
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700162 mutex_lock(&ehea_fw_handles.lock);
163
Thomas Klein21eee2d2008-02-13 16:18:33 +0100164 list_for_each_entry(adapter, &adapter_list, list) {
165 num_adapters++;
166
167 for (k = 0; k < EHEA_MAX_PORTS; k++) {
168 struct ehea_port *port = adapter->port[k];
169
170 if (!port || (port->state != EHEA_PORT_UP))
171 continue;
172
173 num_ports++;
174 num_portres += port->num_def_qps + port->num_add_tx_qps;
175 }
176 }
177
178 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
179 num_ports * EHEA_NUM_PORT_FW_HANDLES +
180 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
181
182 if (num_fw_handles) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000183 arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100184 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700185 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100186 } else
187 goto out_update;
188
189 list_for_each_entry(adapter, &adapter_list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700190 if (num_adapters == 0)
191 break;
192
Thomas Klein21eee2d2008-02-13 16:18:33 +0100193 for (k = 0; k < EHEA_MAX_PORTS; k++) {
194 struct ehea_port *port = adapter->port[k];
195
Joe Perches8e95a202009-12-03 07:58:21 +0000196 if (!port || (port->state != EHEA_PORT_UP) ||
197 (num_ports == 0))
Thomas Klein21eee2d2008-02-13 16:18:33 +0100198 continue;
199
200 for (l = 0;
201 l < port->num_def_qps + port->num_add_tx_qps;
202 l++) {
203 struct ehea_port_res *pr = &port->port_res[l];
204
205 arr[i].adh = adapter->handle;
206 arr[i++].fwh = pr->qp->fw_handle;
207 arr[i].adh = adapter->handle;
208 arr[i++].fwh = pr->send_cq->fw_handle;
209 arr[i].adh = adapter->handle;
210 arr[i++].fwh = pr->recv_cq->fw_handle;
211 arr[i].adh = adapter->handle;
212 arr[i++].fwh = pr->eq->fw_handle;
213 arr[i].adh = adapter->handle;
214 arr[i++].fwh = pr->send_mr.handle;
215 arr[i].adh = adapter->handle;
216 arr[i++].fwh = pr->recv_mr.handle;
217 }
218 arr[i].adh = adapter->handle;
219 arr[i++].fwh = port->qp_eq->fw_handle;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700220 num_ports--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100221 }
222
223 arr[i].adh = adapter->handle;
224 arr[i++].fwh = adapter->neq->fw_handle;
225
226 if (adapter->mr.handle) {
227 arr[i].adh = adapter->handle;
228 arr[i++].fwh = adapter->mr.handle;
229 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700230 num_adapters--;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100231 }
232
233out_update:
234 kfree(ehea_fw_handles.arr);
235 ehea_fw_handles.arr = arr;
236 ehea_fw_handles.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700237out:
238 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100239}
240
241static void ehea_update_bcmc_registrations(void)
242{
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700243 unsigned long flags;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100244 struct ehea_bcmc_reg_entry *arr = NULL;
245 struct ehea_adapter *adapter;
246 struct ehea_mc_list *mc_entry;
247 int num_registrations = 0;
248 int i = 0;
249 int k;
250
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700251 spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
252
Thomas Klein21eee2d2008-02-13 16:18:33 +0100253 /* Determine number of registrations */
254 list_for_each_entry(adapter, &adapter_list, list)
255 for (k = 0; k < EHEA_MAX_PORTS; k++) {
256 struct ehea_port *port = adapter->port[k];
257
258 if (!port || (port->state != EHEA_PORT_UP))
259 continue;
260
261 num_registrations += 2; /* Broadcast registrations */
262
263 list_for_each_entry(mc_entry, &port->mc_list->list,list)
264 num_registrations += 2;
265 }
266
267 if (num_registrations) {
Joe Perchesbaeb2ff2010-08-11 07:02:48 +0000268 arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100269 if (!arr)
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700270 goto out; /* Keep the existing array */
Thomas Klein21eee2d2008-02-13 16:18:33 +0100271 } else
272 goto out_update;
273
274 list_for_each_entry(adapter, &adapter_list, list) {
275 for (k = 0; k < EHEA_MAX_PORTS; k++) {
276 struct ehea_port *port = adapter->port[k];
277
278 if (!port || (port->state != EHEA_PORT_UP))
279 continue;
280
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700281 if (num_registrations == 0)
282 goto out_update;
283
Thomas Klein21eee2d2008-02-13 16:18:33 +0100284 arr[i].adh = adapter->handle;
285 arr[i].port_id = port->logical_port_id;
286 arr[i].reg_type = EHEA_BCMC_BROADCAST |
287 EHEA_BCMC_UNTAGGED;
288 arr[i++].macaddr = port->mac_addr;
289
290 arr[i].adh = adapter->handle;
291 arr[i].port_id = port->logical_port_id;
292 arr[i].reg_type = EHEA_BCMC_BROADCAST |
293 EHEA_BCMC_VLANID_ALL;
294 arr[i++].macaddr = port->mac_addr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700295 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100296
297 list_for_each_entry(mc_entry,
298 &port->mc_list->list, list) {
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700299 if (num_registrations == 0)
300 goto out_update;
301
Thomas Klein21eee2d2008-02-13 16:18:33 +0100302 arr[i].adh = adapter->handle;
303 arr[i].port_id = port->logical_port_id;
304 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
305 EHEA_BCMC_MULTICAST |
306 EHEA_BCMC_UNTAGGED;
307 arr[i++].macaddr = mc_entry->macaddr;
308
309 arr[i].adh = adapter->handle;
310 arr[i].port_id = port->logical_port_id;
311 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
312 EHEA_BCMC_MULTICAST |
313 EHEA_BCMC_VLANID_ALL;
314 arr[i++].macaddr = mc_entry->macaddr;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700315 num_registrations -= 2;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100316 }
317 }
318 }
319
320out_update:
321 kfree(ehea_bcmc_regs.arr);
322 ehea_bcmc_regs.arr = arr;
323 ehea_bcmc_regs.num_entries = i;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -0700324out:
325 spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100326}
327
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200328static struct net_device_stats *ehea_get_stats(struct net_device *dev)
329{
330 struct ehea_port *port = netdev_priv(dev);
331 struct net_device_stats *stats = &port->stats;
332 struct hcp_ehea_port_cb2 *cb2;
Thomas Klein7393b872007-11-21 17:37:58 +0100333 u64 hret, rx_packets, tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200334 int i;
335
336 memset(stats, 0, sizeof(*stats));
337
Brian King3d8009c2010-06-30 11:59:12 +0000338 cb2 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200339 if (!cb2) {
340 ehea_error("no mem for cb2");
341 goto out;
342 }
343
344 hret = ehea_h_query_ehea_port(port->adapter->handle,
345 port->logical_port_id,
346 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
347 if (hret != H_SUCCESS) {
348 ehea_error("query_ehea_port failed");
349 goto out_herr;
350 }
351
352 if (netif_msg_hw(port))
353 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
354
355 rx_packets = 0;
356 for (i = 0; i < port->num_def_qps; i++)
357 rx_packets += port->port_res[i].rx_packets;
358
Thomas Klein7393b872007-11-21 17:37:58 +0100359 tx_packets = 0;
360 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
361 tx_packets += port->port_res[i].tx_packets;
362
363 stats->tx_packets = tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200364 stats->multicast = cb2->rxmcp;
365 stats->rx_errors = cb2->rxuerr;
366 stats->rx_bytes = cb2->rxo;
367 stats->tx_bytes = cb2->txo;
368 stats->rx_packets = rx_packets;
369
370out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -0800371 free_page((unsigned long)cb2);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200372out:
373 return stats;
374}
375
376static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
377{
378 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
379 struct net_device *dev = pr->port->netdev;
380 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200381 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
382 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200383 int i;
384
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200385 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200386
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200387 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200388 if (nr_of_wqes > 0)
389 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200390 pr->rq1_skba.os_skbs = fill_wqes;
391 return;
392 }
393
394 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200395 if (!skb_arr_rq1[index]) {
396 skb_arr_rq1[index] = netdev_alloc_skb(dev,
397 EHEA_L_PKT_SIZE);
398 if (!skb_arr_rq1[index]) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200399 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200400 break;
401 }
402 }
403 index--;
404 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200405 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200406 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200407
408 if (adder == 0)
409 return;
410
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200411 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200412 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200413}
414
Thomas Kleine2878802009-01-21 14:45:57 -0800415static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200416{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200417 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
418 struct net_device *dev = pr->port->netdev;
419 int i;
420
421 for (i = 0; i < pr->rq1_skba.len; i++) {
422 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
Thomas Kleine2878802009-01-21 14:45:57 -0800423 if (!skb_arr_rq1[i])
424 break;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200425 }
426 /* Ring doorbell */
427 ehea_update_rq1a(pr->qp, nr_rq1a);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200428}
429
430static int ehea_refill_rq_def(struct ehea_port_res *pr,
431 struct ehea_q_skb_arr *q_skba, int rq_nr,
432 int num_wqes, int wqe_type, int packet_size)
433{
434 struct net_device *dev = pr->port->netdev;
435 struct ehea_qp *qp = pr->qp;
436 struct sk_buff **skb_arr = q_skba->arr;
437 struct ehea_rwqe *rwqe;
438 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200439 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200440 int ret = 0;
441
442 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200443 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200444
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200445 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
446 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200447 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200448 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200449
450 index = q_skba->index;
451 max_index_mask = q_skba->len - 1;
452 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200453 u64 tmp_addr;
Eric Dumazet89d71a62009-10-13 05:34:20 +0000454 struct sk_buff *skb;
455
456 skb = netdev_alloc_skb_ip_align(dev, packet_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200457 if (!skb) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200458 q_skba->os_skbs = fill_wqes - i;
Thomas Kleine2878802009-01-21 14:45:57 -0800459 if (q_skba->os_skbs == q_skba->len - 2) {
460 ehea_info("%s: rq%i ran dry - no mem for skb",
461 pr->port->netdev->name, rq_nr);
462 ret = -ENOMEM;
463 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200464 break;
465 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200466
467 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200468 tmp_addr = ehea_map_vaddr(skb->data);
469 if (tmp_addr == -1) {
470 dev_kfree_skb(skb);
471 q_skba->os_skbs = fill_wqes - i;
472 ret = 0;
473 break;
474 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200475
476 rwqe = ehea_get_next_rwqe(qp, rq_nr);
477 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200478 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200479 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200480 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200481 rwqe->sg_list[0].len = packet_size;
482 rwqe->data_segments = 1;
483
484 index++;
485 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200486 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200487 }
Thomas Klein44c82152007-07-11 16:32:00 +0200488
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200489 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200490 if (adder == 0)
491 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200492
493 /* Ring doorbell */
494 iosync();
495 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200496 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200497 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200498 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200499out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200500 return ret;
501}
502
503
504static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
505{
506 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
507 nr_of_wqes, EHEA_RWQE2_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000508 EHEA_RQ2_PKT_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200509}
510
511
512static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
513{
514 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
515 nr_of_wqes, EHEA_RWQE3_TYPE,
Eric Dumazet89d71a62009-10-13 05:34:20 +0000516 EHEA_MAX_PACKET_SIZE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200517}
518
519static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
520{
521 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
522 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
523 return 0;
524 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
525 (cqe->header_length == 0))
526 return 0;
527 return -EINVAL;
528}
529
530static inline void ehea_fill_skb(struct net_device *dev,
531 struct sk_buff *skb, struct ehea_cqe *cqe)
532{
533 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
534
535 skb_put(skb, length);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200536 skb->protocol = eth_type_trans(skb, dev);
Breno Leitao71085ce2010-10-07 13:17:33 +0000537
538 /* The packet was not an IPV4 packet so a complemented checksum was
539 calculated. The value is found in the Internet Checksum field. */
540 if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
541 skb->ip_summed = CHECKSUM_COMPLETE;
542 skb->csum = csum_unfold(~cqe->inet_checksum_value);
543 } else
544 skb->ip_summed = CHECKSUM_UNNECESSARY;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200545}
546
547static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
548 int arr_len,
549 struct ehea_cqe *cqe)
550{
551 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
552 struct sk_buff *skb;
553 void *pref;
554 int x;
555
556 x = skb_index + 1;
557 x &= (arr_len - 1);
558
559 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700560 if (pref) {
561 prefetchw(pref);
562 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200563
Hannes Hering0b2febf2009-05-04 11:06:37 -0700564 pref = (skb_array[x]->data);
565 prefetch(pref);
566 prefetch(pref + EHEA_CACHE_LINE);
567 prefetch(pref + EHEA_CACHE_LINE * 2);
568 prefetch(pref + EHEA_CACHE_LINE * 3);
569 }
570
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200571 skb = skb_array[skb_index];
572 skb_array[skb_index] = NULL;
573 return skb;
574}
575
576static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
577 int arr_len, int wqe_index)
578{
579 struct sk_buff *skb;
580 void *pref;
581 int x;
582
583 x = wqe_index + 1;
584 x &= (arr_len - 1);
585
586 pref = skb_array[x];
Hannes Hering0b2febf2009-05-04 11:06:37 -0700587 if (pref) {
588 prefetchw(pref);
589 prefetchw(pref + EHEA_CACHE_LINE);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200590
Hannes Hering0b2febf2009-05-04 11:06:37 -0700591 pref = (skb_array[x]->data);
592 prefetchw(pref);
593 prefetchw(pref + EHEA_CACHE_LINE);
594 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200595
596 skb = skb_array[wqe_index];
597 skb_array[wqe_index] = NULL;
598 return skb;
599}
600
601static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
602 struct ehea_cqe *cqe, int *processed_rq2,
603 int *processed_rq3)
604{
605 struct sk_buff *skb;
606
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100607 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
608 pr->p_stats.err_tcp_cksum++;
609 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
610 pr->p_stats.err_ip_cksum++;
611 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
612 pr->p_stats.err_frame_crc++;
613
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200614 if (rq == 2) {
615 *processed_rq2 += 1;
616 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
617 dev_kfree_skb(skb);
618 } else if (rq == 3) {
619 *processed_rq3 += 1;
620 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
621 dev_kfree_skb(skb);
622 }
623
624 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100625 if (netif_msg_rx_err(pr->port)) {
626 ehea_error("Critical receive error for QP %d. "
627 "Resetting port.", pr->qp->init_attr.qp_nr);
628 ehea_dump(cqe, sizeof(*cqe), "CQE");
629 }
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +0100630 ehea_schedule_port_reset(pr->port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200631 return 1;
632 }
633
634 return 0;
635}
636
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700637static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
638 void **tcph, u64 *hdr_flags, void *priv)
639{
640 struct ehea_cqe *cqe = priv;
641 unsigned int ip_len;
642 struct iphdr *iph;
643
644 /* non tcp/udp packets */
645 if (!cqe->header_length)
646 return -1;
647
648 /* non tcp packet */
649 skb_reset_network_header(skb);
650 iph = ip_hdr(skb);
651 if (iph->protocol != IPPROTO_TCP)
652 return -1;
653
654 ip_len = ip_hdrlen(skb);
655 skb_set_transport_header(skb, ip_len);
656 *tcph = tcp_hdr(skb);
657
658 /* check if ip header and tcp header are complete */
Roland Dreier3ff2cd22008-07-01 10:20:33 -0700659 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700660 return -1;
661
662 *hdr_flags = LRO_IPV4 | LRO_TCP;
663 *iphdr = iph;
664
665 return 0;
666}
667
668static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
669 struct sk_buff *skb)
670{
Joe Perches8e95a202009-12-03 07:58:21 +0000671 int vlan_extracted = ((cqe->status & EHEA_CQE_VLAN_TAG_XTRACT) &&
672 pr->port->vgrp);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700673
674 if (use_lro) {
675 if (vlan_extracted)
676 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
677 pr->port->vgrp,
678 cqe->vlan_tag,
679 cqe);
680 else
681 lro_receive_skb(&pr->lro_mgr, skb, cqe);
682 } else {
683 if (vlan_extracted)
684 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
685 cqe->vlan_tag);
686 else
687 netif_receive_skb(skb);
688 }
689}
690
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700691static int ehea_proc_rwqes(struct net_device *dev,
692 struct ehea_port_res *pr,
693 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200694{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100695 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200696 struct ehea_qp *qp = pr->qp;
697 struct ehea_cqe *cqe;
698 struct sk_buff *skb;
699 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
700 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
701 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
702 int skb_arr_rq1_len = pr->rq1_skba.len;
703 int skb_arr_rq2_len = pr->rq2_skba.len;
704 int skb_arr_rq3_len = pr->rq3_skba.len;
705 int processed, processed_rq1, processed_rq2, processed_rq3;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700706 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200707
708 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
709 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200710
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200711 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700712 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200713 ehea_inc_rq1(qp);
714 processed_rq1++;
715 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200716 if (netif_msg_rx_status(port))
717 ehea_dump(cqe, sizeof(*cqe), "CQE");
718
719 last_wqe_index = wqe_index;
720 rmb();
721 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600722 if (rq == 1) {
723 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200724 skb = get_skb_by_index_ll(skb_arr_rq1,
725 skb_arr_rq1_len,
726 wqe_index);
727 if (unlikely(!skb)) {
728 if (netif_msg_rx_err(port))
729 ehea_error("LL rq1: skb=NULL");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100730
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700731 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200732 EHEA_L_PKT_SIZE);
733 if (!skb)
734 break;
735 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600736 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200737 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700738 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600739 } else if (rq == 2) {
740 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200741 skb = get_skb_by_index(skb_arr_rq2,
742 skb_arr_rq2_len, cqe);
743 if (unlikely(!skb)) {
744 if (netif_msg_rx_err(port))
745 ehea_error("rq2: skb=NULL");
746 break;
747 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700748 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200749 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600750 } else {
751 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200752 skb = get_skb_by_index(skb_arr_rq3,
753 skb_arr_rq3_len, cqe);
754 if (unlikely(!skb)) {
755 if (netif_msg_rx_err(port))
756 ehea_error("rq3: skb=NULL");
757 break;
758 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700759 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200760 processed_rq3++;
761 }
762
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700763 ehea_proc_skb(pr, cqe, skb);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100764 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100765 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200766 port_reset = ehea_treat_poll_error(pr, rq, cqe,
767 &processed_rq2,
768 &processed_rq3);
769 if (port_reset)
770 break;
771 }
772 cqe = ehea_poll_rq1(qp, &wqe_index);
773 }
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700774 if (use_lro)
775 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200776
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200777 pr->rx_packets += processed;
778
779 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
780 ehea_refill_rq2(pr, processed_rq2);
781 ehea_refill_rq3(pr, processed_rq3);
782
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700783 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200784}
785
Andre Detsch2928db42010-08-17 05:49:12 +0000786#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
787
788static void reset_sq_restart_flag(struct ehea_port *port)
789{
790 int i;
791
792 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
793 struct ehea_port_res *pr = &port->port_res[i];
794 pr->sq_restart_flag = 0;
795 }
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000796 wake_up(&port->restart_wq);
Andre Detsch2928db42010-08-17 05:49:12 +0000797}
798
799static void check_sqs(struct ehea_port *port)
800{
801 struct ehea_swqe *swqe;
802 int swqe_index;
803 int i, k;
804
805 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
806 struct ehea_port_res *pr = &port->port_res[i];
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000807 int ret;
Andre Detsch2928db42010-08-17 05:49:12 +0000808 k = 0;
809 swqe = ehea_get_swqe(pr->qp, &swqe_index);
810 memset(swqe, 0, SWQE_HEADER_SIZE);
811 atomic_dec(&pr->swqe_avail);
812
813 swqe->tx_control |= EHEA_SWQE_PURGE;
814 swqe->wr_id = SWQE_RESTART_CHECK;
815 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
816 swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
817 swqe->immediate_data_length = 80;
818
819 ehea_post_swqe(pr->qp, swqe);
820
Breno Leitaoa8bb69f2010-10-05 13:16:23 +0000821 ret = wait_event_timeout(port->restart_wq,
822 pr->sq_restart_flag == 0,
823 msecs_to_jiffies(100));
824
825 if (!ret) {
826 ehea_error("HW/SW queues out of sync");
827 ehea_schedule_port_reset(pr->port);
828 return;
Andre Detsch2928db42010-08-17 05:49:12 +0000829 }
830 }
Andre Detsch2928db42010-08-17 05:49:12 +0000831}
832
833
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100834static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200835{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100836 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200837 struct ehea_cq *send_cq = pr->send_cq;
838 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100839 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200840 int cqe_counter = 0;
841 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100842 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200843 unsigned long flags;
844
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100845 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600846 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100847 ehea_inc_cq(send_cq);
848
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200849 cqe_counter++;
850 rmb();
Andre Detsch2928db42010-08-17 05:49:12 +0000851
852 if (cqe->wr_id == SWQE_RESTART_CHECK) {
853 pr->sq_restart_flag = 1;
854 swqe_av++;
855 break;
856 }
857
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200858 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
Thomas Kleinea96cea2010-04-20 23:10:55 +0000859 ehea_error("Bad send completion status=0x%04X",
860 cqe->status);
861
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200862 if (netif_msg_tx_err(pr->port))
863 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Thomas Kleinea96cea2010-04-20 23:10:55 +0000864
865 if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
866 ehea_error("Resetting port");
867 ehea_schedule_port_reset(pr->port);
868 break;
869 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200870 }
871
872 if (netif_msg_tx_done(pr->port))
873 ehea_dump(cqe, sizeof(*cqe), "CQE");
874
875 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100876 == EHEA_SWQE2_TYPE)) {
877
878 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
879 skb = pr->sq_skba.arr[index];
880 dev_kfree_skb(skb);
881 pr->sq_skba.arr[index] = NULL;
882 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200883
884 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
885 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100886
887 cqe = ehea_poll_cq(send_cq);
Joe Perchesee289b62010-05-17 22:47:34 -0700888 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200889
890 ehea_update_feca(send_cq, cqe_counter);
891 atomic_add(swqe_av, &pr->swqe_avail);
892
893 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100894
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200895 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
896 >= pr->swqe_refill_th)) {
897 netif_wake_queue(pr->port->netdev);
898 pr->queue_stopped = 0;
899 }
900 spin_unlock_irqrestore(&pr->netif_queue, flags);
Breno Leitao5b27d422010-10-05 13:16:22 +0000901 wake_up(&pr->port->swqe_avail_wq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200902
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100903 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200904}
905
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100906#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700907#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100908
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700909static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200910{
Doug Maxey508d2b52008-01-31 20:20:49 -0600911 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
912 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700913 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100914 struct ehea_cqe *cqe;
915 struct ehea_cqe *cqe_skb = NULL;
916 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700917 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100918
919 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700920 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100921
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700922 if (!force_irq)
923 rx += ehea_proc_rwqes(dev, pr, budget - rx);
924
925 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100926 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700927 force_irq = 0;
Ben Hutchings288379f2009-01-19 16:43:59 -0800928 napi_complete(napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100929 ehea_reset_cq_ep(pr->recv_cq);
930 ehea_reset_cq_ep(pr->send_cq);
931 ehea_reset_cq_n1(pr->recv_cq);
932 ehea_reset_cq_n1(pr->send_cq);
Jan-Bernd Themanna91fb142010-06-15 05:35:16 +0000933 rmb();
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100934 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
935 cqe_skb = ehea_poll_cq(pr->send_cq);
936
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100937 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700938 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100939
Ben Hutchings288379f2009-01-19 16:43:59 -0800940 if (!napi_reschedule(napi))
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700941 return rx;
942
943 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
944 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100945 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100946
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700947 pr->poll_counter++;
948 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200949}
950
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200951#ifdef CONFIG_NET_POLL_CONTROLLER
952static void ehea_netpoll(struct net_device *dev)
953{
954 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700955 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200956
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700957 for (i = 0; i < port->num_def_qps; i++)
Ben Hutchings288379f2009-01-19 16:43:59 -0800958 napi_schedule(&port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200959}
960#endif
961
David Howells7d12e782006-10-05 14:55:46 +0100962static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200963{
964 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100965
Ben Hutchings288379f2009-01-19 16:43:59 -0800966 napi_schedule(&pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100967
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200968 return IRQ_HANDLED;
969}
970
David Howells7d12e782006-10-05 14:55:46 +0100971static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200972{
973 struct ehea_port *port = param;
974 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100975 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200976 u32 qp_token;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000977 u64 resource_type, aer, aerr;
978 int reset_port = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200979
980 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100981
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200982 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200983 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Stephen Rothwella1c5a892009-01-06 14:40:06 +0000984 ehea_error("QP aff_err: entry=0x%llx, token=0x%x",
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100985 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100986
987 qp = port->port_res[qp_token].qp;
Thomas Kleinea96cea2010-04-20 23:10:55 +0000988
989 resource_type = ehea_error_data(port->adapter, qp->fw_handle,
990 &aer, &aerr);
991
992 if (resource_type == EHEA_AER_RESTYPE_QP) {
993 if ((aer & EHEA_AER_RESET_MASK) ||
994 (aerr & EHEA_AERR_RESET_MASK))
995 reset_port = 1;
996 } else
997 reset_port = 1; /* Reset in case of CQ or EQ error */
998
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100999 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001000 }
1001
Thomas Kleinea96cea2010-04-20 23:10:55 +00001002 if (reset_port) {
1003 ehea_error("Resetting port");
1004 ehea_schedule_port_reset(port);
1005 }
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +01001006
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001007 return IRQ_HANDLED;
1008}
1009
1010static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
1011 int logical_port)
1012{
1013 int i;
1014
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01001015 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +01001016 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001017 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +01001018 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001019 return NULL;
1020}
1021
1022int ehea_sense_port_attr(struct ehea_port *port)
1023{
1024 int ret;
1025 u64 hret;
1026 struct hcp_ehea_port_cb0 *cb0;
1027
Doug Maxey508d2b52008-01-31 20:20:49 -06001028 /* may be called via ehea_neq_tasklet() */
Thomas Klein3faf2692009-01-21 14:45:33 -08001029 cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
Doug Maxey508d2b52008-01-31 20:20:49 -06001030 if (!cb0) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001031 ehea_error("no mem for cb0");
1032 ret = -ENOMEM;
1033 goto out;
1034 }
1035
1036 hret = ehea_h_query_ehea_port(port->adapter->handle,
1037 port->logical_port_id, H_PORT_CB0,
1038 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
1039 cb0);
1040 if (hret != H_SUCCESS) {
1041 ret = -EIO;
1042 goto out_free;
1043 }
1044
1045 /* MAC address */
1046 port->mac_addr = cb0->port_mac_addr << 16;
1047
Doug Maxey508d2b52008-01-31 20:20:49 -06001048 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001049 ret = -EADDRNOTAVAIL;
1050 goto out_free;
1051 }
1052
1053 /* Port speed */
1054 switch (cb0->port_speed) {
1055 case H_SPEED_10M_H:
1056 port->port_speed = EHEA_SPEED_10M;
1057 port->full_duplex = 0;
1058 break;
1059 case H_SPEED_10M_F:
1060 port->port_speed = EHEA_SPEED_10M;
1061 port->full_duplex = 1;
1062 break;
1063 case H_SPEED_100M_H:
1064 port->port_speed = EHEA_SPEED_100M;
1065 port->full_duplex = 0;
1066 break;
1067 case H_SPEED_100M_F:
1068 port->port_speed = EHEA_SPEED_100M;
1069 port->full_duplex = 1;
1070 break;
1071 case H_SPEED_1G_F:
1072 port->port_speed = EHEA_SPEED_1G;
1073 port->full_duplex = 1;
1074 break;
1075 case H_SPEED_10G_F:
1076 port->port_speed = EHEA_SPEED_10G;
1077 port->full_duplex = 1;
1078 break;
1079 default:
1080 port->port_speed = 0;
1081 port->full_duplex = 0;
1082 break;
1083 }
1084
Thomas Kleine919b592007-01-22 12:53:20 +01001085 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001086 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +01001087
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001088 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001089 if (use_mcs)
1090 port->num_def_qps = cb0->num_default_qps;
1091 else
1092 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001093
1094 if (!port->num_def_qps) {
1095 ret = -EINVAL;
1096 goto out_free;
1097 }
1098
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001099 port->num_tx_qps = num_tx_qps;
1100
1101 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001102 port->num_add_tx_qps = 0;
1103 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001104 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001105
1106 ret = 0;
1107out_free:
1108 if (ret || netif_msg_probe(port))
1109 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
Thomas Klein3faf2692009-01-21 14:45:33 -08001110 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001111out:
1112 return ret;
1113}
1114
1115int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1116{
1117 struct hcp_ehea_port_cb4 *cb4;
1118 u64 hret;
1119 int ret = 0;
1120
Thomas Klein3faf2692009-01-21 14:45:33 -08001121 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001122 if (!cb4) {
1123 ehea_error("no mem for cb4");
1124 ret = -ENOMEM;
1125 goto out;
1126 }
1127
1128 cb4->port_speed = port_speed;
1129
1130 netif_carrier_off(port->netdev);
1131
1132 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1133 port->logical_port_id,
1134 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1135 if (hret == H_SUCCESS) {
1136 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1137
1138 hret = ehea_h_query_ehea_port(port->adapter->handle,
1139 port->logical_port_id,
1140 H_PORT_CB4, H_PORT_CB4_SPEED,
1141 cb4);
1142 if (hret == H_SUCCESS) {
1143 switch (cb4->port_speed) {
1144 case H_SPEED_10M_H:
1145 port->port_speed = EHEA_SPEED_10M;
1146 port->full_duplex = 0;
1147 break;
1148 case H_SPEED_10M_F:
1149 port->port_speed = EHEA_SPEED_10M;
1150 port->full_duplex = 1;
1151 break;
1152 case H_SPEED_100M_H:
1153 port->port_speed = EHEA_SPEED_100M;
1154 port->full_duplex = 0;
1155 break;
1156 case H_SPEED_100M_F:
1157 port->port_speed = EHEA_SPEED_100M;
1158 port->full_duplex = 1;
1159 break;
1160 case H_SPEED_1G_F:
1161 port->port_speed = EHEA_SPEED_1G;
1162 port->full_duplex = 1;
1163 break;
1164 case H_SPEED_10G_F:
1165 port->port_speed = EHEA_SPEED_10G;
1166 port->full_duplex = 1;
1167 break;
1168 default:
1169 port->port_speed = 0;
1170 port->full_duplex = 0;
1171 break;
1172 }
1173 } else {
1174 ehea_error("Failed sensing port speed");
1175 ret = -EIO;
1176 }
1177 } else {
1178 if (hret == H_AUTHORITY) {
Thomas Klein7674a582007-01-22 12:54:20 +01001179 ehea_info("Hypervisor denied setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001180 ret = -EPERM;
1181 } else {
1182 ret = -EIO;
1183 ehea_error("Failed setting port speed");
1184 }
1185 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001186 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1187 netif_carrier_on(port->netdev);
1188
Thomas Klein3faf2692009-01-21 14:45:33 -08001189 free_page((unsigned long)cb4);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001190out:
1191 return ret;
1192}
1193
1194static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1195{
1196 int ret;
1197 u8 ec;
1198 u8 portnum;
1199 struct ehea_port *port;
1200
1201 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1202 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1203 port = ehea_get_port(adapter, portnum);
1204
1205 switch (ec) {
1206 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1207
1208 if (!port) {
1209 ehea_error("unknown portnum %x", portnum);
1210 break;
1211 }
1212
1213 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
1214 if (!netif_carrier_ok(port->netdev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001215 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001216 if (ret) {
1217 ehea_error("failed resensing port "
1218 "attributes");
1219 break;
1220 }
1221
1222 if (netif_msg_link(port))
1223 ehea_info("%s: Logical port up: %dMbps "
1224 "%s Duplex",
1225 port->netdev->name,
1226 port->port_speed,
1227 port->full_duplex ==
1228 1 ? "Full" : "Half");
1229
1230 netif_carrier_on(port->netdev);
1231 netif_wake_queue(port->netdev);
1232 }
1233 } else
1234 if (netif_carrier_ok(port->netdev)) {
1235 if (netif_msg_link(port))
1236 ehea_info("%s: Logical port down",
1237 port->netdev->name);
1238 netif_carrier_off(port->netdev);
1239 netif_stop_queue(port->netdev);
1240 }
1241
1242 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001243 port->phy_link = EHEA_PHY_LINK_UP;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001244 if (netif_msg_link(port))
1245 ehea_info("%s: Physical port up",
1246 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001247 if (prop_carrier_state)
1248 netif_carrier_on(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001249 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001250 port->phy_link = EHEA_PHY_LINK_DOWN;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001251 if (netif_msg_link(port))
1252 ehea_info("%s: Physical port down",
1253 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001254 if (prop_carrier_state)
1255 netif_carrier_off(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001256 }
1257
1258 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
1259 ehea_info("External switch port is primary port");
1260 else
1261 ehea_info("External switch port is backup port");
1262
1263 break;
1264 case EHEA_EC_ADAPTER_MALFUNC:
1265 ehea_error("Adapter malfunction");
1266 break;
1267 case EHEA_EC_PORT_MALFUNC:
1268 ehea_info("Port malfunction: Device: %s", port->netdev->name);
1269 netif_carrier_off(port->netdev);
1270 netif_stop_queue(port->netdev);
1271 break;
1272 default:
Stephen Rothwella1c5a892009-01-06 14:40:06 +00001273 ehea_error("unknown event code %x, eqe=0x%llX", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001274 break;
1275 }
1276}
1277
1278static void ehea_neq_tasklet(unsigned long data)
1279{
Doug Maxey508d2b52008-01-31 20:20:49 -06001280 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001281 struct ehea_eqe *eqe;
1282 u64 event_mask;
1283
1284 eqe = ehea_poll_eq(adapter->neq);
1285 ehea_debug("eqe=%p", eqe);
1286
1287 while (eqe) {
1288 ehea_debug("*eqe=%lx", eqe->entry);
1289 ehea_parse_eqe(adapter, eqe->entry);
1290 eqe = ehea_poll_eq(adapter->neq);
1291 ehea_debug("next eqe=%p", eqe);
1292 }
1293
1294 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1295 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1296 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1297
1298 ehea_h_reset_events(adapter->handle,
1299 adapter->neq->fw_handle, event_mask);
1300}
1301
David Howells7d12e782006-10-05 14:55:46 +01001302static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001303{
1304 struct ehea_adapter *adapter = param;
1305 tasklet_hi_schedule(&adapter->neq_tasklet);
1306 return IRQ_HANDLED;
1307}
1308
1309
1310static int ehea_fill_port_res(struct ehea_port_res *pr)
1311{
1312 int ret;
1313 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1314
Thomas Kleine2878802009-01-21 14:45:57 -08001315 ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1316 - init_attr->act_nr_rwqes_rq2
1317 - init_attr->act_nr_rwqes_rq3 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001318
Thomas Kleine2878802009-01-21 14:45:57 -08001319 ret = ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001320
1321 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1322
1323 return ret;
1324}
1325
1326static int ehea_reg_interrupts(struct net_device *dev)
1327{
1328 struct ehea_port *port = netdev_priv(dev);
1329 struct ehea_port_res *pr;
1330 int i, ret;
1331
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001332
1333 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1334 dev->name);
1335
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001336 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001337 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001338 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001339 if (ret) {
1340 ehea_error("failed registering irq for qp_aff_irq_handler:"
1341 "ist=%X", port->qp_eq->attr.ist1);
1342 goto out_free_qpeq;
1343 }
1344
1345 if (netif_msg_ifup(port))
1346 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1347 "registered", port->qp_eq->attr.ist1);
1348
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001349
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001350 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1351 pr = &port->port_res[i];
1352 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001353 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001354 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001355 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001356 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001357 pr);
1358 if (ret) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001359 ehea_error("failed registering irq for ehea_queue "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001360 "port_res_nr:%d, ist=%X", i,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001361 pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001362 goto out_free_req;
1363 }
1364 if (netif_msg_ifup(port))
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001365 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1366 "%d registered", pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001367 }
1368out:
1369 return ret;
1370
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001371
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001372out_free_req:
1373 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001374 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001375 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001376 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001377
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001378out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001379 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001380 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001381
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001382 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001383
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001384}
1385
1386static void ehea_free_interrupts(struct net_device *dev)
1387{
1388 struct ehea_port *port = netdev_priv(dev);
1389 struct ehea_port_res *pr;
1390 int i;
1391
1392 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001393
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001394 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1395 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001396 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001397 if (netif_msg_intr(port))
1398 ehea_info("free send irq for res %d with handle 0x%X",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001399 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001400 }
1401
1402 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001403 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001404 if (netif_msg_intr(port))
1405 ehea_info("associated event interrupt for handle 0x%X freed",
1406 port->qp_eq->attr.ist1);
1407}
1408
1409static int ehea_configure_port(struct ehea_port *port)
1410{
1411 int ret, i;
1412 u64 hret, mask;
1413 struct hcp_ehea_port_cb0 *cb0;
1414
1415 ret = -ENOMEM;
Thomas Klein3faf2692009-01-21 14:45:33 -08001416 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001417 if (!cb0)
1418 goto out;
1419
1420 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1421 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1422 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1423 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1424 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1425 PXLY_RC_VLAN_FILTER)
1426 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1427
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001428 for (i = 0; i < port->num_mcs; i++)
1429 if (use_mcs)
1430 cb0->default_qpn_arr[i] =
1431 port->port_res[i].qp->init_attr.qp_nr;
1432 else
1433 cb0->default_qpn_arr[i] =
1434 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001435
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001436 if (netif_msg_ifup(port))
1437 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1438
1439 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1440 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1441
1442 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1443 port->logical_port_id,
1444 H_PORT_CB0, mask, cb0);
1445 ret = -EIO;
1446 if (hret != H_SUCCESS)
1447 goto out_free;
1448
1449 ret = 0;
1450
1451out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001452 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001453out:
1454 return ret;
1455}
1456
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001457int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001458{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001459 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001460 struct ehea_adapter *adapter = pr->port->adapter;
1461
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001462 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1463 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001464 goto out;
1465
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001466 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1467 if (ret)
1468 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001469
1470 return 0;
1471
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001472out_free:
1473 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001474out:
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001475 ehea_error("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001476 return -EIO;
1477}
1478
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001479int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001480{
Joe Perches8e95a202009-12-03 07:58:21 +00001481 if ((ehea_rem_mr(&pr->send_mr)) ||
1482 (ehea_rem_mr(&pr->recv_mr)))
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001483 return -EIO;
1484 else
1485 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001486}
1487
1488static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1489{
Doug Maxey508d2b52008-01-31 20:20:49 -06001490 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001491
1492 q_skba->arr = vmalloc(arr_size);
1493 if (!q_skba->arr)
1494 return -ENOMEM;
1495
1496 memset(q_skba->arr, 0, arr_size);
1497
1498 q_skba->len = max_q_entries;
1499 q_skba->index = 0;
1500 q_skba->os_skbs = 0;
1501
1502 return 0;
1503}
1504
1505static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1506 struct port_res_cfg *pr_cfg, int queue_token)
1507{
1508 struct ehea_adapter *adapter = port->adapter;
1509 enum ehea_eq_type eq_type = EHEA_EQ;
1510 struct ehea_qp_init_attr *init_attr = NULL;
1511 int ret = -EIO;
1512
1513 memset(pr, 0, sizeof(struct ehea_port_res));
1514
1515 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001516 spin_lock_init(&pr->xmit_lock);
1517 spin_lock_init(&pr->netif_queue);
1518
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001519 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1520 if (!pr->eq) {
1521 ehea_error("create_eq failed (eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001522 goto out_free;
1523 }
1524
1525 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001526 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001527 port->logical_port_id);
1528 if (!pr->recv_cq) {
1529 ehea_error("create_cq failed (cq_recv)");
1530 goto out_free;
1531 }
1532
1533 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001534 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001535 port->logical_port_id);
1536 if (!pr->send_cq) {
1537 ehea_error("create_cq failed (cq_send)");
1538 goto out_free;
1539 }
1540
1541 if (netif_msg_ifup(port))
1542 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1543 pr->send_cq->attr.act_nr_of_cqes,
1544 pr->recv_cq->attr.act_nr_of_cqes);
1545
1546 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1547 if (!init_attr) {
1548 ret = -ENOMEM;
1549 ehea_error("no mem for ehea_qp_init_attr");
1550 goto out_free;
1551 }
1552
1553 init_attr->low_lat_rq1 = 1;
1554 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1555 init_attr->rq_count = 3;
1556 init_attr->qp_token = queue_token;
1557 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1558 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1559 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1560 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1561 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1562 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1563 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1564 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1565 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1566 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1567 init_attr->port_nr = port->logical_port_id;
1568 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1569 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1570 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1571
1572 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1573 if (!pr->qp) {
1574 ehea_error("create_qp failed");
1575 ret = -EIO;
1576 goto out_free;
1577 }
1578
1579 if (netif_msg_ifup(port))
1580 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1581 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1582 init_attr->act_nr_send_wqes,
1583 init_attr->act_nr_rwqes_rq1,
1584 init_attr->act_nr_rwqes_rq2,
1585 init_attr->act_nr_rwqes_rq3);
1586
Thomas Klein44fb3122008-04-04 15:04:53 +02001587 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1588
1589 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001590 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1591 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1592 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1593 if (ret)
1594 goto out_free;
1595
1596 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1597 if (ehea_gen_smrs(pr) != 0) {
1598 ret = -EIO;
1599 goto out_free;
1600 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001601
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001602 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1603
1604 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001605
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001606 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001607
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001608 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1609 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1610 pr->lro_mgr.lro_arr = pr->lro_desc;
1611 pr->lro_mgr.get_skb_header = get_skb_hdr;
1612 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1613 pr->lro_mgr.dev = port->netdev;
1614 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1615 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1616
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001617 ret = 0;
1618 goto out;
1619
1620out_free:
1621 kfree(init_attr);
1622 vfree(pr->sq_skba.arr);
1623 vfree(pr->rq1_skba.arr);
1624 vfree(pr->rq2_skba.arr);
1625 vfree(pr->rq3_skba.arr);
1626 ehea_destroy_qp(pr->qp);
1627 ehea_destroy_cq(pr->send_cq);
1628 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001629 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001630out:
1631 return ret;
1632}
1633
1634static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1635{
1636 int ret, i;
1637
Hannes Hering357eb462009-08-04 11:48:39 -07001638 if (pr->qp)
1639 netif_napi_del(&pr->napi);
1640
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001641 ret = ehea_destroy_qp(pr->qp);
1642
1643 if (!ret) {
1644 ehea_destroy_cq(pr->send_cq);
1645 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001646 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001647
1648 for (i = 0; i < pr->rq1_skba.len; i++)
1649 if (pr->rq1_skba.arr[i])
1650 dev_kfree_skb(pr->rq1_skba.arr[i]);
1651
1652 for (i = 0; i < pr->rq2_skba.len; i++)
1653 if (pr->rq2_skba.arr[i])
1654 dev_kfree_skb(pr->rq2_skba.arr[i]);
1655
1656 for (i = 0; i < pr->rq3_skba.len; i++)
1657 if (pr->rq3_skba.arr[i])
1658 dev_kfree_skb(pr->rq3_skba.arr[i]);
1659
1660 for (i = 0; i < pr->sq_skba.len; i++)
1661 if (pr->sq_skba.arr[i])
1662 dev_kfree_skb(pr->sq_skba.arr[i]);
1663
1664 vfree(pr->rq1_skba.arr);
1665 vfree(pr->rq2_skba.arr);
1666 vfree(pr->rq3_skba.arr);
1667 vfree(pr->sq_skba.arr);
1668 ret = ehea_rem_smrs(pr);
1669 }
1670 return ret;
1671}
1672
1673/*
1674 * The write_* functions store information in swqe which is used by
1675 * the hardware to calculate the ip/tcp/udp checksum
1676 */
1677
1678static inline void write_ip_start_end(struct ehea_swqe *swqe,
1679 const struct sk_buff *skb)
1680{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001681 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001682 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001683}
1684
1685static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1686 const struct sk_buff *skb)
1687{
1688 swqe->tcp_offset =
1689 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1690
1691 swqe->tcp_end = (u16)skb->len - 1;
1692}
1693
1694static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1695 const struct sk_buff *skb)
1696{
1697 swqe->tcp_offset =
1698 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1699
1700 swqe->tcp_end = (u16)skb->len - 1;
1701}
1702
1703
1704static void write_swqe2_TSO(struct sk_buff *skb,
1705 struct ehea_swqe *swqe, u32 lkey)
1706{
1707 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1708 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
Eric Dumazete743d312010-04-14 15:59:40 -07001709 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001710 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001711
1712 /* Packet is TCP with TSO enabled */
1713 swqe->tx_control |= EHEA_SWQE_TSO;
1714 swqe->mss = skb_shinfo(skb)->gso_size;
1715 /* copy only eth/ip/tcp headers to immediate data and
1716 * the rest of skb->data to sg1entry
1717 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001718 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001719
Eric Dumazete743d312010-04-14 15:59:40 -07001720 skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001721
1722 if (skb_data_size >= headersize) {
1723 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001724 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001725 swqe->immediate_data_length = headersize;
1726
1727 if (skb_data_size > headersize) {
1728 /* set sg1entry data */
1729 sg1entry->l_key = lkey;
1730 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001731 sg1entry->vaddr =
1732 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001733 swqe->descriptors++;
1734 }
1735 } else
1736 ehea_error("cannot handle fragmented headers");
1737}
1738
1739static void write_swqe2_nonTSO(struct sk_buff *skb,
1740 struct ehea_swqe *swqe, u32 lkey)
1741{
Eric Dumazete743d312010-04-14 15:59:40 -07001742 int skb_data_size = skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001743 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1744 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001745
1746 /* Packet is any nonTSO type
1747 *
1748 * Copy as much as possible skb->data to immediate data and
1749 * the rest to sg1entry
1750 */
1751 if (skb_data_size >= SWQE2_MAX_IMM) {
1752 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001753 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001754
1755 swqe->immediate_data_length = SWQE2_MAX_IMM;
1756
1757 if (skb_data_size > SWQE2_MAX_IMM) {
1758 /* copy sg1entry data */
1759 sg1entry->l_key = lkey;
1760 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001761 sg1entry->vaddr =
1762 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001763 swqe->descriptors++;
1764 }
1765 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001766 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001767 swqe->immediate_data_length = skb_data_size;
1768 }
1769}
1770
1771static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1772 struct ehea_swqe *swqe, u32 lkey)
1773{
1774 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1775 skb_frag_t *frag;
1776 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001777
1778 nfrags = skb_shinfo(skb)->nr_frags;
1779 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001780 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001781 swqe->descriptors = 0;
1782 sg1entry_contains_frag_data = 0;
1783
1784 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1785 write_swqe2_TSO(skb, swqe, lkey);
1786 else
1787 write_swqe2_nonTSO(skb, swqe, lkey);
1788
1789 /* write descriptors */
1790 if (nfrags > 0) {
1791 if (swqe->descriptors == 0) {
1792 /* sg1entry not yet used */
1793 frag = &skb_shinfo(skb)->frags[0];
1794
1795 /* copy sg1entry data */
1796 sg1entry->l_key = lkey;
1797 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001798 sg1entry->vaddr =
1799 ehea_map_vaddr(page_address(frag->page)
1800 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001801 swqe->descriptors++;
1802 sg1entry_contains_frag_data = 1;
1803 }
1804
1805 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1806
1807 frag = &skb_shinfo(skb)->frags[i];
1808 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1809
1810 sgentry->l_key = lkey;
1811 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001812 sgentry->vaddr =
1813 ehea_map_vaddr(page_address(frag->page)
1814 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001815 swqe->descriptors++;
1816 }
1817 }
1818}
1819
1820static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1821{
1822 int ret = 0;
1823 u64 hret;
1824 u8 reg_type;
1825
1826 /* De/Register untagged packets */
1827 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1828 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1829 port->logical_port_id,
1830 reg_type, port->mac_addr, 0, hcallid);
1831 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001832 ehea_error("%sregistering bc address failed (tagged)",
Doug Maxey508d2b52008-01-31 20:20:49 -06001833 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001834 ret = -EIO;
1835 goto out_herr;
1836 }
1837
1838 /* De/Register VLAN packets */
1839 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1840 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1841 port->logical_port_id,
1842 reg_type, port->mac_addr, 0, hcallid);
1843 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001844 ehea_error("%sregistering bc address failed (vlan)",
1845 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001846 ret = -EIO;
1847 }
1848out_herr:
1849 return ret;
1850}
1851
1852static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1853{
1854 struct ehea_port *port = netdev_priv(dev);
1855 struct sockaddr *mac_addr = sa;
1856 struct hcp_ehea_port_cb0 *cb0;
1857 int ret;
1858 u64 hret;
1859
1860 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1861 ret = -EADDRNOTAVAIL;
1862 goto out;
1863 }
1864
Thomas Klein3faf2692009-01-21 14:45:33 -08001865 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001866 if (!cb0) {
1867 ehea_error("no mem for cb0");
1868 ret = -ENOMEM;
1869 goto out;
1870 }
1871
1872 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1873
1874 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1875
1876 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1877 port->logical_port_id, H_PORT_CB0,
1878 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1879 if (hret != H_SUCCESS) {
1880 ret = -EIO;
1881 goto out_free;
1882 }
1883
1884 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1885
1886 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001887 if (port->state == EHEA_PORT_UP) {
1888 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1889 if (ret)
1890 goto out_upregs;
1891 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001892
1893 port->mac_addr = cb0->port_mac_addr << 16;
1894
1895 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001896 if (port->state == EHEA_PORT_UP) {
1897 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1898 if (ret)
1899 goto out_upregs;
1900 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001901
1902 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001903
1904out_upregs:
1905 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001906out_free:
Thomas Klein3faf2692009-01-21 14:45:33 -08001907 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001908out:
1909 return ret;
1910}
1911
1912static void ehea_promiscuous_error(u64 hret, int enable)
1913{
Thomas Klein7674a582007-01-22 12:54:20 +01001914 if (hret == H_AUTHORITY)
1915 ehea_info("Hypervisor denied %sabling promiscuous mode",
1916 enable == 1 ? "en" : "dis");
1917 else
1918 ehea_error("failed %sabling promiscuous mode",
1919 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001920}
1921
1922static void ehea_promiscuous(struct net_device *dev, int enable)
1923{
1924 struct ehea_port *port = netdev_priv(dev);
1925 struct hcp_ehea_port_cb7 *cb7;
1926 u64 hret;
1927
Nicolas Kaiseraa3bc6c2010-10-07 13:14:50 +00001928 if (enable == port->promisc)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001929 return;
1930
Thomas Klein3faf2692009-01-21 14:45:33 -08001931 cb7 = (void *)get_zeroed_page(GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001932 if (!cb7) {
1933 ehea_error("no mem for cb7");
1934 goto out;
1935 }
1936
1937 /* Modify Pxs_DUCQPN in CB7 */
1938 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1939
1940 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1941 port->logical_port_id,
1942 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1943 if (hret) {
1944 ehea_promiscuous_error(hret, enable);
1945 goto out;
1946 }
1947
1948 port->promisc = enable;
1949out:
Thomas Klein3faf2692009-01-21 14:45:33 -08001950 free_page((unsigned long)cb7);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001951}
1952
1953static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1954 u32 hcallid)
1955{
1956 u64 hret;
1957 u8 reg_type;
1958
1959 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1960 | EHEA_BCMC_UNTAGGED;
1961
1962 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1963 port->logical_port_id,
1964 reg_type, mc_mac_addr, 0, hcallid);
1965 if (hret)
1966 goto out;
1967
1968 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1969 | EHEA_BCMC_VLANID_ALL;
1970
1971 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1972 port->logical_port_id,
1973 reg_type, mc_mac_addr, 0, hcallid);
1974out:
1975 return hret;
1976}
1977
1978static int ehea_drop_multicast_list(struct net_device *dev)
1979{
1980 struct ehea_port *port = netdev_priv(dev);
1981 struct ehea_mc_list *mc_entry = port->mc_list;
1982 struct list_head *pos;
1983 struct list_head *temp;
1984 int ret = 0;
1985 u64 hret;
1986
1987 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1988 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1989
1990 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1991 H_DEREG_BCMC);
1992 if (hret) {
1993 ehea_error("failed deregistering mcast MAC");
1994 ret = -EIO;
1995 }
1996
1997 list_del(pos);
1998 kfree(mc_entry);
1999 }
2000 return ret;
2001}
2002
2003static void ehea_allmulti(struct net_device *dev, int enable)
2004{
2005 struct ehea_port *port = netdev_priv(dev);
2006 u64 hret;
2007
2008 if (!port->allmulti) {
2009 if (enable) {
2010 /* Enable ALLMULTI */
2011 ehea_drop_multicast_list(dev);
2012 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
2013 if (!hret)
2014 port->allmulti = 1;
2015 else
2016 ehea_error("failed enabling IFF_ALLMULTI");
2017 }
2018 } else
2019 if (!enable) {
2020 /* Disable ALLMULTI */
2021 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
2022 if (!hret)
2023 port->allmulti = 0;
2024 else
2025 ehea_error("failed disabling IFF_ALLMULTI");
2026 }
2027}
2028
Doug Maxey508d2b52008-01-31 20:20:49 -06002029static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002030{
2031 struct ehea_mc_list *ehea_mcl_entry;
2032 u64 hret;
2033
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02002034 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002035 if (!ehea_mcl_entry) {
2036 ehea_error("no mem for mcl_entry");
2037 return;
2038 }
2039
2040 INIT_LIST_HEAD(&ehea_mcl_entry->list);
2041
2042 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
2043
2044 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
2045 H_REG_BCMC);
2046 if (!hret)
2047 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
2048 else {
2049 ehea_error("failed registering mcast MAC");
2050 kfree(ehea_mcl_entry);
2051 }
2052}
2053
2054static void ehea_set_multicast_list(struct net_device *dev)
2055{
2056 struct ehea_port *port = netdev_priv(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +00002057 struct netdev_hw_addr *ha;
Jiri Pirko48e2f182010-02-22 09:22:26 +00002058 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002059
2060 if (dev->flags & IFF_PROMISC) {
2061 ehea_promiscuous(dev, 1);
2062 return;
2063 }
2064 ehea_promiscuous(dev, 0);
2065
2066 if (dev->flags & IFF_ALLMULTI) {
2067 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002068 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002069 }
2070 ehea_allmulti(dev, 0);
2071
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002072 if (!netdev_mc_empty(dev)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002073 ret = ehea_drop_multicast_list(dev);
2074 if (ret) {
2075 /* Dropping the current multicast list failed.
2076 * Enabling ALL_MULTI is the best we can do.
2077 */
2078 ehea_allmulti(dev, 1);
2079 }
2080
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00002081 if (netdev_mc_count(dev) > port->adapter->max_mc_mac) {
Stephen Rothwella1c5a892009-01-06 14:40:06 +00002082 ehea_info("Mcast registration limit reached (0x%llx). "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002083 "Use ALLMULTI!",
2084 port->adapter->max_mc_mac);
2085 goto out;
2086 }
2087
Jiri Pirko22bedad32010-04-01 21:22:57 +00002088 netdev_for_each_mc_addr(ha, dev)
2089 ehea_add_multicast_entry(port, ha->addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06002090
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002091 }
2092out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01002093 ehea_update_bcmc_registrations();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002094}
2095
2096static int ehea_change_mtu(struct net_device *dev, int new_mtu)
2097{
2098 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
2099 return -EINVAL;
2100 dev->mtu = new_mtu;
2101 return 0;
2102}
2103
2104static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
2105 struct ehea_swqe *swqe, u32 lkey)
2106{
2107 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002108 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002109
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002110 /* IPv4 */
2111 swqe->tx_control |= EHEA_SWQE_CRC
2112 | EHEA_SWQE_IP_CHECKSUM
2113 | EHEA_SWQE_TCP_CHECKSUM
2114 | EHEA_SWQE_IMM_DATA_PRESENT
2115 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2116
2117 write_ip_start_end(swqe, skb);
2118
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002119 if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002120 if ((iph->frag_off & IP_MF) ||
2121 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002122 /* IP fragment, so don't change cs */
2123 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2124 else
2125 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002126 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002127 write_tcp_offset_end(swqe, skb);
2128 }
2129
2130 /* icmp (big data) and ip segmentation packets (all other ip
2131 packets) do not require any special handling */
2132
2133 } else {
2134 /* Other Ethernet Protocol */
2135 swqe->tx_control |= EHEA_SWQE_CRC
2136 | EHEA_SWQE_IMM_DATA_PRESENT
2137 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2138 }
2139
2140 write_swqe2_data(skb, dev, swqe, lkey);
2141}
2142
2143static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2144 struct ehea_swqe *swqe)
2145{
2146 int nfrags = skb_shinfo(skb)->nr_frags;
2147 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2148 skb_frag_t *frag;
2149 int i;
2150
2151 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002152 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002153
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002154 /* IPv4 */
2155 write_ip_start_end(swqe, skb);
2156
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002157 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002158 swqe->tx_control |= EHEA_SWQE_CRC
2159 | EHEA_SWQE_IP_CHECKSUM
2160 | EHEA_SWQE_TCP_CHECKSUM
2161 | EHEA_SWQE_IMM_DATA_PRESENT;
2162
2163 write_tcp_offset_end(swqe, skb);
2164
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002165 } else if (iph->protocol == IPPROTO_UDP) {
Joe Perches8e95a202009-12-03 07:58:21 +00002166 if ((iph->frag_off & IP_MF) ||
2167 (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002168 /* IP fragment, so don't change cs */
2169 swqe->tx_control |= EHEA_SWQE_CRC
2170 | EHEA_SWQE_IMM_DATA_PRESENT;
2171 else {
2172 swqe->tx_control |= EHEA_SWQE_CRC
2173 | EHEA_SWQE_IP_CHECKSUM
2174 | EHEA_SWQE_TCP_CHECKSUM
2175 | EHEA_SWQE_IMM_DATA_PRESENT;
2176
2177 write_udp_offset_end(swqe, skb);
2178 }
2179 } else {
2180 /* icmp (big data) and
2181 ip segmentation packets (all other ip packets) */
2182 swqe->tx_control |= EHEA_SWQE_CRC
2183 | EHEA_SWQE_IP_CHECKSUM
2184 | EHEA_SWQE_IMM_DATA_PRESENT;
2185 }
2186 } else {
2187 /* Other Ethernet Protocol */
2188 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2189 }
2190 /* copy (immediate) data */
2191 if (nfrags == 0) {
2192 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002193 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002194 } else {
2195 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002196 skb_copy_from_linear_data(skb, imm_data,
Eric Dumazete743d312010-04-14 15:59:40 -07002197 skb_headlen(skb));
2198 imm_data += skb_headlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002199
2200 /* ... then copy data from the fragments */
2201 for (i = 0; i < nfrags; i++) {
2202 frag = &skb_shinfo(skb)->frags[i];
2203 memcpy(imm_data,
2204 page_address(frag->page) + frag->page_offset,
2205 frag->size);
2206 imm_data += frag->size;
2207 }
2208 }
2209 swqe->immediate_data_length = skb->len;
2210 dev_kfree_skb(skb);
2211}
2212
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002213static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2214{
2215 struct tcphdr *tcp;
2216 u32 tmp;
2217
2218 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002219 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002220 tcp = (struct tcphdr *)(skb_network_header(skb) +
2221 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002222 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002223 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002224 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002225 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002226 return 0;
2227}
2228
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002229static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2230{
2231 struct ehea_port *port = netdev_priv(dev);
2232 struct ehea_swqe *swqe;
2233 unsigned long flags;
2234 u32 lkey;
2235 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002236 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002237
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002238 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2239
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002240 if (!spin_trylock(&pr->xmit_lock))
2241 return NETDEV_TX_BUSY;
2242
2243 if (pr->queue_stopped) {
2244 spin_unlock(&pr->xmit_lock);
2245 return NETDEV_TX_BUSY;
2246 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002247
2248 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2249 memset(swqe, 0, SWQE_HEADER_SIZE);
2250 atomic_dec(&pr->swqe_avail);
2251
Eric Dumazete5ccd962010-10-26 19:21:07 +00002252 if (vlan_tx_tag_present(skb)) {
2253 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2254 swqe->vlan_tag = vlan_tx_tag_get(skb);
2255 }
2256
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002257 if (skb->len <= SWQE3_MAX_IMM) {
2258 u32 sig_iv = port->sig_comp_iv;
2259 u32 swqe_num = pr->swqe_id_counter;
2260 ehea_xmit3(skb, dev, swqe);
2261 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2262 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2263 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2264 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2265 sig_iv);
2266 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2267 pr->swqe_ll_count = 0;
2268 } else
2269 pr->swqe_ll_count += 1;
2270 } else {
2271 swqe->wr_id =
2272 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2273 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002274 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002275 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2276 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2277
2278 pr->sq_skba.index++;
2279 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2280
2281 lkey = pr->send_mr.lkey;
2282 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002283 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002284 }
2285 pr->swqe_id_counter += 1;
2286
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002287 if (netif_msg_tx_queued(port)) {
2288 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002289 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002290 }
2291
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002292 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2293 netif_stop_queue(dev);
2294 swqe->tx_control |= EHEA_SWQE_PURGE;
2295 }
Thomas Klein44c82152007-07-11 16:32:00 +02002296
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002297 ehea_post_swqe(pr->qp, swqe);
Thomas Klein7393b872007-11-21 17:37:58 +01002298 pr->tx_packets++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002299
2300 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2301 spin_lock_irqsave(&pr->netif_queue, flags);
2302 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002303 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002304 netif_stop_queue(dev);
2305 pr->queue_stopped = 1;
2306 }
2307 spin_unlock_irqrestore(&pr->netif_queue, flags);
2308 }
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07002309 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002310 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002311
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002312 return NETDEV_TX_OK;
2313}
2314
2315static void ehea_vlan_rx_register(struct net_device *dev,
2316 struct vlan_group *grp)
2317{
2318 struct ehea_port *port = netdev_priv(dev);
2319 struct ehea_adapter *adapter = port->adapter;
2320 struct hcp_ehea_port_cb1 *cb1;
2321 u64 hret;
2322
2323 port->vgrp = grp;
2324
Thomas Klein3faf2692009-01-21 14:45:33 -08002325 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002326 if (!cb1) {
2327 ehea_error("no mem for cb1");
2328 goto out;
2329 }
2330
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002331 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2332 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2333 if (hret != H_SUCCESS)
2334 ehea_error("modify_ehea_port failed");
2335
Thomas Klein3faf2692009-01-21 14:45:33 -08002336 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002337out:
2338 return;
2339}
2340
2341static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2342{
2343 struct ehea_port *port = netdev_priv(dev);
2344 struct ehea_adapter *adapter = port->adapter;
2345 struct hcp_ehea_port_cb1 *cb1;
2346 int index;
2347 u64 hret;
2348
Thomas Klein3faf2692009-01-21 14:45:33 -08002349 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002350 if (!cb1) {
2351 ehea_error("no mem for cb1");
2352 goto out;
2353 }
2354
2355 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2356 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2357 if (hret != H_SUCCESS) {
2358 ehea_error("query_ehea_port failed");
2359 goto out;
2360 }
2361
2362 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002363 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002364
2365 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2366 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2367 if (hret != H_SUCCESS)
2368 ehea_error("modify_ehea_port failed");
2369out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002370 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002371 return;
2372}
2373
2374static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2375{
2376 struct ehea_port *port = netdev_priv(dev);
2377 struct ehea_adapter *adapter = port->adapter;
2378 struct hcp_ehea_port_cb1 *cb1;
2379 int index;
2380 u64 hret;
2381
Dan Aloni5c15bde2007-03-02 20:44:51 -08002382 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002383
Thomas Klein3faf2692009-01-21 14:45:33 -08002384 cb1 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002385 if (!cb1) {
2386 ehea_error("no mem for cb1");
2387 goto out;
2388 }
2389
2390 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2391 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2392 if (hret != H_SUCCESS) {
2393 ehea_error("query_ehea_port failed");
2394 goto out;
2395 }
2396
2397 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002398 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002399
2400 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2401 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2402 if (hret != H_SUCCESS)
2403 ehea_error("modify_ehea_port failed");
2404out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002405 free_page((unsigned long)cb1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002406}
2407
2408int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2409{
2410 int ret = -EIO;
2411 u64 hret;
2412 u16 dummy16 = 0;
2413 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002414 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002415
Thomas Klein3faf2692009-01-21 14:45:33 -08002416 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002417 if (!cb0) {
2418 ret = -ENOMEM;
2419 goto out;
2420 }
2421
2422 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2423 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2424 if (hret != H_SUCCESS) {
2425 ehea_error("query_ehea_qp failed (1)");
2426 goto out;
2427 }
2428
2429 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2430 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2431 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2432 &dummy64, &dummy64, &dummy16, &dummy16);
2433 if (hret != H_SUCCESS) {
2434 ehea_error("modify_ehea_qp failed (1)");
2435 goto out;
2436 }
2437
2438 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2439 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2440 if (hret != H_SUCCESS) {
2441 ehea_error("query_ehea_qp failed (2)");
2442 goto out;
2443 }
2444
2445 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2446 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2447 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2448 &dummy64, &dummy64, &dummy16, &dummy16);
2449 if (hret != H_SUCCESS) {
2450 ehea_error("modify_ehea_qp failed (2)");
2451 goto out;
2452 }
2453
2454 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2455 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2456 if (hret != H_SUCCESS) {
2457 ehea_error("query_ehea_qp failed (3)");
2458 goto out;
2459 }
2460
2461 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2462 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2463 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2464 &dummy64, &dummy64, &dummy16, &dummy16);
2465 if (hret != H_SUCCESS) {
2466 ehea_error("modify_ehea_qp failed (3)");
2467 goto out;
2468 }
2469
2470 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2471 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2472 if (hret != H_SUCCESS) {
2473 ehea_error("query_ehea_qp failed (4)");
2474 goto out;
2475 }
2476
2477 ret = 0;
2478out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002479 free_page((unsigned long)cb0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002480 return ret;
2481}
2482
2483static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2484 int add_tx_qps)
2485{
2486 int ret, i;
2487 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2488 enum ehea_eq_type eq_type = EHEA_EQ;
2489
2490 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2491 EHEA_MAX_ENTRIES_EQ, 1);
2492 if (!port->qp_eq) {
2493 ret = -EINVAL;
2494 ehea_error("ehea_create_eq failed (qp_eq)");
2495 goto out_kill_eq;
2496 }
2497
2498 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002499 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002500 pr_cfg.max_entries_sq = sq_entries;
2501 pr_cfg.max_entries_rq1 = rq1_entries;
2502 pr_cfg.max_entries_rq2 = rq2_entries;
2503 pr_cfg.max_entries_rq3 = rq3_entries;
2504
2505 pr_cfg_small_rx.max_entries_rcq = 1;
2506 pr_cfg_small_rx.max_entries_scq = sq_entries;
2507 pr_cfg_small_rx.max_entries_sq = sq_entries;
2508 pr_cfg_small_rx.max_entries_rq1 = 1;
2509 pr_cfg_small_rx.max_entries_rq2 = 1;
2510 pr_cfg_small_rx.max_entries_rq3 = 1;
2511
2512 for (i = 0; i < def_qps; i++) {
2513 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2514 if (ret)
2515 goto out_clean_pr;
2516 }
2517 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2518 ret = ehea_init_port_res(port, &port->port_res[i],
2519 &pr_cfg_small_rx, i);
2520 if (ret)
2521 goto out_clean_pr;
2522 }
2523
2524 return 0;
2525
2526out_clean_pr:
2527 while (--i >= 0)
2528 ehea_clean_portres(port, &port->port_res[i]);
2529
2530out_kill_eq:
2531 ehea_destroy_eq(port->qp_eq);
2532 return ret;
2533}
2534
2535static int ehea_clean_all_portres(struct ehea_port *port)
2536{
2537 int ret = 0;
2538 int i;
2539
Doug Maxey508d2b52008-01-31 20:20:49 -06002540 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002541 ret |= ehea_clean_portres(port, &port->port_res[i]);
2542
2543 ret |= ehea_destroy_eq(port->qp_eq);
2544
2545 return ret;
2546}
2547
Thomas Klein35cf2e22007-08-06 13:55:14 +02002548static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002549{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002550 if (adapter->active_ports)
2551 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002552
2553 ehea_rem_mr(&adapter->mr);
2554}
2555
Thomas Klein35cf2e22007-08-06 13:55:14 +02002556static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002557{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002558 if (adapter->active_ports)
2559 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002560
2561 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2562}
2563
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002564static int ehea_up(struct net_device *dev)
2565{
2566 int ret, i;
2567 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002568
2569 if (port->state == EHEA_PORT_UP)
2570 return 0;
2571
2572 ret = ehea_port_res_setup(port, port->num_def_qps,
2573 port->num_add_tx_qps);
2574 if (ret) {
2575 ehea_error("port_res_failed");
2576 goto out;
2577 }
2578
2579 /* Set default QP for this port */
2580 ret = ehea_configure_port(port);
2581 if (ret) {
2582 ehea_error("ehea_configure_port failed. ret:%d", ret);
2583 goto out_clean_pr;
2584 }
2585
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002586 ret = ehea_reg_interrupts(dev);
2587 if (ret) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02002588 ehea_error("reg_interrupts failed. ret:%d", ret);
2589 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002590 }
2591
Doug Maxey508d2b52008-01-31 20:20:49 -06002592 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002593 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2594 if (ret) {
2595 ehea_error("activate_qp failed");
2596 goto out_free_irqs;
2597 }
2598 }
2599
Doug Maxey508d2b52008-01-31 20:20:49 -06002600 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002601 ret = ehea_fill_port_res(&port->port_res[i]);
2602 if (ret) {
2603 ehea_error("out_free_irqs");
2604 goto out_free_irqs;
2605 }
2606 }
2607
Thomas Klein21eee2d2008-02-13 16:18:33 +01002608 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2609 if (ret) {
2610 ret = -EIO;
2611 goto out_free_irqs;
2612 }
2613
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002614 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002615
2616 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002617 goto out;
2618
2619out_free_irqs:
2620 ehea_free_interrupts(dev);
2621
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002622out_clean_pr:
2623 ehea_clean_all_portres(port);
2624out:
Thomas Klein44c82152007-07-11 16:32:00 +02002625 if (ret)
2626 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
2627
Thomas Klein21eee2d2008-02-13 16:18:33 +01002628 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002629 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002630
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002631 return ret;
2632}
2633
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002634static void port_napi_disable(struct ehea_port *port)
2635{
2636 int i;
2637
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002638 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002639 napi_disable(&port->port_res[i].napi);
2640}
2641
2642static void port_napi_enable(struct ehea_port *port)
2643{
2644 int i;
2645
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002646 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002647 napi_enable(&port->port_res[i].napi);
2648}
2649
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002650static int ehea_open(struct net_device *dev)
2651{
2652 int ret;
2653 struct ehea_port *port = netdev_priv(dev);
2654
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002655 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002656
2657 if (netif_msg_ifup(port))
2658 ehea_info("enabling port %s", dev->name);
2659
2660 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002661 if (!ret) {
2662 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002663 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002664 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002665
Breno Leitao5b27d422010-10-05 13:16:22 +00002666 init_waitqueue_head(&port->swqe_avail_wq);
Breno Leitaoa8bb69f2010-10-05 13:16:23 +00002667 init_waitqueue_head(&port->restart_wq);
Breno Leitao5b27d422010-10-05 13:16:22 +00002668
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002669 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002670
2671 return ret;
2672}
2673
2674static int ehea_down(struct net_device *dev)
2675{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002676 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002677 struct ehea_port *port = netdev_priv(dev);
2678
2679 if (port->state == EHEA_PORT_DOWN)
2680 return 0;
2681
2682 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002683 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2684
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002685 ehea_free_interrupts(dev);
2686
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002687 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002688
Thomas Klein21eee2d2008-02-13 16:18:33 +01002689 ehea_update_bcmc_registrations();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002690
Thomas Klein44c82152007-07-11 16:32:00 +02002691 ret = ehea_clean_all_portres(port);
2692 if (ret)
2693 ehea_info("Failed freeing resources for %s. ret=%i",
2694 dev->name, ret);
2695
Thomas Klein21eee2d2008-02-13 16:18:33 +01002696 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01002697
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002698 return ret;
2699}
2700
2701static int ehea_stop(struct net_device *dev)
2702{
2703 int ret;
2704 struct ehea_port *port = netdev_priv(dev);
2705
2706 if (netif_msg_ifdown(port))
2707 ehea_info("disabling port %s", dev->name);
2708
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002709 set_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
David S. Miller4bb073c2008-06-12 02:22:02 -07002710 cancel_work_sync(&port->reset_task);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002711 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002712 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002713 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002714 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002715 mutex_unlock(&port->port_lock);
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01002716 clear_bit(__EHEA_DISABLE_PORT_RESET, &port->flags);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002717 return ret;
2718}
2719
Andrew Morton22559c52008-04-18 13:50:39 -07002720static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002721{
2722 struct ehea_qp qp = *orig_qp;
2723 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2724 struct ehea_swqe *swqe;
2725 int wqe_index;
2726 int i;
2727
2728 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2729 swqe = ehea_get_swqe(&qp, &wqe_index);
2730 swqe->tx_control |= EHEA_SWQE_PURGE;
2731 }
2732}
2733
Andrew Morton22559c52008-04-18 13:50:39 -07002734static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002735{
2736 int i;
2737
2738 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2739 struct ehea_port_res *pr = &port->port_res[i];
2740 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
Breno Leitao5b27d422010-10-05 13:16:22 +00002741 int ret;
2742
2743 ret = wait_event_timeout(port->swqe_avail_wq,
2744 atomic_read(&pr->swqe_avail) >= swqe_max,
2745 msecs_to_jiffies(100));
2746
2747 if (!ret) {
2748 ehea_error("WARNING: sq not flushed completely");
2749 break;
Thomas Klein44fb3122008-04-04 15:04:53 +02002750 }
2751 }
2752}
2753
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002754int ehea_stop_qps(struct net_device *dev)
2755{
2756 struct ehea_port *port = netdev_priv(dev);
2757 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002758 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002759 int ret = -EIO;
2760 int dret;
2761 int i;
2762 u64 hret;
2763 u64 dummy64 = 0;
2764 u16 dummy16 = 0;
2765
Thomas Klein3faf2692009-01-21 14:45:33 -08002766 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002767 if (!cb0) {
2768 ret = -ENOMEM;
2769 goto out;
2770 }
2771
2772 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2773 struct ehea_port_res *pr = &port->port_res[i];
2774 struct ehea_qp *qp = pr->qp;
2775
2776 /* Purge send queue */
2777 ehea_purge_sq(qp);
2778
2779 /* Disable queue pair */
2780 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2781 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2782 cb0);
2783 if (hret != H_SUCCESS) {
2784 ehea_error("query_ehea_qp failed (1)");
2785 goto out;
2786 }
2787
2788 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2789 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2790
2791 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2792 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2793 1), cb0, &dummy64,
2794 &dummy64, &dummy16, &dummy16);
2795 if (hret != H_SUCCESS) {
2796 ehea_error("modify_ehea_qp failed (1)");
2797 goto out;
2798 }
2799
2800 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2801 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2802 cb0);
2803 if (hret != H_SUCCESS) {
2804 ehea_error("query_ehea_qp failed (2)");
2805 goto out;
2806 }
2807
2808 /* deregister shared memory regions */
2809 dret = ehea_rem_smrs(pr);
2810 if (dret) {
2811 ehea_error("unreg shared memory region failed");
2812 goto out;
2813 }
2814 }
2815
2816 ret = 0;
2817out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002818 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002819
2820 return ret;
2821}
2822
Doug Maxey508d2b52008-01-31 20:20:49 -06002823void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002824{
2825 struct ehea_qp qp = *orig_qp;
2826 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2827 struct ehea_rwqe *rwqe;
2828 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2829 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2830 struct sk_buff *skb;
2831 u32 lkey = pr->recv_mr.lkey;
2832
2833
2834 int i;
2835 int index;
2836
2837 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2838 rwqe = ehea_get_next_rwqe(&qp, 2);
2839 rwqe->sg_list[0].l_key = lkey;
2840 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2841 skb = skba_rq2[index];
2842 if (skb)
2843 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2844 }
2845
2846 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2847 rwqe = ehea_get_next_rwqe(&qp, 3);
2848 rwqe->sg_list[0].l_key = lkey;
2849 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2850 skb = skba_rq3[index];
2851 if (skb)
2852 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2853 }
2854}
2855
2856int ehea_restart_qps(struct net_device *dev)
2857{
2858 struct ehea_port *port = netdev_priv(dev);
2859 struct ehea_adapter *adapter = port->adapter;
2860 int ret = 0;
2861 int i;
2862
Doug Maxey508d2b52008-01-31 20:20:49 -06002863 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002864 u64 hret;
2865 u64 dummy64 = 0;
2866 u16 dummy16 = 0;
2867
Thomas Klein3faf2692009-01-21 14:45:33 -08002868 cb0 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002869 if (!cb0) {
2870 ret = -ENOMEM;
2871 goto out;
2872 }
2873
2874 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2875 struct ehea_port_res *pr = &port->port_res[i];
2876 struct ehea_qp *qp = pr->qp;
2877
2878 ret = ehea_gen_smrs(pr);
2879 if (ret) {
2880 ehea_error("creation of shared memory regions failed");
2881 goto out;
2882 }
2883
2884 ehea_update_rqs(qp, pr);
2885
2886 /* Enable queue pair */
2887 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2888 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2889 cb0);
2890 if (hret != H_SUCCESS) {
2891 ehea_error("query_ehea_qp failed (1)");
2892 goto out;
2893 }
2894
2895 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2896 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2897
2898 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2899 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2900 1), cb0, &dummy64,
2901 &dummy64, &dummy16, &dummy16);
2902 if (hret != H_SUCCESS) {
2903 ehea_error("modify_ehea_qp failed (1)");
2904 goto out;
2905 }
2906
2907 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2908 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2909 cb0);
2910 if (hret != H_SUCCESS) {
2911 ehea_error("query_ehea_qp failed (2)");
2912 goto out;
2913 }
2914
2915 /* refill entire queue */
2916 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2917 ehea_refill_rq2(pr, 0);
2918 ehea_refill_rq3(pr, 0);
2919 }
2920out:
Thomas Klein3faf2692009-01-21 14:45:33 -08002921 free_page((unsigned long)cb0);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002922
2923 return ret;
2924}
2925
David Howellsc4028952006-11-22 14:57:56 +00002926static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002927{
2928 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002929 struct ehea_port *port =
2930 container_of(work, struct ehea_port, reset_task);
2931 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002932
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002933 mutex_lock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002934 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002935 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002936 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002937
2938 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002939
Thomas Klein44c82152007-07-11 16:32:00 +02002940 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002941
2942 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002943 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002944 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002945
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002946 ehea_set_multicast_list(dev);
2947
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002948 if (netif_msg_timer(port))
2949 ehea_info("Device %s resetted successfully", dev->name);
2950
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002951 port_napi_enable(port);
2952
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002953 netif_wake_queue(dev);
2954out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002955 mutex_unlock(&port->port_lock);
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00002956 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002957}
2958
Thomas Klein44c82152007-07-11 16:32:00 +02002959static void ehea_rereg_mrs(struct work_struct *work)
2960{
2961 int ret, i;
2962 struct ehea_adapter *adapter;
2963
Hannes Heringd4f12da2008-10-16 11:36:42 +02002964 ehea_info("LPAR memory changed - re-initializing driver");
Thomas Klein44c82152007-07-11 16:32:00 +02002965
2966 list_for_each_entry(adapter, &adapter_list, list)
2967 if (adapter->active_ports) {
2968 /* Shutdown all ports */
2969 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2970 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002971 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002972
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002973 if (!port)
2974 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002975
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002976 dev = port->netdev;
2977
2978 if (dev->flags & IFF_UP) {
2979 mutex_lock(&port->port_lock);
2980 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002981 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002982 ret = ehea_stop_qps(dev);
2983 if (ret) {
2984 mutex_unlock(&port->port_lock);
2985 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002986 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002987 port_napi_disable(port);
2988 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002989 }
Andre Detsch2928db42010-08-17 05:49:12 +00002990 reset_sq_restart_flag(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002991 }
2992
2993 /* Unregister old memory region */
2994 ret = ehea_rem_mr(&adapter->mr);
2995 if (ret) {
2996 ehea_error("unregister MR failed - driver"
2997 " inoperable!");
2998 goto out;
2999 }
3000 }
3001
Thomas Klein44c82152007-07-11 16:32:00 +02003002 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
3003
3004 list_for_each_entry(adapter, &adapter_list, list)
3005 if (adapter->active_ports) {
3006 /* Register new memory region */
3007 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
3008 if (ret) {
3009 ehea_error("register MR failed - driver"
3010 " inoperable!");
3011 goto out;
3012 }
3013
3014 /* Restart all ports */
3015 for (i = 0; i < EHEA_MAX_PORTS; i++) {
3016 struct ehea_port *port = adapter->port[i];
3017
3018 if (port) {
3019 struct net_device *dev = port->netdev;
3020
3021 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003022 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003023 port_napi_enable(port);
3024 ret = ehea_restart_qps(dev);
Andre Detsch2928db42010-08-17 05:49:12 +00003025 check_sqs(port);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003026 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02003027 netif_wake_queue(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003028 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003029 }
3030 }
3031 }
3032 }
Julia Lawall68905eb2008-07-21 09:57:26 +02003033 ehea_info("re-initializing driver complete");
Thomas Klein44c82152007-07-11 16:32:00 +02003034out:
3035 return;
3036}
3037
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003038static void ehea_tx_watchdog(struct net_device *dev)
3039{
3040 struct ehea_port *port = netdev_priv(dev);
3041
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003042 if (netif_carrier_ok(dev) &&
3043 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann2f69ae02008-07-03 15:18:51 +01003044 ehea_schedule_port_reset(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003045}
3046
3047int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
3048{
3049 struct hcp_query_ehea *cb;
3050 u64 hret;
3051 int ret;
3052
Thomas Klein3faf2692009-01-21 14:45:33 -08003053 cb = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003054 if (!cb) {
3055 ret = -ENOMEM;
3056 goto out;
3057 }
3058
3059 hret = ehea_h_query_ehea(adapter->handle, cb);
3060
3061 if (hret != H_SUCCESS) {
3062 ret = -EIO;
3063 goto out_herr;
3064 }
3065
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003066 adapter->max_mc_mac = cb->max_mc_mac - 1;
3067 ret = 0;
3068
3069out_herr:
Thomas Klein3faf2692009-01-21 14:45:33 -08003070 free_page((unsigned long)cb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003071out:
3072 return ret;
3073}
3074
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003075int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
3076{
3077 struct hcp_ehea_port_cb4 *cb4;
3078 u64 hret;
3079 int ret = 0;
3080
3081 *jumbo = 0;
3082
3083 /* (Try to) enable *jumbo frames */
Thomas Klein3faf2692009-01-21 14:45:33 -08003084 cb4 = (void *)get_zeroed_page(GFP_KERNEL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003085 if (!cb4) {
3086 ehea_error("no mem for cb4");
3087 ret = -ENOMEM;
3088 goto out;
3089 } else {
3090 hret = ehea_h_query_ehea_port(port->adapter->handle,
3091 port->logical_port_id,
3092 H_PORT_CB4,
3093 H_PORT_CB4_JUMBO, cb4);
3094 if (hret == H_SUCCESS) {
3095 if (cb4->jumbo_frame)
3096 *jumbo = 1;
3097 else {
3098 cb4->jumbo_frame = 1;
3099 hret = ehea_h_modify_ehea_port(port->adapter->
3100 handle,
3101 port->
3102 logical_port_id,
3103 H_PORT_CB4,
3104 H_PORT_CB4_JUMBO,
3105 cb4);
3106 if (hret == H_SUCCESS)
3107 *jumbo = 1;
3108 }
3109 } else
3110 ret = -EINVAL;
3111
Thomas Klein3faf2692009-01-21 14:45:33 -08003112 free_page((unsigned long)cb4);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003113 }
3114out:
3115 return ret;
3116}
3117
3118static ssize_t ehea_show_port_id(struct device *dev,
3119 struct device_attribute *attr, char *buf)
3120{
3121 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003122 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003123}
3124
3125static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3126 NULL);
3127
3128static void __devinit logical_port_release(struct device *dev)
3129{
3130 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Grant Likely61c7a082010-04-13 16:12:29 -07003131 of_node_put(port->ofdev.dev.of_node);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003132}
3133
3134static struct device *ehea_register_port(struct ehea_port *port,
3135 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003136{
3137 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003138
Grant Likely61c7a082010-04-13 16:12:29 -07003139 port->ofdev.dev.of_node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003140 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003141 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003142
Kay Sieversdb1d7bf2009-01-26 21:12:58 -08003143 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003144 port->ofdev.dev.release = logical_port_release;
3145
3146 ret = of_device_register(&port->ofdev);
3147 if (ret) {
3148 ehea_error("failed to register device. ret=%d", ret);
3149 goto out;
3150 }
3151
3152 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003153 if (ret) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003154 ehea_error("failed to register attributes, ret=%d", ret);
3155 goto out_unreg_of_dev;
3156 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003157
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003158 return &port->ofdev.dev;
3159
3160out_unreg_of_dev:
3161 of_device_unregister(&port->ofdev);
3162out:
3163 return NULL;
3164}
3165
3166static void ehea_unregister_port(struct ehea_port *port)
3167{
3168 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3169 of_device_unregister(&port->ofdev);
3170}
3171
Thomas Klein086c1b22009-01-21 14:43:59 -08003172static const struct net_device_ops ehea_netdev_ops = {
3173 .ndo_open = ehea_open,
3174 .ndo_stop = ehea_stop,
3175 .ndo_start_xmit = ehea_start_xmit,
3176#ifdef CONFIG_NET_POLL_CONTROLLER
3177 .ndo_poll_controller = ehea_netpoll,
3178#endif
3179 .ndo_get_stats = ehea_get_stats,
3180 .ndo_set_mac_address = ehea_set_mac_addr,
Ben Hutchings240c1022009-07-09 17:54:35 +00003181 .ndo_validate_addr = eth_validate_addr,
Thomas Klein086c1b22009-01-21 14:43:59 -08003182 .ndo_set_multicast_list = ehea_set_multicast_list,
3183 .ndo_change_mtu = ehea_change_mtu,
3184 .ndo_vlan_rx_register = ehea_vlan_rx_register,
3185 .ndo_vlan_rx_add_vid = ehea_vlan_rx_add_vid,
Alexander Beregalov32e8f9a2009-04-14 15:18:00 -07003186 .ndo_vlan_rx_kill_vid = ehea_vlan_rx_kill_vid,
3187 .ndo_tx_timeout = ehea_tx_watchdog,
Thomas Klein086c1b22009-01-21 14:43:59 -08003188};
3189
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003190struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3191 u32 logical_port_id,
3192 struct device_node *dn)
3193{
3194 int ret;
3195 struct net_device *dev;
3196 struct ehea_port *port;
3197 struct device *port_dev;
3198 int jumbo;
3199
3200 /* allocate memory for the port structures */
3201 dev = alloc_etherdev(sizeof(struct ehea_port));
3202
3203 if (!dev) {
3204 ehea_error("no mem for net_device");
3205 ret = -ENOMEM;
3206 goto out_err;
3207 }
3208
3209 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003210
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003211 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003212 port->state = EHEA_PORT_DOWN;
3213 port->sig_comp_iv = sq_entries / 10;
3214
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003215 port->adapter = adapter;
3216 port->netdev = dev;
3217 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003218
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003219 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003220
3221 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3222 if (!port->mc_list) {
3223 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003224 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003225 }
3226
3227 INIT_LIST_HEAD(&port->mc_list->list);
3228
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003229 ret = ehea_sense_port_attr(port);
3230 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003231 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003232
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003233 port_dev = ehea_register_port(port, dn);
3234 if (!port_dev)
3235 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003236
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003237 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003238
3239 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003240 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3241
Thomas Klein086c1b22009-01-21 14:43:59 -08003242 dev->netdev_ops = &ehea_netdev_ops;
3243 ehea_set_ethtool_ops(dev);
3244
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003245 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003246 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003247 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3248 | NETIF_F_LLTX;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003249 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3250
David Howellsc4028952006-11-22 14:57:56 +00003251 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003252
3253 ret = register_netdev(dev);
3254 if (ret) {
3255 ehea_error("register_netdev failed. ret=%d", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003256 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003257 }
3258
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003259 port->lro_max_aggr = lro_max_aggr;
3260
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003261 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003262 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003263 ehea_error("failed determining jumbo frame status for %s",
3264 port->netdev->name);
3265
Thomas Klein9c750b72007-01-29 18:44:01 +01003266 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3267 jumbo == 1 ? "en" : "dis");
3268
Thomas Klein44c82152007-07-11 16:32:00 +02003269 adapter->active_ports++;
3270
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003271 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003272
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003273out_unreg_port:
3274 ehea_unregister_port(port);
3275
3276out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003277 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003278
3279out_free_ethdev:
3280 free_netdev(dev);
3281
3282out_err:
3283 ehea_error("setting up logical port with id=%d failed, ret=%d",
3284 logical_port_id, ret);
3285 return NULL;
3286}
3287
3288static void ehea_shutdown_single_port(struct ehea_port *port)
3289{
Brian King7fb1c2a2008-05-14 09:48:25 -05003290 struct ehea_adapter *adapter = port->adapter;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003291 unregister_netdev(port->netdev);
3292 ehea_unregister_port(port);
3293 kfree(port->mc_list);
3294 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003295 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003296}
3297
3298static int ehea_setup_ports(struct ehea_adapter *adapter)
3299{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003300 struct device_node *lhea_dn;
3301 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003302
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003303 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003304 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003305
Grant Likely61c7a082010-04-13 16:12:29 -07003306 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003307 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003308
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003309 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003310 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003311 if (!dn_log_port_id) {
3312 ehea_error("bad device node: eth_dn name=%s",
3313 eth_dn->full_name);
3314 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003315 }
3316
Thomas Klein1211bb62007-04-26 11:56:43 +02003317 if (ehea_add_adapter_mr(adapter)) {
3318 ehea_error("creating MR failed");
3319 of_node_put(eth_dn);
3320 return -EIO;
3321 }
3322
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003323 adapter->port[i] = ehea_setup_single_port(adapter,
3324 *dn_log_port_id,
3325 eth_dn);
3326 if (adapter->port[i])
3327 ehea_info("%s -> logical port id #%d",
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003328 adapter->port[i]->netdev->name,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003329 *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003330 else
3331 ehea_remove_adapter_mr(adapter);
3332
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003333 i++;
Joe Perchesee289b62010-05-17 22:47:34 -07003334 }
Thomas Klein1211bb62007-04-26 11:56:43 +02003335 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003336}
3337
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003338static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3339 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003340{
3341 struct device_node *lhea_dn;
3342 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003343 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003344
Grant Likely61c7a082010-04-13 16:12:29 -07003345 lhea_dn = adapter->ofdev->dev.of_node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003346 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003347
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003348 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003349 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003350 if (dn_log_port_id)
3351 if (*dn_log_port_id == logical_port_id)
3352 return eth_dn;
Joe Perchesee289b62010-05-17 22:47:34 -07003353 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003354
3355 return NULL;
3356}
3357
3358static ssize_t ehea_probe_port(struct device *dev,
3359 struct device_attribute *attr,
3360 const char *buf, size_t count)
3361{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003362 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003363 struct ehea_port *port;
3364 struct device_node *eth_dn = NULL;
3365 int i;
3366
3367 u32 logical_port_id;
3368
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003369 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003370
3371 port = ehea_get_port(adapter, logical_port_id);
3372
3373 if (port) {
3374 ehea_info("adding port with logical port id=%d failed. port "
3375 "already configured as %s.", logical_port_id,
3376 port->netdev->name);
3377 return -EINVAL;
3378 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003379
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003380 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3381
3382 if (!eth_dn) {
3383 ehea_info("no logical port with id %d found", logical_port_id);
3384 return -EINVAL;
3385 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003386
Thomas Klein1211bb62007-04-26 11:56:43 +02003387 if (ehea_add_adapter_mr(adapter)) {
3388 ehea_error("creating MR failed");
3389 return -EIO;
3390 }
3391
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003392 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3393
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003394 of_node_put(eth_dn);
3395
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003396 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003397 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003398 if (!adapter->port[i]) {
3399 adapter->port[i] = port;
3400 break;
3401 }
3402
3403 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3404 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003405 } else {
3406 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003407 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003408 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003409
3410 return (ssize_t) count;
3411}
3412
3413static ssize_t ehea_remove_port(struct device *dev,
3414 struct device_attribute *attr,
3415 const char *buf, size_t count)
3416{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003417 struct ehea_adapter *adapter = dev_get_drvdata(dev);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003418 struct ehea_port *port;
3419 int i;
3420 u32 logical_port_id;
3421
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003422 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003423
3424 port = ehea_get_port(adapter, logical_port_id);
3425
3426 if (port) {
3427 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3428 logical_port_id);
3429
3430 ehea_shutdown_single_port(port);
3431
Doug Maxey508d2b52008-01-31 20:20:49 -06003432 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003433 if (adapter->port[i] == port) {
3434 adapter->port[i] = NULL;
3435 break;
3436 }
3437 } else {
3438 ehea_error("removing port with logical port id=%d failed. port "
3439 "not configured.", logical_port_id);
3440 return -EINVAL;
3441 }
3442
Thomas Klein1211bb62007-04-26 11:56:43 +02003443 ehea_remove_adapter_mr(adapter);
3444
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003445 return (ssize_t) count;
3446}
3447
3448static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3449static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3450
Grant Likely2dc11582010-08-06 09:25:50 -06003451int ehea_create_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003452{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003453 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003454 if (ret)
3455 goto out;
3456
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003457 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003458out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003459 return ret;
3460}
3461
Grant Likely2dc11582010-08-06 09:25:50 -06003462void ehea_remove_device_sysfs(struct platform_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003463{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003464 device_remove_file(&dev->dev, &dev_attr_probe_port);
3465 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003466}
3467
Grant Likely2dc11582010-08-06 09:25:50 -06003468static int __devinit ehea_probe_adapter(struct platform_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003469 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003470{
3471 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003472 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003473 int ret;
3474
Grant Likely61c7a082010-04-13 16:12:29 -07003475 if (!dev || !dev->dev.of_node) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003476 ehea_error("Invalid ibmebus device probed");
3477 return -EINVAL;
3478 }
3479
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003480 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3481 if (!adapter) {
3482 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003483 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003484 goto out;
3485 }
3486
Thomas Klein44c82152007-07-11 16:32:00 +02003487 list_add(&adapter->list, &adapter_list);
3488
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003489 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003490
Grant Likely61c7a082010-04-13 16:12:29 -07003491 adapter_handle = of_get_property(dev->dev.of_node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003492 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003493 if (adapter_handle)
3494 adapter->handle = *adapter_handle;
3495
3496 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003497 dev_err(&dev->dev, "failed getting handle for adapter"
Grant Likely61c7a082010-04-13 16:12:29 -07003498 " '%s'\n", dev->dev.of_node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003499 ret = -ENODEV;
3500 goto out_free_ad;
3501 }
3502
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003503 adapter->pd = EHEA_PD_ID;
3504
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003505 dev_set_drvdata(&dev->dev, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003506
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003507
3508 /* initialize adapter and ports */
3509 /* get adapter properties */
3510 ret = ehea_sense_adapter_attr(adapter);
3511 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003512 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003513 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003514 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003515
3516 adapter->neq = ehea_create_eq(adapter,
3517 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3518 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003519 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003520 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003521 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003522 }
3523
3524 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3525 (unsigned long)adapter);
3526
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003527 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003528 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003529 "ehea_neq", adapter);
3530 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003531 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003532 goto out_kill_eq;
3533 }
3534
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003535 ret = ehea_create_device_sysfs(dev);
3536 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003537 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003538
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003539 ret = ehea_setup_ports(adapter);
3540 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003541 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003542 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003543 }
3544
3545 ret = 0;
3546 goto out;
3547
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003548out_rem_dev_sysfs:
3549 ehea_remove_device_sysfs(dev);
3550
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003551out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003552 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003553
3554out_kill_eq:
3555 ehea_destroy_eq(adapter->neq);
3556
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003557out_free_ad:
Hannes Hering51621fb2009-02-11 13:47:57 -08003558 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003559 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003560
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003561out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003562 ehea_update_firmware_handles();
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003563
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003564 return ret;
3565}
3566
Grant Likely2dc11582010-08-06 09:25:50 -06003567static int __devexit ehea_remove(struct platform_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003568{
Greg Kroah-Hartmanc7ae0112009-05-04 21:33:19 -07003569 struct ehea_adapter *adapter = dev_get_drvdata(&dev->dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003570 int i;
3571
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003572 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003573 if (adapter->port[i]) {
3574 ehea_shutdown_single_port(adapter->port[i]);
3575 adapter->port[i] = NULL;
3576 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003577
3578 ehea_remove_device_sysfs(dev);
3579
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003580 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003581
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003582 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003583 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003584
3585 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003586 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003587 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003588 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003589
Thomas Klein21eee2d2008-02-13 16:18:33 +01003590 ehea_update_firmware_handles();
Thomas Klein21eee2d2008-02-13 16:18:33 +01003591
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003592 return 0;
3593}
3594
Thomas Klein21eee2d2008-02-13 16:18:33 +01003595void ehea_crash_handler(void)
3596{
3597 int i;
3598
3599 if (ehea_fw_handles.arr)
3600 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3601 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3602 ehea_fw_handles.arr[i].fwh,
3603 FORCE_FREE);
3604
3605 if (ehea_bcmc_regs.arr)
3606 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3607 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3608 ehea_bcmc_regs.arr[i].port_id,
3609 ehea_bcmc_regs.arr[i].reg_type,
3610 ehea_bcmc_regs.arr[i].macaddr,
3611 0, H_DEREG_BCMC);
3612}
3613
Hannes Hering48cfb142008-05-07 14:43:36 +02003614static int ehea_mem_notifier(struct notifier_block *nb,
3615 unsigned long action, void *data)
3616{
Thomas Kleina7c561f22010-04-20 23:11:31 +00003617 int ret = NOTIFY_BAD;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003618 struct memory_notify *arg = data;
Thomas Kleina7c561f22010-04-20 23:11:31 +00003619
Jan-Bernd Themann099473c2010-06-15 05:35:42 +00003620 mutex_lock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003621
Hannes Hering48cfb142008-05-07 14:43:36 +02003622 switch (action) {
Hannes Heringd4f12da2008-10-16 11:36:42 +02003623 case MEM_CANCEL_OFFLINE:
3624 ehea_info("memory offlining canceled");
3625 /* Readd canceled memory block */
3626 case MEM_ONLINE:
3627 ehea_info("memory is going online");
Thomas Klein38767322009-02-20 00:42:01 -08003628 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003629 if (ehea_add_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003630 goto out_unlock;
Hannes Heringd4f12da2008-10-16 11:36:42 +02003631 ehea_rereg_mrs(NULL);
3632 break;
3633 case MEM_GOING_OFFLINE:
3634 ehea_info("memory is going offline");
Thomas Klein38767322009-02-20 00:42:01 -08003635 set_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
Hannes Heringd4f12da2008-10-16 11:36:42 +02003636 if (ehea_rem_sect_bmap(arg->start_pfn, arg->nr_pages))
Thomas Kleina7c561f22010-04-20 23:11:31 +00003637 goto out_unlock;
Hannes Hering48cfb142008-05-07 14:43:36 +02003638 ehea_rereg_mrs(NULL);
3639 break;
3640 default:
3641 break;
3642 }
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003643
3644 ehea_update_firmware_handles();
Thomas Kleina7c561f22010-04-20 23:11:31 +00003645 ret = NOTIFY_OK;
Jan-Bernd Themann52e21b12009-03-13 13:50:40 -07003646
Thomas Kleina7c561f22010-04-20 23:11:31 +00003647out_unlock:
3648 mutex_unlock(&dlpar_mem_lock);
Thomas Kleina7c561f22010-04-20 23:11:31 +00003649 return ret;
Hannes Hering48cfb142008-05-07 14:43:36 +02003650}
3651
3652static struct notifier_block ehea_mem_nb = {
3653 .notifier_call = ehea_mem_notifier,
3654};
3655
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003656static int ehea_reboot_notifier(struct notifier_block *nb,
3657 unsigned long action, void *unused)
3658{
3659 if (action == SYS_RESTART) {
3660 ehea_info("Reboot: freeing all eHEA resources");
3661 ibmebus_unregister_driver(&ehea_driver);
3662 }
3663 return NOTIFY_DONE;
3664}
3665
3666static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003667 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003668};
3669
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003670static int check_module_parm(void)
3671{
3672 int ret = 0;
3673
3674 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3675 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
3676 ehea_info("Bad parameter: rq1_entries");
3677 ret = -EINVAL;
3678 }
3679 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3680 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
3681 ehea_info("Bad parameter: rq2_entries");
3682 ret = -EINVAL;
3683 }
3684 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3685 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
3686 ehea_info("Bad parameter: rq3_entries");
3687 ret = -EINVAL;
3688 }
3689 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3690 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
3691 ehea_info("Bad parameter: sq_entries");
3692 ret = -EINVAL;
3693 }
3694
3695 return ret;
3696}
3697
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003698static ssize_t ehea_show_capabilities(struct device_driver *drv,
3699 char *buf)
3700{
3701 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3702}
3703
3704static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3705 ehea_show_capabilities, NULL);
3706
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003707int __init ehea_module_init(void)
3708{
3709 int ret;
3710
3711 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3712 DRV_VERSION);
3713
Thomas Klein44c82152007-07-11 16:32:00 +02003714
3715 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003716 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3717 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3718
Daniel Walker9f71a562008-03-28 14:41:26 -07003719 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003720 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003721
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003722 ret = check_module_parm();
3723 if (ret)
3724 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003725
3726 ret = ehea_create_busmap();
3727 if (ret)
3728 goto out;
3729
Thomas Klein21eee2d2008-02-13 16:18:33 +01003730 ret = register_reboot_notifier(&ehea_reboot_nb);
3731 if (ret)
3732 ehea_info("failed registering reboot notifier");
3733
Hannes Hering48cfb142008-05-07 14:43:36 +02003734 ret = register_memory_notifier(&ehea_mem_nb);
3735 if (ret)
3736 ehea_info("failed registering memory remove notifier");
3737
Joe Perchesc061b182010-08-23 18:20:03 +00003738 ret = crash_shutdown_register(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003739 if (ret)
3740 ehea_info("failed registering crash handler");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003741
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003742 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003743 if (ret) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003744 ehea_error("failed registering eHEA device driver on ebus");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003745 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003746 }
3747
3748 ret = driver_create_file(&ehea_driver.driver,
3749 &driver_attr_capabilities);
3750 if (ret) {
3751 ehea_error("failed to register capabilities attribute, ret=%d",
3752 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003753 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003754 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003755
Thomas Klein21eee2d2008-02-13 16:18:33 +01003756 return ret;
3757
3758out3:
3759 ibmebus_unregister_driver(&ehea_driver);
3760out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003761 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003762 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003763 crash_shutdown_unregister(ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003764out:
3765 return ret;
3766}
3767
3768static void __exit ehea_module_exit(void)
3769{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003770 int ret;
3771
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003772 flush_scheduled_work();
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003773 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003774 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003775 unregister_reboot_notifier(&ehea_reboot_nb);
Joe Perchesc061b182010-08-23 18:20:03 +00003776 ret = crash_shutdown_unregister(ehea_crash_handler);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003777 if (ret)
3778 ehea_info("failed unregistering crash handler");
Hannes Hering48cfb142008-05-07 14:43:36 +02003779 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003780 kfree(ehea_fw_handles.arr);
3781 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003782 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003783}
3784
3785module_init(ehea_module_init);
3786module_exit(ehea_module_exit);