blob: 6ebcb221cd5e8923d26927d515f3a5c51e1af10b [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>
35#include <linux/if_ether.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020036#include <linux/notifier.h>
37#include <linux/reboot.h>
Hannes Hering48cfb142008-05-07 14:43:36 +020038#include <linux/memory.h>
Thomas Klein21eee2d2008-02-13 16:18:33 +010039#include <asm/kexec.h>
Daniel Walker06f89ed2008-03-28 14:41:26 -070040#include <linux/mutex.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020041
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020042#include <net/ip.h>
43
44#include "ehea.h"
45#include "ehea_qmr.h"
46#include "ehea_phyp.h"
47
48
49MODULE_LICENSE("GPL");
50MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
51MODULE_DESCRIPTION("IBM eServer HEA Driver");
52MODULE_VERSION(DRV_VERSION);
53
54
55static int msg_level = -1;
56static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
57static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
58static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
59static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Doug Maxey508d2b52008-01-31 20:20:49 -060060static int use_mcs;
61static int use_lro;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070062static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010063static int num_tx_qps = EHEA_NUM_TX_QP;
Doug Maxey508d2b52008-01-31 20:20:49 -060064static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020065
66module_param(msg_level, int, 0);
67module_param(rq1_entries, int, 0);
68module_param(rq2_entries, int, 0);
69module_param(rq3_entries, int, 0);
70module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020071module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010072module_param(use_mcs, int, 0);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070073module_param(use_lro, int, 0);
74module_param(lro_max_aggr, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010075module_param(num_tx_qps, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020076
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010077MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020078MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020079MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
80 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020081MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
82 "[2^x - 1], x = [6..14]. Default = "
83 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
84MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
85 "[2^x - 1], x = [6..14]. Default = "
86 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
87MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
88 "[2^x - 1], x = [6..14]. Default = "
89 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
90MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
91 "[2^x - 1], x = [6..14]. Default = "
92 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Jan-Bernd Themann18072a52007-08-22 16:21:24 +020093MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020094
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070095MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
96 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
97MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
98 "Default = 0");
99
Doug Maxey508d2b52008-01-31 20:20:49 -0600100static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +0200101static LIST_HEAD(adapter_list);
Doug Maxey508d2b52008-01-31 20:20:49 -0600102u64 ehea_driver_flags;
Thomas Klein44c82152007-07-11 16:32:00 +0200103struct work_struct ehea_rereg_mr_task;
Daniel Walker06f89ed2008-03-28 14:41:26 -0700104static DEFINE_MUTEX(dlpar_mem_lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100105struct ehea_fw_handle_array ehea_fw_handles;
106struct ehea_bcmc_reg_array ehea_bcmc_regs;
107
Thomas Kleind1dea382007-04-26 11:56:13 +0200108
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000109static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200110 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200111
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000112static int __devexit ehea_remove(struct of_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200113
114static struct of_device_id ehea_device_table[] = {
115 {
116 .name = "lhea",
117 .compatible = "IBM,lhea",
118 },
119 {},
120};
Jan-Bernd Themannb0afffe2008-07-03 15:18:48 +0100121MODULE_DEVICE_TABLE(of, ehea_device_table);
Thomas Kleind1dea382007-04-26 11:56:13 +0200122
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000123static struct of_platform_driver ehea_driver = {
Thomas Kleind1dea382007-04-26 11:56:13 +0200124 .name = "ehea",
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000125 .match_table = ehea_device_table,
Thomas Kleind1dea382007-04-26 11:56:13 +0200126 .probe = ehea_probe_adapter,
127 .remove = ehea_remove,
128};
129
Doug Maxey508d2b52008-01-31 20:20:49 -0600130void ehea_dump(void *adr, int len, char *msg)
131{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200132 int x;
133 unsigned char *deb = adr;
134 for (x = 0; x < len; x += 16) {
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100135 printk(DRV_NAME " %s adr=%p ofs=%04x %016lx %016lx\n", msg,
Doug Maxey508d2b52008-01-31 20:20:49 -0600136 deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200137 deb += 16;
138 }
139}
140
Thomas Klein21eee2d2008-02-13 16:18:33 +0100141static void ehea_update_firmware_handles(void)
142{
143 struct ehea_fw_handle_entry *arr = NULL;
144 struct ehea_adapter *adapter;
145 int num_adapters = 0;
146 int num_ports = 0;
147 int num_portres = 0;
148 int i = 0;
149 int num_fw_handles, k, l;
150
151 /* Determine number of handles */
152 list_for_each_entry(adapter, &adapter_list, list) {
153 num_adapters++;
154
155 for (k = 0; k < EHEA_MAX_PORTS; k++) {
156 struct ehea_port *port = adapter->port[k];
157
158 if (!port || (port->state != EHEA_PORT_UP))
159 continue;
160
161 num_ports++;
162 num_portres += port->num_def_qps + port->num_add_tx_qps;
163 }
164 }
165
166 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
167 num_ports * EHEA_NUM_PORT_FW_HANDLES +
168 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
169
170 if (num_fw_handles) {
171 arr = kzalloc(num_fw_handles * sizeof(*arr), GFP_KERNEL);
172 if (!arr)
173 return; /* Keep the existing array */
174 } else
175 goto out_update;
176
177 list_for_each_entry(adapter, &adapter_list, list) {
178 for (k = 0; k < EHEA_MAX_PORTS; k++) {
179 struct ehea_port *port = adapter->port[k];
180
181 if (!port || (port->state != EHEA_PORT_UP))
182 continue;
183
184 for (l = 0;
185 l < port->num_def_qps + port->num_add_tx_qps;
186 l++) {
187 struct ehea_port_res *pr = &port->port_res[l];
188
189 arr[i].adh = adapter->handle;
190 arr[i++].fwh = pr->qp->fw_handle;
191 arr[i].adh = adapter->handle;
192 arr[i++].fwh = pr->send_cq->fw_handle;
193 arr[i].adh = adapter->handle;
194 arr[i++].fwh = pr->recv_cq->fw_handle;
195 arr[i].adh = adapter->handle;
196 arr[i++].fwh = pr->eq->fw_handle;
197 arr[i].adh = adapter->handle;
198 arr[i++].fwh = pr->send_mr.handle;
199 arr[i].adh = adapter->handle;
200 arr[i++].fwh = pr->recv_mr.handle;
201 }
202 arr[i].adh = adapter->handle;
203 arr[i++].fwh = port->qp_eq->fw_handle;
204 }
205
206 arr[i].adh = adapter->handle;
207 arr[i++].fwh = adapter->neq->fw_handle;
208
209 if (adapter->mr.handle) {
210 arr[i].adh = adapter->handle;
211 arr[i++].fwh = adapter->mr.handle;
212 }
213 }
214
215out_update:
216 kfree(ehea_fw_handles.arr);
217 ehea_fw_handles.arr = arr;
218 ehea_fw_handles.num_entries = i;
219}
220
221static void ehea_update_bcmc_registrations(void)
222{
223 struct ehea_bcmc_reg_entry *arr = NULL;
224 struct ehea_adapter *adapter;
225 struct ehea_mc_list *mc_entry;
226 int num_registrations = 0;
227 int i = 0;
228 int k;
229
230 /* Determine number of registrations */
231 list_for_each_entry(adapter, &adapter_list, list)
232 for (k = 0; k < EHEA_MAX_PORTS; k++) {
233 struct ehea_port *port = adapter->port[k];
234
235 if (!port || (port->state != EHEA_PORT_UP))
236 continue;
237
238 num_registrations += 2; /* Broadcast registrations */
239
240 list_for_each_entry(mc_entry, &port->mc_list->list,list)
241 num_registrations += 2;
242 }
243
244 if (num_registrations) {
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +0100245 arr = kzalloc(num_registrations * sizeof(*arr), GFP_ATOMIC);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100246 if (!arr)
247 return; /* Keep the existing array */
248 } else
249 goto out_update;
250
251 list_for_each_entry(adapter, &adapter_list, list) {
252 for (k = 0; k < EHEA_MAX_PORTS; k++) {
253 struct ehea_port *port = adapter->port[k];
254
255 if (!port || (port->state != EHEA_PORT_UP))
256 continue;
257
258 arr[i].adh = adapter->handle;
259 arr[i].port_id = port->logical_port_id;
260 arr[i].reg_type = EHEA_BCMC_BROADCAST |
261 EHEA_BCMC_UNTAGGED;
262 arr[i++].macaddr = port->mac_addr;
263
264 arr[i].adh = adapter->handle;
265 arr[i].port_id = port->logical_port_id;
266 arr[i].reg_type = EHEA_BCMC_BROADCAST |
267 EHEA_BCMC_VLANID_ALL;
268 arr[i++].macaddr = port->mac_addr;
269
270 list_for_each_entry(mc_entry,
271 &port->mc_list->list, list) {
272 arr[i].adh = adapter->handle;
273 arr[i].port_id = port->logical_port_id;
274 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
275 EHEA_BCMC_MULTICAST |
276 EHEA_BCMC_UNTAGGED;
277 arr[i++].macaddr = mc_entry->macaddr;
278
279 arr[i].adh = adapter->handle;
280 arr[i].port_id = port->logical_port_id;
281 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
282 EHEA_BCMC_MULTICAST |
283 EHEA_BCMC_VLANID_ALL;
284 arr[i++].macaddr = mc_entry->macaddr;
285 }
286 }
287 }
288
289out_update:
290 kfree(ehea_bcmc_regs.arr);
291 ehea_bcmc_regs.arr = arr;
292 ehea_bcmc_regs.num_entries = i;
293}
294
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200295static struct net_device_stats *ehea_get_stats(struct net_device *dev)
296{
297 struct ehea_port *port = netdev_priv(dev);
298 struct net_device_stats *stats = &port->stats;
299 struct hcp_ehea_port_cb2 *cb2;
Thomas Klein7393b872007-11-21 17:37:58 +0100300 u64 hret, rx_packets, tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200301 int i;
302
303 memset(stats, 0, sizeof(*stats));
304
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +0100305 cb2 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200306 if (!cb2) {
307 ehea_error("no mem for cb2");
308 goto out;
309 }
310
311 hret = ehea_h_query_ehea_port(port->adapter->handle,
312 port->logical_port_id,
313 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
314 if (hret != H_SUCCESS) {
315 ehea_error("query_ehea_port failed");
316 goto out_herr;
317 }
318
319 if (netif_msg_hw(port))
320 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
321
322 rx_packets = 0;
323 for (i = 0; i < port->num_def_qps; i++)
324 rx_packets += port->port_res[i].rx_packets;
325
Thomas Klein7393b872007-11-21 17:37:58 +0100326 tx_packets = 0;
327 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
328 tx_packets += port->port_res[i].tx_packets;
329
330 stats->tx_packets = tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200331 stats->multicast = cb2->rxmcp;
332 stats->rx_errors = cb2->rxuerr;
333 stats->rx_bytes = cb2->rxo;
334 stats->tx_bytes = cb2->txo;
335 stats->rx_packets = rx_packets;
336
337out_herr:
338 kfree(cb2);
339out:
340 return stats;
341}
342
343static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
344{
345 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
346 struct net_device *dev = pr->port->netdev;
347 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200348 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
349 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200350 int i;
351
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200352 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200353
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200354 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200355 if (nr_of_wqes > 0)
356 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200357 pr->rq1_skba.os_skbs = fill_wqes;
358 return;
359 }
360
361 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200362 if (!skb_arr_rq1[index]) {
363 skb_arr_rq1[index] = netdev_alloc_skb(dev,
364 EHEA_L_PKT_SIZE);
365 if (!skb_arr_rq1[index]) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200366 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200367 ehea_error("%s: no mem for skb/%d wqes filled",
368 dev->name, i);
369 break;
370 }
371 }
372 index--;
373 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200374 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200375 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200376
377 if (adder == 0)
378 return;
379
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200380 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200381 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200382}
383
384static int ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
385{
386 int ret = 0;
387 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
388 struct net_device *dev = pr->port->netdev;
389 int i;
390
391 for (i = 0; i < pr->rq1_skba.len; i++) {
392 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
393 if (!skb_arr_rq1[i]) {
394 ehea_error("%s: no mem for skb/%d wqes filled",
395 dev->name, i);
396 ret = -ENOMEM;
397 goto out;
398 }
399 }
400 /* Ring doorbell */
401 ehea_update_rq1a(pr->qp, nr_rq1a);
402out:
403 return ret;
404}
405
406static int ehea_refill_rq_def(struct ehea_port_res *pr,
407 struct ehea_q_skb_arr *q_skba, int rq_nr,
408 int num_wqes, int wqe_type, int packet_size)
409{
410 struct net_device *dev = pr->port->netdev;
411 struct ehea_qp *qp = pr->qp;
412 struct sk_buff **skb_arr = q_skba->arr;
413 struct ehea_rwqe *rwqe;
414 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200415 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200416 int ret = 0;
417
418 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200419 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200420
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200421 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
422 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200423 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200424 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200425
426 index = q_skba->index;
427 max_index_mask = q_skba->len - 1;
428 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200429 u64 tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200430 struct sk_buff *skb = netdev_alloc_skb(dev, packet_size);
431 if (!skb) {
432 ehea_error("%s: no mem for skb/%d wqes filled",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100433 pr->port->netdev->name, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200434 q_skba->os_skbs = fill_wqes - i;
435 ret = -ENOMEM;
436 break;
437 }
438 skb_reserve(skb, NET_IP_ALIGN);
439
440 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200441 tmp_addr = ehea_map_vaddr(skb->data);
442 if (tmp_addr == -1) {
443 dev_kfree_skb(skb);
444 q_skba->os_skbs = fill_wqes - i;
445 ret = 0;
446 break;
447 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200448
449 rwqe = ehea_get_next_rwqe(qp, rq_nr);
450 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200451 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200452 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200453 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200454 rwqe->sg_list[0].len = packet_size;
455 rwqe->data_segments = 1;
456
457 index++;
458 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200459 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200460 }
Thomas Klein44c82152007-07-11 16:32:00 +0200461
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200462 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200463 if (adder == 0)
464 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200465
466 /* Ring doorbell */
467 iosync();
468 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200469 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200470 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200471 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200472out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200473 return ret;
474}
475
476
477static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
478{
479 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
480 nr_of_wqes, EHEA_RWQE2_TYPE,
481 EHEA_RQ2_PKT_SIZE + NET_IP_ALIGN);
482}
483
484
485static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
486{
487 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
488 nr_of_wqes, EHEA_RWQE3_TYPE,
489 EHEA_MAX_PACKET_SIZE + NET_IP_ALIGN);
490}
491
492static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
493{
494 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
495 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
496 return 0;
497 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
498 (cqe->header_length == 0))
499 return 0;
500 return -EINVAL;
501}
502
503static inline void ehea_fill_skb(struct net_device *dev,
504 struct sk_buff *skb, struct ehea_cqe *cqe)
505{
506 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
507
508 skb_put(skb, length);
509 skb->ip_summed = CHECKSUM_UNNECESSARY;
510 skb->protocol = eth_type_trans(skb, dev);
511}
512
513static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
514 int arr_len,
515 struct ehea_cqe *cqe)
516{
517 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
518 struct sk_buff *skb;
519 void *pref;
520 int x;
521
522 x = skb_index + 1;
523 x &= (arr_len - 1);
524
525 pref = skb_array[x];
526 prefetchw(pref);
527 prefetchw(pref + EHEA_CACHE_LINE);
528
529 pref = (skb_array[x]->data);
530 prefetch(pref);
531 prefetch(pref + EHEA_CACHE_LINE);
532 prefetch(pref + EHEA_CACHE_LINE * 2);
533 prefetch(pref + EHEA_CACHE_LINE * 3);
534 skb = skb_array[skb_index];
535 skb_array[skb_index] = NULL;
536 return skb;
537}
538
539static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
540 int arr_len, int wqe_index)
541{
542 struct sk_buff *skb;
543 void *pref;
544 int x;
545
546 x = wqe_index + 1;
547 x &= (arr_len - 1);
548
549 pref = skb_array[x];
550 prefetchw(pref);
551 prefetchw(pref + EHEA_CACHE_LINE);
552
553 pref = (skb_array[x]->data);
554 prefetchw(pref);
555 prefetchw(pref + EHEA_CACHE_LINE);
556
557 skb = skb_array[wqe_index];
558 skb_array[wqe_index] = NULL;
559 return skb;
560}
561
562static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
563 struct ehea_cqe *cqe, int *processed_rq2,
564 int *processed_rq3)
565{
566 struct sk_buff *skb;
567
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100568 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
569 pr->p_stats.err_tcp_cksum++;
570 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
571 pr->p_stats.err_ip_cksum++;
572 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
573 pr->p_stats.err_frame_crc++;
574
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200575 if (rq == 2) {
576 *processed_rq2 += 1;
577 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
578 dev_kfree_skb(skb);
579 } else if (rq == 3) {
580 *processed_rq3 += 1;
581 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
582 dev_kfree_skb(skb);
583 }
584
585 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100586 if (netif_msg_rx_err(pr->port)) {
587 ehea_error("Critical receive error for QP %d. "
588 "Resetting port.", pr->qp->init_attr.qp_nr);
589 ehea_dump(cqe, sizeof(*cqe), "CQE");
590 }
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +0200591 schedule_work(&pr->port->reset_task);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200592 return 1;
593 }
594
595 return 0;
596}
597
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700598static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
599 void **tcph, u64 *hdr_flags, void *priv)
600{
601 struct ehea_cqe *cqe = priv;
602 unsigned int ip_len;
603 struct iphdr *iph;
604
605 /* non tcp/udp packets */
606 if (!cqe->header_length)
607 return -1;
608
609 /* non tcp packet */
610 skb_reset_network_header(skb);
611 iph = ip_hdr(skb);
612 if (iph->protocol != IPPROTO_TCP)
613 return -1;
614
615 ip_len = ip_hdrlen(skb);
616 skb_set_transport_header(skb, ip_len);
617 *tcph = tcp_hdr(skb);
618
619 /* check if ip header and tcp header are complete */
620 if (iph->tot_len < ip_len + tcp_hdrlen(skb))
621 return -1;
622
623 *hdr_flags = LRO_IPV4 | LRO_TCP;
624 *iphdr = iph;
625
626 return 0;
627}
628
629static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
630 struct sk_buff *skb)
631{
632 int vlan_extracted = (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
633 && pr->port->vgrp;
634
635 if (use_lro) {
636 if (vlan_extracted)
637 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
638 pr->port->vgrp,
639 cqe->vlan_tag,
640 cqe);
641 else
642 lro_receive_skb(&pr->lro_mgr, skb, cqe);
643 } else {
644 if (vlan_extracted)
645 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
646 cqe->vlan_tag);
647 else
648 netif_receive_skb(skb);
649 }
650}
651
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700652static int ehea_proc_rwqes(struct net_device *dev,
653 struct ehea_port_res *pr,
654 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200655{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100656 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200657 struct ehea_qp *qp = pr->qp;
658 struct ehea_cqe *cqe;
659 struct sk_buff *skb;
660 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
661 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
662 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
663 int skb_arr_rq1_len = pr->rq1_skba.len;
664 int skb_arr_rq2_len = pr->rq2_skba.len;
665 int skb_arr_rq3_len = pr->rq3_skba.len;
666 int processed, processed_rq1, processed_rq2, processed_rq3;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700667 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200668
669 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
670 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200671
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200672 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700673 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200674 ehea_inc_rq1(qp);
675 processed_rq1++;
676 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200677 if (netif_msg_rx_status(port))
678 ehea_dump(cqe, sizeof(*cqe), "CQE");
679
680 last_wqe_index = wqe_index;
681 rmb();
682 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600683 if (rq == 1) {
684 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200685 skb = get_skb_by_index_ll(skb_arr_rq1,
686 skb_arr_rq1_len,
687 wqe_index);
688 if (unlikely(!skb)) {
689 if (netif_msg_rx_err(port))
690 ehea_error("LL rq1: skb=NULL");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100691
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700692 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200693 EHEA_L_PKT_SIZE);
694 if (!skb)
695 break;
696 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600697 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200698 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700699 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600700 } else if (rq == 2) {
701 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200702 skb = get_skb_by_index(skb_arr_rq2,
703 skb_arr_rq2_len, cqe);
704 if (unlikely(!skb)) {
705 if (netif_msg_rx_err(port))
706 ehea_error("rq2: skb=NULL");
707 break;
708 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700709 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200710 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600711 } else {
712 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200713 skb = get_skb_by_index(skb_arr_rq3,
714 skb_arr_rq3_len, cqe);
715 if (unlikely(!skb)) {
716 if (netif_msg_rx_err(port))
717 ehea_error("rq3: skb=NULL");
718 break;
719 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700720 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200721 processed_rq3++;
722 }
723
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700724 ehea_proc_skb(pr, cqe, skb);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700725 dev->last_rx = jiffies;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100726 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100727 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200728 port_reset = ehea_treat_poll_error(pr, rq, cqe,
729 &processed_rq2,
730 &processed_rq3);
731 if (port_reset)
732 break;
733 }
734 cqe = ehea_poll_rq1(qp, &wqe_index);
735 }
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700736 if (use_lro)
737 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200738
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200739 pr->rx_packets += processed;
740
741 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
742 ehea_refill_rq2(pr, processed_rq2);
743 ehea_refill_rq3(pr, processed_rq3);
744
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700745 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200746}
747
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100748static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200749{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100750 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200751 struct ehea_cq *send_cq = pr->send_cq;
752 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100753 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200754 int cqe_counter = 0;
755 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100756 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200757 unsigned long flags;
758
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100759 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600760 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100761 ehea_inc_cq(send_cq);
762
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200763 cqe_counter++;
764 rmb();
765 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
766 ehea_error("Send Completion Error: Resetting port");
767 if (netif_msg_tx_err(pr->port))
768 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +0200769 schedule_work(&pr->port->reset_task);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200770 break;
771 }
772
773 if (netif_msg_tx_done(pr->port))
774 ehea_dump(cqe, sizeof(*cqe), "CQE");
775
776 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100777 == EHEA_SWQE2_TYPE)) {
778
779 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
780 skb = pr->sq_skba.arr[index];
781 dev_kfree_skb(skb);
782 pr->sq_skba.arr[index] = NULL;
783 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200784
785 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
786 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100787
788 cqe = ehea_poll_cq(send_cq);
789 };
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200790
791 ehea_update_feca(send_cq, cqe_counter);
792 atomic_add(swqe_av, &pr->swqe_avail);
793
794 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100795
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200796 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
797 >= pr->swqe_refill_th)) {
798 netif_wake_queue(pr->port->netdev);
799 pr->queue_stopped = 0;
800 }
801 spin_unlock_irqrestore(&pr->netif_queue, flags);
802
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100803 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200804}
805
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100806#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700807#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100808
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700809static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200810{
Doug Maxey508d2b52008-01-31 20:20:49 -0600811 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
812 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700813 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100814 struct ehea_cqe *cqe;
815 struct ehea_cqe *cqe_skb = NULL;
816 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700817 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100818
819 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700820 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100821
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700822 if (!force_irq)
823 rx += ehea_proc_rwqes(dev, pr, budget - rx);
824
825 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100826 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700827 force_irq = 0;
828 netif_rx_complete(dev, napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100829 ehea_reset_cq_ep(pr->recv_cq);
830 ehea_reset_cq_ep(pr->send_cq);
831 ehea_reset_cq_n1(pr->recv_cq);
832 ehea_reset_cq_n1(pr->send_cq);
833 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
834 cqe_skb = ehea_poll_cq(pr->send_cq);
835
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100836 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700837 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100838
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700839 if (!netif_rx_reschedule(dev, napi))
840 return rx;
841
842 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
843 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100844 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100845
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700846 pr->poll_counter++;
847 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200848}
849
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200850#ifdef CONFIG_NET_POLL_CONTROLLER
851static void ehea_netpoll(struct net_device *dev)
852{
853 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700854 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200855
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700856 for (i = 0; i < port->num_def_qps; i++)
857 netif_rx_schedule(dev, &port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200858}
859#endif
860
David Howells7d12e782006-10-05 14:55:46 +0100861static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200862{
863 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100864
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700865 netif_rx_schedule(pr->port->netdev, &pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100866
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200867 return IRQ_HANDLED;
868}
869
David Howells7d12e782006-10-05 14:55:46 +0100870static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200871{
872 struct ehea_port *port = param;
873 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100874 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200875 u32 qp_token;
876
877 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100878
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200879 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200880 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100881 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
882 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100883
884 qp = port->port_res[qp_token].qp;
885 ehea_error_data(port->adapter, qp->fw_handle);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100886 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200887 }
888
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +0200889 schedule_work(&port->reset_task);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100890
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200891 return IRQ_HANDLED;
892}
893
894static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
895 int logical_port)
896{
897 int i;
898
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100899 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100900 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200901 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +0100902 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200903 return NULL;
904}
905
906int ehea_sense_port_attr(struct ehea_port *port)
907{
908 int ret;
909 u64 hret;
910 struct hcp_ehea_port_cb0 *cb0;
911
Doug Maxey508d2b52008-01-31 20:20:49 -0600912 /* may be called via ehea_neq_tasklet() */
913 cb0 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
914 if (!cb0) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200915 ehea_error("no mem for cb0");
916 ret = -ENOMEM;
917 goto out;
918 }
919
920 hret = ehea_h_query_ehea_port(port->adapter->handle,
921 port->logical_port_id, H_PORT_CB0,
922 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
923 cb0);
924 if (hret != H_SUCCESS) {
925 ret = -EIO;
926 goto out_free;
927 }
928
929 /* MAC address */
930 port->mac_addr = cb0->port_mac_addr << 16;
931
Doug Maxey508d2b52008-01-31 20:20:49 -0600932 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200933 ret = -EADDRNOTAVAIL;
934 goto out_free;
935 }
936
937 /* Port speed */
938 switch (cb0->port_speed) {
939 case H_SPEED_10M_H:
940 port->port_speed = EHEA_SPEED_10M;
941 port->full_duplex = 0;
942 break;
943 case H_SPEED_10M_F:
944 port->port_speed = EHEA_SPEED_10M;
945 port->full_duplex = 1;
946 break;
947 case H_SPEED_100M_H:
948 port->port_speed = EHEA_SPEED_100M;
949 port->full_duplex = 0;
950 break;
951 case H_SPEED_100M_F:
952 port->port_speed = EHEA_SPEED_100M;
953 port->full_duplex = 1;
954 break;
955 case H_SPEED_1G_F:
956 port->port_speed = EHEA_SPEED_1G;
957 port->full_duplex = 1;
958 break;
959 case H_SPEED_10G_F:
960 port->port_speed = EHEA_SPEED_10G;
961 port->full_duplex = 1;
962 break;
963 default:
964 port->port_speed = 0;
965 port->full_duplex = 0;
966 break;
967 }
968
Thomas Kleine919b592007-01-22 12:53:20 +0100969 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100970 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +0100971
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200972 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100973 if (use_mcs)
974 port->num_def_qps = cb0->num_default_qps;
975 else
976 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200977
978 if (!port->num_def_qps) {
979 ret = -EINVAL;
980 goto out_free;
981 }
982
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100983 port->num_tx_qps = num_tx_qps;
984
985 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200986 port->num_add_tx_qps = 0;
987 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100988 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200989
990 ret = 0;
991out_free:
992 if (ret || netif_msg_probe(port))
993 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
994 kfree(cb0);
995out:
996 return ret;
997}
998
999int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
1000{
1001 struct hcp_ehea_port_cb4 *cb4;
1002 u64 hret;
1003 int ret = 0;
1004
Thomas Kleina1d261c2006-11-03 17:48:23 +01001005 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001006 if (!cb4) {
1007 ehea_error("no mem for cb4");
1008 ret = -ENOMEM;
1009 goto out;
1010 }
1011
1012 cb4->port_speed = port_speed;
1013
1014 netif_carrier_off(port->netdev);
1015
1016 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1017 port->logical_port_id,
1018 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1019 if (hret == H_SUCCESS) {
1020 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1021
1022 hret = ehea_h_query_ehea_port(port->adapter->handle,
1023 port->logical_port_id,
1024 H_PORT_CB4, H_PORT_CB4_SPEED,
1025 cb4);
1026 if (hret == H_SUCCESS) {
1027 switch (cb4->port_speed) {
1028 case H_SPEED_10M_H:
1029 port->port_speed = EHEA_SPEED_10M;
1030 port->full_duplex = 0;
1031 break;
1032 case H_SPEED_10M_F:
1033 port->port_speed = EHEA_SPEED_10M;
1034 port->full_duplex = 1;
1035 break;
1036 case H_SPEED_100M_H:
1037 port->port_speed = EHEA_SPEED_100M;
1038 port->full_duplex = 0;
1039 break;
1040 case H_SPEED_100M_F:
1041 port->port_speed = EHEA_SPEED_100M;
1042 port->full_duplex = 1;
1043 break;
1044 case H_SPEED_1G_F:
1045 port->port_speed = EHEA_SPEED_1G;
1046 port->full_duplex = 1;
1047 break;
1048 case H_SPEED_10G_F:
1049 port->port_speed = EHEA_SPEED_10G;
1050 port->full_duplex = 1;
1051 break;
1052 default:
1053 port->port_speed = 0;
1054 port->full_duplex = 0;
1055 break;
1056 }
1057 } else {
1058 ehea_error("Failed sensing port speed");
1059 ret = -EIO;
1060 }
1061 } else {
1062 if (hret == H_AUTHORITY) {
Thomas Klein7674a582007-01-22 12:54:20 +01001063 ehea_info("Hypervisor denied setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001064 ret = -EPERM;
1065 } else {
1066 ret = -EIO;
1067 ehea_error("Failed setting port speed");
1068 }
1069 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001070 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1071 netif_carrier_on(port->netdev);
1072
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001073 kfree(cb4);
1074out:
1075 return ret;
1076}
1077
1078static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1079{
1080 int ret;
1081 u8 ec;
1082 u8 portnum;
1083 struct ehea_port *port;
1084
1085 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1086 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1087 port = ehea_get_port(adapter, portnum);
1088
1089 switch (ec) {
1090 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1091
1092 if (!port) {
1093 ehea_error("unknown portnum %x", portnum);
1094 break;
1095 }
1096
1097 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
1098 if (!netif_carrier_ok(port->netdev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001099 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001100 if (ret) {
1101 ehea_error("failed resensing port "
1102 "attributes");
1103 break;
1104 }
1105
1106 if (netif_msg_link(port))
1107 ehea_info("%s: Logical port up: %dMbps "
1108 "%s Duplex",
1109 port->netdev->name,
1110 port->port_speed,
1111 port->full_duplex ==
1112 1 ? "Full" : "Half");
1113
1114 netif_carrier_on(port->netdev);
1115 netif_wake_queue(port->netdev);
1116 }
1117 } else
1118 if (netif_carrier_ok(port->netdev)) {
1119 if (netif_msg_link(port))
1120 ehea_info("%s: Logical port down",
1121 port->netdev->name);
1122 netif_carrier_off(port->netdev);
1123 netif_stop_queue(port->netdev);
1124 }
1125
1126 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001127 port->phy_link = EHEA_PHY_LINK_UP;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001128 if (netif_msg_link(port))
1129 ehea_info("%s: Physical port up",
1130 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001131 if (prop_carrier_state)
1132 netif_carrier_on(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001133 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001134 port->phy_link = EHEA_PHY_LINK_DOWN;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001135 if (netif_msg_link(port))
1136 ehea_info("%s: Physical port down",
1137 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001138 if (prop_carrier_state)
1139 netif_carrier_off(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001140 }
1141
1142 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
1143 ehea_info("External switch port is primary port");
1144 else
1145 ehea_info("External switch port is backup port");
1146
1147 break;
1148 case EHEA_EC_ADAPTER_MALFUNC:
1149 ehea_error("Adapter malfunction");
1150 break;
1151 case EHEA_EC_PORT_MALFUNC:
1152 ehea_info("Port malfunction: Device: %s", port->netdev->name);
1153 netif_carrier_off(port->netdev);
1154 netif_stop_queue(port->netdev);
1155 break;
1156 default:
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02001157 ehea_error("unknown event code %x, eqe=0x%lX", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001158 break;
1159 }
1160}
1161
1162static void ehea_neq_tasklet(unsigned long data)
1163{
Doug Maxey508d2b52008-01-31 20:20:49 -06001164 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001165 struct ehea_eqe *eqe;
1166 u64 event_mask;
1167
1168 eqe = ehea_poll_eq(adapter->neq);
1169 ehea_debug("eqe=%p", eqe);
1170
1171 while (eqe) {
1172 ehea_debug("*eqe=%lx", eqe->entry);
1173 ehea_parse_eqe(adapter, eqe->entry);
1174 eqe = ehea_poll_eq(adapter->neq);
1175 ehea_debug("next eqe=%p", eqe);
1176 }
1177
1178 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1179 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1180 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1181
1182 ehea_h_reset_events(adapter->handle,
1183 adapter->neq->fw_handle, event_mask);
1184}
1185
David Howells7d12e782006-10-05 14:55:46 +01001186static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001187{
1188 struct ehea_adapter *adapter = param;
1189 tasklet_hi_schedule(&adapter->neq_tasklet);
1190 return IRQ_HANDLED;
1191}
1192
1193
1194static int ehea_fill_port_res(struct ehea_port_res *pr)
1195{
1196 int ret;
1197 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1198
1199 ret = ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1200 - init_attr->act_nr_rwqes_rq2
1201 - init_attr->act_nr_rwqes_rq3 - 1);
1202
1203 ret |= ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
1204
1205 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1206
1207 return ret;
1208}
1209
1210static int ehea_reg_interrupts(struct net_device *dev)
1211{
1212 struct ehea_port *port = netdev_priv(dev);
1213 struct ehea_port_res *pr;
1214 int i, ret;
1215
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001216
1217 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1218 dev->name);
1219
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001220 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001221 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001222 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001223 if (ret) {
1224 ehea_error("failed registering irq for qp_aff_irq_handler:"
1225 "ist=%X", port->qp_eq->attr.ist1);
1226 goto out_free_qpeq;
1227 }
1228
1229 if (netif_msg_ifup(port))
1230 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1231 "registered", port->qp_eq->attr.ist1);
1232
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001233
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001234 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1235 pr = &port->port_res[i];
1236 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001237 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001238 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001239 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001240 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001241 pr);
1242 if (ret) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001243 ehea_error("failed registering irq for ehea_queue "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001244 "port_res_nr:%d, ist=%X", i,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001245 pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001246 goto out_free_req;
1247 }
1248 if (netif_msg_ifup(port))
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001249 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1250 "%d registered", pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001251 }
1252out:
1253 return ret;
1254
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001255
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001256out_free_req:
1257 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001258 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001259 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001260 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001261
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001262out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001263 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001264 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001265
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001266 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001267
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001268}
1269
1270static void ehea_free_interrupts(struct net_device *dev)
1271{
1272 struct ehea_port *port = netdev_priv(dev);
1273 struct ehea_port_res *pr;
1274 int i;
1275
1276 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001277
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001278 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1279 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001280 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001281 if (netif_msg_intr(port))
1282 ehea_info("free send irq for res %d with handle 0x%X",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001283 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001284 }
1285
1286 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001287 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001288 if (netif_msg_intr(port))
1289 ehea_info("associated event interrupt for handle 0x%X freed",
1290 port->qp_eq->attr.ist1);
1291}
1292
1293static int ehea_configure_port(struct ehea_port *port)
1294{
1295 int ret, i;
1296 u64 hret, mask;
1297 struct hcp_ehea_port_cb0 *cb0;
1298
1299 ret = -ENOMEM;
Thomas Kleina1d261c2006-11-03 17:48:23 +01001300 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001301 if (!cb0)
1302 goto out;
1303
1304 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1305 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1306 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1307 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1308 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1309 PXLY_RC_VLAN_FILTER)
1310 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1311
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001312 for (i = 0; i < port->num_mcs; i++)
1313 if (use_mcs)
1314 cb0->default_qpn_arr[i] =
1315 port->port_res[i].qp->init_attr.qp_nr;
1316 else
1317 cb0->default_qpn_arr[i] =
1318 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001319
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001320 if (netif_msg_ifup(port))
1321 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1322
1323 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1324 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1325
1326 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1327 port->logical_port_id,
1328 H_PORT_CB0, mask, cb0);
1329 ret = -EIO;
1330 if (hret != H_SUCCESS)
1331 goto out_free;
1332
1333 ret = 0;
1334
1335out_free:
1336 kfree(cb0);
1337out:
1338 return ret;
1339}
1340
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001341int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001342{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001343 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001344 struct ehea_adapter *adapter = pr->port->adapter;
1345
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001346 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1347 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001348 goto out;
1349
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001350 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1351 if (ret)
1352 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001353
1354 return 0;
1355
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001356out_free:
1357 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001358out:
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001359 ehea_error("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001360 return -EIO;
1361}
1362
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001363int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001364{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001365 if ((ehea_rem_mr(&pr->send_mr))
1366 || (ehea_rem_mr(&pr->recv_mr)))
1367 return -EIO;
1368 else
1369 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001370}
1371
1372static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1373{
Doug Maxey508d2b52008-01-31 20:20:49 -06001374 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001375
1376 q_skba->arr = vmalloc(arr_size);
1377 if (!q_skba->arr)
1378 return -ENOMEM;
1379
1380 memset(q_skba->arr, 0, arr_size);
1381
1382 q_skba->len = max_q_entries;
1383 q_skba->index = 0;
1384 q_skba->os_skbs = 0;
1385
1386 return 0;
1387}
1388
1389static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1390 struct port_res_cfg *pr_cfg, int queue_token)
1391{
1392 struct ehea_adapter *adapter = port->adapter;
1393 enum ehea_eq_type eq_type = EHEA_EQ;
1394 struct ehea_qp_init_attr *init_attr = NULL;
1395 int ret = -EIO;
1396
1397 memset(pr, 0, sizeof(struct ehea_port_res));
1398
1399 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001400 spin_lock_init(&pr->xmit_lock);
1401 spin_lock_init(&pr->netif_queue);
1402
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001403 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1404 if (!pr->eq) {
1405 ehea_error("create_eq failed (eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001406 goto out_free;
1407 }
1408
1409 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001410 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001411 port->logical_port_id);
1412 if (!pr->recv_cq) {
1413 ehea_error("create_cq failed (cq_recv)");
1414 goto out_free;
1415 }
1416
1417 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001418 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001419 port->logical_port_id);
1420 if (!pr->send_cq) {
1421 ehea_error("create_cq failed (cq_send)");
1422 goto out_free;
1423 }
1424
1425 if (netif_msg_ifup(port))
1426 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1427 pr->send_cq->attr.act_nr_of_cqes,
1428 pr->recv_cq->attr.act_nr_of_cqes);
1429
1430 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1431 if (!init_attr) {
1432 ret = -ENOMEM;
1433 ehea_error("no mem for ehea_qp_init_attr");
1434 goto out_free;
1435 }
1436
1437 init_attr->low_lat_rq1 = 1;
1438 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1439 init_attr->rq_count = 3;
1440 init_attr->qp_token = queue_token;
1441 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1442 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1443 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1444 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1445 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1446 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1447 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1448 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1449 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1450 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1451 init_attr->port_nr = port->logical_port_id;
1452 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1453 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1454 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1455
1456 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1457 if (!pr->qp) {
1458 ehea_error("create_qp failed");
1459 ret = -EIO;
1460 goto out_free;
1461 }
1462
1463 if (netif_msg_ifup(port))
1464 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1465 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1466 init_attr->act_nr_send_wqes,
1467 init_attr->act_nr_rwqes_rq1,
1468 init_attr->act_nr_rwqes_rq2,
1469 init_attr->act_nr_rwqes_rq3);
1470
Thomas Klein44fb3122008-04-04 15:04:53 +02001471 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1472
1473 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001474 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1475 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1476 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1477 if (ret)
1478 goto out_free;
1479
1480 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1481 if (ehea_gen_smrs(pr) != 0) {
1482 ret = -EIO;
1483 goto out_free;
1484 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001485
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001486 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1487
1488 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001489
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001490 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001491
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001492 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1493 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1494 pr->lro_mgr.lro_arr = pr->lro_desc;
1495 pr->lro_mgr.get_skb_header = get_skb_hdr;
1496 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1497 pr->lro_mgr.dev = port->netdev;
1498 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1499 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1500
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001501 ret = 0;
1502 goto out;
1503
1504out_free:
1505 kfree(init_attr);
1506 vfree(pr->sq_skba.arr);
1507 vfree(pr->rq1_skba.arr);
1508 vfree(pr->rq2_skba.arr);
1509 vfree(pr->rq3_skba.arr);
1510 ehea_destroy_qp(pr->qp);
1511 ehea_destroy_cq(pr->send_cq);
1512 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001513 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001514out:
1515 return ret;
1516}
1517
1518static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1519{
1520 int ret, i;
1521
1522 ret = ehea_destroy_qp(pr->qp);
1523
1524 if (!ret) {
1525 ehea_destroy_cq(pr->send_cq);
1526 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001527 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001528
1529 for (i = 0; i < pr->rq1_skba.len; i++)
1530 if (pr->rq1_skba.arr[i])
1531 dev_kfree_skb(pr->rq1_skba.arr[i]);
1532
1533 for (i = 0; i < pr->rq2_skba.len; i++)
1534 if (pr->rq2_skba.arr[i])
1535 dev_kfree_skb(pr->rq2_skba.arr[i]);
1536
1537 for (i = 0; i < pr->rq3_skba.len; i++)
1538 if (pr->rq3_skba.arr[i])
1539 dev_kfree_skb(pr->rq3_skba.arr[i]);
1540
1541 for (i = 0; i < pr->sq_skba.len; i++)
1542 if (pr->sq_skba.arr[i])
1543 dev_kfree_skb(pr->sq_skba.arr[i]);
1544
1545 vfree(pr->rq1_skba.arr);
1546 vfree(pr->rq2_skba.arr);
1547 vfree(pr->rq3_skba.arr);
1548 vfree(pr->sq_skba.arr);
1549 ret = ehea_rem_smrs(pr);
1550 }
1551 return ret;
1552}
1553
1554/*
1555 * The write_* functions store information in swqe which is used by
1556 * the hardware to calculate the ip/tcp/udp checksum
1557 */
1558
1559static inline void write_ip_start_end(struct ehea_swqe *swqe,
1560 const struct sk_buff *skb)
1561{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001562 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001563 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001564}
1565
1566static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1567 const struct sk_buff *skb)
1568{
1569 swqe->tcp_offset =
1570 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1571
1572 swqe->tcp_end = (u16)skb->len - 1;
1573}
1574
1575static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1576 const struct sk_buff *skb)
1577{
1578 swqe->tcp_offset =
1579 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1580
1581 swqe->tcp_end = (u16)skb->len - 1;
1582}
1583
1584
1585static void write_swqe2_TSO(struct sk_buff *skb,
1586 struct ehea_swqe *swqe, u32 lkey)
1587{
1588 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1589 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1590 int skb_data_size = skb->len - skb->data_len;
1591 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001592
1593 /* Packet is TCP with TSO enabled */
1594 swqe->tx_control |= EHEA_SWQE_TSO;
1595 swqe->mss = skb_shinfo(skb)->gso_size;
1596 /* copy only eth/ip/tcp headers to immediate data and
1597 * the rest of skb->data to sg1entry
1598 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001599 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001600
1601 skb_data_size = skb->len - skb->data_len;
1602
1603 if (skb_data_size >= headersize) {
1604 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001605 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001606 swqe->immediate_data_length = headersize;
1607
1608 if (skb_data_size > headersize) {
1609 /* set sg1entry data */
1610 sg1entry->l_key = lkey;
1611 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001612 sg1entry->vaddr =
1613 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001614 swqe->descriptors++;
1615 }
1616 } else
1617 ehea_error("cannot handle fragmented headers");
1618}
1619
1620static void write_swqe2_nonTSO(struct sk_buff *skb,
1621 struct ehea_swqe *swqe, u32 lkey)
1622{
1623 int skb_data_size = skb->len - skb->data_len;
1624 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1625 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001626
1627 /* Packet is any nonTSO type
1628 *
1629 * Copy as much as possible skb->data to immediate data and
1630 * the rest to sg1entry
1631 */
1632 if (skb_data_size >= SWQE2_MAX_IMM) {
1633 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001634 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001635
1636 swqe->immediate_data_length = SWQE2_MAX_IMM;
1637
1638 if (skb_data_size > SWQE2_MAX_IMM) {
1639 /* copy sg1entry data */
1640 sg1entry->l_key = lkey;
1641 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001642 sg1entry->vaddr =
1643 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001644 swqe->descriptors++;
1645 }
1646 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001647 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001648 swqe->immediate_data_length = skb_data_size;
1649 }
1650}
1651
1652static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1653 struct ehea_swqe *swqe, u32 lkey)
1654{
1655 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1656 skb_frag_t *frag;
1657 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001658
1659 nfrags = skb_shinfo(skb)->nr_frags;
1660 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001661 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001662 swqe->descriptors = 0;
1663 sg1entry_contains_frag_data = 0;
1664
1665 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1666 write_swqe2_TSO(skb, swqe, lkey);
1667 else
1668 write_swqe2_nonTSO(skb, swqe, lkey);
1669
1670 /* write descriptors */
1671 if (nfrags > 0) {
1672 if (swqe->descriptors == 0) {
1673 /* sg1entry not yet used */
1674 frag = &skb_shinfo(skb)->frags[0];
1675
1676 /* copy sg1entry data */
1677 sg1entry->l_key = lkey;
1678 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001679 sg1entry->vaddr =
1680 ehea_map_vaddr(page_address(frag->page)
1681 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001682 swqe->descriptors++;
1683 sg1entry_contains_frag_data = 1;
1684 }
1685
1686 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1687
1688 frag = &skb_shinfo(skb)->frags[i];
1689 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1690
1691 sgentry->l_key = lkey;
1692 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001693 sgentry->vaddr =
1694 ehea_map_vaddr(page_address(frag->page)
1695 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001696 swqe->descriptors++;
1697 }
1698 }
1699}
1700
1701static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1702{
1703 int ret = 0;
1704 u64 hret;
1705 u8 reg_type;
1706
1707 /* De/Register untagged packets */
1708 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1709 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1710 port->logical_port_id,
1711 reg_type, port->mac_addr, 0, hcallid);
1712 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001713 ehea_error("%sregistering bc address failed (tagged)",
Doug Maxey508d2b52008-01-31 20:20:49 -06001714 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001715 ret = -EIO;
1716 goto out_herr;
1717 }
1718
1719 /* De/Register VLAN packets */
1720 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1721 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1722 port->logical_port_id,
1723 reg_type, port->mac_addr, 0, hcallid);
1724 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001725 ehea_error("%sregistering bc address failed (vlan)",
1726 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001727 ret = -EIO;
1728 }
1729out_herr:
1730 return ret;
1731}
1732
1733static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1734{
1735 struct ehea_port *port = netdev_priv(dev);
1736 struct sockaddr *mac_addr = sa;
1737 struct hcp_ehea_port_cb0 *cb0;
1738 int ret;
1739 u64 hret;
1740
1741 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1742 ret = -EADDRNOTAVAIL;
1743 goto out;
1744 }
1745
Thomas Kleina1d261c2006-11-03 17:48:23 +01001746 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001747 if (!cb0) {
1748 ehea_error("no mem for cb0");
1749 ret = -ENOMEM;
1750 goto out;
1751 }
1752
1753 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1754
1755 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1756
1757 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1758 port->logical_port_id, H_PORT_CB0,
1759 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1760 if (hret != H_SUCCESS) {
1761 ret = -EIO;
1762 goto out_free;
1763 }
1764
1765 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1766
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01001767 spin_lock(&ehea_bcmc_regs.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001768
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001769 /* Deregister old MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001770 if (port->state == EHEA_PORT_UP) {
1771 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1772 if (ret)
1773 goto out_upregs;
1774 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001775
1776 port->mac_addr = cb0->port_mac_addr << 16;
1777
1778 /* Register new MAC in pHYP */
Jan-Bernd Themann00aaea22008-06-09 15:17:37 +01001779 if (port->state == EHEA_PORT_UP) {
1780 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1781 if (ret)
1782 goto out_upregs;
1783 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001784
1785 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001786
1787out_upregs:
1788 ehea_update_bcmc_registrations();
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01001789 spin_unlock(&ehea_bcmc_regs.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001790out_free:
1791 kfree(cb0);
1792out:
1793 return ret;
1794}
1795
1796static void ehea_promiscuous_error(u64 hret, int enable)
1797{
Thomas Klein7674a582007-01-22 12:54:20 +01001798 if (hret == H_AUTHORITY)
1799 ehea_info("Hypervisor denied %sabling promiscuous mode",
1800 enable == 1 ? "en" : "dis");
1801 else
1802 ehea_error("failed %sabling promiscuous mode",
1803 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001804}
1805
1806static void ehea_promiscuous(struct net_device *dev, int enable)
1807{
1808 struct ehea_port *port = netdev_priv(dev);
1809 struct hcp_ehea_port_cb7 *cb7;
1810 u64 hret;
1811
1812 if ((enable && port->promisc) || (!enable && !port->promisc))
1813 return;
1814
Thomas Kleina1d261c2006-11-03 17:48:23 +01001815 cb7 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001816 if (!cb7) {
1817 ehea_error("no mem for cb7");
1818 goto out;
1819 }
1820
1821 /* Modify Pxs_DUCQPN in CB7 */
1822 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1823
1824 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1825 port->logical_port_id,
1826 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1827 if (hret) {
1828 ehea_promiscuous_error(hret, enable);
1829 goto out;
1830 }
1831
1832 port->promisc = enable;
1833out:
1834 kfree(cb7);
1835 return;
1836}
1837
1838static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1839 u32 hcallid)
1840{
1841 u64 hret;
1842 u8 reg_type;
1843
1844 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1845 | EHEA_BCMC_UNTAGGED;
1846
1847 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1848 port->logical_port_id,
1849 reg_type, mc_mac_addr, 0, hcallid);
1850 if (hret)
1851 goto out;
1852
1853 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1854 | EHEA_BCMC_VLANID_ALL;
1855
1856 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1857 port->logical_port_id,
1858 reg_type, mc_mac_addr, 0, hcallid);
1859out:
1860 return hret;
1861}
1862
1863static int ehea_drop_multicast_list(struct net_device *dev)
1864{
1865 struct ehea_port *port = netdev_priv(dev);
1866 struct ehea_mc_list *mc_entry = port->mc_list;
1867 struct list_head *pos;
1868 struct list_head *temp;
1869 int ret = 0;
1870 u64 hret;
1871
1872 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1873 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1874
1875 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1876 H_DEREG_BCMC);
1877 if (hret) {
1878 ehea_error("failed deregistering mcast MAC");
1879 ret = -EIO;
1880 }
1881
1882 list_del(pos);
1883 kfree(mc_entry);
1884 }
1885 return ret;
1886}
1887
1888static void ehea_allmulti(struct net_device *dev, int enable)
1889{
1890 struct ehea_port *port = netdev_priv(dev);
1891 u64 hret;
1892
1893 if (!port->allmulti) {
1894 if (enable) {
1895 /* Enable ALLMULTI */
1896 ehea_drop_multicast_list(dev);
1897 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1898 if (!hret)
1899 port->allmulti = 1;
1900 else
1901 ehea_error("failed enabling IFF_ALLMULTI");
1902 }
1903 } else
1904 if (!enable) {
1905 /* Disable ALLMULTI */
1906 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1907 if (!hret)
1908 port->allmulti = 0;
1909 else
1910 ehea_error("failed disabling IFF_ALLMULTI");
1911 }
1912}
1913
Doug Maxey508d2b52008-01-31 20:20:49 -06001914static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001915{
1916 struct ehea_mc_list *ehea_mcl_entry;
1917 u64 hret;
1918
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001919 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001920 if (!ehea_mcl_entry) {
1921 ehea_error("no mem for mcl_entry");
1922 return;
1923 }
1924
1925 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1926
1927 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1928
1929 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1930 H_REG_BCMC);
1931 if (!hret)
1932 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1933 else {
1934 ehea_error("failed registering mcast MAC");
1935 kfree(ehea_mcl_entry);
1936 }
1937}
1938
1939static void ehea_set_multicast_list(struct net_device *dev)
1940{
1941 struct ehea_port *port = netdev_priv(dev);
1942 struct dev_mc_list *k_mcl_entry;
1943 int ret, i;
1944
1945 if (dev->flags & IFF_PROMISC) {
1946 ehea_promiscuous(dev, 1);
1947 return;
1948 }
1949 ehea_promiscuous(dev, 0);
1950
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01001951 spin_lock(&ehea_bcmc_regs.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001952
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001953 if (dev->flags & IFF_ALLMULTI) {
1954 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001955 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001956 }
1957 ehea_allmulti(dev, 0);
1958
1959 if (dev->mc_count) {
1960 ret = ehea_drop_multicast_list(dev);
1961 if (ret) {
1962 /* Dropping the current multicast list failed.
1963 * Enabling ALL_MULTI is the best we can do.
1964 */
1965 ehea_allmulti(dev, 1);
1966 }
1967
1968 if (dev->mc_count > port->adapter->max_mc_mac) {
1969 ehea_info("Mcast registration limit reached (0x%lx). "
1970 "Use ALLMULTI!",
1971 port->adapter->max_mc_mac);
1972 goto out;
1973 }
1974
Doug Maxey508d2b52008-01-31 20:20:49 -06001975 for (i = 0, k_mcl_entry = dev->mc_list; i < dev->mc_count; i++,
1976 k_mcl_entry = k_mcl_entry->next)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001977 ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06001978
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001979 }
1980out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01001981 ehea_update_bcmc_registrations();
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01001982 spin_unlock(&ehea_bcmc_regs.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001983 return;
1984}
1985
1986static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1987{
1988 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1989 return -EINVAL;
1990 dev->mtu = new_mtu;
1991 return 0;
1992}
1993
1994static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
1995 struct ehea_swqe *swqe, u32 lkey)
1996{
1997 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001998 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001999
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002000 /* IPv4 */
2001 swqe->tx_control |= EHEA_SWQE_CRC
2002 | EHEA_SWQE_IP_CHECKSUM
2003 | EHEA_SWQE_TCP_CHECKSUM
2004 | EHEA_SWQE_IMM_DATA_PRESENT
2005 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2006
2007 write_ip_start_end(swqe, skb);
2008
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002009 if (iph->protocol == IPPROTO_UDP) {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002010 if ((iph->frag_off & IP_MF)
2011 || (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002012 /* IP fragment, so don't change cs */
2013 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2014 else
2015 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002016 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002017 write_tcp_offset_end(swqe, skb);
2018 }
2019
2020 /* icmp (big data) and ip segmentation packets (all other ip
2021 packets) do not require any special handling */
2022
2023 } else {
2024 /* Other Ethernet Protocol */
2025 swqe->tx_control |= EHEA_SWQE_CRC
2026 | EHEA_SWQE_IMM_DATA_PRESENT
2027 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2028 }
2029
2030 write_swqe2_data(skb, dev, swqe, lkey);
2031}
2032
2033static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2034 struct ehea_swqe *swqe)
2035{
2036 int nfrags = skb_shinfo(skb)->nr_frags;
2037 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2038 skb_frag_t *frag;
2039 int i;
2040
2041 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002042 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002043
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002044 /* IPv4 */
2045 write_ip_start_end(swqe, skb);
2046
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002047 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002048 swqe->tx_control |= EHEA_SWQE_CRC
2049 | EHEA_SWQE_IP_CHECKSUM
2050 | EHEA_SWQE_TCP_CHECKSUM
2051 | EHEA_SWQE_IMM_DATA_PRESENT;
2052
2053 write_tcp_offset_end(swqe, skb);
2054
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002055 } else if (iph->protocol == IPPROTO_UDP) {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002056 if ((iph->frag_off & IP_MF)
2057 || (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002058 /* IP fragment, so don't change cs */
2059 swqe->tx_control |= EHEA_SWQE_CRC
2060 | EHEA_SWQE_IMM_DATA_PRESENT;
2061 else {
2062 swqe->tx_control |= EHEA_SWQE_CRC
2063 | EHEA_SWQE_IP_CHECKSUM
2064 | EHEA_SWQE_TCP_CHECKSUM
2065 | EHEA_SWQE_IMM_DATA_PRESENT;
2066
2067 write_udp_offset_end(swqe, skb);
2068 }
2069 } else {
2070 /* icmp (big data) and
2071 ip segmentation packets (all other ip packets) */
2072 swqe->tx_control |= EHEA_SWQE_CRC
2073 | EHEA_SWQE_IP_CHECKSUM
2074 | EHEA_SWQE_IMM_DATA_PRESENT;
2075 }
2076 } else {
2077 /* Other Ethernet Protocol */
2078 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2079 }
2080 /* copy (immediate) data */
2081 if (nfrags == 0) {
2082 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002083 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002084 } else {
2085 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002086 skb_copy_from_linear_data(skb, imm_data,
2087 skb->len - skb->data_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002088 imm_data += skb->len - skb->data_len;
2089
2090 /* ... then copy data from the fragments */
2091 for (i = 0; i < nfrags; i++) {
2092 frag = &skb_shinfo(skb)->frags[i];
2093 memcpy(imm_data,
2094 page_address(frag->page) + frag->page_offset,
2095 frag->size);
2096 imm_data += frag->size;
2097 }
2098 }
2099 swqe->immediate_data_length = skb->len;
2100 dev_kfree_skb(skb);
2101}
2102
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002103static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2104{
2105 struct tcphdr *tcp;
2106 u32 tmp;
2107
2108 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002109 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002110 tcp = (struct tcphdr *)(skb_network_header(skb) +
2111 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002112 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002113 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002114 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002115 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002116 return 0;
2117}
2118
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002119static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2120{
2121 struct ehea_port *port = netdev_priv(dev);
2122 struct ehea_swqe *swqe;
2123 unsigned long flags;
2124 u32 lkey;
2125 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002126 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002127
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002128 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2129
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002130 if (!spin_trylock(&pr->xmit_lock))
2131 return NETDEV_TX_BUSY;
2132
2133 if (pr->queue_stopped) {
2134 spin_unlock(&pr->xmit_lock);
2135 return NETDEV_TX_BUSY;
2136 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002137
2138 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2139 memset(swqe, 0, SWQE_HEADER_SIZE);
2140 atomic_dec(&pr->swqe_avail);
2141
2142 if (skb->len <= SWQE3_MAX_IMM) {
2143 u32 sig_iv = port->sig_comp_iv;
2144 u32 swqe_num = pr->swqe_id_counter;
2145 ehea_xmit3(skb, dev, swqe);
2146 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2147 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2148 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2149 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2150 sig_iv);
2151 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2152 pr->swqe_ll_count = 0;
2153 } else
2154 pr->swqe_ll_count += 1;
2155 } else {
2156 swqe->wr_id =
2157 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2158 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002159 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002160 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2161 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2162
2163 pr->sq_skba.index++;
2164 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2165
2166 lkey = pr->send_mr.lkey;
2167 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002168 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002169 }
2170 pr->swqe_id_counter += 1;
2171
2172 if (port->vgrp && vlan_tx_tag_present(skb)) {
2173 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2174 swqe->vlan_tag = vlan_tx_tag_get(skb);
2175 }
2176
2177 if (netif_msg_tx_queued(port)) {
2178 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002179 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002180 }
2181
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002182 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2183 netif_stop_queue(dev);
2184 swqe->tx_control |= EHEA_SWQE_PURGE;
2185 }
Thomas Klein44c82152007-07-11 16:32:00 +02002186
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002187 ehea_post_swqe(pr->qp, swqe);
Thomas Klein7393b872007-11-21 17:37:58 +01002188 pr->tx_packets++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002189
2190 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2191 spin_lock_irqsave(&pr->netif_queue, flags);
2192 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002193 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002194 netif_stop_queue(dev);
2195 pr->queue_stopped = 1;
2196 }
2197 spin_unlock_irqrestore(&pr->netif_queue, flags);
2198 }
2199 dev->trans_start = jiffies;
2200 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002201
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002202 return NETDEV_TX_OK;
2203}
2204
2205static void ehea_vlan_rx_register(struct net_device *dev,
2206 struct vlan_group *grp)
2207{
2208 struct ehea_port *port = netdev_priv(dev);
2209 struct ehea_adapter *adapter = port->adapter;
2210 struct hcp_ehea_port_cb1 *cb1;
2211 u64 hret;
2212
2213 port->vgrp = grp;
2214
Thomas Kleina1d261c2006-11-03 17:48:23 +01002215 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002216 if (!cb1) {
2217 ehea_error("no mem for cb1");
2218 goto out;
2219 }
2220
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002221 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2222 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2223 if (hret != H_SUCCESS)
2224 ehea_error("modify_ehea_port failed");
2225
2226 kfree(cb1);
2227out:
2228 return;
2229}
2230
2231static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2232{
2233 struct ehea_port *port = netdev_priv(dev);
2234 struct ehea_adapter *adapter = port->adapter;
2235 struct hcp_ehea_port_cb1 *cb1;
2236 int index;
2237 u64 hret;
2238
Thomas Kleina1d261c2006-11-03 17:48:23 +01002239 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002240 if (!cb1) {
2241 ehea_error("no mem for cb1");
2242 goto out;
2243 }
2244
2245 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2246 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2247 if (hret != H_SUCCESS) {
2248 ehea_error("query_ehea_port failed");
2249 goto out;
2250 }
2251
2252 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002253 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002254
2255 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2256 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2257 if (hret != H_SUCCESS)
2258 ehea_error("modify_ehea_port failed");
2259out:
2260 kfree(cb1);
2261 return;
2262}
2263
2264static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2265{
2266 struct ehea_port *port = netdev_priv(dev);
2267 struct ehea_adapter *adapter = port->adapter;
2268 struct hcp_ehea_port_cb1 *cb1;
2269 int index;
2270 u64 hret;
2271
Dan Aloni5c15bde2007-03-02 20:44:51 -08002272 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002273
Thomas Kleina1d261c2006-11-03 17:48:23 +01002274 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002275 if (!cb1) {
2276 ehea_error("no mem for cb1");
2277 goto out;
2278 }
2279
2280 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2281 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2282 if (hret != H_SUCCESS) {
2283 ehea_error("query_ehea_port failed");
2284 goto out;
2285 }
2286
2287 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002288 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002289
2290 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2291 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2292 if (hret != H_SUCCESS)
2293 ehea_error("modify_ehea_port failed");
2294out:
2295 kfree(cb1);
2296 return;
2297}
2298
2299int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2300{
2301 int ret = -EIO;
2302 u64 hret;
2303 u16 dummy16 = 0;
2304 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002305 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002306
Thomas Kleina1d261c2006-11-03 17:48:23 +01002307 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002308 if (!cb0) {
2309 ret = -ENOMEM;
2310 goto out;
2311 }
2312
2313 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2314 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2315 if (hret != H_SUCCESS) {
2316 ehea_error("query_ehea_qp failed (1)");
2317 goto out;
2318 }
2319
2320 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2321 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2322 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2323 &dummy64, &dummy64, &dummy16, &dummy16);
2324 if (hret != H_SUCCESS) {
2325 ehea_error("modify_ehea_qp failed (1)");
2326 goto out;
2327 }
2328
2329 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2330 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2331 if (hret != H_SUCCESS) {
2332 ehea_error("query_ehea_qp failed (2)");
2333 goto out;
2334 }
2335
2336 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2337 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2338 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2339 &dummy64, &dummy64, &dummy16, &dummy16);
2340 if (hret != H_SUCCESS) {
2341 ehea_error("modify_ehea_qp failed (2)");
2342 goto out;
2343 }
2344
2345 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2346 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2347 if (hret != H_SUCCESS) {
2348 ehea_error("query_ehea_qp failed (3)");
2349 goto out;
2350 }
2351
2352 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2353 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2354 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2355 &dummy64, &dummy64, &dummy16, &dummy16);
2356 if (hret != H_SUCCESS) {
2357 ehea_error("modify_ehea_qp failed (3)");
2358 goto out;
2359 }
2360
2361 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2362 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2363 if (hret != H_SUCCESS) {
2364 ehea_error("query_ehea_qp failed (4)");
2365 goto out;
2366 }
2367
2368 ret = 0;
2369out:
2370 kfree(cb0);
2371 return ret;
2372}
2373
2374static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2375 int add_tx_qps)
2376{
2377 int ret, i;
2378 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2379 enum ehea_eq_type eq_type = EHEA_EQ;
2380
2381 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2382 EHEA_MAX_ENTRIES_EQ, 1);
2383 if (!port->qp_eq) {
2384 ret = -EINVAL;
2385 ehea_error("ehea_create_eq failed (qp_eq)");
2386 goto out_kill_eq;
2387 }
2388
2389 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002390 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002391 pr_cfg.max_entries_sq = sq_entries;
2392 pr_cfg.max_entries_rq1 = rq1_entries;
2393 pr_cfg.max_entries_rq2 = rq2_entries;
2394 pr_cfg.max_entries_rq3 = rq3_entries;
2395
2396 pr_cfg_small_rx.max_entries_rcq = 1;
2397 pr_cfg_small_rx.max_entries_scq = sq_entries;
2398 pr_cfg_small_rx.max_entries_sq = sq_entries;
2399 pr_cfg_small_rx.max_entries_rq1 = 1;
2400 pr_cfg_small_rx.max_entries_rq2 = 1;
2401 pr_cfg_small_rx.max_entries_rq3 = 1;
2402
2403 for (i = 0; i < def_qps; i++) {
2404 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2405 if (ret)
2406 goto out_clean_pr;
2407 }
2408 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2409 ret = ehea_init_port_res(port, &port->port_res[i],
2410 &pr_cfg_small_rx, i);
2411 if (ret)
2412 goto out_clean_pr;
2413 }
2414
2415 return 0;
2416
2417out_clean_pr:
2418 while (--i >= 0)
2419 ehea_clean_portres(port, &port->port_res[i]);
2420
2421out_kill_eq:
2422 ehea_destroy_eq(port->qp_eq);
2423 return ret;
2424}
2425
2426static int ehea_clean_all_portres(struct ehea_port *port)
2427{
2428 int ret = 0;
2429 int i;
2430
Doug Maxey508d2b52008-01-31 20:20:49 -06002431 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002432 ret |= ehea_clean_portres(port, &port->port_res[i]);
2433
2434 ret |= ehea_destroy_eq(port->qp_eq);
2435
2436 return ret;
2437}
2438
Thomas Klein35cf2e22007-08-06 13:55:14 +02002439static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002440{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002441 if (adapter->active_ports)
2442 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002443
2444 ehea_rem_mr(&adapter->mr);
2445}
2446
Thomas Klein35cf2e22007-08-06 13:55:14 +02002447static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002448{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002449 if (adapter->active_ports)
2450 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002451
2452 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2453}
2454
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002455static int ehea_up(struct net_device *dev)
2456{
2457 int ret, i;
2458 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002459
2460 if (port->state == EHEA_PORT_UP)
2461 return 0;
2462
Daniel Walker9f71a562008-03-28 14:41:26 -07002463 mutex_lock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002464
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002465 ret = ehea_port_res_setup(port, port->num_def_qps,
2466 port->num_add_tx_qps);
2467 if (ret) {
2468 ehea_error("port_res_failed");
2469 goto out;
2470 }
2471
2472 /* Set default QP for this port */
2473 ret = ehea_configure_port(port);
2474 if (ret) {
2475 ehea_error("ehea_configure_port failed. ret:%d", ret);
2476 goto out_clean_pr;
2477 }
2478
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002479 ret = ehea_reg_interrupts(dev);
2480 if (ret) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02002481 ehea_error("reg_interrupts failed. ret:%d", ret);
2482 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002483 }
2484
Doug Maxey508d2b52008-01-31 20:20:49 -06002485 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002486 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2487 if (ret) {
2488 ehea_error("activate_qp failed");
2489 goto out_free_irqs;
2490 }
2491 }
2492
Doug Maxey508d2b52008-01-31 20:20:49 -06002493 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002494 ret = ehea_fill_port_res(&port->port_res[i]);
2495 if (ret) {
2496 ehea_error("out_free_irqs");
2497 goto out_free_irqs;
2498 }
2499 }
2500
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01002501 spin_lock(&ehea_bcmc_regs.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002502
2503 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2504 if (ret) {
2505 ret = -EIO;
2506 goto out_free_irqs;
2507 }
2508
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002509 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002510
2511 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002512 goto out;
2513
2514out_free_irqs:
2515 ehea_free_interrupts(dev);
2516
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002517out_clean_pr:
2518 ehea_clean_all_portres(port);
2519out:
Thomas Klein44c82152007-07-11 16:32:00 +02002520 if (ret)
2521 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
2522
Thomas Klein21eee2d2008-02-13 16:18:33 +01002523 ehea_update_bcmc_registrations();
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01002524 spin_unlock(&ehea_bcmc_regs.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002525
2526 ehea_update_firmware_handles();
Daniel Walker9f71a562008-03-28 14:41:26 -07002527 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002528
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002529 return ret;
2530}
2531
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002532static void port_napi_disable(struct ehea_port *port)
2533{
2534 int i;
2535
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002536 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002537 napi_disable(&port->port_res[i].napi);
2538}
2539
2540static void port_napi_enable(struct ehea_port *port)
2541{
2542 int i;
2543
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002544 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002545 napi_enable(&port->port_res[i].napi);
2546}
2547
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002548static int ehea_open(struct net_device *dev)
2549{
2550 int ret;
2551 struct ehea_port *port = netdev_priv(dev);
2552
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002553 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002554
2555 if (netif_msg_ifup(port))
2556 ehea_info("enabling port %s", dev->name);
2557
2558 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002559 if (!ret) {
2560 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002561 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002562 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002563
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002564 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002565
2566 return ret;
2567}
2568
2569static int ehea_down(struct net_device *dev)
2570{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002571 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002572 struct ehea_port *port = netdev_priv(dev);
2573
2574 if (port->state == EHEA_PORT_DOWN)
2575 return 0;
2576
Daniel Walkerdbbcbb22008-03-28 14:41:27 -07002577 mutex_lock(&ehea_fw_handles.lock);
2578
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01002579 spin_lock(&ehea_bcmc_regs.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002580 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002581 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2582
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002583 ehea_free_interrupts(dev);
2584
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002585 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002586
Thomas Klein21eee2d2008-02-13 16:18:33 +01002587 ehea_update_bcmc_registrations();
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01002588 spin_unlock(&ehea_bcmc_regs.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002589
Thomas Klein44c82152007-07-11 16:32:00 +02002590 ret = ehea_clean_all_portres(port);
2591 if (ret)
2592 ehea_info("Failed freeing resources for %s. ret=%i",
2593 dev->name, ret);
2594
Thomas Klein21eee2d2008-02-13 16:18:33 +01002595 ehea_update_firmware_handles();
Daniel Walker9f71a562008-03-28 14:41:26 -07002596 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002597
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002598 return ret;
2599}
2600
2601static int ehea_stop(struct net_device *dev)
2602{
2603 int ret;
2604 struct ehea_port *port = netdev_priv(dev);
2605
2606 if (netif_msg_ifdown(port))
2607 ehea_info("disabling port %s", dev->name);
2608
David S. Miller4bb073c2008-06-12 02:22:02 -07002609 cancel_work_sync(&port->reset_task);
2610
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002611 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002612 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002613 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002614 ret = ehea_down(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002615 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002616 return ret;
2617}
2618
Andrew Morton22559c52008-04-18 13:50:39 -07002619static void ehea_purge_sq(struct ehea_qp *orig_qp)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002620{
2621 struct ehea_qp qp = *orig_qp;
2622 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2623 struct ehea_swqe *swqe;
2624 int wqe_index;
2625 int i;
2626
2627 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2628 swqe = ehea_get_swqe(&qp, &wqe_index);
2629 swqe->tx_control |= EHEA_SWQE_PURGE;
2630 }
2631}
2632
Andrew Morton22559c52008-04-18 13:50:39 -07002633static void ehea_flush_sq(struct ehea_port *port)
Thomas Klein44fb3122008-04-04 15:04:53 +02002634{
2635 int i;
2636
2637 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2638 struct ehea_port_res *pr = &port->port_res[i];
2639 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
2640 int k = 0;
2641 while (atomic_read(&pr->swqe_avail) < swqe_max) {
2642 msleep(5);
2643 if (++k == 20)
2644 break;
2645 }
2646 }
2647}
2648
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002649int ehea_stop_qps(struct net_device *dev)
2650{
2651 struct ehea_port *port = netdev_priv(dev);
2652 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002653 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002654 int ret = -EIO;
2655 int dret;
2656 int i;
2657 u64 hret;
2658 u64 dummy64 = 0;
2659 u16 dummy16 = 0;
2660
2661 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2662 if (!cb0) {
2663 ret = -ENOMEM;
2664 goto out;
2665 }
2666
2667 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2668 struct ehea_port_res *pr = &port->port_res[i];
2669 struct ehea_qp *qp = pr->qp;
2670
2671 /* Purge send queue */
2672 ehea_purge_sq(qp);
2673
2674 /* Disable queue pair */
2675 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2676 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2677 cb0);
2678 if (hret != H_SUCCESS) {
2679 ehea_error("query_ehea_qp failed (1)");
2680 goto out;
2681 }
2682
2683 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2684 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2685
2686 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2687 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2688 1), cb0, &dummy64,
2689 &dummy64, &dummy16, &dummy16);
2690 if (hret != H_SUCCESS) {
2691 ehea_error("modify_ehea_qp failed (1)");
2692 goto out;
2693 }
2694
2695 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2696 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2697 cb0);
2698 if (hret != H_SUCCESS) {
2699 ehea_error("query_ehea_qp failed (2)");
2700 goto out;
2701 }
2702
2703 /* deregister shared memory regions */
2704 dret = ehea_rem_smrs(pr);
2705 if (dret) {
2706 ehea_error("unreg shared memory region failed");
2707 goto out;
2708 }
2709 }
2710
2711 ret = 0;
2712out:
2713 kfree(cb0);
2714
2715 return ret;
2716}
2717
Doug Maxey508d2b52008-01-31 20:20:49 -06002718void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002719{
2720 struct ehea_qp qp = *orig_qp;
2721 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2722 struct ehea_rwqe *rwqe;
2723 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2724 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2725 struct sk_buff *skb;
2726 u32 lkey = pr->recv_mr.lkey;
2727
2728
2729 int i;
2730 int index;
2731
2732 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2733 rwqe = ehea_get_next_rwqe(&qp, 2);
2734 rwqe->sg_list[0].l_key = lkey;
2735 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2736 skb = skba_rq2[index];
2737 if (skb)
2738 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2739 }
2740
2741 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2742 rwqe = ehea_get_next_rwqe(&qp, 3);
2743 rwqe->sg_list[0].l_key = lkey;
2744 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2745 skb = skba_rq3[index];
2746 if (skb)
2747 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2748 }
2749}
2750
2751int ehea_restart_qps(struct net_device *dev)
2752{
2753 struct ehea_port *port = netdev_priv(dev);
2754 struct ehea_adapter *adapter = port->adapter;
2755 int ret = 0;
2756 int i;
2757
Doug Maxey508d2b52008-01-31 20:20:49 -06002758 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002759 u64 hret;
2760 u64 dummy64 = 0;
2761 u16 dummy16 = 0;
2762
2763 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2764 if (!cb0) {
2765 ret = -ENOMEM;
2766 goto out;
2767 }
2768
2769 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2770 struct ehea_port_res *pr = &port->port_res[i];
2771 struct ehea_qp *qp = pr->qp;
2772
2773 ret = ehea_gen_smrs(pr);
2774 if (ret) {
2775 ehea_error("creation of shared memory regions failed");
2776 goto out;
2777 }
2778
2779 ehea_update_rqs(qp, pr);
2780
2781 /* Enable queue pair */
2782 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2783 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2784 cb0);
2785 if (hret != H_SUCCESS) {
2786 ehea_error("query_ehea_qp failed (1)");
2787 goto out;
2788 }
2789
2790 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2791 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2792
2793 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2794 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2795 1), cb0, &dummy64,
2796 &dummy64, &dummy16, &dummy16);
2797 if (hret != H_SUCCESS) {
2798 ehea_error("modify_ehea_qp failed (1)");
2799 goto out;
2800 }
2801
2802 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2803 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2804 cb0);
2805 if (hret != H_SUCCESS) {
2806 ehea_error("query_ehea_qp failed (2)");
2807 goto out;
2808 }
2809
2810 /* refill entire queue */
2811 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2812 ehea_refill_rq2(pr, 0);
2813 ehea_refill_rq3(pr, 0);
2814 }
2815out:
2816 kfree(cb0);
2817
2818 return ret;
2819}
2820
David Howellsc4028952006-11-22 14:57:56 +00002821static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002822{
2823 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002824 struct ehea_port *port =
2825 container_of(work, struct ehea_port, reset_task);
2826 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002827
2828 port->resets++;
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002829 mutex_lock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002830 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002831
2832 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002833
Thomas Klein44c82152007-07-11 16:32:00 +02002834 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002835
2836 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002837 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002838 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002839
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002840 ehea_set_multicast_list(dev);
2841
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002842 if (netif_msg_timer(port))
2843 ehea_info("Device %s resetted successfully", dev->name);
2844
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002845 port_napi_enable(port);
2846
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002847 netif_wake_queue(dev);
2848out:
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002849 mutex_unlock(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002850 return;
2851}
2852
Thomas Klein44c82152007-07-11 16:32:00 +02002853static void ehea_rereg_mrs(struct work_struct *work)
2854{
2855 int ret, i;
2856 struct ehea_adapter *adapter;
2857
Daniel Walker06f89ed2008-03-28 14:41:26 -07002858 mutex_lock(&dlpar_mem_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002859 ehea_info("LPAR memory enlarged - re-initializing driver");
2860
2861 list_for_each_entry(adapter, &adapter_list, list)
2862 if (adapter->active_ports) {
2863 /* Shutdown all ports */
2864 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2865 struct ehea_port *port = adapter->port[i];
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002866 struct net_device *dev;
Thomas Klein44c82152007-07-11 16:32:00 +02002867
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002868 if (!port)
2869 continue;
Thomas Klein44c82152007-07-11 16:32:00 +02002870
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002871 dev = port->netdev;
2872
2873 if (dev->flags & IFF_UP) {
2874 mutex_lock(&port->port_lock);
2875 netif_stop_queue(dev);
David S. Millerdf39e8b2008-04-14 02:30:23 -07002876 ehea_flush_sq(port);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002877 ret = ehea_stop_qps(dev);
2878 if (ret) {
2879 mutex_unlock(&port->port_lock);
2880 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02002881 }
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002882 port_napi_disable(port);
2883 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002884 }
2885 }
2886
2887 /* Unregister old memory region */
2888 ret = ehea_rem_mr(&adapter->mr);
2889 if (ret) {
2890 ehea_error("unregister MR failed - driver"
2891 " inoperable!");
2892 goto out;
2893 }
2894 }
2895
2896 ehea_destroy_busmap();
Thomas Klein44c82152007-07-11 16:32:00 +02002897 ret = ehea_create_busmap();
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002898 if (ret) {
2899 ehea_error("creating ehea busmap failed");
Thomas Klein44c82152007-07-11 16:32:00 +02002900 goto out;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002901 }
Thomas Klein44c82152007-07-11 16:32:00 +02002902
2903 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2904
2905 list_for_each_entry(adapter, &adapter_list, list)
2906 if (adapter->active_ports) {
2907 /* Register new memory region */
2908 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2909 if (ret) {
2910 ehea_error("register MR failed - driver"
2911 " inoperable!");
2912 goto out;
2913 }
2914
2915 /* Restart all ports */
2916 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2917 struct ehea_port *port = adapter->port[i];
2918
2919 if (port) {
2920 struct net_device *dev = port->netdev;
2921
2922 if (dev->flags & IFF_UP) {
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002923 mutex_lock(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002924 port_napi_enable(port);
2925 ret = ehea_restart_qps(dev);
2926 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02002927 netif_wake_queue(dev);
Daniel Walkera5af6ad2008-03-28 14:41:28 -07002928 mutex_unlock(&port->port_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002929 }
2930 }
2931 }
2932 }
Daniel Walker06f89ed2008-03-28 14:41:26 -07002933 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002934 ehea_info("re-initializing driver complete");
Thomas Klein44c82152007-07-11 16:32:00 +02002935out:
2936 return;
2937}
2938
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002939static void ehea_tx_watchdog(struct net_device *dev)
2940{
2941 struct ehea_port *port = netdev_priv(dev);
2942
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002943 if (netif_carrier_ok(dev) &&
2944 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02002945 schedule_work(&port->reset_task);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002946}
2947
2948int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2949{
2950 struct hcp_query_ehea *cb;
2951 u64 hret;
2952 int ret;
2953
Thomas Kleina1d261c2006-11-03 17:48:23 +01002954 cb = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002955 if (!cb) {
2956 ret = -ENOMEM;
2957 goto out;
2958 }
2959
2960 hret = ehea_h_query_ehea(adapter->handle, cb);
2961
2962 if (hret != H_SUCCESS) {
2963 ret = -EIO;
2964 goto out_herr;
2965 }
2966
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002967 adapter->max_mc_mac = cb->max_mc_mac - 1;
2968 ret = 0;
2969
2970out_herr:
2971 kfree(cb);
2972out:
2973 return ret;
2974}
2975
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002976int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
2977{
2978 struct hcp_ehea_port_cb4 *cb4;
2979 u64 hret;
2980 int ret = 0;
2981
2982 *jumbo = 0;
2983
2984 /* (Try to) enable *jumbo frames */
2985 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2986 if (!cb4) {
2987 ehea_error("no mem for cb4");
2988 ret = -ENOMEM;
2989 goto out;
2990 } else {
2991 hret = ehea_h_query_ehea_port(port->adapter->handle,
2992 port->logical_port_id,
2993 H_PORT_CB4,
2994 H_PORT_CB4_JUMBO, cb4);
2995 if (hret == H_SUCCESS) {
2996 if (cb4->jumbo_frame)
2997 *jumbo = 1;
2998 else {
2999 cb4->jumbo_frame = 1;
3000 hret = ehea_h_modify_ehea_port(port->adapter->
3001 handle,
3002 port->
3003 logical_port_id,
3004 H_PORT_CB4,
3005 H_PORT_CB4_JUMBO,
3006 cb4);
3007 if (hret == H_SUCCESS)
3008 *jumbo = 1;
3009 }
3010 } else
3011 ret = -EINVAL;
3012
3013 kfree(cb4);
3014 }
3015out:
3016 return ret;
3017}
3018
3019static ssize_t ehea_show_port_id(struct device *dev,
3020 struct device_attribute *attr, char *buf)
3021{
3022 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003023 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003024}
3025
3026static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3027 NULL);
3028
3029static void __devinit logical_port_release(struct device *dev)
3030{
3031 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
3032 of_node_put(port->ofdev.node);
3033}
3034
3035static struct device *ehea_register_port(struct ehea_port *port,
3036 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003037{
3038 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003039
3040 port->ofdev.node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003041 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003042 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003043
Thomas Kleind1dea382007-04-26 11:56:13 +02003044 sprintf(port->ofdev.dev.bus_id, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003045 port->ofdev.dev.release = logical_port_release;
3046
3047 ret = of_device_register(&port->ofdev);
3048 if (ret) {
3049 ehea_error("failed to register device. ret=%d", ret);
3050 goto out;
3051 }
3052
3053 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003054 if (ret) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003055 ehea_error("failed to register attributes, ret=%d", ret);
3056 goto out_unreg_of_dev;
3057 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003058
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003059 return &port->ofdev.dev;
3060
3061out_unreg_of_dev:
3062 of_device_unregister(&port->ofdev);
3063out:
3064 return NULL;
3065}
3066
3067static void ehea_unregister_port(struct ehea_port *port)
3068{
3069 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3070 of_device_unregister(&port->ofdev);
3071}
3072
3073struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3074 u32 logical_port_id,
3075 struct device_node *dn)
3076{
3077 int ret;
3078 struct net_device *dev;
3079 struct ehea_port *port;
3080 struct device *port_dev;
3081 int jumbo;
3082
3083 /* allocate memory for the port structures */
3084 dev = alloc_etherdev(sizeof(struct ehea_port));
3085
3086 if (!dev) {
3087 ehea_error("no mem for net_device");
3088 ret = -ENOMEM;
3089 goto out_err;
3090 }
3091
3092 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003093
Daniel Walkera5af6ad2008-03-28 14:41:28 -07003094 mutex_init(&port->port_lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003095 port->state = EHEA_PORT_DOWN;
3096 port->sig_comp_iv = sq_entries / 10;
3097
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003098 port->adapter = adapter;
3099 port->netdev = dev;
3100 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003101
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003102 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003103
3104 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3105 if (!port->mc_list) {
3106 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003107 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003108 }
3109
3110 INIT_LIST_HEAD(&port->mc_list->list);
3111
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003112 ret = ehea_sense_port_attr(port);
3113 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003114 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003115
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003116 port_dev = ehea_register_port(port, dn);
3117 if (!port_dev)
3118 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003119
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003120 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003121
3122 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003123 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3124
3125 dev->open = ehea_open;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +02003126#ifdef CONFIG_NET_POLL_CONTROLLER
3127 dev->poll_controller = ehea_netpoll;
3128#endif
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003129 dev->stop = ehea_stop;
3130 dev->hard_start_xmit = ehea_start_xmit;
3131 dev->get_stats = ehea_get_stats;
3132 dev->set_multicast_list = ehea_set_multicast_list;
3133 dev->set_mac_address = ehea_set_mac_addr;
3134 dev->change_mtu = ehea_change_mtu;
3135 dev->vlan_rx_register = ehea_vlan_rx_register;
3136 dev->vlan_rx_add_vid = ehea_vlan_rx_add_vid;
3137 dev->vlan_rx_kill_vid = ehea_vlan_rx_kill_vid;
3138 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003139 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003140 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3141 | NETIF_F_LLTX;
3142 dev->tx_timeout = &ehea_tx_watchdog;
3143 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3144
David Howellsc4028952006-11-22 14:57:56 +00003145 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003146 ehea_set_ethtool_ops(dev);
3147
3148 ret = register_netdev(dev);
3149 if (ret) {
3150 ehea_error("register_netdev failed. ret=%d", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003151 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003152 }
3153
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003154 port->lro_max_aggr = lro_max_aggr;
3155
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003156 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003157 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003158 ehea_error("failed determining jumbo frame status for %s",
3159 port->netdev->name);
3160
Thomas Klein9c750b72007-01-29 18:44:01 +01003161 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3162 jumbo == 1 ? "en" : "dis");
3163
Thomas Klein44c82152007-07-11 16:32:00 +02003164 adapter->active_ports++;
3165
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003166 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003167
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003168out_unreg_port:
3169 ehea_unregister_port(port);
3170
3171out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003172 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003173
3174out_free_ethdev:
3175 free_netdev(dev);
3176
3177out_err:
3178 ehea_error("setting up logical port with id=%d failed, ret=%d",
3179 logical_port_id, ret);
3180 return NULL;
3181}
3182
3183static void ehea_shutdown_single_port(struct ehea_port *port)
3184{
Brian King7fb1c2a2008-05-14 09:48:25 -05003185 struct ehea_adapter *adapter = port->adapter;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003186 unregister_netdev(port->netdev);
3187 ehea_unregister_port(port);
3188 kfree(port->mc_list);
3189 free_netdev(port->netdev);
Brian King7fb1c2a2008-05-14 09:48:25 -05003190 adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003191}
3192
3193static int ehea_setup_ports(struct ehea_adapter *adapter)
3194{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003195 struct device_node *lhea_dn;
3196 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003197
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003198 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003199 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003200
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003201 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003202 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003203
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003204 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003205 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003206 if (!dn_log_port_id) {
3207 ehea_error("bad device node: eth_dn name=%s",
3208 eth_dn->full_name);
3209 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003210 }
3211
Thomas Klein1211bb62007-04-26 11:56:43 +02003212 if (ehea_add_adapter_mr(adapter)) {
3213 ehea_error("creating MR failed");
3214 of_node_put(eth_dn);
3215 return -EIO;
3216 }
3217
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003218 adapter->port[i] = ehea_setup_single_port(adapter,
3219 *dn_log_port_id,
3220 eth_dn);
3221 if (adapter->port[i])
3222 ehea_info("%s -> logical port id #%d",
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003223 adapter->port[i]->netdev->name,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003224 *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003225 else
3226 ehea_remove_adapter_mr(adapter);
3227
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003228 i++;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003229 };
Thomas Klein1211bb62007-04-26 11:56:43 +02003230 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003231}
3232
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003233static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3234 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003235{
3236 struct device_node *lhea_dn;
3237 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003238 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003239
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003240 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003241 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003242
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003243 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003244 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003245 if (dn_log_port_id)
3246 if (*dn_log_port_id == logical_port_id)
3247 return eth_dn;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003248 };
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003249
3250 return NULL;
3251}
3252
3253static ssize_t ehea_probe_port(struct device *dev,
3254 struct device_attribute *attr,
3255 const char *buf, size_t count)
3256{
3257 struct ehea_adapter *adapter = dev->driver_data;
3258 struct ehea_port *port;
3259 struct device_node *eth_dn = NULL;
3260 int i;
3261
3262 u32 logical_port_id;
3263
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003264 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003265
3266 port = ehea_get_port(adapter, logical_port_id);
3267
3268 if (port) {
3269 ehea_info("adding port with logical port id=%d failed. port "
3270 "already configured as %s.", logical_port_id,
3271 port->netdev->name);
3272 return -EINVAL;
3273 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003274
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003275 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3276
3277 if (!eth_dn) {
3278 ehea_info("no logical port with id %d found", logical_port_id);
3279 return -EINVAL;
3280 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003281
Thomas Klein1211bb62007-04-26 11:56:43 +02003282 if (ehea_add_adapter_mr(adapter)) {
3283 ehea_error("creating MR failed");
3284 return -EIO;
3285 }
3286
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003287 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3288
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003289 of_node_put(eth_dn);
3290
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003291 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003292 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003293 if (!adapter->port[i]) {
3294 adapter->port[i] = port;
3295 break;
3296 }
3297
3298 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3299 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003300 } else {
3301 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003302 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003303 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003304
3305 return (ssize_t) count;
3306}
3307
3308static ssize_t ehea_remove_port(struct device *dev,
3309 struct device_attribute *attr,
3310 const char *buf, size_t count)
3311{
3312 struct ehea_adapter *adapter = dev->driver_data;
3313 struct ehea_port *port;
3314 int i;
3315 u32 logical_port_id;
3316
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003317 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003318
3319 port = ehea_get_port(adapter, logical_port_id);
3320
3321 if (port) {
3322 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3323 logical_port_id);
3324
3325 ehea_shutdown_single_port(port);
3326
Doug Maxey508d2b52008-01-31 20:20:49 -06003327 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003328 if (adapter->port[i] == port) {
3329 adapter->port[i] = NULL;
3330 break;
3331 }
3332 } else {
3333 ehea_error("removing port with logical port id=%d failed. port "
3334 "not configured.", logical_port_id);
3335 return -EINVAL;
3336 }
3337
Thomas Klein1211bb62007-04-26 11:56:43 +02003338 ehea_remove_adapter_mr(adapter);
3339
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003340 return (ssize_t) count;
3341}
3342
3343static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3344static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3345
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003346int ehea_create_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003347{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003348 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003349 if (ret)
3350 goto out;
3351
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003352 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003353out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003354 return ret;
3355}
3356
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003357void ehea_remove_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003358{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003359 device_remove_file(&dev->dev, &dev_attr_probe_port);
3360 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003361}
3362
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003363static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003364 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003365{
3366 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003367 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003368 int ret;
3369
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003370 if (!dev || !dev->node) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003371 ehea_error("Invalid ibmebus device probed");
3372 return -EINVAL;
3373 }
Daniel Walker9f71a562008-03-28 14:41:26 -07003374 mutex_lock(&ehea_fw_handles.lock);
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003375
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003376 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3377 if (!adapter) {
3378 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003379 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003380 goto out;
3381 }
3382
Thomas Klein44c82152007-07-11 16:32:00 +02003383 list_add(&adapter->list, &adapter_list);
3384
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003385 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003386
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003387 adapter_handle = of_get_property(dev->node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003388 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003389 if (adapter_handle)
3390 adapter->handle = *adapter_handle;
3391
3392 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003393 dev_err(&dev->dev, "failed getting handle for adapter"
3394 " '%s'\n", dev->node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003395 ret = -ENODEV;
3396 goto out_free_ad;
3397 }
3398
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003399 adapter->pd = EHEA_PD_ID;
3400
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003401 dev->dev.driver_data = adapter;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003402
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003403
3404 /* initialize adapter and ports */
3405 /* get adapter properties */
3406 ret = ehea_sense_adapter_attr(adapter);
3407 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003408 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003409 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003410 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003411
3412 adapter->neq = ehea_create_eq(adapter,
3413 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3414 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003415 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003416 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003417 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003418 }
3419
3420 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3421 (unsigned long)adapter);
3422
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003423 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003424 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003425 "ehea_neq", adapter);
3426 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003427 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003428 goto out_kill_eq;
3429 }
3430
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003431 ret = ehea_create_device_sysfs(dev);
3432 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003433 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003434
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003435 ret = ehea_setup_ports(adapter);
3436 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003437 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003438 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003439 }
3440
3441 ret = 0;
3442 goto out;
3443
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003444out_rem_dev_sysfs:
3445 ehea_remove_device_sysfs(dev);
3446
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003447out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003448 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003449
3450out_kill_eq:
3451 ehea_destroy_eq(adapter->neq);
3452
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003453out_free_ad:
3454 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003455
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003456out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003457 ehea_update_firmware_handles();
Daniel Walker9f71a562008-03-28 14:41:26 -07003458 mutex_unlock(&ehea_fw_handles.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003459 return ret;
3460}
3461
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003462static int __devexit ehea_remove(struct of_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003463{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003464 struct ehea_adapter *adapter = dev->dev.driver_data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003465 int i;
3466
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003467 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003468 if (adapter->port[i]) {
3469 ehea_shutdown_single_port(adapter->port[i]);
3470 adapter->port[i] = NULL;
3471 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003472
3473 ehea_remove_device_sysfs(dev);
3474
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003475 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003476
Daniel Walker9f71a562008-03-28 14:41:26 -07003477 mutex_lock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003478
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003479 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003480 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003481
3482 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003483 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003484 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003485 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003486
Thomas Klein21eee2d2008-02-13 16:18:33 +01003487 ehea_update_firmware_handles();
Daniel Walker9f71a562008-03-28 14:41:26 -07003488 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003489
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003490 return 0;
3491}
3492
Thomas Klein21eee2d2008-02-13 16:18:33 +01003493void ehea_crash_handler(void)
3494{
3495 int i;
3496
3497 if (ehea_fw_handles.arr)
3498 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3499 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3500 ehea_fw_handles.arr[i].fwh,
3501 FORCE_FREE);
3502
3503 if (ehea_bcmc_regs.arr)
3504 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3505 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3506 ehea_bcmc_regs.arr[i].port_id,
3507 ehea_bcmc_regs.arr[i].reg_type,
3508 ehea_bcmc_regs.arr[i].macaddr,
3509 0, H_DEREG_BCMC);
3510}
3511
Hannes Hering48cfb142008-05-07 14:43:36 +02003512static int ehea_mem_notifier(struct notifier_block *nb,
3513 unsigned long action, void *data)
3514{
3515 switch (action) {
3516 case MEM_OFFLINE:
3517 ehea_info("memory has been removed");
3518 ehea_rereg_mrs(NULL);
3519 break;
3520 default:
3521 break;
3522 }
3523 return NOTIFY_OK;
3524}
3525
3526static struct notifier_block ehea_mem_nb = {
3527 .notifier_call = ehea_mem_notifier,
3528};
3529
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003530static int ehea_reboot_notifier(struct notifier_block *nb,
3531 unsigned long action, void *unused)
3532{
3533 if (action == SYS_RESTART) {
3534 ehea_info("Reboot: freeing all eHEA resources");
3535 ibmebus_unregister_driver(&ehea_driver);
3536 }
3537 return NOTIFY_DONE;
3538}
3539
3540static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003541 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003542};
3543
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003544static int check_module_parm(void)
3545{
3546 int ret = 0;
3547
3548 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3549 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
3550 ehea_info("Bad parameter: rq1_entries");
3551 ret = -EINVAL;
3552 }
3553 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3554 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
3555 ehea_info("Bad parameter: rq2_entries");
3556 ret = -EINVAL;
3557 }
3558 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3559 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
3560 ehea_info("Bad parameter: rq3_entries");
3561 ret = -EINVAL;
3562 }
3563 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3564 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
3565 ehea_info("Bad parameter: sq_entries");
3566 ret = -EINVAL;
3567 }
3568
3569 return ret;
3570}
3571
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003572static ssize_t ehea_show_capabilities(struct device_driver *drv,
3573 char *buf)
3574{
3575 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3576}
3577
3578static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3579 ehea_show_capabilities, NULL);
3580
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003581int __init ehea_module_init(void)
3582{
3583 int ret;
3584
3585 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3586 DRV_VERSION);
3587
Thomas Klein44c82152007-07-11 16:32:00 +02003588
3589 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003590 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3591 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3592
Daniel Walker9f71a562008-03-28 14:41:26 -07003593 mutex_init(&ehea_fw_handles.lock);
Jan-Bernd Themann5c2cec12008-07-03 15:18:45 +01003594 spin_lock_init(&ehea_bcmc_regs.lock);
Thomas Klein44c82152007-07-11 16:32:00 +02003595
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003596 ret = check_module_parm();
3597 if (ret)
3598 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003599
3600 ret = ehea_create_busmap();
3601 if (ret)
3602 goto out;
3603
Thomas Klein21eee2d2008-02-13 16:18:33 +01003604 ret = register_reboot_notifier(&ehea_reboot_nb);
3605 if (ret)
3606 ehea_info("failed registering reboot notifier");
3607
Hannes Hering48cfb142008-05-07 14:43:36 +02003608 ret = register_memory_notifier(&ehea_mem_nb);
3609 if (ret)
3610 ehea_info("failed registering memory remove notifier");
3611
Thomas Klein21eee2d2008-02-13 16:18:33 +01003612 ret = crash_shutdown_register(&ehea_crash_handler);
3613 if (ret)
3614 ehea_info("failed registering crash handler");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003615
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003616 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003617 if (ret) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003618 ehea_error("failed registering eHEA device driver on ebus");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003619 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003620 }
3621
3622 ret = driver_create_file(&ehea_driver.driver,
3623 &driver_attr_capabilities);
3624 if (ret) {
3625 ehea_error("failed to register capabilities attribute, ret=%d",
3626 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003627 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003628 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003629
Thomas Klein21eee2d2008-02-13 16:18:33 +01003630 return ret;
3631
3632out3:
3633 ibmebus_unregister_driver(&ehea_driver);
3634out2:
Hannes Hering48cfb142008-05-07 14:43:36 +02003635 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003636 unregister_reboot_notifier(&ehea_reboot_nb);
3637 crash_shutdown_unregister(&ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003638out:
3639 return ret;
3640}
3641
3642static void __exit ehea_module_exit(void)
3643{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003644 int ret;
3645
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003646 flush_scheduled_work();
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003647 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003648 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003649 unregister_reboot_notifier(&ehea_reboot_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003650 ret = crash_shutdown_unregister(&ehea_crash_handler);
3651 if (ret)
3652 ehea_info("failed unregistering crash handler");
Hannes Hering48cfb142008-05-07 14:43:36 +02003653 unregister_memory_notifier(&ehea_mem_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003654 kfree(ehea_fw_handles.arr);
3655 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003656 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003657}
3658
3659module_init(ehea_module_init);
3660module_exit(ehea_module_exit);