blob: f460b623c0771356acca11780e06b62efac2e0c4 [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>
Thomas Klein21eee2d2008-02-13 16:18:33 +010038#include <asm/kexec.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020039
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020040#include <net/ip.h>
41
42#include "ehea.h"
43#include "ehea_qmr.h"
44#include "ehea_phyp.h"
45
46
47MODULE_LICENSE("GPL");
48MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
49MODULE_DESCRIPTION("IBM eServer HEA Driver");
50MODULE_VERSION(DRV_VERSION);
51
52
53static int msg_level = -1;
54static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
55static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
56static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
57static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Doug Maxey508d2b52008-01-31 20:20:49 -060058static int use_mcs;
59static int use_lro;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070060static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010061static int num_tx_qps = EHEA_NUM_TX_QP;
Doug Maxey508d2b52008-01-31 20:20:49 -060062static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020063
64module_param(msg_level, int, 0);
65module_param(rq1_entries, int, 0);
66module_param(rq2_entries, int, 0);
67module_param(rq3_entries, int, 0);
68module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020069module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010070module_param(use_mcs, int, 0);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070071module_param(use_lro, int, 0);
72module_param(lro_max_aggr, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010073module_param(num_tx_qps, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020074
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010075MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020076MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020077MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
78 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020079MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
80 "[2^x - 1], x = [6..14]. Default = "
81 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
82MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
83 "[2^x - 1], x = [6..14]. Default = "
84 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
85MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
86 "[2^x - 1], x = [6..14]. Default = "
87 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
88MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
89 "[2^x - 1], x = [6..14]. Default = "
90 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Jan-Bernd Themann18072a52007-08-22 16:21:24 +020091MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020092
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070093MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
94 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
95MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
96 "Default = 0");
97
Doug Maxey508d2b52008-01-31 20:20:49 -060098static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +020099static LIST_HEAD(adapter_list);
Doug Maxey508d2b52008-01-31 20:20:49 -0600100u64 ehea_driver_flags;
Thomas Klein44c82152007-07-11 16:32:00 +0200101struct work_struct ehea_rereg_mr_task;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200102struct semaphore dlpar_mem_lock;
Thomas Klein21eee2d2008-02-13 16:18:33 +0100103struct ehea_fw_handle_array ehea_fw_handles;
104struct ehea_bcmc_reg_array ehea_bcmc_regs;
105
Thomas Kleind1dea382007-04-26 11:56:13 +0200106
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000107static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200108 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200109
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000110static int __devexit ehea_remove(struct of_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200111
112static struct of_device_id ehea_device_table[] = {
113 {
114 .name = "lhea",
115 .compatible = "IBM,lhea",
116 },
117 {},
118};
119
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000120static struct of_platform_driver ehea_driver = {
Thomas Kleind1dea382007-04-26 11:56:13 +0200121 .name = "ehea",
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000122 .match_table = ehea_device_table,
Thomas Kleind1dea382007-04-26 11:56:13 +0200123 .probe = ehea_probe_adapter,
124 .remove = ehea_remove,
125};
126
Doug Maxey508d2b52008-01-31 20:20:49 -0600127void ehea_dump(void *adr, int len, char *msg)
128{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200129 int x;
130 unsigned char *deb = adr;
131 for (x = 0; x < len; x += 16) {
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100132 printk(DRV_NAME " %s adr=%p ofs=%04x %016lx %016lx\n", msg,
Doug Maxey508d2b52008-01-31 20:20:49 -0600133 deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200134 deb += 16;
135 }
136}
137
Thomas Klein21eee2d2008-02-13 16:18:33 +0100138static void ehea_update_firmware_handles(void)
139{
140 struct ehea_fw_handle_entry *arr = NULL;
141 struct ehea_adapter *adapter;
142 int num_adapters = 0;
143 int num_ports = 0;
144 int num_portres = 0;
145 int i = 0;
146 int num_fw_handles, k, l;
147
148 /* Determine number of handles */
149 list_for_each_entry(adapter, &adapter_list, list) {
150 num_adapters++;
151
152 for (k = 0; k < EHEA_MAX_PORTS; k++) {
153 struct ehea_port *port = adapter->port[k];
154
155 if (!port || (port->state != EHEA_PORT_UP))
156 continue;
157
158 num_ports++;
159 num_portres += port->num_def_qps + port->num_add_tx_qps;
160 }
161 }
162
163 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
164 num_ports * EHEA_NUM_PORT_FW_HANDLES +
165 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
166
167 if (num_fw_handles) {
168 arr = kzalloc(num_fw_handles * sizeof(*arr), GFP_KERNEL);
169 if (!arr)
170 return; /* Keep the existing array */
171 } else
172 goto out_update;
173
174 list_for_each_entry(adapter, &adapter_list, list) {
175 for (k = 0; k < EHEA_MAX_PORTS; k++) {
176 struct ehea_port *port = adapter->port[k];
177
178 if (!port || (port->state != EHEA_PORT_UP))
179 continue;
180
181 for (l = 0;
182 l < port->num_def_qps + port->num_add_tx_qps;
183 l++) {
184 struct ehea_port_res *pr = &port->port_res[l];
185
186 arr[i].adh = adapter->handle;
187 arr[i++].fwh = pr->qp->fw_handle;
188 arr[i].adh = adapter->handle;
189 arr[i++].fwh = pr->send_cq->fw_handle;
190 arr[i].adh = adapter->handle;
191 arr[i++].fwh = pr->recv_cq->fw_handle;
192 arr[i].adh = adapter->handle;
193 arr[i++].fwh = pr->eq->fw_handle;
194 arr[i].adh = adapter->handle;
195 arr[i++].fwh = pr->send_mr.handle;
196 arr[i].adh = adapter->handle;
197 arr[i++].fwh = pr->recv_mr.handle;
198 }
199 arr[i].adh = adapter->handle;
200 arr[i++].fwh = port->qp_eq->fw_handle;
201 }
202
203 arr[i].adh = adapter->handle;
204 arr[i++].fwh = adapter->neq->fw_handle;
205
206 if (adapter->mr.handle) {
207 arr[i].adh = adapter->handle;
208 arr[i++].fwh = adapter->mr.handle;
209 }
210 }
211
212out_update:
213 kfree(ehea_fw_handles.arr);
214 ehea_fw_handles.arr = arr;
215 ehea_fw_handles.num_entries = i;
216}
217
218static void ehea_update_bcmc_registrations(void)
219{
220 struct ehea_bcmc_reg_entry *arr = NULL;
221 struct ehea_adapter *adapter;
222 struct ehea_mc_list *mc_entry;
223 int num_registrations = 0;
224 int i = 0;
225 int k;
226
227 /* Determine number of registrations */
228 list_for_each_entry(adapter, &adapter_list, list)
229 for (k = 0; k < EHEA_MAX_PORTS; k++) {
230 struct ehea_port *port = adapter->port[k];
231
232 if (!port || (port->state != EHEA_PORT_UP))
233 continue;
234
235 num_registrations += 2; /* Broadcast registrations */
236
237 list_for_each_entry(mc_entry, &port->mc_list->list,list)
238 num_registrations += 2;
239 }
240
241 if (num_registrations) {
242 arr = kzalloc(num_registrations * sizeof(*arr), GFP_KERNEL);
243 if (!arr)
244 return; /* Keep the existing array */
245 } else
246 goto out_update;
247
248 list_for_each_entry(adapter, &adapter_list, list) {
249 for (k = 0; k < EHEA_MAX_PORTS; k++) {
250 struct ehea_port *port = adapter->port[k];
251
252 if (!port || (port->state != EHEA_PORT_UP))
253 continue;
254
255 arr[i].adh = adapter->handle;
256 arr[i].port_id = port->logical_port_id;
257 arr[i].reg_type = EHEA_BCMC_BROADCAST |
258 EHEA_BCMC_UNTAGGED;
259 arr[i++].macaddr = port->mac_addr;
260
261 arr[i].adh = adapter->handle;
262 arr[i].port_id = port->logical_port_id;
263 arr[i].reg_type = EHEA_BCMC_BROADCAST |
264 EHEA_BCMC_VLANID_ALL;
265 arr[i++].macaddr = port->mac_addr;
266
267 list_for_each_entry(mc_entry,
268 &port->mc_list->list, list) {
269 arr[i].adh = adapter->handle;
270 arr[i].port_id = port->logical_port_id;
271 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
272 EHEA_BCMC_MULTICAST |
273 EHEA_BCMC_UNTAGGED;
274 arr[i++].macaddr = mc_entry->macaddr;
275
276 arr[i].adh = adapter->handle;
277 arr[i].port_id = port->logical_port_id;
278 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
279 EHEA_BCMC_MULTICAST |
280 EHEA_BCMC_VLANID_ALL;
281 arr[i++].macaddr = mc_entry->macaddr;
282 }
283 }
284 }
285
286out_update:
287 kfree(ehea_bcmc_regs.arr);
288 ehea_bcmc_regs.arr = arr;
289 ehea_bcmc_regs.num_entries = i;
290}
291
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200292static struct net_device_stats *ehea_get_stats(struct net_device *dev)
293{
294 struct ehea_port *port = netdev_priv(dev);
295 struct net_device_stats *stats = &port->stats;
296 struct hcp_ehea_port_cb2 *cb2;
Thomas Klein7393b872007-11-21 17:37:58 +0100297 u64 hret, rx_packets, tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200298 int i;
299
300 memset(stats, 0, sizeof(*stats));
301
Thomas Kleina1d261c2006-11-03 17:48:23 +0100302 cb2 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200303 if (!cb2) {
304 ehea_error("no mem for cb2");
305 goto out;
306 }
307
308 hret = ehea_h_query_ehea_port(port->adapter->handle,
309 port->logical_port_id,
310 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
311 if (hret != H_SUCCESS) {
312 ehea_error("query_ehea_port failed");
313 goto out_herr;
314 }
315
316 if (netif_msg_hw(port))
317 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
318
319 rx_packets = 0;
320 for (i = 0; i < port->num_def_qps; i++)
321 rx_packets += port->port_res[i].rx_packets;
322
Thomas Klein7393b872007-11-21 17:37:58 +0100323 tx_packets = 0;
324 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
325 tx_packets += port->port_res[i].tx_packets;
326
327 stats->tx_packets = tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200328 stats->multicast = cb2->rxmcp;
329 stats->rx_errors = cb2->rxuerr;
330 stats->rx_bytes = cb2->rxo;
331 stats->tx_bytes = cb2->txo;
332 stats->rx_packets = rx_packets;
333
334out_herr:
335 kfree(cb2);
336out:
337 return stats;
338}
339
340static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
341{
342 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
343 struct net_device *dev = pr->port->netdev;
344 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200345 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
346 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200347 int i;
348
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200349 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200350
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200351 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
Thomas Klein44fb3122008-04-04 15:04:53 +0200352 if (nr_of_wqes > 0)
353 pr->rq1_skba.index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200354 pr->rq1_skba.os_skbs = fill_wqes;
355 return;
356 }
357
358 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200359 if (!skb_arr_rq1[index]) {
360 skb_arr_rq1[index] = netdev_alloc_skb(dev,
361 EHEA_L_PKT_SIZE);
362 if (!skb_arr_rq1[index]) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200363 pr->rq1_skba.os_skbs = fill_wqes - i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200364 ehea_error("%s: no mem for skb/%d wqes filled",
365 dev->name, i);
366 break;
367 }
368 }
369 index--;
370 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200371 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200372 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200373
374 if (adder == 0)
375 return;
376
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200377 /* Ring doorbell */
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200378 ehea_update_rq1a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200379}
380
381static int ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
382{
383 int ret = 0;
384 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
385 struct net_device *dev = pr->port->netdev;
386 int i;
387
388 for (i = 0; i < pr->rq1_skba.len; i++) {
389 skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
390 if (!skb_arr_rq1[i]) {
391 ehea_error("%s: no mem for skb/%d wqes filled",
392 dev->name, i);
393 ret = -ENOMEM;
394 goto out;
395 }
396 }
397 /* Ring doorbell */
398 ehea_update_rq1a(pr->qp, nr_rq1a);
399out:
400 return ret;
401}
402
403static int ehea_refill_rq_def(struct ehea_port_res *pr,
404 struct ehea_q_skb_arr *q_skba, int rq_nr,
405 int num_wqes, int wqe_type, int packet_size)
406{
407 struct net_device *dev = pr->port->netdev;
408 struct ehea_qp *qp = pr->qp;
409 struct sk_buff **skb_arr = q_skba->arr;
410 struct ehea_rwqe *rwqe;
411 int i, index, max_index_mask, fill_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200412 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200413 int ret = 0;
414
415 fill_wqes = q_skba->os_skbs + num_wqes;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200416 q_skba->os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200417
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200418 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
419 q_skba->os_skbs = fill_wqes;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200420 return ret;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200421 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200422
423 index = q_skba->index;
424 max_index_mask = q_skba->len - 1;
425 for (i = 0; i < fill_wqes; i++) {
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200426 u64 tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200427 struct sk_buff *skb = netdev_alloc_skb(dev, packet_size);
428 if (!skb) {
429 ehea_error("%s: no mem for skb/%d wqes filled",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100430 pr->port->netdev->name, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200431 q_skba->os_skbs = fill_wqes - i;
432 ret = -ENOMEM;
433 break;
434 }
435 skb_reserve(skb, NET_IP_ALIGN);
436
437 skb_arr[index] = skb;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200438 tmp_addr = ehea_map_vaddr(skb->data);
439 if (tmp_addr == -1) {
440 dev_kfree_skb(skb);
441 q_skba->os_skbs = fill_wqes - i;
442 ret = 0;
443 break;
444 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200445
446 rwqe = ehea_get_next_rwqe(qp, rq_nr);
447 rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200448 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200449 rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200450 rwqe->sg_list[0].vaddr = tmp_addr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200451 rwqe->sg_list[0].len = packet_size;
452 rwqe->data_segments = 1;
453
454 index++;
455 index &= max_index_mask;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200456 adder++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200457 }
Thomas Klein44c82152007-07-11 16:32:00 +0200458
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200459 q_skba->index = index;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200460 if (adder == 0)
461 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200462
463 /* Ring doorbell */
464 iosync();
465 if (rq_nr == 2)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200466 ehea_update_rq2a(pr->qp, adder);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200467 else
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200468 ehea_update_rq3a(pr->qp, adder);
Thomas Klein44c82152007-07-11 16:32:00 +0200469out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200470 return ret;
471}
472
473
474static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
475{
476 return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
477 nr_of_wqes, EHEA_RWQE2_TYPE,
478 EHEA_RQ2_PKT_SIZE + NET_IP_ALIGN);
479}
480
481
482static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
483{
484 return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
485 nr_of_wqes, EHEA_RWQE3_TYPE,
486 EHEA_MAX_PACKET_SIZE + NET_IP_ALIGN);
487}
488
489static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
490{
491 *rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
492 if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
493 return 0;
494 if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
495 (cqe->header_length == 0))
496 return 0;
497 return -EINVAL;
498}
499
500static inline void ehea_fill_skb(struct net_device *dev,
501 struct sk_buff *skb, struct ehea_cqe *cqe)
502{
503 int length = cqe->num_bytes_transfered - 4; /*remove CRC */
504
505 skb_put(skb, length);
506 skb->ip_summed = CHECKSUM_UNNECESSARY;
507 skb->protocol = eth_type_trans(skb, dev);
508}
509
510static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
511 int arr_len,
512 struct ehea_cqe *cqe)
513{
514 int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
515 struct sk_buff *skb;
516 void *pref;
517 int x;
518
519 x = skb_index + 1;
520 x &= (arr_len - 1);
521
522 pref = skb_array[x];
523 prefetchw(pref);
524 prefetchw(pref + EHEA_CACHE_LINE);
525
526 pref = (skb_array[x]->data);
527 prefetch(pref);
528 prefetch(pref + EHEA_CACHE_LINE);
529 prefetch(pref + EHEA_CACHE_LINE * 2);
530 prefetch(pref + EHEA_CACHE_LINE * 3);
531 skb = skb_array[skb_index];
532 skb_array[skb_index] = NULL;
533 return skb;
534}
535
536static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
537 int arr_len, int wqe_index)
538{
539 struct sk_buff *skb;
540 void *pref;
541 int x;
542
543 x = wqe_index + 1;
544 x &= (arr_len - 1);
545
546 pref = skb_array[x];
547 prefetchw(pref);
548 prefetchw(pref + EHEA_CACHE_LINE);
549
550 pref = (skb_array[x]->data);
551 prefetchw(pref);
552 prefetchw(pref + EHEA_CACHE_LINE);
553
554 skb = skb_array[wqe_index];
555 skb_array[wqe_index] = NULL;
556 return skb;
557}
558
559static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
560 struct ehea_cqe *cqe, int *processed_rq2,
561 int *processed_rq3)
562{
563 struct sk_buff *skb;
564
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100565 if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
566 pr->p_stats.err_tcp_cksum++;
567 if (cqe->status & EHEA_CQE_STAT_ERR_IP)
568 pr->p_stats.err_ip_cksum++;
569 if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
570 pr->p_stats.err_frame_crc++;
571
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200572 if (rq == 2) {
573 *processed_rq2 += 1;
574 skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
575 dev_kfree_skb(skb);
576 } else if (rq == 3) {
577 *processed_rq3 += 1;
578 skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
579 dev_kfree_skb(skb);
580 }
581
582 if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
Thomas Klein58dd8252007-11-21 17:42:27 +0100583 if (netif_msg_rx_err(pr->port)) {
584 ehea_error("Critical receive error for QP %d. "
585 "Resetting port.", pr->qp->init_attr.qp_nr);
586 ehea_dump(cqe, sizeof(*cqe), "CQE");
587 }
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +0200588 schedule_work(&pr->port->reset_task);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200589 return 1;
590 }
591
592 return 0;
593}
594
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700595static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
596 void **tcph, u64 *hdr_flags, void *priv)
597{
598 struct ehea_cqe *cqe = priv;
599 unsigned int ip_len;
600 struct iphdr *iph;
601
602 /* non tcp/udp packets */
603 if (!cqe->header_length)
604 return -1;
605
606 /* non tcp packet */
607 skb_reset_network_header(skb);
608 iph = ip_hdr(skb);
609 if (iph->protocol != IPPROTO_TCP)
610 return -1;
611
612 ip_len = ip_hdrlen(skb);
613 skb_set_transport_header(skb, ip_len);
614 *tcph = tcp_hdr(skb);
615
616 /* check if ip header and tcp header are complete */
617 if (iph->tot_len < ip_len + tcp_hdrlen(skb))
618 return -1;
619
620 *hdr_flags = LRO_IPV4 | LRO_TCP;
621 *iphdr = iph;
622
623 return 0;
624}
625
626static void ehea_proc_skb(struct ehea_port_res *pr, struct ehea_cqe *cqe,
627 struct sk_buff *skb)
628{
629 int vlan_extracted = (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
630 && pr->port->vgrp;
631
632 if (use_lro) {
633 if (vlan_extracted)
634 lro_vlan_hwaccel_receive_skb(&pr->lro_mgr, skb,
635 pr->port->vgrp,
636 cqe->vlan_tag,
637 cqe);
638 else
639 lro_receive_skb(&pr->lro_mgr, skb, cqe);
640 } else {
641 if (vlan_extracted)
642 vlan_hwaccel_receive_skb(skb, pr->port->vgrp,
643 cqe->vlan_tag);
644 else
645 netif_receive_skb(skb);
646 }
647}
648
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700649static int ehea_proc_rwqes(struct net_device *dev,
650 struct ehea_port_res *pr,
651 int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200652{
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100653 struct ehea_port *port = pr->port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200654 struct ehea_qp *qp = pr->qp;
655 struct ehea_cqe *cqe;
656 struct sk_buff *skb;
657 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
658 struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
659 struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
660 int skb_arr_rq1_len = pr->rq1_skba.len;
661 int skb_arr_rq2_len = pr->rq2_skba.len;
662 int skb_arr_rq3_len = pr->rq3_skba.len;
663 int processed, processed_rq1, processed_rq2, processed_rq3;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700664 int wqe_index, last_wqe_index, rq, port_reset;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200665
666 processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
667 last_wqe_index = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200668
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200669 cqe = ehea_poll_rq1(qp, &wqe_index);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700670 while ((processed < budget) && cqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200671 ehea_inc_rq1(qp);
672 processed_rq1++;
673 processed++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200674 if (netif_msg_rx_status(port))
675 ehea_dump(cqe, sizeof(*cqe), "CQE");
676
677 last_wqe_index = wqe_index;
678 rmb();
679 if (!ehea_check_cqe(cqe, &rq)) {
Doug Maxey508d2b52008-01-31 20:20:49 -0600680 if (rq == 1) {
681 /* LL RQ1 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200682 skb = get_skb_by_index_ll(skb_arr_rq1,
683 skb_arr_rq1_len,
684 wqe_index);
685 if (unlikely(!skb)) {
686 if (netif_msg_rx_err(port))
687 ehea_error("LL rq1: skb=NULL");
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100688
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700689 skb = netdev_alloc_skb(dev,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200690 EHEA_L_PKT_SIZE);
691 if (!skb)
692 break;
693 }
Doug Maxey508d2b52008-01-31 20:20:49 -0600694 skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200695 cqe->num_bytes_transfered - 4);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700696 ehea_fill_skb(dev, skb, cqe);
Doug Maxey508d2b52008-01-31 20:20:49 -0600697 } else if (rq == 2) {
698 /* RQ2 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200699 skb = get_skb_by_index(skb_arr_rq2,
700 skb_arr_rq2_len, cqe);
701 if (unlikely(!skb)) {
702 if (netif_msg_rx_err(port))
703 ehea_error("rq2: skb=NULL");
704 break;
705 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700706 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200707 processed_rq2++;
Doug Maxey508d2b52008-01-31 20:20:49 -0600708 } else {
709 /* RQ3 */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200710 skb = get_skb_by_index(skb_arr_rq3,
711 skb_arr_rq3_len, cqe);
712 if (unlikely(!skb)) {
713 if (netif_msg_rx_err(port))
714 ehea_error("rq3: skb=NULL");
715 break;
716 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700717 ehea_fill_skb(dev, skb, cqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200718 processed_rq3++;
719 }
720
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700721 ehea_proc_skb(pr, cqe, skb);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700722 dev->last_rx = jiffies;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100723 } else {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100724 pr->p_stats.poll_receive_errors++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200725 port_reset = ehea_treat_poll_error(pr, rq, cqe,
726 &processed_rq2,
727 &processed_rq3);
728 if (port_reset)
729 break;
730 }
731 cqe = ehea_poll_rq1(qp, &wqe_index);
732 }
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -0700733 if (use_lro)
734 lro_flush_all(&pr->lro_mgr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200735
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200736 pr->rx_packets += processed;
737
738 ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
739 ehea_refill_rq2(pr, processed_rq2);
740 ehea_refill_rq3(pr, processed_rq3);
741
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700742 return processed;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200743}
744
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100745static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200746{
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100747 struct sk_buff *skb;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200748 struct ehea_cq *send_cq = pr->send_cq;
749 struct ehea_cqe *cqe;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100750 int quota = my_quota;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200751 int cqe_counter = 0;
752 int swqe_av = 0;
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100753 int index;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200754 unsigned long flags;
755
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100756 cqe = ehea_poll_cq(send_cq);
Doug Maxey508d2b52008-01-31 20:20:49 -0600757 while (cqe && (quota > 0)) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100758 ehea_inc_cq(send_cq);
759
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200760 cqe_counter++;
761 rmb();
762 if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
763 ehea_error("Send Completion Error: Resetting port");
764 if (netif_msg_tx_err(pr->port))
765 ehea_dump(cqe, sizeof(*cqe), "Send CQE");
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +0200766 schedule_work(&pr->port->reset_task);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200767 break;
768 }
769
770 if (netif_msg_tx_done(pr->port))
771 ehea_dump(cqe, sizeof(*cqe), "CQE");
772
773 if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +0100774 == EHEA_SWQE2_TYPE)) {
775
776 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
777 skb = pr->sq_skba.arr[index];
778 dev_kfree_skb(skb);
779 pr->sq_skba.arr[index] = NULL;
780 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200781
782 swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
783 quota--;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100784
785 cqe = ehea_poll_cq(send_cq);
786 };
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200787
788 ehea_update_feca(send_cq, cqe_counter);
789 atomic_add(swqe_av, &pr->swqe_avail);
790
791 spin_lock_irqsave(&pr->netif_queue, flags);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100792
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200793 if (pr->queue_stopped && (atomic_read(&pr->swqe_avail)
794 >= pr->swqe_refill_th)) {
795 netif_wake_queue(pr->port->netdev);
796 pr->queue_stopped = 0;
797 }
798 spin_unlock_irqrestore(&pr->netif_queue, flags);
799
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100800 return cqe;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200801}
802
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100803#define EHEA_NAPI_POLL_NUM_BEFORE_IRQ 16
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700804#define EHEA_POLL_MAX_CQES 65535
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100805
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700806static int ehea_poll(struct napi_struct *napi, int budget)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200807{
Doug Maxey508d2b52008-01-31 20:20:49 -0600808 struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
809 napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700810 struct net_device *dev = pr->port->netdev;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100811 struct ehea_cqe *cqe;
812 struct ehea_cqe *cqe_skb = NULL;
813 int force_irq, wqe_index;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700814 int rx = 0;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100815
816 force_irq = (pr->poll_counter > EHEA_NAPI_POLL_NUM_BEFORE_IRQ);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700817 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100818
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700819 if (!force_irq)
820 rx += ehea_proc_rwqes(dev, pr, budget - rx);
821
822 while ((rx != budget) || force_irq) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100823 pr->poll_counter = 0;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700824 force_irq = 0;
825 netif_rx_complete(dev, napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100826 ehea_reset_cq_ep(pr->recv_cq);
827 ehea_reset_cq_ep(pr->send_cq);
828 ehea_reset_cq_n1(pr->recv_cq);
829 ehea_reset_cq_n1(pr->send_cq);
830 cqe = ehea_poll_rq1(pr->qp, &wqe_index);
831 cqe_skb = ehea_poll_cq(pr->send_cq);
832
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100833 if (!cqe && !cqe_skb)
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700834 return rx;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100835
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700836 if (!netif_rx_reschedule(dev, napi))
837 return rx;
838
839 cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
840 rx += ehea_proc_rwqes(dev, pr, budget - rx);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100841 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +0100842
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700843 pr->poll_counter++;
844 return rx;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200845}
846
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200847#ifdef CONFIG_NET_POLL_CONTROLLER
848static void ehea_netpoll(struct net_device *dev)
849{
850 struct ehea_port *port = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700851 int i;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200852
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700853 for (i = 0; i < port->num_def_qps; i++)
854 netif_rx_schedule(dev, &port->port_res[i].napi);
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +0200855}
856#endif
857
David Howells7d12e782006-10-05 14:55:46 +0100858static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200859{
860 struct ehea_port_res *pr = param;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100861
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700862 netif_rx_schedule(pr->port->netdev, &pr->napi);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100863
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200864 return IRQ_HANDLED;
865}
866
David Howells7d12e782006-10-05 14:55:46 +0100867static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200868{
869 struct ehea_port *port = param;
870 struct ehea_eqe *eqe;
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100871 struct ehea_qp *qp;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200872 u32 qp_token;
873
874 eqe = ehea_poll_eq(port->qp_eq);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100875
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200876 while (eqe) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200877 qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100878 ehea_error("QP aff_err: entry=0x%lx, token=0x%x",
879 eqe->entry, qp_token);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100880
881 qp = port->port_res[qp_token].qp;
882 ehea_error_data(port->adapter, qp->fw_handle);
Thomas Kleinbb3a6442007-01-22 12:54:50 +0100883 eqe = ehea_poll_eq(port->qp_eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200884 }
885
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +0200886 schedule_work(&port->reset_task);
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100887
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200888 return IRQ_HANDLED;
889}
890
891static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
892 int logical_port)
893{
894 int i;
895
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +0100896 for (i = 0; i < EHEA_MAX_PORTS; i++)
Thomas Klein41b69c72007-01-22 12:55:20 +0100897 if (adapter->port[i])
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200898 if (adapter->port[i]->logical_port_id == logical_port)
Thomas Klein41b69c72007-01-22 12:55:20 +0100899 return adapter->port[i];
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200900 return NULL;
901}
902
903int ehea_sense_port_attr(struct ehea_port *port)
904{
905 int ret;
906 u64 hret;
907 struct hcp_ehea_port_cb0 *cb0;
908
Doug Maxey508d2b52008-01-31 20:20:49 -0600909 /* may be called via ehea_neq_tasklet() */
910 cb0 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
911 if (!cb0) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200912 ehea_error("no mem for cb0");
913 ret = -ENOMEM;
914 goto out;
915 }
916
917 hret = ehea_h_query_ehea_port(port->adapter->handle,
918 port->logical_port_id, H_PORT_CB0,
919 EHEA_BMASK_SET(H_PORT_CB0_ALL, 0xFFFF),
920 cb0);
921 if (hret != H_SUCCESS) {
922 ret = -EIO;
923 goto out_free;
924 }
925
926 /* MAC address */
927 port->mac_addr = cb0->port_mac_addr << 16;
928
Doug Maxey508d2b52008-01-31 20:20:49 -0600929 if (!is_valid_ether_addr((u8 *)&port->mac_addr)) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200930 ret = -EADDRNOTAVAIL;
931 goto out_free;
932 }
933
934 /* Port speed */
935 switch (cb0->port_speed) {
936 case H_SPEED_10M_H:
937 port->port_speed = EHEA_SPEED_10M;
938 port->full_duplex = 0;
939 break;
940 case H_SPEED_10M_F:
941 port->port_speed = EHEA_SPEED_10M;
942 port->full_duplex = 1;
943 break;
944 case H_SPEED_100M_H:
945 port->port_speed = EHEA_SPEED_100M;
946 port->full_duplex = 0;
947 break;
948 case H_SPEED_100M_F:
949 port->port_speed = EHEA_SPEED_100M;
950 port->full_duplex = 1;
951 break;
952 case H_SPEED_1G_F:
953 port->port_speed = EHEA_SPEED_1G;
954 port->full_duplex = 1;
955 break;
956 case H_SPEED_10G_F:
957 port->port_speed = EHEA_SPEED_10G;
958 port->full_duplex = 1;
959 break;
960 default:
961 port->port_speed = 0;
962 port->full_duplex = 0;
963 break;
964 }
965
Thomas Kleine919b592007-01-22 12:53:20 +0100966 port->autoneg = 1;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100967 port->num_mcs = cb0->num_default_qps;
Thomas Kleine919b592007-01-22 12:53:20 +0100968
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200969 /* Number of default QPs */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100970 if (use_mcs)
971 port->num_def_qps = cb0->num_default_qps;
972 else
973 port->num_def_qps = 1;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200974
975 if (!port->num_def_qps) {
976 ret = -EINVAL;
977 goto out_free;
978 }
979
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100980 port->num_tx_qps = num_tx_qps;
981
982 if (port->num_def_qps >= port->num_tx_qps)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200983 port->num_add_tx_qps = 0;
984 else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +0100985 port->num_add_tx_qps = port->num_tx_qps - port->num_def_qps;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200986
987 ret = 0;
988out_free:
989 if (ret || netif_msg_probe(port))
990 ehea_dump(cb0, sizeof(*cb0), "ehea_sense_port_attr");
991 kfree(cb0);
992out:
993 return ret;
994}
995
996int ehea_set_portspeed(struct ehea_port *port, u32 port_speed)
997{
998 struct hcp_ehea_port_cb4 *cb4;
999 u64 hret;
1000 int ret = 0;
1001
Thomas Kleina1d261c2006-11-03 17:48:23 +01001002 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001003 if (!cb4) {
1004 ehea_error("no mem for cb4");
1005 ret = -ENOMEM;
1006 goto out;
1007 }
1008
1009 cb4->port_speed = port_speed;
1010
1011 netif_carrier_off(port->netdev);
1012
1013 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1014 port->logical_port_id,
1015 H_PORT_CB4, H_PORT_CB4_SPEED, cb4);
1016 if (hret == H_SUCCESS) {
1017 port->autoneg = port_speed == EHEA_SPEED_AUTONEG ? 1 : 0;
1018
1019 hret = ehea_h_query_ehea_port(port->adapter->handle,
1020 port->logical_port_id,
1021 H_PORT_CB4, H_PORT_CB4_SPEED,
1022 cb4);
1023 if (hret == H_SUCCESS) {
1024 switch (cb4->port_speed) {
1025 case H_SPEED_10M_H:
1026 port->port_speed = EHEA_SPEED_10M;
1027 port->full_duplex = 0;
1028 break;
1029 case H_SPEED_10M_F:
1030 port->port_speed = EHEA_SPEED_10M;
1031 port->full_duplex = 1;
1032 break;
1033 case H_SPEED_100M_H:
1034 port->port_speed = EHEA_SPEED_100M;
1035 port->full_duplex = 0;
1036 break;
1037 case H_SPEED_100M_F:
1038 port->port_speed = EHEA_SPEED_100M;
1039 port->full_duplex = 1;
1040 break;
1041 case H_SPEED_1G_F:
1042 port->port_speed = EHEA_SPEED_1G;
1043 port->full_duplex = 1;
1044 break;
1045 case H_SPEED_10G_F:
1046 port->port_speed = EHEA_SPEED_10G;
1047 port->full_duplex = 1;
1048 break;
1049 default:
1050 port->port_speed = 0;
1051 port->full_duplex = 0;
1052 break;
1053 }
1054 } else {
1055 ehea_error("Failed sensing port speed");
1056 ret = -EIO;
1057 }
1058 } else {
1059 if (hret == H_AUTHORITY) {
Thomas Klein7674a582007-01-22 12:54:20 +01001060 ehea_info("Hypervisor denied setting port speed");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001061 ret = -EPERM;
1062 } else {
1063 ret = -EIO;
1064 ehea_error("Failed setting port speed");
1065 }
1066 }
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001067 if (!prop_carrier_state || (port->phy_link == EHEA_PHY_LINK_UP))
1068 netif_carrier_on(port->netdev);
1069
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001070 kfree(cb4);
1071out:
1072 return ret;
1073}
1074
1075static void ehea_parse_eqe(struct ehea_adapter *adapter, u64 eqe)
1076{
1077 int ret;
1078 u8 ec;
1079 u8 portnum;
1080 struct ehea_port *port;
1081
1082 ec = EHEA_BMASK_GET(NEQE_EVENT_CODE, eqe);
1083 portnum = EHEA_BMASK_GET(NEQE_PORTNUM, eqe);
1084 port = ehea_get_port(adapter, portnum);
1085
1086 switch (ec) {
1087 case EHEA_EC_PORTSTATE_CHG: /* port state change */
1088
1089 if (!port) {
1090 ehea_error("unknown portnum %x", portnum);
1091 break;
1092 }
1093
1094 if (EHEA_BMASK_GET(NEQE_PORT_UP, eqe)) {
1095 if (!netif_carrier_ok(port->netdev)) {
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001096 ret = ehea_sense_port_attr(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001097 if (ret) {
1098 ehea_error("failed resensing port "
1099 "attributes");
1100 break;
1101 }
1102
1103 if (netif_msg_link(port))
1104 ehea_info("%s: Logical port up: %dMbps "
1105 "%s Duplex",
1106 port->netdev->name,
1107 port->port_speed,
1108 port->full_duplex ==
1109 1 ? "Full" : "Half");
1110
1111 netif_carrier_on(port->netdev);
1112 netif_wake_queue(port->netdev);
1113 }
1114 } else
1115 if (netif_carrier_ok(port->netdev)) {
1116 if (netif_msg_link(port))
1117 ehea_info("%s: Logical port down",
1118 port->netdev->name);
1119 netif_carrier_off(port->netdev);
1120 netif_stop_queue(port->netdev);
1121 }
1122
1123 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PORT_UP, eqe)) {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001124 port->phy_link = EHEA_PHY_LINK_UP;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001125 if (netif_msg_link(port))
1126 ehea_info("%s: Physical port up",
1127 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001128 if (prop_carrier_state)
1129 netif_carrier_on(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001130 } else {
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001131 port->phy_link = EHEA_PHY_LINK_DOWN;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001132 if (netif_msg_link(port))
1133 ehea_info("%s: Physical port down",
1134 port->netdev->name);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +02001135 if (prop_carrier_state)
1136 netif_carrier_off(port->netdev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001137 }
1138
1139 if (EHEA_BMASK_GET(NEQE_EXTSWITCH_PRIMARY, eqe))
1140 ehea_info("External switch port is primary port");
1141 else
1142 ehea_info("External switch port is backup port");
1143
1144 break;
1145 case EHEA_EC_ADAPTER_MALFUNC:
1146 ehea_error("Adapter malfunction");
1147 break;
1148 case EHEA_EC_PORT_MALFUNC:
1149 ehea_info("Port malfunction: Device: %s", port->netdev->name);
1150 netif_carrier_off(port->netdev);
1151 netif_stop_queue(port->netdev);
1152 break;
1153 default:
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02001154 ehea_error("unknown event code %x, eqe=0x%lX", ec, eqe);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001155 break;
1156 }
1157}
1158
1159static void ehea_neq_tasklet(unsigned long data)
1160{
Doug Maxey508d2b52008-01-31 20:20:49 -06001161 struct ehea_adapter *adapter = (struct ehea_adapter *)data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001162 struct ehea_eqe *eqe;
1163 u64 event_mask;
1164
1165 eqe = ehea_poll_eq(adapter->neq);
1166 ehea_debug("eqe=%p", eqe);
1167
1168 while (eqe) {
1169 ehea_debug("*eqe=%lx", eqe->entry);
1170 ehea_parse_eqe(adapter, eqe->entry);
1171 eqe = ehea_poll_eq(adapter->neq);
1172 ehea_debug("next eqe=%p", eqe);
1173 }
1174
1175 event_mask = EHEA_BMASK_SET(NELR_PORTSTATE_CHG, 1)
1176 | EHEA_BMASK_SET(NELR_ADAPTER_MALFUNC, 1)
1177 | EHEA_BMASK_SET(NELR_PORT_MALFUNC, 1);
1178
1179 ehea_h_reset_events(adapter->handle,
1180 adapter->neq->fw_handle, event_mask);
1181}
1182
David Howells7d12e782006-10-05 14:55:46 +01001183static irqreturn_t ehea_interrupt_neq(int irq, void *param)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001184{
1185 struct ehea_adapter *adapter = param;
1186 tasklet_hi_schedule(&adapter->neq_tasklet);
1187 return IRQ_HANDLED;
1188}
1189
1190
1191static int ehea_fill_port_res(struct ehea_port_res *pr)
1192{
1193 int ret;
1194 struct ehea_qp_init_attr *init_attr = &pr->qp->init_attr;
1195
1196 ret = ehea_init_fill_rq1(pr, init_attr->act_nr_rwqes_rq1
1197 - init_attr->act_nr_rwqes_rq2
1198 - init_attr->act_nr_rwqes_rq3 - 1);
1199
1200 ret |= ehea_refill_rq2(pr, init_attr->act_nr_rwqes_rq2 - 1);
1201
1202 ret |= ehea_refill_rq3(pr, init_attr->act_nr_rwqes_rq3 - 1);
1203
1204 return ret;
1205}
1206
1207static int ehea_reg_interrupts(struct net_device *dev)
1208{
1209 struct ehea_port *port = netdev_priv(dev);
1210 struct ehea_port_res *pr;
1211 int i, ret;
1212
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001213
1214 snprintf(port->int_aff_name, EHEA_IRQ_NAME_SIZE - 1, "%s-aff",
1215 dev->name);
1216
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001217 ret = ibmebus_request_irq(port->qp_eq->attr.ist1,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001218 ehea_qp_aff_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001219 IRQF_DISABLED, port->int_aff_name, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001220 if (ret) {
1221 ehea_error("failed registering irq for qp_aff_irq_handler:"
1222 "ist=%X", port->qp_eq->attr.ist1);
1223 goto out_free_qpeq;
1224 }
1225
1226 if (netif_msg_ifup(port))
1227 ehea_info("irq_handle 0x%X for function qp_aff_irq_handler "
1228 "registered", port->qp_eq->attr.ist1);
1229
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001230
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001231 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1232 pr = &port->port_res[i];
1233 snprintf(pr->int_send_name, EHEA_IRQ_NAME_SIZE - 1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001234 "%s-queue%d", dev->name, i);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001235 ret = ibmebus_request_irq(pr->eq->attr.ist1,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001236 ehea_recv_irq_handler,
Thomas Gleixner38515e92007-02-14 00:33:16 -08001237 IRQF_DISABLED, pr->int_send_name,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001238 pr);
1239 if (ret) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001240 ehea_error("failed registering irq for ehea_queue "
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001241 "port_res_nr:%d, ist=%X", i,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001242 pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001243 goto out_free_req;
1244 }
1245 if (netif_msg_ifup(port))
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001246 ehea_info("irq_handle 0x%X for function ehea_queue_int "
1247 "%d registered", pr->eq->attr.ist1, i);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001248 }
1249out:
1250 return ret;
1251
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001252
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001253out_free_req:
1254 while (--i >= 0) {
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001255 u32 ist = port->port_res[i].eq->attr.ist1;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001256 ibmebus_free_irq(ist, &port->port_res[i]);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001257 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001258
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001259out_free_qpeq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001260 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001261 i = port->num_def_qps;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001262
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001263 goto out;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001264
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001265}
1266
1267static void ehea_free_interrupts(struct net_device *dev)
1268{
1269 struct ehea_port *port = netdev_priv(dev);
1270 struct ehea_port_res *pr;
1271 int i;
1272
1273 /* send */
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001274
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001275 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
1276 pr = &port->port_res[i];
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001277 ibmebus_free_irq(pr->eq->attr.ist1, pr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001278 if (netif_msg_intr(port))
1279 ehea_info("free send irq for res %d with handle 0x%X",
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001280 i, pr->eq->attr.ist1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001281 }
1282
1283 /* associated events */
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10001284 ibmebus_free_irq(port->qp_eq->attr.ist1, port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001285 if (netif_msg_intr(port))
1286 ehea_info("associated event interrupt for handle 0x%X freed",
1287 port->qp_eq->attr.ist1);
1288}
1289
1290static int ehea_configure_port(struct ehea_port *port)
1291{
1292 int ret, i;
1293 u64 hret, mask;
1294 struct hcp_ehea_port_cb0 *cb0;
1295
1296 ret = -ENOMEM;
Thomas Kleina1d261c2006-11-03 17:48:23 +01001297 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001298 if (!cb0)
1299 goto out;
1300
1301 cb0->port_rc = EHEA_BMASK_SET(PXLY_RC_VALID, 1)
1302 | EHEA_BMASK_SET(PXLY_RC_IP_CHKSUM, 1)
1303 | EHEA_BMASK_SET(PXLY_RC_TCP_UDP_CHKSUM, 1)
1304 | EHEA_BMASK_SET(PXLY_RC_VLAN_XTRACT, 1)
1305 | EHEA_BMASK_SET(PXLY_RC_VLAN_TAG_FILTER,
1306 PXLY_RC_VLAN_FILTER)
1307 | EHEA_BMASK_SET(PXLY_RC_JUMBO_FRAME, 1);
1308
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001309 for (i = 0; i < port->num_mcs; i++)
1310 if (use_mcs)
1311 cb0->default_qpn_arr[i] =
1312 port->port_res[i].qp->init_attr.qp_nr;
1313 else
1314 cb0->default_qpn_arr[i] =
1315 port->port_res[0].qp->init_attr.qp_nr;
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001316
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001317 if (netif_msg_ifup(port))
1318 ehea_dump(cb0, sizeof(*cb0), "ehea_configure_port");
1319
1320 mask = EHEA_BMASK_SET(H_PORT_CB0_PRC, 1)
1321 | EHEA_BMASK_SET(H_PORT_CB0_DEFQPNARRAY, 1);
1322
1323 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1324 port->logical_port_id,
1325 H_PORT_CB0, mask, cb0);
1326 ret = -EIO;
1327 if (hret != H_SUCCESS)
1328 goto out_free;
1329
1330 ret = 0;
1331
1332out_free:
1333 kfree(cb0);
1334out:
1335 return ret;
1336}
1337
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001338int ehea_gen_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001339{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001340 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001341 struct ehea_adapter *adapter = pr->port->adapter;
1342
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001343 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->send_mr);
1344 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001345 goto out;
1346
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001347 ret = ehea_gen_smr(adapter, &adapter->mr, &pr->recv_mr);
1348 if (ret)
1349 goto out_free;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001350
1351 return 0;
1352
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001353out_free:
1354 ehea_rem_mr(&pr->send_mr);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001355out:
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001356 ehea_error("Generating SMRS failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001357 return -EIO;
1358}
1359
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001360int ehea_rem_smrs(struct ehea_port_res *pr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001361{
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01001362 if ((ehea_rem_mr(&pr->send_mr))
1363 || (ehea_rem_mr(&pr->recv_mr)))
1364 return -EIO;
1365 else
1366 return 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001367}
1368
1369static int ehea_init_q_skba(struct ehea_q_skb_arr *q_skba, int max_q_entries)
1370{
Doug Maxey508d2b52008-01-31 20:20:49 -06001371 int arr_size = sizeof(void *) * max_q_entries;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001372
1373 q_skba->arr = vmalloc(arr_size);
1374 if (!q_skba->arr)
1375 return -ENOMEM;
1376
1377 memset(q_skba->arr, 0, arr_size);
1378
1379 q_skba->len = max_q_entries;
1380 q_skba->index = 0;
1381 q_skba->os_skbs = 0;
1382
1383 return 0;
1384}
1385
1386static int ehea_init_port_res(struct ehea_port *port, struct ehea_port_res *pr,
1387 struct port_res_cfg *pr_cfg, int queue_token)
1388{
1389 struct ehea_adapter *adapter = port->adapter;
1390 enum ehea_eq_type eq_type = EHEA_EQ;
1391 struct ehea_qp_init_attr *init_attr = NULL;
1392 int ret = -EIO;
1393
1394 memset(pr, 0, sizeof(struct ehea_port_res));
1395
1396 pr->port = port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001397 spin_lock_init(&pr->xmit_lock);
1398 spin_lock_init(&pr->netif_queue);
1399
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001400 pr->eq = ehea_create_eq(adapter, eq_type, EHEA_MAX_ENTRIES_EQ, 0);
1401 if (!pr->eq) {
1402 ehea_error("create_eq failed (eq)");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001403 goto out_free;
1404 }
1405
1406 pr->recv_cq = ehea_create_cq(adapter, pr_cfg->max_entries_rcq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001407 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001408 port->logical_port_id);
1409 if (!pr->recv_cq) {
1410 ehea_error("create_cq failed (cq_recv)");
1411 goto out_free;
1412 }
1413
1414 pr->send_cq = ehea_create_cq(adapter, pr_cfg->max_entries_scq,
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001415 pr->eq->fw_handle,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001416 port->logical_port_id);
1417 if (!pr->send_cq) {
1418 ehea_error("create_cq failed (cq_send)");
1419 goto out_free;
1420 }
1421
1422 if (netif_msg_ifup(port))
1423 ehea_info("Send CQ: act_nr_cqes=%d, Recv CQ: act_nr_cqes=%d",
1424 pr->send_cq->attr.act_nr_of_cqes,
1425 pr->recv_cq->attr.act_nr_of_cqes);
1426
1427 init_attr = kzalloc(sizeof(*init_attr), GFP_KERNEL);
1428 if (!init_attr) {
1429 ret = -ENOMEM;
1430 ehea_error("no mem for ehea_qp_init_attr");
1431 goto out_free;
1432 }
1433
1434 init_attr->low_lat_rq1 = 1;
1435 init_attr->signalingtype = 1; /* generate CQE if specified in WQE */
1436 init_attr->rq_count = 3;
1437 init_attr->qp_token = queue_token;
1438 init_attr->max_nr_send_wqes = pr_cfg->max_entries_sq;
1439 init_attr->max_nr_rwqes_rq1 = pr_cfg->max_entries_rq1;
1440 init_attr->max_nr_rwqes_rq2 = pr_cfg->max_entries_rq2;
1441 init_attr->max_nr_rwqes_rq3 = pr_cfg->max_entries_rq3;
1442 init_attr->wqe_size_enc_sq = EHEA_SG_SQ;
1443 init_attr->wqe_size_enc_rq1 = EHEA_SG_RQ1;
1444 init_attr->wqe_size_enc_rq2 = EHEA_SG_RQ2;
1445 init_attr->wqe_size_enc_rq3 = EHEA_SG_RQ3;
1446 init_attr->rq2_threshold = EHEA_RQ2_THRESHOLD;
1447 init_attr->rq3_threshold = EHEA_RQ3_THRESHOLD;
1448 init_attr->port_nr = port->logical_port_id;
1449 init_attr->send_cq_handle = pr->send_cq->fw_handle;
1450 init_attr->recv_cq_handle = pr->recv_cq->fw_handle;
1451 init_attr->aff_eq_handle = port->qp_eq->fw_handle;
1452
1453 pr->qp = ehea_create_qp(adapter, adapter->pd, init_attr);
1454 if (!pr->qp) {
1455 ehea_error("create_qp failed");
1456 ret = -EIO;
1457 goto out_free;
1458 }
1459
1460 if (netif_msg_ifup(port))
1461 ehea_info("QP: qp_nr=%d\n act_nr_snd_wqe=%d\n nr_rwqe_rq1=%d\n "
1462 "nr_rwqe_rq2=%d\n nr_rwqe_rq3=%d", init_attr->qp_nr,
1463 init_attr->act_nr_send_wqes,
1464 init_attr->act_nr_rwqes_rq1,
1465 init_attr->act_nr_rwqes_rq2,
1466 init_attr->act_nr_rwqes_rq3);
1467
Thomas Klein44fb3122008-04-04 15:04:53 +02001468 pr->sq_skba_size = init_attr->act_nr_send_wqes + 1;
1469
1470 ret = ehea_init_q_skba(&pr->sq_skba, pr->sq_skba_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001471 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1472 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1473 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1474 if (ret)
1475 goto out_free;
1476
1477 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1478 if (ehea_gen_smrs(pr) != 0) {
1479 ret = -EIO;
1480 goto out_free;
1481 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001482
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001483 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1484
1485 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001486
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001487 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001488
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001489 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1490 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1491 pr->lro_mgr.lro_arr = pr->lro_desc;
1492 pr->lro_mgr.get_skb_header = get_skb_hdr;
1493 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1494 pr->lro_mgr.dev = port->netdev;
1495 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1496 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1497
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001498 ret = 0;
1499 goto out;
1500
1501out_free:
1502 kfree(init_attr);
1503 vfree(pr->sq_skba.arr);
1504 vfree(pr->rq1_skba.arr);
1505 vfree(pr->rq2_skba.arr);
1506 vfree(pr->rq3_skba.arr);
1507 ehea_destroy_qp(pr->qp);
1508 ehea_destroy_cq(pr->send_cq);
1509 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001510 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001511out:
1512 return ret;
1513}
1514
1515static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1516{
1517 int ret, i;
1518
1519 ret = ehea_destroy_qp(pr->qp);
1520
1521 if (!ret) {
1522 ehea_destroy_cq(pr->send_cq);
1523 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001524 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001525
1526 for (i = 0; i < pr->rq1_skba.len; i++)
1527 if (pr->rq1_skba.arr[i])
1528 dev_kfree_skb(pr->rq1_skba.arr[i]);
1529
1530 for (i = 0; i < pr->rq2_skba.len; i++)
1531 if (pr->rq2_skba.arr[i])
1532 dev_kfree_skb(pr->rq2_skba.arr[i]);
1533
1534 for (i = 0; i < pr->rq3_skba.len; i++)
1535 if (pr->rq3_skba.arr[i])
1536 dev_kfree_skb(pr->rq3_skba.arr[i]);
1537
1538 for (i = 0; i < pr->sq_skba.len; i++)
1539 if (pr->sq_skba.arr[i])
1540 dev_kfree_skb(pr->sq_skba.arr[i]);
1541
1542 vfree(pr->rq1_skba.arr);
1543 vfree(pr->rq2_skba.arr);
1544 vfree(pr->rq3_skba.arr);
1545 vfree(pr->sq_skba.arr);
1546 ret = ehea_rem_smrs(pr);
1547 }
1548 return ret;
1549}
1550
1551/*
1552 * The write_* functions store information in swqe which is used by
1553 * the hardware to calculate the ip/tcp/udp checksum
1554 */
1555
1556static inline void write_ip_start_end(struct ehea_swqe *swqe,
1557 const struct sk_buff *skb)
1558{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001559 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001560 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001561}
1562
1563static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1564 const struct sk_buff *skb)
1565{
1566 swqe->tcp_offset =
1567 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1568
1569 swqe->tcp_end = (u16)skb->len - 1;
1570}
1571
1572static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1573 const struct sk_buff *skb)
1574{
1575 swqe->tcp_offset =
1576 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1577
1578 swqe->tcp_end = (u16)skb->len - 1;
1579}
1580
1581
1582static void write_swqe2_TSO(struct sk_buff *skb,
1583 struct ehea_swqe *swqe, u32 lkey)
1584{
1585 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1586 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1587 int skb_data_size = skb->len - skb->data_len;
1588 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001589
1590 /* Packet is TCP with TSO enabled */
1591 swqe->tx_control |= EHEA_SWQE_TSO;
1592 swqe->mss = skb_shinfo(skb)->gso_size;
1593 /* copy only eth/ip/tcp headers to immediate data and
1594 * the rest of skb->data to sg1entry
1595 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001596 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001597
1598 skb_data_size = skb->len - skb->data_len;
1599
1600 if (skb_data_size >= headersize) {
1601 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001602 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001603 swqe->immediate_data_length = headersize;
1604
1605 if (skb_data_size > headersize) {
1606 /* set sg1entry data */
1607 sg1entry->l_key = lkey;
1608 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001609 sg1entry->vaddr =
1610 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001611 swqe->descriptors++;
1612 }
1613 } else
1614 ehea_error("cannot handle fragmented headers");
1615}
1616
1617static void write_swqe2_nonTSO(struct sk_buff *skb,
1618 struct ehea_swqe *swqe, u32 lkey)
1619{
1620 int skb_data_size = skb->len - skb->data_len;
1621 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1622 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001623
1624 /* Packet is any nonTSO type
1625 *
1626 * Copy as much as possible skb->data to immediate data and
1627 * the rest to sg1entry
1628 */
1629 if (skb_data_size >= SWQE2_MAX_IMM) {
1630 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001631 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001632
1633 swqe->immediate_data_length = SWQE2_MAX_IMM;
1634
1635 if (skb_data_size > SWQE2_MAX_IMM) {
1636 /* copy sg1entry data */
1637 sg1entry->l_key = lkey;
1638 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001639 sg1entry->vaddr =
1640 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001641 swqe->descriptors++;
1642 }
1643 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001644 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001645 swqe->immediate_data_length = skb_data_size;
1646 }
1647}
1648
1649static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1650 struct ehea_swqe *swqe, u32 lkey)
1651{
1652 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1653 skb_frag_t *frag;
1654 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001655
1656 nfrags = skb_shinfo(skb)->nr_frags;
1657 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001658 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001659 swqe->descriptors = 0;
1660 sg1entry_contains_frag_data = 0;
1661
1662 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1663 write_swqe2_TSO(skb, swqe, lkey);
1664 else
1665 write_swqe2_nonTSO(skb, swqe, lkey);
1666
1667 /* write descriptors */
1668 if (nfrags > 0) {
1669 if (swqe->descriptors == 0) {
1670 /* sg1entry not yet used */
1671 frag = &skb_shinfo(skb)->frags[0];
1672
1673 /* copy sg1entry data */
1674 sg1entry->l_key = lkey;
1675 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001676 sg1entry->vaddr =
1677 ehea_map_vaddr(page_address(frag->page)
1678 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001679 swqe->descriptors++;
1680 sg1entry_contains_frag_data = 1;
1681 }
1682
1683 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1684
1685 frag = &skb_shinfo(skb)->frags[i];
1686 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1687
1688 sgentry->l_key = lkey;
1689 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001690 sgentry->vaddr =
1691 ehea_map_vaddr(page_address(frag->page)
1692 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001693 swqe->descriptors++;
1694 }
1695 }
1696}
1697
1698static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1699{
1700 int ret = 0;
1701 u64 hret;
1702 u8 reg_type;
1703
1704 /* De/Register untagged packets */
1705 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1706 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1707 port->logical_port_id,
1708 reg_type, port->mac_addr, 0, hcallid);
1709 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001710 ehea_error("%sregistering bc address failed (tagged)",
Doug Maxey508d2b52008-01-31 20:20:49 -06001711 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001712 ret = -EIO;
1713 goto out_herr;
1714 }
1715
1716 /* De/Register VLAN packets */
1717 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1718 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1719 port->logical_port_id,
1720 reg_type, port->mac_addr, 0, hcallid);
1721 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001722 ehea_error("%sregistering bc address failed (vlan)",
1723 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001724 ret = -EIO;
1725 }
1726out_herr:
1727 return ret;
1728}
1729
1730static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1731{
1732 struct ehea_port *port = netdev_priv(dev);
1733 struct sockaddr *mac_addr = sa;
1734 struct hcp_ehea_port_cb0 *cb0;
1735 int ret;
1736 u64 hret;
1737
1738 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1739 ret = -EADDRNOTAVAIL;
1740 goto out;
1741 }
1742
Thomas Kleina1d261c2006-11-03 17:48:23 +01001743 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001744 if (!cb0) {
1745 ehea_error("no mem for cb0");
1746 ret = -ENOMEM;
1747 goto out;
1748 }
1749
1750 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1751
1752 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1753
1754 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1755 port->logical_port_id, H_PORT_CB0,
1756 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1757 if (hret != H_SUCCESS) {
1758 ret = -EIO;
1759 goto out_free;
1760 }
1761
1762 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1763
Thomas Klein21eee2d2008-02-13 16:18:33 +01001764 down(&ehea_bcmc_regs.lock);
1765
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001766 /* Deregister old MAC in pHYP */
1767 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1768 if (ret)
Thomas Klein21eee2d2008-02-13 16:18:33 +01001769 goto out_upregs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001770
1771 port->mac_addr = cb0->port_mac_addr << 16;
1772
1773 /* Register new MAC in pHYP */
1774 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1775 if (ret)
Thomas Klein21eee2d2008-02-13 16:18:33 +01001776 goto out_upregs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001777
1778 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001779
1780out_upregs:
1781 ehea_update_bcmc_registrations();
1782 up(&ehea_bcmc_regs.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001783out_free:
1784 kfree(cb0);
1785out:
1786 return ret;
1787}
1788
1789static void ehea_promiscuous_error(u64 hret, int enable)
1790{
Thomas Klein7674a582007-01-22 12:54:20 +01001791 if (hret == H_AUTHORITY)
1792 ehea_info("Hypervisor denied %sabling promiscuous mode",
1793 enable == 1 ? "en" : "dis");
1794 else
1795 ehea_error("failed %sabling promiscuous mode",
1796 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001797}
1798
1799static void ehea_promiscuous(struct net_device *dev, int enable)
1800{
1801 struct ehea_port *port = netdev_priv(dev);
1802 struct hcp_ehea_port_cb7 *cb7;
1803 u64 hret;
1804
1805 if ((enable && port->promisc) || (!enable && !port->promisc))
1806 return;
1807
Thomas Kleina1d261c2006-11-03 17:48:23 +01001808 cb7 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001809 if (!cb7) {
1810 ehea_error("no mem for cb7");
1811 goto out;
1812 }
1813
1814 /* Modify Pxs_DUCQPN in CB7 */
1815 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1816
1817 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1818 port->logical_port_id,
1819 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1820 if (hret) {
1821 ehea_promiscuous_error(hret, enable);
1822 goto out;
1823 }
1824
1825 port->promisc = enable;
1826out:
1827 kfree(cb7);
1828 return;
1829}
1830
1831static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1832 u32 hcallid)
1833{
1834 u64 hret;
1835 u8 reg_type;
1836
1837 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1838 | EHEA_BCMC_UNTAGGED;
1839
1840 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1841 port->logical_port_id,
1842 reg_type, mc_mac_addr, 0, hcallid);
1843 if (hret)
1844 goto out;
1845
1846 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1847 | EHEA_BCMC_VLANID_ALL;
1848
1849 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1850 port->logical_port_id,
1851 reg_type, mc_mac_addr, 0, hcallid);
1852out:
1853 return hret;
1854}
1855
1856static int ehea_drop_multicast_list(struct net_device *dev)
1857{
1858 struct ehea_port *port = netdev_priv(dev);
1859 struct ehea_mc_list *mc_entry = port->mc_list;
1860 struct list_head *pos;
1861 struct list_head *temp;
1862 int ret = 0;
1863 u64 hret;
1864
1865 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1866 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1867
1868 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1869 H_DEREG_BCMC);
1870 if (hret) {
1871 ehea_error("failed deregistering mcast MAC");
1872 ret = -EIO;
1873 }
1874
1875 list_del(pos);
1876 kfree(mc_entry);
1877 }
1878 return ret;
1879}
1880
1881static void ehea_allmulti(struct net_device *dev, int enable)
1882{
1883 struct ehea_port *port = netdev_priv(dev);
1884 u64 hret;
1885
1886 if (!port->allmulti) {
1887 if (enable) {
1888 /* Enable ALLMULTI */
1889 ehea_drop_multicast_list(dev);
1890 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1891 if (!hret)
1892 port->allmulti = 1;
1893 else
1894 ehea_error("failed enabling IFF_ALLMULTI");
1895 }
1896 } else
1897 if (!enable) {
1898 /* Disable ALLMULTI */
1899 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1900 if (!hret)
1901 port->allmulti = 0;
1902 else
1903 ehea_error("failed disabling IFF_ALLMULTI");
1904 }
1905}
1906
Doug Maxey508d2b52008-01-31 20:20:49 -06001907static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001908{
1909 struct ehea_mc_list *ehea_mcl_entry;
1910 u64 hret;
1911
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001912 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001913 if (!ehea_mcl_entry) {
1914 ehea_error("no mem for mcl_entry");
1915 return;
1916 }
1917
1918 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1919
1920 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1921
1922 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1923 H_REG_BCMC);
1924 if (!hret)
1925 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1926 else {
1927 ehea_error("failed registering mcast MAC");
1928 kfree(ehea_mcl_entry);
1929 }
1930}
1931
1932static void ehea_set_multicast_list(struct net_device *dev)
1933{
1934 struct ehea_port *port = netdev_priv(dev);
1935 struct dev_mc_list *k_mcl_entry;
1936 int ret, i;
1937
1938 if (dev->flags & IFF_PROMISC) {
1939 ehea_promiscuous(dev, 1);
1940 return;
1941 }
1942 ehea_promiscuous(dev, 0);
1943
Thomas Klein21eee2d2008-02-13 16:18:33 +01001944 down(&ehea_bcmc_regs.lock);
1945
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001946 if (dev->flags & IFF_ALLMULTI) {
1947 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001948 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001949 }
1950 ehea_allmulti(dev, 0);
1951
1952 if (dev->mc_count) {
1953 ret = ehea_drop_multicast_list(dev);
1954 if (ret) {
1955 /* Dropping the current multicast list failed.
1956 * Enabling ALL_MULTI is the best we can do.
1957 */
1958 ehea_allmulti(dev, 1);
1959 }
1960
1961 if (dev->mc_count > port->adapter->max_mc_mac) {
1962 ehea_info("Mcast registration limit reached (0x%lx). "
1963 "Use ALLMULTI!",
1964 port->adapter->max_mc_mac);
1965 goto out;
1966 }
1967
Doug Maxey508d2b52008-01-31 20:20:49 -06001968 for (i = 0, k_mcl_entry = dev->mc_list; i < dev->mc_count; i++,
1969 k_mcl_entry = k_mcl_entry->next)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001970 ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06001971
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001972 }
1973out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01001974 ehea_update_bcmc_registrations();
1975 up(&ehea_bcmc_regs.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001976 return;
1977}
1978
1979static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1980{
1981 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1982 return -EINVAL;
1983 dev->mtu = new_mtu;
1984 return 0;
1985}
1986
1987static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
1988 struct ehea_swqe *swqe, u32 lkey)
1989{
1990 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001991 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001992
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001993 /* IPv4 */
1994 swqe->tx_control |= EHEA_SWQE_CRC
1995 | EHEA_SWQE_IP_CHECKSUM
1996 | EHEA_SWQE_TCP_CHECKSUM
1997 | EHEA_SWQE_IMM_DATA_PRESENT
1998 | EHEA_SWQE_DESCRIPTORS_PRESENT;
1999
2000 write_ip_start_end(swqe, skb);
2001
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002002 if (iph->protocol == IPPROTO_UDP) {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002003 if ((iph->frag_off & IP_MF)
2004 || (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002005 /* IP fragment, so don't change cs */
2006 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2007 else
2008 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002009 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002010 write_tcp_offset_end(swqe, skb);
2011 }
2012
2013 /* icmp (big data) and ip segmentation packets (all other ip
2014 packets) do not require any special handling */
2015
2016 } else {
2017 /* Other Ethernet Protocol */
2018 swqe->tx_control |= EHEA_SWQE_CRC
2019 | EHEA_SWQE_IMM_DATA_PRESENT
2020 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2021 }
2022
2023 write_swqe2_data(skb, dev, swqe, lkey);
2024}
2025
2026static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2027 struct ehea_swqe *swqe)
2028{
2029 int nfrags = skb_shinfo(skb)->nr_frags;
2030 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2031 skb_frag_t *frag;
2032 int i;
2033
2034 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002035 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002036
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002037 /* IPv4 */
2038 write_ip_start_end(swqe, skb);
2039
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002040 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002041 swqe->tx_control |= EHEA_SWQE_CRC
2042 | EHEA_SWQE_IP_CHECKSUM
2043 | EHEA_SWQE_TCP_CHECKSUM
2044 | EHEA_SWQE_IMM_DATA_PRESENT;
2045
2046 write_tcp_offset_end(swqe, skb);
2047
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002048 } else if (iph->protocol == IPPROTO_UDP) {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002049 if ((iph->frag_off & IP_MF)
2050 || (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002051 /* IP fragment, so don't change cs */
2052 swqe->tx_control |= EHEA_SWQE_CRC
2053 | EHEA_SWQE_IMM_DATA_PRESENT;
2054 else {
2055 swqe->tx_control |= EHEA_SWQE_CRC
2056 | EHEA_SWQE_IP_CHECKSUM
2057 | EHEA_SWQE_TCP_CHECKSUM
2058 | EHEA_SWQE_IMM_DATA_PRESENT;
2059
2060 write_udp_offset_end(swqe, skb);
2061 }
2062 } else {
2063 /* icmp (big data) and
2064 ip segmentation packets (all other ip packets) */
2065 swqe->tx_control |= EHEA_SWQE_CRC
2066 | EHEA_SWQE_IP_CHECKSUM
2067 | EHEA_SWQE_IMM_DATA_PRESENT;
2068 }
2069 } else {
2070 /* Other Ethernet Protocol */
2071 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2072 }
2073 /* copy (immediate) data */
2074 if (nfrags == 0) {
2075 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002076 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002077 } else {
2078 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002079 skb_copy_from_linear_data(skb, imm_data,
2080 skb->len - skb->data_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002081 imm_data += skb->len - skb->data_len;
2082
2083 /* ... then copy data from the fragments */
2084 for (i = 0; i < nfrags; i++) {
2085 frag = &skb_shinfo(skb)->frags[i];
2086 memcpy(imm_data,
2087 page_address(frag->page) + frag->page_offset,
2088 frag->size);
2089 imm_data += frag->size;
2090 }
2091 }
2092 swqe->immediate_data_length = skb->len;
2093 dev_kfree_skb(skb);
2094}
2095
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002096static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2097{
2098 struct tcphdr *tcp;
2099 u32 tmp;
2100
2101 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002102 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002103 tcp = (struct tcphdr *)(skb_network_header(skb) +
2104 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002105 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002106 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002107 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002108 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002109 return 0;
2110}
2111
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002112static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2113{
2114 struct ehea_port *port = netdev_priv(dev);
2115 struct ehea_swqe *swqe;
2116 unsigned long flags;
2117 u32 lkey;
2118 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002119 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002120
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002121 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2122
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002123 if (!spin_trylock(&pr->xmit_lock))
2124 return NETDEV_TX_BUSY;
2125
2126 if (pr->queue_stopped) {
2127 spin_unlock(&pr->xmit_lock);
2128 return NETDEV_TX_BUSY;
2129 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002130
2131 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2132 memset(swqe, 0, SWQE_HEADER_SIZE);
2133 atomic_dec(&pr->swqe_avail);
2134
2135 if (skb->len <= SWQE3_MAX_IMM) {
2136 u32 sig_iv = port->sig_comp_iv;
2137 u32 swqe_num = pr->swqe_id_counter;
2138 ehea_xmit3(skb, dev, swqe);
2139 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2140 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2141 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2142 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2143 sig_iv);
2144 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2145 pr->swqe_ll_count = 0;
2146 } else
2147 pr->swqe_ll_count += 1;
2148 } else {
2149 swqe->wr_id =
2150 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2151 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002152 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002153 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2154 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2155
2156 pr->sq_skba.index++;
2157 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2158
2159 lkey = pr->send_mr.lkey;
2160 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002161 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002162 }
2163 pr->swqe_id_counter += 1;
2164
2165 if (port->vgrp && vlan_tx_tag_present(skb)) {
2166 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2167 swqe->vlan_tag = vlan_tx_tag_get(skb);
2168 }
2169
2170 if (netif_msg_tx_queued(port)) {
2171 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002172 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002173 }
2174
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002175 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2176 netif_stop_queue(dev);
2177 swqe->tx_control |= EHEA_SWQE_PURGE;
2178 }
Thomas Klein44c82152007-07-11 16:32:00 +02002179
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002180 ehea_post_swqe(pr->qp, swqe);
Thomas Klein7393b872007-11-21 17:37:58 +01002181 pr->tx_packets++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002182
2183 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2184 spin_lock_irqsave(&pr->netif_queue, flags);
2185 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002186 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002187 netif_stop_queue(dev);
2188 pr->queue_stopped = 1;
2189 }
2190 spin_unlock_irqrestore(&pr->netif_queue, flags);
2191 }
2192 dev->trans_start = jiffies;
2193 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002194
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002195 return NETDEV_TX_OK;
2196}
2197
2198static void ehea_vlan_rx_register(struct net_device *dev,
2199 struct vlan_group *grp)
2200{
2201 struct ehea_port *port = netdev_priv(dev);
2202 struct ehea_adapter *adapter = port->adapter;
2203 struct hcp_ehea_port_cb1 *cb1;
2204 u64 hret;
2205
2206 port->vgrp = grp;
2207
Thomas Kleina1d261c2006-11-03 17:48:23 +01002208 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002209 if (!cb1) {
2210 ehea_error("no mem for cb1");
2211 goto out;
2212 }
2213
Thomas Kleindec590c2007-06-06 20:53:16 +02002214 memset(cb1->vlan_filter, 0, sizeof(cb1->vlan_filter));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002215
2216 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2217 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2218 if (hret != H_SUCCESS)
2219 ehea_error("modify_ehea_port failed");
2220
2221 kfree(cb1);
2222out:
2223 return;
2224}
2225
2226static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2227{
2228 struct ehea_port *port = netdev_priv(dev);
2229 struct ehea_adapter *adapter = port->adapter;
2230 struct hcp_ehea_port_cb1 *cb1;
2231 int index;
2232 u64 hret;
2233
Thomas Kleina1d261c2006-11-03 17:48:23 +01002234 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002235 if (!cb1) {
2236 ehea_error("no mem for cb1");
2237 goto out;
2238 }
2239
2240 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2241 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2242 if (hret != H_SUCCESS) {
2243 ehea_error("query_ehea_port failed");
2244 goto out;
2245 }
2246
2247 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002248 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002249
2250 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2251 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2252 if (hret != H_SUCCESS)
2253 ehea_error("modify_ehea_port failed");
2254out:
2255 kfree(cb1);
2256 return;
2257}
2258
2259static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2260{
2261 struct ehea_port *port = netdev_priv(dev);
2262 struct ehea_adapter *adapter = port->adapter;
2263 struct hcp_ehea_port_cb1 *cb1;
2264 int index;
2265 u64 hret;
2266
Dan Aloni5c15bde2007-03-02 20:44:51 -08002267 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002268
Thomas Kleina1d261c2006-11-03 17:48:23 +01002269 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002270 if (!cb1) {
2271 ehea_error("no mem for cb1");
2272 goto out;
2273 }
2274
2275 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2276 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2277 if (hret != H_SUCCESS) {
2278 ehea_error("query_ehea_port failed");
2279 goto out;
2280 }
2281
2282 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002283 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002284
2285 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2286 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2287 if (hret != H_SUCCESS)
2288 ehea_error("modify_ehea_port failed");
2289out:
2290 kfree(cb1);
2291 return;
2292}
2293
2294int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2295{
2296 int ret = -EIO;
2297 u64 hret;
2298 u16 dummy16 = 0;
2299 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002300 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002301
Thomas Kleina1d261c2006-11-03 17:48:23 +01002302 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002303 if (!cb0) {
2304 ret = -ENOMEM;
2305 goto out;
2306 }
2307
2308 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2309 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2310 if (hret != H_SUCCESS) {
2311 ehea_error("query_ehea_qp failed (1)");
2312 goto out;
2313 }
2314
2315 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2316 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2317 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2318 &dummy64, &dummy64, &dummy16, &dummy16);
2319 if (hret != H_SUCCESS) {
2320 ehea_error("modify_ehea_qp failed (1)");
2321 goto out;
2322 }
2323
2324 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2325 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2326 if (hret != H_SUCCESS) {
2327 ehea_error("query_ehea_qp failed (2)");
2328 goto out;
2329 }
2330
2331 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2332 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2333 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2334 &dummy64, &dummy64, &dummy16, &dummy16);
2335 if (hret != H_SUCCESS) {
2336 ehea_error("modify_ehea_qp failed (2)");
2337 goto out;
2338 }
2339
2340 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2341 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2342 if (hret != H_SUCCESS) {
2343 ehea_error("query_ehea_qp failed (3)");
2344 goto out;
2345 }
2346
2347 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2348 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2349 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2350 &dummy64, &dummy64, &dummy16, &dummy16);
2351 if (hret != H_SUCCESS) {
2352 ehea_error("modify_ehea_qp failed (3)");
2353 goto out;
2354 }
2355
2356 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2357 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2358 if (hret != H_SUCCESS) {
2359 ehea_error("query_ehea_qp failed (4)");
2360 goto out;
2361 }
2362
2363 ret = 0;
2364out:
2365 kfree(cb0);
2366 return ret;
2367}
2368
2369static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2370 int add_tx_qps)
2371{
2372 int ret, i;
2373 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2374 enum ehea_eq_type eq_type = EHEA_EQ;
2375
2376 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2377 EHEA_MAX_ENTRIES_EQ, 1);
2378 if (!port->qp_eq) {
2379 ret = -EINVAL;
2380 ehea_error("ehea_create_eq failed (qp_eq)");
2381 goto out_kill_eq;
2382 }
2383
2384 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002385 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002386 pr_cfg.max_entries_sq = sq_entries;
2387 pr_cfg.max_entries_rq1 = rq1_entries;
2388 pr_cfg.max_entries_rq2 = rq2_entries;
2389 pr_cfg.max_entries_rq3 = rq3_entries;
2390
2391 pr_cfg_small_rx.max_entries_rcq = 1;
2392 pr_cfg_small_rx.max_entries_scq = sq_entries;
2393 pr_cfg_small_rx.max_entries_sq = sq_entries;
2394 pr_cfg_small_rx.max_entries_rq1 = 1;
2395 pr_cfg_small_rx.max_entries_rq2 = 1;
2396 pr_cfg_small_rx.max_entries_rq3 = 1;
2397
2398 for (i = 0; i < def_qps; i++) {
2399 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2400 if (ret)
2401 goto out_clean_pr;
2402 }
2403 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2404 ret = ehea_init_port_res(port, &port->port_res[i],
2405 &pr_cfg_small_rx, i);
2406 if (ret)
2407 goto out_clean_pr;
2408 }
2409
2410 return 0;
2411
2412out_clean_pr:
2413 while (--i >= 0)
2414 ehea_clean_portres(port, &port->port_res[i]);
2415
2416out_kill_eq:
2417 ehea_destroy_eq(port->qp_eq);
2418 return ret;
2419}
2420
2421static int ehea_clean_all_portres(struct ehea_port *port)
2422{
2423 int ret = 0;
2424 int i;
2425
Doug Maxey508d2b52008-01-31 20:20:49 -06002426 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002427 ret |= ehea_clean_portres(port, &port->port_res[i]);
2428
2429 ret |= ehea_destroy_eq(port->qp_eq);
2430
2431 return ret;
2432}
2433
Thomas Klein35cf2e22007-08-06 13:55:14 +02002434static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002435{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002436 if (adapter->active_ports)
2437 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002438
2439 ehea_rem_mr(&adapter->mr);
2440}
2441
Thomas Klein35cf2e22007-08-06 13:55:14 +02002442static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002443{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002444 if (adapter->active_ports)
2445 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002446
2447 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2448}
2449
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002450static int ehea_up(struct net_device *dev)
2451{
2452 int ret, i;
2453 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002454
2455 if (port->state == EHEA_PORT_UP)
2456 return 0;
2457
Thomas Klein21eee2d2008-02-13 16:18:33 +01002458 down(&ehea_fw_handles.lock);
2459
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002460 ret = ehea_port_res_setup(port, port->num_def_qps,
2461 port->num_add_tx_qps);
2462 if (ret) {
2463 ehea_error("port_res_failed");
2464 goto out;
2465 }
2466
2467 /* Set default QP for this port */
2468 ret = ehea_configure_port(port);
2469 if (ret) {
2470 ehea_error("ehea_configure_port failed. ret:%d", ret);
2471 goto out_clean_pr;
2472 }
2473
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002474 ret = ehea_reg_interrupts(dev);
2475 if (ret) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02002476 ehea_error("reg_interrupts failed. ret:%d", ret);
2477 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002478 }
2479
Doug Maxey508d2b52008-01-31 20:20:49 -06002480 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002481 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2482 if (ret) {
2483 ehea_error("activate_qp failed");
2484 goto out_free_irqs;
2485 }
2486 }
2487
Doug Maxey508d2b52008-01-31 20:20:49 -06002488 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002489 ret = ehea_fill_port_res(&port->port_res[i]);
2490 if (ret) {
2491 ehea_error("out_free_irqs");
2492 goto out_free_irqs;
2493 }
2494 }
2495
Thomas Klein21eee2d2008-02-13 16:18:33 +01002496 down(&ehea_bcmc_regs.lock);
2497
2498 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2499 if (ret) {
2500 ret = -EIO;
2501 goto out_free_irqs;
2502 }
2503
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002504 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002505
2506 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002507 goto out;
2508
2509out_free_irqs:
2510 ehea_free_interrupts(dev);
2511
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002512out_clean_pr:
2513 ehea_clean_all_portres(port);
2514out:
Thomas Klein44c82152007-07-11 16:32:00 +02002515 if (ret)
2516 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
2517
Thomas Klein21eee2d2008-02-13 16:18:33 +01002518 ehea_update_bcmc_registrations();
2519 up(&ehea_bcmc_regs.lock);
2520
2521 ehea_update_firmware_handles();
2522 up(&ehea_fw_handles.lock);
2523
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002524 return ret;
2525}
2526
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002527static void port_napi_disable(struct ehea_port *port)
2528{
2529 int i;
2530
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002531 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002532 napi_disable(&port->port_res[i].napi);
2533}
2534
2535static void port_napi_enable(struct ehea_port *port)
2536{
2537 int i;
2538
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002539 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002540 napi_enable(&port->port_res[i].napi);
2541}
2542
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002543static int ehea_open(struct net_device *dev)
2544{
2545 int ret;
2546 struct ehea_port *port = netdev_priv(dev);
2547
2548 down(&port->port_lock);
2549
2550 if (netif_msg_ifup(port))
2551 ehea_info("enabling port %s", dev->name);
2552
2553 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002554 if (!ret) {
2555 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002556 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002557 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002558
2559 up(&port->port_lock);
2560
2561 return ret;
2562}
2563
2564static int ehea_down(struct net_device *dev)
2565{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002566 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002567 struct ehea_port *port = netdev_priv(dev);
2568
2569 if (port->state == EHEA_PORT_DOWN)
2570 return 0;
2571
Thomas Klein21eee2d2008-02-13 16:18:33 +01002572 down(&ehea_bcmc_regs.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002573 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002574 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2575
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002576 ehea_free_interrupts(dev);
2577
Thomas Klein21eee2d2008-02-13 16:18:33 +01002578 down(&ehea_fw_handles.lock);
2579
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002580 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002581
Thomas Klein21eee2d2008-02-13 16:18:33 +01002582 ehea_update_bcmc_registrations();
2583 up(&ehea_bcmc_regs.lock);
2584
Thomas Klein44c82152007-07-11 16:32:00 +02002585 ret = ehea_clean_all_portres(port);
2586 if (ret)
2587 ehea_info("Failed freeing resources for %s. ret=%i",
2588 dev->name, ret);
2589
Thomas Klein21eee2d2008-02-13 16:18:33 +01002590 ehea_update_firmware_handles();
2591 up(&ehea_fw_handles.lock);
2592
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002593 return ret;
2594}
2595
2596static int ehea_stop(struct net_device *dev)
2597{
2598 int ret;
2599 struct ehea_port *port = netdev_priv(dev);
2600
2601 if (netif_msg_ifdown(port))
2602 ehea_info("disabling port %s", dev->name);
2603
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02002604 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002605 down(&port->port_lock);
2606 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002607 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002608 ret = ehea_down(dev);
2609 up(&port->port_lock);
2610 return ret;
2611}
2612
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002613void ehea_purge_sq(struct ehea_qp *orig_qp)
2614{
2615 struct ehea_qp qp = *orig_qp;
2616 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2617 struct ehea_swqe *swqe;
2618 int wqe_index;
2619 int i;
2620
2621 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2622 swqe = ehea_get_swqe(&qp, &wqe_index);
2623 swqe->tx_control |= EHEA_SWQE_PURGE;
2624 }
2625}
2626
Thomas Klein44fb3122008-04-04 15:04:53 +02002627void ehea_flush_sq(struct ehea_port *port)
2628{
2629 int i;
2630
2631 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
2632 struct ehea_port_res *pr = &port->port_res[i];
2633 int swqe_max = pr->sq_skba_size - 2 - pr->swqe_ll_count;
2634 int k = 0;
2635 while (atomic_read(&pr->swqe_avail) < swqe_max) {
2636 msleep(5);
2637 if (++k == 20)
2638 break;
2639 }
2640 }
2641}
2642
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002643int ehea_stop_qps(struct net_device *dev)
2644{
2645 struct ehea_port *port = netdev_priv(dev);
2646 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002647 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002648 int ret = -EIO;
2649 int dret;
2650 int i;
2651 u64 hret;
2652 u64 dummy64 = 0;
2653 u16 dummy16 = 0;
2654
2655 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2656 if (!cb0) {
2657 ret = -ENOMEM;
2658 goto out;
2659 }
2660
2661 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2662 struct ehea_port_res *pr = &port->port_res[i];
2663 struct ehea_qp *qp = pr->qp;
2664
2665 /* Purge send queue */
2666 ehea_purge_sq(qp);
2667
2668 /* Disable queue pair */
2669 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2670 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2671 cb0);
2672 if (hret != H_SUCCESS) {
2673 ehea_error("query_ehea_qp failed (1)");
2674 goto out;
2675 }
2676
2677 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2678 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2679
2680 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2681 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2682 1), cb0, &dummy64,
2683 &dummy64, &dummy16, &dummy16);
2684 if (hret != H_SUCCESS) {
2685 ehea_error("modify_ehea_qp failed (1)");
2686 goto out;
2687 }
2688
2689 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2690 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2691 cb0);
2692 if (hret != H_SUCCESS) {
2693 ehea_error("query_ehea_qp failed (2)");
2694 goto out;
2695 }
2696
2697 /* deregister shared memory regions */
2698 dret = ehea_rem_smrs(pr);
2699 if (dret) {
2700 ehea_error("unreg shared memory region failed");
2701 goto out;
2702 }
2703 }
2704
2705 ret = 0;
2706out:
2707 kfree(cb0);
2708
2709 return ret;
2710}
2711
Doug Maxey508d2b52008-01-31 20:20:49 -06002712void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002713{
2714 struct ehea_qp qp = *orig_qp;
2715 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2716 struct ehea_rwqe *rwqe;
2717 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2718 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2719 struct sk_buff *skb;
2720 u32 lkey = pr->recv_mr.lkey;
2721
2722
2723 int i;
2724 int index;
2725
2726 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2727 rwqe = ehea_get_next_rwqe(&qp, 2);
2728 rwqe->sg_list[0].l_key = lkey;
2729 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2730 skb = skba_rq2[index];
2731 if (skb)
2732 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2733 }
2734
2735 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2736 rwqe = ehea_get_next_rwqe(&qp, 3);
2737 rwqe->sg_list[0].l_key = lkey;
2738 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2739 skb = skba_rq3[index];
2740 if (skb)
2741 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2742 }
2743}
2744
2745int ehea_restart_qps(struct net_device *dev)
2746{
2747 struct ehea_port *port = netdev_priv(dev);
2748 struct ehea_adapter *adapter = port->adapter;
2749 int ret = 0;
2750 int i;
2751
Doug Maxey508d2b52008-01-31 20:20:49 -06002752 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002753 u64 hret;
2754 u64 dummy64 = 0;
2755 u16 dummy16 = 0;
2756
2757 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2758 if (!cb0) {
2759 ret = -ENOMEM;
2760 goto out;
2761 }
2762
2763 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2764 struct ehea_port_res *pr = &port->port_res[i];
2765 struct ehea_qp *qp = pr->qp;
2766
2767 ret = ehea_gen_smrs(pr);
2768 if (ret) {
2769 ehea_error("creation of shared memory regions failed");
2770 goto out;
2771 }
2772
2773 ehea_update_rqs(qp, pr);
2774
2775 /* Enable queue pair */
2776 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2777 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2778 cb0);
2779 if (hret != H_SUCCESS) {
2780 ehea_error("query_ehea_qp failed (1)");
2781 goto out;
2782 }
2783
2784 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2785 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2786
2787 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2788 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2789 1), cb0, &dummy64,
2790 &dummy64, &dummy16, &dummy16);
2791 if (hret != H_SUCCESS) {
2792 ehea_error("modify_ehea_qp failed (1)");
2793 goto out;
2794 }
2795
2796 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2797 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2798 cb0);
2799 if (hret != H_SUCCESS) {
2800 ehea_error("query_ehea_qp failed (2)");
2801 goto out;
2802 }
2803
2804 /* refill entire queue */
2805 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2806 ehea_refill_rq2(pr, 0);
2807 ehea_refill_rq3(pr, 0);
2808 }
2809out:
2810 kfree(cb0);
2811
2812 return ret;
2813}
2814
David Howellsc4028952006-11-22 14:57:56 +00002815static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002816{
2817 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002818 struct ehea_port *port =
2819 container_of(work, struct ehea_port, reset_task);
2820 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002821
2822 port->resets++;
2823 down(&port->port_lock);
2824 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002825
2826 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002827
Thomas Klein44c82152007-07-11 16:32:00 +02002828 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002829
2830 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002831 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002832 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002833
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002834 ehea_set_multicast_list(dev);
2835
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002836 if (netif_msg_timer(port))
2837 ehea_info("Device %s resetted successfully", dev->name);
2838
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002839 port_napi_enable(port);
2840
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002841 netif_wake_queue(dev);
2842out:
2843 up(&port->port_lock);
2844 return;
2845}
2846
Thomas Klein44c82152007-07-11 16:32:00 +02002847static void ehea_rereg_mrs(struct work_struct *work)
2848{
2849 int ret, i;
2850 struct ehea_adapter *adapter;
2851
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002852 down(&dlpar_mem_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002853 ehea_info("LPAR memory enlarged - re-initializing driver");
2854
2855 list_for_each_entry(adapter, &adapter_list, list)
2856 if (adapter->active_ports) {
2857 /* Shutdown all ports */
2858 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2859 struct ehea_port *port = adapter->port[i];
2860
2861 if (port) {
2862 struct net_device *dev = port->netdev;
2863
2864 if (dev->flags & IFF_UP) {
Thomas Klein44c82152007-07-11 16:32:00 +02002865 down(&port->port_lock);
2866 netif_stop_queue(dev);
Thomas Klein44fb3122008-04-04 15:04:53 +02002867 ehea_flush_sq(port);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002868 ret = ehea_stop_qps(dev);
2869 if (ret) {
2870 up(&port->port_lock);
2871 goto out;
2872 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002873 port_napi_disable(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002874 up(&port->port_lock);
2875 }
2876 }
2877 }
2878
2879 /* Unregister old memory region */
2880 ret = ehea_rem_mr(&adapter->mr);
2881 if (ret) {
2882 ehea_error("unregister MR failed - driver"
2883 " inoperable!");
2884 goto out;
2885 }
2886 }
2887
2888 ehea_destroy_busmap();
Thomas Klein44c82152007-07-11 16:32:00 +02002889 ret = ehea_create_busmap();
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002890 if (ret) {
2891 ehea_error("creating ehea busmap failed");
Thomas Klein44c82152007-07-11 16:32:00 +02002892 goto out;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002893 }
Thomas Klein44c82152007-07-11 16:32:00 +02002894
2895 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2896
2897 list_for_each_entry(adapter, &adapter_list, list)
2898 if (adapter->active_ports) {
2899 /* Register new memory region */
2900 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2901 if (ret) {
2902 ehea_error("register MR failed - driver"
2903 " inoperable!");
2904 goto out;
2905 }
2906
2907 /* Restart all ports */
2908 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2909 struct ehea_port *port = adapter->port[i];
2910
2911 if (port) {
2912 struct net_device *dev = port->netdev;
2913
2914 if (dev->flags & IFF_UP) {
Thomas Klein44c82152007-07-11 16:32:00 +02002915 down(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002916 port_napi_enable(port);
2917 ret = ehea_restart_qps(dev);
2918 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02002919 netif_wake_queue(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002920 up(&port->port_lock);
2921 }
2922 }
2923 }
2924 }
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002925 up(&dlpar_mem_lock);
2926 ehea_info("re-initializing driver complete");
Thomas Klein44c82152007-07-11 16:32:00 +02002927out:
2928 return;
2929}
2930
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002931static void ehea_tx_watchdog(struct net_device *dev)
2932{
2933 struct ehea_port *port = netdev_priv(dev);
2934
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002935 if (netif_carrier_ok(dev) &&
2936 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02002937 schedule_work(&port->reset_task);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002938}
2939
2940int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2941{
2942 struct hcp_query_ehea *cb;
2943 u64 hret;
2944 int ret;
2945
Thomas Kleina1d261c2006-11-03 17:48:23 +01002946 cb = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002947 if (!cb) {
2948 ret = -ENOMEM;
2949 goto out;
2950 }
2951
2952 hret = ehea_h_query_ehea(adapter->handle, cb);
2953
2954 if (hret != H_SUCCESS) {
2955 ret = -EIO;
2956 goto out_herr;
2957 }
2958
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002959 adapter->max_mc_mac = cb->max_mc_mac - 1;
2960 ret = 0;
2961
2962out_herr:
2963 kfree(cb);
2964out:
2965 return ret;
2966}
2967
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002968int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
2969{
2970 struct hcp_ehea_port_cb4 *cb4;
2971 u64 hret;
2972 int ret = 0;
2973
2974 *jumbo = 0;
2975
2976 /* (Try to) enable *jumbo frames */
2977 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2978 if (!cb4) {
2979 ehea_error("no mem for cb4");
2980 ret = -ENOMEM;
2981 goto out;
2982 } else {
2983 hret = ehea_h_query_ehea_port(port->adapter->handle,
2984 port->logical_port_id,
2985 H_PORT_CB4,
2986 H_PORT_CB4_JUMBO, cb4);
2987 if (hret == H_SUCCESS) {
2988 if (cb4->jumbo_frame)
2989 *jumbo = 1;
2990 else {
2991 cb4->jumbo_frame = 1;
2992 hret = ehea_h_modify_ehea_port(port->adapter->
2993 handle,
2994 port->
2995 logical_port_id,
2996 H_PORT_CB4,
2997 H_PORT_CB4_JUMBO,
2998 cb4);
2999 if (hret == H_SUCCESS)
3000 *jumbo = 1;
3001 }
3002 } else
3003 ret = -EINVAL;
3004
3005 kfree(cb4);
3006 }
3007out:
3008 return ret;
3009}
3010
3011static ssize_t ehea_show_port_id(struct device *dev,
3012 struct device_attribute *attr, char *buf)
3013{
3014 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003015 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003016}
3017
3018static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3019 NULL);
3020
3021static void __devinit logical_port_release(struct device *dev)
3022{
3023 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
3024 of_node_put(port->ofdev.node);
3025}
3026
3027static struct device *ehea_register_port(struct ehea_port *port,
3028 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003029{
3030 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003031
3032 port->ofdev.node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003033 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003034 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003035
Thomas Kleind1dea382007-04-26 11:56:13 +02003036 sprintf(port->ofdev.dev.bus_id, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003037 port->ofdev.dev.release = logical_port_release;
3038
3039 ret = of_device_register(&port->ofdev);
3040 if (ret) {
3041 ehea_error("failed to register device. ret=%d", ret);
3042 goto out;
3043 }
3044
3045 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003046 if (ret) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003047 ehea_error("failed to register attributes, ret=%d", ret);
3048 goto out_unreg_of_dev;
3049 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003050
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003051 return &port->ofdev.dev;
3052
3053out_unreg_of_dev:
3054 of_device_unregister(&port->ofdev);
3055out:
3056 return NULL;
3057}
3058
3059static void ehea_unregister_port(struct ehea_port *port)
3060{
3061 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3062 of_device_unregister(&port->ofdev);
3063}
3064
3065struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3066 u32 logical_port_id,
3067 struct device_node *dn)
3068{
3069 int ret;
3070 struct net_device *dev;
3071 struct ehea_port *port;
3072 struct device *port_dev;
3073 int jumbo;
3074
3075 /* allocate memory for the port structures */
3076 dev = alloc_etherdev(sizeof(struct ehea_port));
3077
3078 if (!dev) {
3079 ehea_error("no mem for net_device");
3080 ret = -ENOMEM;
3081 goto out_err;
3082 }
3083
3084 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003085
3086 sema_init(&port->port_lock, 1);
3087 port->state = EHEA_PORT_DOWN;
3088 port->sig_comp_iv = sq_entries / 10;
3089
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003090 port->adapter = adapter;
3091 port->netdev = dev;
3092 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003093
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003094 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003095
3096 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3097 if (!port->mc_list) {
3098 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003099 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003100 }
3101
3102 INIT_LIST_HEAD(&port->mc_list->list);
3103
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003104 ret = ehea_sense_port_attr(port);
3105 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003106 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003107
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003108 port_dev = ehea_register_port(port, dn);
3109 if (!port_dev)
3110 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003111
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003112 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003113
3114 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003115 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3116
3117 dev->open = ehea_open;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +02003118#ifdef CONFIG_NET_POLL_CONTROLLER
3119 dev->poll_controller = ehea_netpoll;
3120#endif
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003121 dev->stop = ehea_stop;
3122 dev->hard_start_xmit = ehea_start_xmit;
3123 dev->get_stats = ehea_get_stats;
3124 dev->set_multicast_list = ehea_set_multicast_list;
3125 dev->set_mac_address = ehea_set_mac_addr;
3126 dev->change_mtu = ehea_change_mtu;
3127 dev->vlan_rx_register = ehea_vlan_rx_register;
3128 dev->vlan_rx_add_vid = ehea_vlan_rx_add_vid;
3129 dev->vlan_rx_kill_vid = ehea_vlan_rx_kill_vid;
3130 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003131 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003132 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3133 | NETIF_F_LLTX;
3134 dev->tx_timeout = &ehea_tx_watchdog;
3135 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3136
David Howellsc4028952006-11-22 14:57:56 +00003137 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003138 ehea_set_ethtool_ops(dev);
3139
3140 ret = register_netdev(dev);
3141 if (ret) {
3142 ehea_error("register_netdev failed. ret=%d", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003143 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003144 }
3145
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003146 port->lro_max_aggr = lro_max_aggr;
3147
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003148 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003149 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003150 ehea_error("failed determining jumbo frame status for %s",
3151 port->netdev->name);
3152
Thomas Klein9c750b72007-01-29 18:44:01 +01003153 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3154 jumbo == 1 ? "en" : "dis");
3155
Thomas Klein44c82152007-07-11 16:32:00 +02003156 adapter->active_ports++;
3157
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003158 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003159
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003160out_unreg_port:
3161 ehea_unregister_port(port);
3162
3163out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003164 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003165
3166out_free_ethdev:
3167 free_netdev(dev);
3168
3169out_err:
3170 ehea_error("setting up logical port with id=%d failed, ret=%d",
3171 logical_port_id, ret);
3172 return NULL;
3173}
3174
3175static void ehea_shutdown_single_port(struct ehea_port *port)
3176{
3177 unregister_netdev(port->netdev);
3178 ehea_unregister_port(port);
3179 kfree(port->mc_list);
3180 free_netdev(port->netdev);
Thomas Klein44c82152007-07-11 16:32:00 +02003181 port->adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003182}
3183
3184static int ehea_setup_ports(struct ehea_adapter *adapter)
3185{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003186 struct device_node *lhea_dn;
3187 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003188
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003189 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003190 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003191
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003192 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003193 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003194
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003195 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003196 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003197 if (!dn_log_port_id) {
3198 ehea_error("bad device node: eth_dn name=%s",
3199 eth_dn->full_name);
3200 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003201 }
3202
Thomas Klein1211bb62007-04-26 11:56:43 +02003203 if (ehea_add_adapter_mr(adapter)) {
3204 ehea_error("creating MR failed");
3205 of_node_put(eth_dn);
3206 return -EIO;
3207 }
3208
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003209 adapter->port[i] = ehea_setup_single_port(adapter,
3210 *dn_log_port_id,
3211 eth_dn);
3212 if (adapter->port[i])
3213 ehea_info("%s -> logical port id #%d",
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003214 adapter->port[i]->netdev->name,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003215 *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003216 else
3217 ehea_remove_adapter_mr(adapter);
3218
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003219 i++;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003220 };
Thomas Klein1211bb62007-04-26 11:56:43 +02003221 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003222}
3223
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003224static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3225 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003226{
3227 struct device_node *lhea_dn;
3228 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003229 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003230
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003231 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003232 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003233
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003234 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003235 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003236 if (dn_log_port_id)
3237 if (*dn_log_port_id == logical_port_id)
3238 return eth_dn;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003239 };
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003240
3241 return NULL;
3242}
3243
3244static ssize_t ehea_probe_port(struct device *dev,
3245 struct device_attribute *attr,
3246 const char *buf, size_t count)
3247{
3248 struct ehea_adapter *adapter = dev->driver_data;
3249 struct ehea_port *port;
3250 struct device_node *eth_dn = NULL;
3251 int i;
3252
3253 u32 logical_port_id;
3254
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003255 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003256
3257 port = ehea_get_port(adapter, logical_port_id);
3258
3259 if (port) {
3260 ehea_info("adding port with logical port id=%d failed. port "
3261 "already configured as %s.", logical_port_id,
3262 port->netdev->name);
3263 return -EINVAL;
3264 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003265
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003266 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3267
3268 if (!eth_dn) {
3269 ehea_info("no logical port with id %d found", logical_port_id);
3270 return -EINVAL;
3271 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003272
Thomas Klein1211bb62007-04-26 11:56:43 +02003273 if (ehea_add_adapter_mr(adapter)) {
3274 ehea_error("creating MR failed");
3275 return -EIO;
3276 }
3277
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003278 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3279
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003280 of_node_put(eth_dn);
3281
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003282 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003283 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003284 if (!adapter->port[i]) {
3285 adapter->port[i] = port;
3286 break;
3287 }
3288
3289 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3290 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003291 } else {
3292 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003293 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003294 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003295
3296 return (ssize_t) count;
3297}
3298
3299static ssize_t ehea_remove_port(struct device *dev,
3300 struct device_attribute *attr,
3301 const char *buf, size_t count)
3302{
3303 struct ehea_adapter *adapter = dev->driver_data;
3304 struct ehea_port *port;
3305 int i;
3306 u32 logical_port_id;
3307
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003308 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003309
3310 port = ehea_get_port(adapter, logical_port_id);
3311
3312 if (port) {
3313 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3314 logical_port_id);
3315
3316 ehea_shutdown_single_port(port);
3317
Doug Maxey508d2b52008-01-31 20:20:49 -06003318 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003319 if (adapter->port[i] == port) {
3320 adapter->port[i] = NULL;
3321 break;
3322 }
3323 } else {
3324 ehea_error("removing port with logical port id=%d failed. port "
3325 "not configured.", logical_port_id);
3326 return -EINVAL;
3327 }
3328
Thomas Klein1211bb62007-04-26 11:56:43 +02003329 ehea_remove_adapter_mr(adapter);
3330
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003331 return (ssize_t) count;
3332}
3333
3334static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3335static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3336
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003337int ehea_create_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003338{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003339 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003340 if (ret)
3341 goto out;
3342
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003343 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003344out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003345 return ret;
3346}
3347
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003348void ehea_remove_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003349{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003350 device_remove_file(&dev->dev, &dev_attr_probe_port);
3351 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003352}
3353
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003354static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003355 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003356{
3357 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003358 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003359 int ret;
3360
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003361 if (!dev || !dev->node) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003362 ehea_error("Invalid ibmebus device probed");
3363 return -EINVAL;
3364 }
Thomas Klein21eee2d2008-02-13 16:18:33 +01003365 down(&ehea_fw_handles.lock);
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003366
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003367 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3368 if (!adapter) {
3369 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003370 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003371 goto out;
3372 }
3373
Thomas Klein44c82152007-07-11 16:32:00 +02003374 list_add(&adapter->list, &adapter_list);
3375
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003376 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003377
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003378 adapter_handle = of_get_property(dev->node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003379 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003380 if (adapter_handle)
3381 adapter->handle = *adapter_handle;
3382
3383 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003384 dev_err(&dev->dev, "failed getting handle for adapter"
3385 " '%s'\n", dev->node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003386 ret = -ENODEV;
3387 goto out_free_ad;
3388 }
3389
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003390 adapter->pd = EHEA_PD_ID;
3391
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003392 dev->dev.driver_data = adapter;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003393
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003394
3395 /* initialize adapter and ports */
3396 /* get adapter properties */
3397 ret = ehea_sense_adapter_attr(adapter);
3398 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003399 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003400 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003401 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003402
3403 adapter->neq = ehea_create_eq(adapter,
3404 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3405 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003406 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003407 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003408 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003409 }
3410
3411 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3412 (unsigned long)adapter);
3413
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003414 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003415 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003416 "ehea_neq", adapter);
3417 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003418 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003419 goto out_kill_eq;
3420 }
3421
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003422 ret = ehea_create_device_sysfs(dev);
3423 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003424 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003425
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003426 ret = ehea_setup_ports(adapter);
3427 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003428 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003429 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003430 }
3431
3432 ret = 0;
3433 goto out;
3434
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003435out_rem_dev_sysfs:
3436 ehea_remove_device_sysfs(dev);
3437
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003438out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003439 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003440
3441out_kill_eq:
3442 ehea_destroy_eq(adapter->neq);
3443
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003444out_free_ad:
3445 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003446
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003447out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003448 ehea_update_firmware_handles();
3449 up(&ehea_fw_handles.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003450 return ret;
3451}
3452
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003453static int __devexit ehea_remove(struct of_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003454{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003455 struct ehea_adapter *adapter = dev->dev.driver_data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003456 int i;
3457
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003458 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003459 if (adapter->port[i]) {
3460 ehea_shutdown_single_port(adapter->port[i]);
3461 adapter->port[i] = NULL;
3462 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003463
3464 ehea_remove_device_sysfs(dev);
3465
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003466 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003467
Thomas Klein21eee2d2008-02-13 16:18:33 +01003468 down(&ehea_fw_handles.lock);
3469
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003470 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003471 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003472
3473 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003474 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003475 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003476 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003477
Thomas Klein21eee2d2008-02-13 16:18:33 +01003478 ehea_update_firmware_handles();
3479 up(&ehea_fw_handles.lock);
3480
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003481 return 0;
3482}
3483
Thomas Klein21eee2d2008-02-13 16:18:33 +01003484void ehea_crash_handler(void)
3485{
3486 int i;
3487
3488 if (ehea_fw_handles.arr)
3489 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3490 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3491 ehea_fw_handles.arr[i].fwh,
3492 FORCE_FREE);
3493
3494 if (ehea_bcmc_regs.arr)
3495 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3496 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3497 ehea_bcmc_regs.arr[i].port_id,
3498 ehea_bcmc_regs.arr[i].reg_type,
3499 ehea_bcmc_regs.arr[i].macaddr,
3500 0, H_DEREG_BCMC);
3501}
3502
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003503static int ehea_reboot_notifier(struct notifier_block *nb,
3504 unsigned long action, void *unused)
3505{
3506 if (action == SYS_RESTART) {
3507 ehea_info("Reboot: freeing all eHEA resources");
3508 ibmebus_unregister_driver(&ehea_driver);
3509 }
3510 return NOTIFY_DONE;
3511}
3512
3513static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003514 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003515};
3516
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003517static int check_module_parm(void)
3518{
3519 int ret = 0;
3520
3521 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3522 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
3523 ehea_info("Bad parameter: rq1_entries");
3524 ret = -EINVAL;
3525 }
3526 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3527 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
3528 ehea_info("Bad parameter: rq2_entries");
3529 ret = -EINVAL;
3530 }
3531 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3532 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
3533 ehea_info("Bad parameter: rq3_entries");
3534 ret = -EINVAL;
3535 }
3536 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3537 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
3538 ehea_info("Bad parameter: sq_entries");
3539 ret = -EINVAL;
3540 }
3541
3542 return ret;
3543}
3544
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003545static ssize_t ehea_show_capabilities(struct device_driver *drv,
3546 char *buf)
3547{
3548 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3549}
3550
3551static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3552 ehea_show_capabilities, NULL);
3553
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003554int __init ehea_module_init(void)
3555{
3556 int ret;
3557
3558 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3559 DRV_VERSION);
3560
Thomas Klein44c82152007-07-11 16:32:00 +02003561
3562 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003563 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3564 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3565
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02003566 sema_init(&dlpar_mem_lock, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003567 sema_init(&ehea_fw_handles.lock, 1);
3568 sema_init(&ehea_bcmc_regs.lock, 1);
Thomas Klein44c82152007-07-11 16:32:00 +02003569
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003570 ret = check_module_parm();
3571 if (ret)
3572 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003573
3574 ret = ehea_create_busmap();
3575 if (ret)
3576 goto out;
3577
Thomas Klein21eee2d2008-02-13 16:18:33 +01003578 ret = register_reboot_notifier(&ehea_reboot_nb);
3579 if (ret)
3580 ehea_info("failed registering reboot notifier");
3581
3582 ret = crash_shutdown_register(&ehea_crash_handler);
3583 if (ret)
3584 ehea_info("failed registering crash handler");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003585
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003586 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003587 if (ret) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003588 ehea_error("failed registering eHEA device driver on ebus");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003589 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003590 }
3591
3592 ret = driver_create_file(&ehea_driver.driver,
3593 &driver_attr_capabilities);
3594 if (ret) {
3595 ehea_error("failed to register capabilities attribute, ret=%d",
3596 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003597 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003598 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003599
Thomas Klein21eee2d2008-02-13 16:18:33 +01003600 return ret;
3601
3602out3:
3603 ibmebus_unregister_driver(&ehea_driver);
3604out2:
3605 unregister_reboot_notifier(&ehea_reboot_nb);
3606 crash_shutdown_unregister(&ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003607out:
3608 return ret;
3609}
3610
3611static void __exit ehea_module_exit(void)
3612{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003613 int ret;
3614
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003615 flush_scheduled_work();
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003616 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003617 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003618 unregister_reboot_notifier(&ehea_reboot_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003619 ret = crash_shutdown_unregister(&ehea_crash_handler);
3620 if (ret)
3621 ehea_info("failed unregistering crash handler");
3622 kfree(ehea_fw_handles.arr);
3623 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003624 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003625}
3626
3627module_init(ehea_module_init);
3628module_exit(ehea_module_exit);