blob: 4ae65e876487693e7d6eeb2b29400b2aeca15602 [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>
Daniel Walker06f89ed2008-03-28 14:41:26 -070039#include <linux/mutex.h>
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +020040
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020041#include <net/ip.h>
42
43#include "ehea.h"
44#include "ehea_qmr.h"
45#include "ehea_phyp.h"
46
47
48MODULE_LICENSE("GPL");
49MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
50MODULE_DESCRIPTION("IBM eServer HEA Driver");
51MODULE_VERSION(DRV_VERSION);
52
53
54static int msg_level = -1;
55static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
56static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
57static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
58static int sq_entries = EHEA_DEF_ENTRIES_SQ;
Doug Maxey508d2b52008-01-31 20:20:49 -060059static int use_mcs;
60static int use_lro;
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070061static int lro_max_aggr = EHEA_LRO_MAX_AGGR;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010062static int num_tx_qps = EHEA_NUM_TX_QP;
Doug Maxey508d2b52008-01-31 20:20:49 -060063static int prop_carrier_state;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020064
65module_param(msg_level, int, 0);
66module_param(rq1_entries, int, 0);
67module_param(rq2_entries, int, 0);
68module_param(rq3_entries, int, 0);
69module_param(sq_entries, int, 0);
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020070module_param(prop_carrier_state, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010071module_param(use_mcs, int, 0);
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070072module_param(use_lro, int, 0);
73module_param(lro_max_aggr, int, 0);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010074module_param(num_tx_qps, int, 0);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020075
Jan-Bernd Themann18604c52007-02-28 18:34:10 +010076MODULE_PARM_DESC(num_tx_qps, "Number of TX-QPS");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020077MODULE_PARM_DESC(msg_level, "msg_level");
Jan-Bernd Themann8759cf72007-09-07 12:30:17 +020078MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
79 "port to stack. 1:yes, 0:no. Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020080MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
81 "[2^x - 1], x = [6..14]. Default = "
82 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
83MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
84 "[2^x - 1], x = [6..14]. Default = "
85 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
86MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
87 "[2^x - 1], x = [6..14]. Default = "
88 __MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
89MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
90 "[2^x - 1], x = [6..14]. Default = "
91 __MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
Jan-Bernd Themann18072a52007-08-22 16:21:24 +020092MODULE_PARM_DESC(use_mcs, " 0:NAPI, 1:Multiple receive queues, Default = 0 ");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +020093
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -070094MODULE_PARM_DESC(lro_max_aggr, " LRO: Max packets to be aggregated. Default = "
95 __MODULE_STRING(EHEA_LRO_MAX_AGGR));
96MODULE_PARM_DESC(use_lro, " Large Receive Offload, 1: enable, 0: disable, "
97 "Default = 0");
98
Doug Maxey508d2b52008-01-31 20:20:49 -060099static int port_name_cnt;
Thomas Klein44c82152007-07-11 16:32:00 +0200100static LIST_HEAD(adapter_list);
Doug Maxey508d2b52008-01-31 20:20:49 -0600101u64 ehea_driver_flags;
Thomas Klein44c82152007-07-11 16:32:00 +0200102struct work_struct ehea_rereg_mr_task;
Daniel Walker06f89ed2008-03-28 14:41:26 -0700103static DEFINE_MUTEX(dlpar_mem_lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +0100104struct ehea_fw_handle_array ehea_fw_handles;
105struct ehea_bcmc_reg_array ehea_bcmc_regs;
106
Thomas Kleind1dea382007-04-26 11:56:13 +0200107
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000108static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +0200109 const struct of_device_id *id);
Thomas Kleind1dea382007-04-26 11:56:13 +0200110
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000111static int __devexit ehea_remove(struct of_device *dev);
Thomas Kleind1dea382007-04-26 11:56:13 +0200112
113static struct of_device_id ehea_device_table[] = {
114 {
115 .name = "lhea",
116 .compatible = "IBM,lhea",
117 },
118 {},
119};
120
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000121static struct of_platform_driver ehea_driver = {
Thomas Kleind1dea382007-04-26 11:56:13 +0200122 .name = "ehea",
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +1000123 .match_table = ehea_device_table,
Thomas Kleind1dea382007-04-26 11:56:13 +0200124 .probe = ehea_probe_adapter,
125 .remove = ehea_remove,
126};
127
Doug Maxey508d2b52008-01-31 20:20:49 -0600128void ehea_dump(void *adr, int len, char *msg)
129{
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200130 int x;
131 unsigned char *deb = adr;
132 for (x = 0; x < len; x += 16) {
Jan-Bernd Themannd2db9ee2007-02-09 09:10:51 +0100133 printk(DRV_NAME " %s adr=%p ofs=%04x %016lx %016lx\n", msg,
Doug Maxey508d2b52008-01-31 20:20:49 -0600134 deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200135 deb += 16;
136 }
137}
138
Thomas Klein21eee2d2008-02-13 16:18:33 +0100139static void ehea_update_firmware_handles(void)
140{
141 struct ehea_fw_handle_entry *arr = NULL;
142 struct ehea_adapter *adapter;
143 int num_adapters = 0;
144 int num_ports = 0;
145 int num_portres = 0;
146 int i = 0;
147 int num_fw_handles, k, l;
148
149 /* Determine number of handles */
150 list_for_each_entry(adapter, &adapter_list, list) {
151 num_adapters++;
152
153 for (k = 0; k < EHEA_MAX_PORTS; k++) {
154 struct ehea_port *port = adapter->port[k];
155
156 if (!port || (port->state != EHEA_PORT_UP))
157 continue;
158
159 num_ports++;
160 num_portres += port->num_def_qps + port->num_add_tx_qps;
161 }
162 }
163
164 num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
165 num_ports * EHEA_NUM_PORT_FW_HANDLES +
166 num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
167
168 if (num_fw_handles) {
169 arr = kzalloc(num_fw_handles * sizeof(*arr), GFP_KERNEL);
170 if (!arr)
171 return; /* Keep the existing array */
172 } else
173 goto out_update;
174
175 list_for_each_entry(adapter, &adapter_list, list) {
176 for (k = 0; k < EHEA_MAX_PORTS; k++) {
177 struct ehea_port *port = adapter->port[k];
178
179 if (!port || (port->state != EHEA_PORT_UP))
180 continue;
181
182 for (l = 0;
183 l < port->num_def_qps + port->num_add_tx_qps;
184 l++) {
185 struct ehea_port_res *pr = &port->port_res[l];
186
187 arr[i].adh = adapter->handle;
188 arr[i++].fwh = pr->qp->fw_handle;
189 arr[i].adh = adapter->handle;
190 arr[i++].fwh = pr->send_cq->fw_handle;
191 arr[i].adh = adapter->handle;
192 arr[i++].fwh = pr->recv_cq->fw_handle;
193 arr[i].adh = adapter->handle;
194 arr[i++].fwh = pr->eq->fw_handle;
195 arr[i].adh = adapter->handle;
196 arr[i++].fwh = pr->send_mr.handle;
197 arr[i].adh = adapter->handle;
198 arr[i++].fwh = pr->recv_mr.handle;
199 }
200 arr[i].adh = adapter->handle;
201 arr[i++].fwh = port->qp_eq->fw_handle;
202 }
203
204 arr[i].adh = adapter->handle;
205 arr[i++].fwh = adapter->neq->fw_handle;
206
207 if (adapter->mr.handle) {
208 arr[i].adh = adapter->handle;
209 arr[i++].fwh = adapter->mr.handle;
210 }
211 }
212
213out_update:
214 kfree(ehea_fw_handles.arr);
215 ehea_fw_handles.arr = arr;
216 ehea_fw_handles.num_entries = i;
217}
218
219static void ehea_update_bcmc_registrations(void)
220{
221 struct ehea_bcmc_reg_entry *arr = NULL;
222 struct ehea_adapter *adapter;
223 struct ehea_mc_list *mc_entry;
224 int num_registrations = 0;
225 int i = 0;
226 int k;
227
228 /* Determine number of registrations */
229 list_for_each_entry(adapter, &adapter_list, list)
230 for (k = 0; k < EHEA_MAX_PORTS; k++) {
231 struct ehea_port *port = adapter->port[k];
232
233 if (!port || (port->state != EHEA_PORT_UP))
234 continue;
235
236 num_registrations += 2; /* Broadcast registrations */
237
238 list_for_each_entry(mc_entry, &port->mc_list->list,list)
239 num_registrations += 2;
240 }
241
242 if (num_registrations) {
243 arr = kzalloc(num_registrations * sizeof(*arr), GFP_KERNEL);
244 if (!arr)
245 return; /* Keep the existing array */
246 } else
247 goto out_update;
248
249 list_for_each_entry(adapter, &adapter_list, list) {
250 for (k = 0; k < EHEA_MAX_PORTS; k++) {
251 struct ehea_port *port = adapter->port[k];
252
253 if (!port || (port->state != EHEA_PORT_UP))
254 continue;
255
256 arr[i].adh = adapter->handle;
257 arr[i].port_id = port->logical_port_id;
258 arr[i].reg_type = EHEA_BCMC_BROADCAST |
259 EHEA_BCMC_UNTAGGED;
260 arr[i++].macaddr = port->mac_addr;
261
262 arr[i].adh = adapter->handle;
263 arr[i].port_id = port->logical_port_id;
264 arr[i].reg_type = EHEA_BCMC_BROADCAST |
265 EHEA_BCMC_VLANID_ALL;
266 arr[i++].macaddr = port->mac_addr;
267
268 list_for_each_entry(mc_entry,
269 &port->mc_list->list, list) {
270 arr[i].adh = adapter->handle;
271 arr[i].port_id = port->logical_port_id;
272 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
273 EHEA_BCMC_MULTICAST |
274 EHEA_BCMC_UNTAGGED;
275 arr[i++].macaddr = mc_entry->macaddr;
276
277 arr[i].adh = adapter->handle;
278 arr[i].port_id = port->logical_port_id;
279 arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
280 EHEA_BCMC_MULTICAST |
281 EHEA_BCMC_VLANID_ALL;
282 arr[i++].macaddr = mc_entry->macaddr;
283 }
284 }
285 }
286
287out_update:
288 kfree(ehea_bcmc_regs.arr);
289 ehea_bcmc_regs.arr = arr;
290 ehea_bcmc_regs.num_entries = i;
291}
292
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200293static struct net_device_stats *ehea_get_stats(struct net_device *dev)
294{
295 struct ehea_port *port = netdev_priv(dev);
296 struct net_device_stats *stats = &port->stats;
297 struct hcp_ehea_port_cb2 *cb2;
Thomas Klein7393b872007-11-21 17:37:58 +0100298 u64 hret, rx_packets, tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200299 int i;
300
301 memset(stats, 0, sizeof(*stats));
302
Thomas Kleina1d261c2006-11-03 17:48:23 +0100303 cb2 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200304 if (!cb2) {
305 ehea_error("no mem for cb2");
306 goto out;
307 }
308
309 hret = ehea_h_query_ehea_port(port->adapter->handle,
310 port->logical_port_id,
311 H_PORT_CB2, H_PORT_CB2_ALL, cb2);
312 if (hret != H_SUCCESS) {
313 ehea_error("query_ehea_port failed");
314 goto out_herr;
315 }
316
317 if (netif_msg_hw(port))
318 ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
319
320 rx_packets = 0;
321 for (i = 0; i < port->num_def_qps; i++)
322 rx_packets += port->port_res[i].rx_packets;
323
Thomas Klein7393b872007-11-21 17:37:58 +0100324 tx_packets = 0;
325 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
326 tx_packets += port->port_res[i].tx_packets;
327
328 stats->tx_packets = tx_packets;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200329 stats->multicast = cb2->rxmcp;
330 stats->rx_errors = cb2->rxuerr;
331 stats->rx_bytes = cb2->rxo;
332 stats->tx_bytes = cb2->txo;
333 stats->rx_packets = rx_packets;
334
335out_herr:
336 kfree(cb2);
337out:
338 return stats;
339}
340
341static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
342{
343 struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
344 struct net_device *dev = pr->port->netdev;
345 int max_index_mask = pr->rq1_skba.len - 1;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200346 int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
347 int adder = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200348 int i;
349
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200350 pr->rq1_skba.os_skbs = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +0200351
Jan-Bernd Themann2c694482007-10-01 16:33:18 +0200352 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
353 pr->rq1_skba.index = index;
354 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
1468 ret = ehea_init_q_skba(&pr->sq_skba, init_attr->act_nr_send_wqes + 1);
1469 ret |= ehea_init_q_skba(&pr->rq1_skba, init_attr->act_nr_rwqes_rq1 + 1);
1470 ret |= ehea_init_q_skba(&pr->rq2_skba, init_attr->act_nr_rwqes_rq2 + 1);
1471 ret |= ehea_init_q_skba(&pr->rq3_skba, init_attr->act_nr_rwqes_rq3 + 1);
1472 if (ret)
1473 goto out_free;
1474
1475 pr->swqe_refill_th = init_attr->act_nr_send_wqes / 10;
1476 if (ehea_gen_smrs(pr) != 0) {
1477 ret = -EIO;
1478 goto out_free;
1479 }
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001480
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001481 atomic_set(&pr->swqe_avail, init_attr->act_nr_send_wqes - 1);
1482
1483 kfree(init_attr);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001484
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001485 netif_napi_add(pr->port->netdev, &pr->napi, ehea_poll, 64);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001486
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07001487 pr->lro_mgr.max_aggr = pr->port->lro_max_aggr;
1488 pr->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1489 pr->lro_mgr.lro_arr = pr->lro_desc;
1490 pr->lro_mgr.get_skb_header = get_skb_hdr;
1491 pr->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1492 pr->lro_mgr.dev = port->netdev;
1493 pr->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1494 pr->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1495
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001496 ret = 0;
1497 goto out;
1498
1499out_free:
1500 kfree(init_attr);
1501 vfree(pr->sq_skba.arr);
1502 vfree(pr->rq1_skba.arr);
1503 vfree(pr->rq2_skba.arr);
1504 vfree(pr->rq3_skba.arr);
1505 ehea_destroy_qp(pr->qp);
1506 ehea_destroy_cq(pr->send_cq);
1507 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001508 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001509out:
1510 return ret;
1511}
1512
1513static int ehea_clean_portres(struct ehea_port *port, struct ehea_port_res *pr)
1514{
1515 int ret, i;
1516
1517 ret = ehea_destroy_qp(pr->qp);
1518
1519 if (!ret) {
1520 ehea_destroy_cq(pr->send_cq);
1521 ehea_destroy_cq(pr->recv_cq);
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01001522 ehea_destroy_eq(pr->eq);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001523
1524 for (i = 0; i < pr->rq1_skba.len; i++)
1525 if (pr->rq1_skba.arr[i])
1526 dev_kfree_skb(pr->rq1_skba.arr[i]);
1527
1528 for (i = 0; i < pr->rq2_skba.len; i++)
1529 if (pr->rq2_skba.arr[i])
1530 dev_kfree_skb(pr->rq2_skba.arr[i]);
1531
1532 for (i = 0; i < pr->rq3_skba.len; i++)
1533 if (pr->rq3_skba.arr[i])
1534 dev_kfree_skb(pr->rq3_skba.arr[i]);
1535
1536 for (i = 0; i < pr->sq_skba.len; i++)
1537 if (pr->sq_skba.arr[i])
1538 dev_kfree_skb(pr->sq_skba.arr[i]);
1539
1540 vfree(pr->rq1_skba.arr);
1541 vfree(pr->rq2_skba.arr);
1542 vfree(pr->rq3_skba.arr);
1543 vfree(pr->sq_skba.arr);
1544 ret = ehea_rem_smrs(pr);
1545 }
1546 return ret;
1547}
1548
1549/*
1550 * The write_* functions store information in swqe which is used by
1551 * the hardware to calculate the ip/tcp/udp checksum
1552 */
1553
1554static inline void write_ip_start_end(struct ehea_swqe *swqe,
1555 const struct sk_buff *skb)
1556{
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001557 swqe->ip_start = skb_network_offset(skb);
Arnaldo Carvalho de Meloc9bdd4b2007-03-12 20:09:15 -03001558 swqe->ip_end = (u8)(swqe->ip_start + ip_hdrlen(skb) - 1);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001559}
1560
1561static inline void write_tcp_offset_end(struct ehea_swqe *swqe,
1562 const struct sk_buff *skb)
1563{
1564 swqe->tcp_offset =
1565 (u8)(swqe->ip_end + 1 + offsetof(struct tcphdr, check));
1566
1567 swqe->tcp_end = (u16)skb->len - 1;
1568}
1569
1570static inline void write_udp_offset_end(struct ehea_swqe *swqe,
1571 const struct sk_buff *skb)
1572{
1573 swqe->tcp_offset =
1574 (u8)(swqe->ip_end + 1 + offsetof(struct udphdr, check));
1575
1576 swqe->tcp_end = (u16)skb->len - 1;
1577}
1578
1579
1580static void write_swqe2_TSO(struct sk_buff *skb,
1581 struct ehea_swqe *swqe, u32 lkey)
1582{
1583 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
1584 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1585 int skb_data_size = skb->len - skb->data_len;
1586 int headersize;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001587
1588 /* Packet is TCP with TSO enabled */
1589 swqe->tx_control |= EHEA_SWQE_TSO;
1590 swqe->mss = skb_shinfo(skb)->gso_size;
1591 /* copy only eth/ip/tcp headers to immediate data and
1592 * the rest of skb->data to sg1entry
1593 */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001594 headersize = ETH_HLEN + ip_hdrlen(skb) + tcp_hdrlen(skb);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001595
1596 skb_data_size = skb->len - skb->data_len;
1597
1598 if (skb_data_size >= headersize) {
1599 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001600 skb_copy_from_linear_data(skb, imm_data, headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001601 swqe->immediate_data_length = headersize;
1602
1603 if (skb_data_size > headersize) {
1604 /* set sg1entry data */
1605 sg1entry->l_key = lkey;
1606 sg1entry->len = skb_data_size - headersize;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001607 sg1entry->vaddr =
1608 ehea_map_vaddr(skb->data + headersize);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001609 swqe->descriptors++;
1610 }
1611 } else
1612 ehea_error("cannot handle fragmented headers");
1613}
1614
1615static void write_swqe2_nonTSO(struct sk_buff *skb,
1616 struct ehea_swqe *swqe, u32 lkey)
1617{
1618 int skb_data_size = skb->len - skb->data_len;
1619 u8 *imm_data = &swqe->u.immdata_desc.immediate_data[0];
1620 struct ehea_vsgentry *sg1entry = &swqe->u.immdata_desc.sg_entry;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001621
1622 /* Packet is any nonTSO type
1623 *
1624 * Copy as much as possible skb->data to immediate data and
1625 * the rest to sg1entry
1626 */
1627 if (skb_data_size >= SWQE2_MAX_IMM) {
1628 /* copy immediate data */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001629 skb_copy_from_linear_data(skb, imm_data, SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001630
1631 swqe->immediate_data_length = SWQE2_MAX_IMM;
1632
1633 if (skb_data_size > SWQE2_MAX_IMM) {
1634 /* copy sg1entry data */
1635 sg1entry->l_key = lkey;
1636 sg1entry->len = skb_data_size - SWQE2_MAX_IMM;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001637 sg1entry->vaddr =
1638 ehea_map_vaddr(skb->data + SWQE2_MAX_IMM);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001639 swqe->descriptors++;
1640 }
1641 } else {
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001642 skb_copy_from_linear_data(skb, imm_data, skb_data_size);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001643 swqe->immediate_data_length = skb_data_size;
1644 }
1645}
1646
1647static inline void write_swqe2_data(struct sk_buff *skb, struct net_device *dev,
1648 struct ehea_swqe *swqe, u32 lkey)
1649{
1650 struct ehea_vsgentry *sg_list, *sg1entry, *sgentry;
1651 skb_frag_t *frag;
1652 int nfrags, sg1entry_contains_frag_data, i;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001653
1654 nfrags = skb_shinfo(skb)->nr_frags;
1655 sg1entry = &swqe->u.immdata_desc.sg_entry;
Doug Maxey508d2b52008-01-31 20:20:49 -06001656 sg_list = (struct ehea_vsgentry *)&swqe->u.immdata_desc.sg_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001657 swqe->descriptors = 0;
1658 sg1entry_contains_frag_data = 0;
1659
1660 if ((dev->features & NETIF_F_TSO) && skb_shinfo(skb)->gso_size)
1661 write_swqe2_TSO(skb, swqe, lkey);
1662 else
1663 write_swqe2_nonTSO(skb, swqe, lkey);
1664
1665 /* write descriptors */
1666 if (nfrags > 0) {
1667 if (swqe->descriptors == 0) {
1668 /* sg1entry not yet used */
1669 frag = &skb_shinfo(skb)->frags[0];
1670
1671 /* copy sg1entry data */
1672 sg1entry->l_key = lkey;
1673 sg1entry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001674 sg1entry->vaddr =
1675 ehea_map_vaddr(page_address(frag->page)
1676 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001677 swqe->descriptors++;
1678 sg1entry_contains_frag_data = 1;
1679 }
1680
1681 for (i = sg1entry_contains_frag_data; i < nfrags; i++) {
1682
1683 frag = &skb_shinfo(skb)->frags[i];
1684 sgentry = &sg_list[i - sg1entry_contains_frag_data];
1685
1686 sgentry->l_key = lkey;
1687 sgentry->len = frag->size;
Thomas Klein44a5b3d2007-08-06 13:55:44 +02001688 sgentry->vaddr =
1689 ehea_map_vaddr(page_address(frag->page)
1690 + frag->page_offset);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001691 swqe->descriptors++;
1692 }
1693 }
1694}
1695
1696static int ehea_broadcast_reg_helper(struct ehea_port *port, u32 hcallid)
1697{
1698 int ret = 0;
1699 u64 hret;
1700 u8 reg_type;
1701
1702 /* De/Register untagged packets */
1703 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_UNTAGGED;
1704 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1705 port->logical_port_id,
1706 reg_type, port->mac_addr, 0, hcallid);
1707 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001708 ehea_error("%sregistering bc address failed (tagged)",
Doug Maxey508d2b52008-01-31 20:20:49 -06001709 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001710 ret = -EIO;
1711 goto out_herr;
1712 }
1713
1714 /* De/Register VLAN packets */
1715 reg_type = EHEA_BCMC_BROADCAST | EHEA_BCMC_VLANID_ALL;
1716 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1717 port->logical_port_id,
1718 reg_type, port->mac_addr, 0, hcallid);
1719 if (hret != H_SUCCESS) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02001720 ehea_error("%sregistering bc address failed (vlan)",
1721 hcallid == H_REG_BCMC ? "" : "de");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001722 ret = -EIO;
1723 }
1724out_herr:
1725 return ret;
1726}
1727
1728static int ehea_set_mac_addr(struct net_device *dev, void *sa)
1729{
1730 struct ehea_port *port = netdev_priv(dev);
1731 struct sockaddr *mac_addr = sa;
1732 struct hcp_ehea_port_cb0 *cb0;
1733 int ret;
1734 u64 hret;
1735
1736 if (!is_valid_ether_addr(mac_addr->sa_data)) {
1737 ret = -EADDRNOTAVAIL;
1738 goto out;
1739 }
1740
Thomas Kleina1d261c2006-11-03 17:48:23 +01001741 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001742 if (!cb0) {
1743 ehea_error("no mem for cb0");
1744 ret = -ENOMEM;
1745 goto out;
1746 }
1747
1748 memcpy(&(cb0->port_mac_addr), &(mac_addr->sa_data[0]), ETH_ALEN);
1749
1750 cb0->port_mac_addr = cb0->port_mac_addr >> 16;
1751
1752 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1753 port->logical_port_id, H_PORT_CB0,
1754 EHEA_BMASK_SET(H_PORT_CB0_MAC, 1), cb0);
1755 if (hret != H_SUCCESS) {
1756 ret = -EIO;
1757 goto out_free;
1758 }
1759
1760 memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
1761
Thomas Klein21eee2d2008-02-13 16:18:33 +01001762 down(&ehea_bcmc_regs.lock);
1763
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001764 /* Deregister old MAC in pHYP */
1765 ret = ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
1766 if (ret)
Thomas Klein21eee2d2008-02-13 16:18:33 +01001767 goto out_upregs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001768
1769 port->mac_addr = cb0->port_mac_addr << 16;
1770
1771 /* Register new MAC in pHYP */
1772 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
1773 if (ret)
Thomas Klein21eee2d2008-02-13 16:18:33 +01001774 goto out_upregs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001775
1776 ret = 0;
Thomas Klein21eee2d2008-02-13 16:18:33 +01001777
1778out_upregs:
1779 ehea_update_bcmc_registrations();
1780 up(&ehea_bcmc_regs.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001781out_free:
1782 kfree(cb0);
1783out:
1784 return ret;
1785}
1786
1787static void ehea_promiscuous_error(u64 hret, int enable)
1788{
Thomas Klein7674a582007-01-22 12:54:20 +01001789 if (hret == H_AUTHORITY)
1790 ehea_info("Hypervisor denied %sabling promiscuous mode",
1791 enable == 1 ? "en" : "dis");
1792 else
1793 ehea_error("failed %sabling promiscuous mode",
1794 enable == 1 ? "en" : "dis");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001795}
1796
1797static void ehea_promiscuous(struct net_device *dev, int enable)
1798{
1799 struct ehea_port *port = netdev_priv(dev);
1800 struct hcp_ehea_port_cb7 *cb7;
1801 u64 hret;
1802
1803 if ((enable && port->promisc) || (!enable && !port->promisc))
1804 return;
1805
Thomas Kleina1d261c2006-11-03 17:48:23 +01001806 cb7 = kzalloc(PAGE_SIZE, GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001807 if (!cb7) {
1808 ehea_error("no mem for cb7");
1809 goto out;
1810 }
1811
1812 /* Modify Pxs_DUCQPN in CB7 */
1813 cb7->def_uc_qpn = enable == 1 ? port->port_res[0].qp->fw_handle : 0;
1814
1815 hret = ehea_h_modify_ehea_port(port->adapter->handle,
1816 port->logical_port_id,
1817 H_PORT_CB7, H_PORT_CB7_DUCQPN, cb7);
1818 if (hret) {
1819 ehea_promiscuous_error(hret, enable);
1820 goto out;
1821 }
1822
1823 port->promisc = enable;
1824out:
1825 kfree(cb7);
1826 return;
1827}
1828
1829static u64 ehea_multicast_reg_helper(struct ehea_port *port, u64 mc_mac_addr,
1830 u32 hcallid)
1831{
1832 u64 hret;
1833 u8 reg_type;
1834
1835 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1836 | EHEA_BCMC_UNTAGGED;
1837
1838 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1839 port->logical_port_id,
1840 reg_type, mc_mac_addr, 0, hcallid);
1841 if (hret)
1842 goto out;
1843
1844 reg_type = EHEA_BCMC_SCOPE_ALL | EHEA_BCMC_MULTICAST
1845 | EHEA_BCMC_VLANID_ALL;
1846
1847 hret = ehea_h_reg_dereg_bcmc(port->adapter->handle,
1848 port->logical_port_id,
1849 reg_type, mc_mac_addr, 0, hcallid);
1850out:
1851 return hret;
1852}
1853
1854static int ehea_drop_multicast_list(struct net_device *dev)
1855{
1856 struct ehea_port *port = netdev_priv(dev);
1857 struct ehea_mc_list *mc_entry = port->mc_list;
1858 struct list_head *pos;
1859 struct list_head *temp;
1860 int ret = 0;
1861 u64 hret;
1862
1863 list_for_each_safe(pos, temp, &(port->mc_list->list)) {
1864 mc_entry = list_entry(pos, struct ehea_mc_list, list);
1865
1866 hret = ehea_multicast_reg_helper(port, mc_entry->macaddr,
1867 H_DEREG_BCMC);
1868 if (hret) {
1869 ehea_error("failed deregistering mcast MAC");
1870 ret = -EIO;
1871 }
1872
1873 list_del(pos);
1874 kfree(mc_entry);
1875 }
1876 return ret;
1877}
1878
1879static void ehea_allmulti(struct net_device *dev, int enable)
1880{
1881 struct ehea_port *port = netdev_priv(dev);
1882 u64 hret;
1883
1884 if (!port->allmulti) {
1885 if (enable) {
1886 /* Enable ALLMULTI */
1887 ehea_drop_multicast_list(dev);
1888 hret = ehea_multicast_reg_helper(port, 0, H_REG_BCMC);
1889 if (!hret)
1890 port->allmulti = 1;
1891 else
1892 ehea_error("failed enabling IFF_ALLMULTI");
1893 }
1894 } else
1895 if (!enable) {
1896 /* Disable ALLMULTI */
1897 hret = ehea_multicast_reg_helper(port, 0, H_DEREG_BCMC);
1898 if (!hret)
1899 port->allmulti = 0;
1900 else
1901 ehea_error("failed disabling IFF_ALLMULTI");
1902 }
1903}
1904
Doug Maxey508d2b52008-01-31 20:20:49 -06001905static void ehea_add_multicast_entry(struct ehea_port *port, u8 *mc_mac_addr)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001906{
1907 struct ehea_mc_list *ehea_mcl_entry;
1908 u64 hret;
1909
Jan-Bernd Themann1e1675c2006-10-25 13:11:42 +02001910 ehea_mcl_entry = kzalloc(sizeof(*ehea_mcl_entry), GFP_ATOMIC);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001911 if (!ehea_mcl_entry) {
1912 ehea_error("no mem for mcl_entry");
1913 return;
1914 }
1915
1916 INIT_LIST_HEAD(&ehea_mcl_entry->list);
1917
1918 memcpy(&ehea_mcl_entry->macaddr, mc_mac_addr, ETH_ALEN);
1919
1920 hret = ehea_multicast_reg_helper(port, ehea_mcl_entry->macaddr,
1921 H_REG_BCMC);
1922 if (!hret)
1923 list_add(&ehea_mcl_entry->list, &port->mc_list->list);
1924 else {
1925 ehea_error("failed registering mcast MAC");
1926 kfree(ehea_mcl_entry);
1927 }
1928}
1929
1930static void ehea_set_multicast_list(struct net_device *dev)
1931{
1932 struct ehea_port *port = netdev_priv(dev);
1933 struct dev_mc_list *k_mcl_entry;
1934 int ret, i;
1935
1936 if (dev->flags & IFF_PROMISC) {
1937 ehea_promiscuous(dev, 1);
1938 return;
1939 }
1940 ehea_promiscuous(dev, 0);
1941
Thomas Klein21eee2d2008-02-13 16:18:33 +01001942 down(&ehea_bcmc_regs.lock);
1943
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001944 if (dev->flags & IFF_ALLMULTI) {
1945 ehea_allmulti(dev, 1);
Thomas Klein21eee2d2008-02-13 16:18:33 +01001946 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001947 }
1948 ehea_allmulti(dev, 0);
1949
1950 if (dev->mc_count) {
1951 ret = ehea_drop_multicast_list(dev);
1952 if (ret) {
1953 /* Dropping the current multicast list failed.
1954 * Enabling ALL_MULTI is the best we can do.
1955 */
1956 ehea_allmulti(dev, 1);
1957 }
1958
1959 if (dev->mc_count > port->adapter->max_mc_mac) {
1960 ehea_info("Mcast registration limit reached (0x%lx). "
1961 "Use ALLMULTI!",
1962 port->adapter->max_mc_mac);
1963 goto out;
1964 }
1965
Doug Maxey508d2b52008-01-31 20:20:49 -06001966 for (i = 0, k_mcl_entry = dev->mc_list; i < dev->mc_count; i++,
1967 k_mcl_entry = k_mcl_entry->next)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001968 ehea_add_multicast_entry(port, k_mcl_entry->dmi_addr);
Doug Maxey508d2b52008-01-31 20:20:49 -06001969
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001970 }
1971out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01001972 ehea_update_bcmc_registrations();
1973 up(&ehea_bcmc_regs.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001974 return;
1975}
1976
1977static int ehea_change_mtu(struct net_device *dev, int new_mtu)
1978{
1979 if ((new_mtu < 68) || (new_mtu > EHEA_MAX_PACKET_SIZE))
1980 return -EINVAL;
1981 dev->mtu = new_mtu;
1982 return 0;
1983}
1984
1985static void ehea_xmit2(struct sk_buff *skb, struct net_device *dev,
1986 struct ehea_swqe *swqe, u32 lkey)
1987{
1988 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001989 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02001990
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02001991 /* IPv4 */
1992 swqe->tx_control |= EHEA_SWQE_CRC
1993 | EHEA_SWQE_IP_CHECKSUM
1994 | EHEA_SWQE_TCP_CHECKSUM
1995 | EHEA_SWQE_IMM_DATA_PRESENT
1996 | EHEA_SWQE_DESCRIPTORS_PRESENT;
1997
1998 write_ip_start_end(swqe, skb);
1999
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002000 if (iph->protocol == IPPROTO_UDP) {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002001 if ((iph->frag_off & IP_MF)
2002 || (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002003 /* IP fragment, so don't change cs */
2004 swqe->tx_control &= ~EHEA_SWQE_TCP_CHECKSUM;
2005 else
2006 write_udp_offset_end(swqe, skb);
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002007 } else if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002008 write_tcp_offset_end(swqe, skb);
2009 }
2010
2011 /* icmp (big data) and ip segmentation packets (all other ip
2012 packets) do not require any special handling */
2013
2014 } else {
2015 /* Other Ethernet Protocol */
2016 swqe->tx_control |= EHEA_SWQE_CRC
2017 | EHEA_SWQE_IMM_DATA_PRESENT
2018 | EHEA_SWQE_DESCRIPTORS_PRESENT;
2019 }
2020
2021 write_swqe2_data(skb, dev, swqe, lkey);
2022}
2023
2024static void ehea_xmit3(struct sk_buff *skb, struct net_device *dev,
2025 struct ehea_swqe *swqe)
2026{
2027 int nfrags = skb_shinfo(skb)->nr_frags;
2028 u8 *imm_data = &swqe->u.immdata_nodesc.immediate_data[0];
2029 skb_frag_t *frag;
2030 int i;
2031
2032 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002033 const struct iphdr *iph = ip_hdr(skb);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002034
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002035 /* IPv4 */
2036 write_ip_start_end(swqe, skb);
2037
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002038 if (iph->protocol == IPPROTO_TCP) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002039 swqe->tx_control |= EHEA_SWQE_CRC
2040 | EHEA_SWQE_IP_CHECKSUM
2041 | EHEA_SWQE_TCP_CHECKSUM
2042 | EHEA_SWQE_IMM_DATA_PRESENT;
2043
2044 write_tcp_offset_end(swqe, skb);
2045
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07002046 } else if (iph->protocol == IPPROTO_UDP) {
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02002047 if ((iph->frag_off & IP_MF)
2048 || (iph->frag_off & IP_OFFSET))
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002049 /* IP fragment, so don't change cs */
2050 swqe->tx_control |= EHEA_SWQE_CRC
2051 | EHEA_SWQE_IMM_DATA_PRESENT;
2052 else {
2053 swqe->tx_control |= EHEA_SWQE_CRC
2054 | EHEA_SWQE_IP_CHECKSUM
2055 | EHEA_SWQE_TCP_CHECKSUM
2056 | EHEA_SWQE_IMM_DATA_PRESENT;
2057
2058 write_udp_offset_end(swqe, skb);
2059 }
2060 } else {
2061 /* icmp (big data) and
2062 ip segmentation packets (all other ip packets) */
2063 swqe->tx_control |= EHEA_SWQE_CRC
2064 | EHEA_SWQE_IP_CHECKSUM
2065 | EHEA_SWQE_IMM_DATA_PRESENT;
2066 }
2067 } else {
2068 /* Other Ethernet Protocol */
2069 swqe->tx_control |= EHEA_SWQE_CRC | EHEA_SWQE_IMM_DATA_PRESENT;
2070 }
2071 /* copy (immediate) data */
2072 if (nfrags == 0) {
2073 /* data is in a single piece */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002074 skb_copy_from_linear_data(skb, imm_data, skb->len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002075 } else {
2076 /* first copy data from the skb->data buffer ... */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03002077 skb_copy_from_linear_data(skb, imm_data,
2078 skb->len - skb->data_len);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002079 imm_data += skb->len - skb->data_len;
2080
2081 /* ... then copy data from the fragments */
2082 for (i = 0; i < nfrags; i++) {
2083 frag = &skb_shinfo(skb)->frags[i];
2084 memcpy(imm_data,
2085 page_address(frag->page) + frag->page_offset,
2086 frag->size);
2087 imm_data += frag->size;
2088 }
2089 }
2090 swqe->immediate_data_length = skb->len;
2091 dev_kfree_skb(skb);
2092}
2093
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002094static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
2095{
2096 struct tcphdr *tcp;
2097 u32 tmp;
2098
2099 if ((skb->protocol == htons(ETH_P_IP)) &&
Thomas Klein88ca2d02007-05-02 16:07:05 +02002100 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
Doug Maxey508d2b52008-01-31 20:20:49 -06002101 tcp = (struct tcphdr *)(skb_network_header(skb) +
2102 (ip_hdr(skb)->ihl * 4));
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002103 tmp = (tcp->source + (tcp->dest << 16)) % 31;
Thomas Klein88ca2d02007-05-02 16:07:05 +02002104 tmp += ip_hdr(skb)->daddr % 31;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002105 return tmp % num_qps;
Doug Maxey508d2b52008-01-31 20:20:49 -06002106 } else
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002107 return 0;
2108}
2109
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002110static int ehea_start_xmit(struct sk_buff *skb, struct net_device *dev)
2111{
2112 struct ehea_port *port = netdev_priv(dev);
2113 struct ehea_swqe *swqe;
2114 unsigned long flags;
2115 u32 lkey;
2116 int swqe_index;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002117 struct ehea_port_res *pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002118
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002119 pr = &port->port_res[ehea_hash_skb(skb, port->num_tx_qps)];
2120
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002121 if (!spin_trylock(&pr->xmit_lock))
2122 return NETDEV_TX_BUSY;
2123
2124 if (pr->queue_stopped) {
2125 spin_unlock(&pr->xmit_lock);
2126 return NETDEV_TX_BUSY;
2127 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002128
2129 swqe = ehea_get_swqe(pr->qp, &swqe_index);
2130 memset(swqe, 0, SWQE_HEADER_SIZE);
2131 atomic_dec(&pr->swqe_avail);
2132
2133 if (skb->len <= SWQE3_MAX_IMM) {
2134 u32 sig_iv = port->sig_comp_iv;
2135 u32 swqe_num = pr->swqe_id_counter;
2136 ehea_xmit3(skb, dev, swqe);
2137 swqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE3_TYPE)
2138 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, swqe_num);
2139 if (pr->swqe_ll_count >= (sig_iv - 1)) {
2140 swqe->wr_id |= EHEA_BMASK_SET(EHEA_WR_ID_REFILL,
2141 sig_iv);
2142 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
2143 pr->swqe_ll_count = 0;
2144 } else
2145 pr->swqe_ll_count += 1;
2146 } else {
2147 swqe->wr_id =
2148 EHEA_BMASK_SET(EHEA_WR_ID_TYPE, EHEA_SWQE2_TYPE)
2149 | EHEA_BMASK_SET(EHEA_WR_ID_COUNT, pr->swqe_id_counter)
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002150 | EHEA_BMASK_SET(EHEA_WR_ID_REFILL, 1)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002151 | EHEA_BMASK_SET(EHEA_WR_ID_INDEX, pr->sq_skba.index);
2152 pr->sq_skba.arr[pr->sq_skba.index] = skb;
2153
2154 pr->sq_skba.index++;
2155 pr->sq_skba.index &= (pr->sq_skba.len - 1);
2156
2157 lkey = pr->send_mr.lkey;
2158 ehea_xmit2(skb, dev, swqe, lkey);
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002159 swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002160 }
2161 pr->swqe_id_counter += 1;
2162
2163 if (port->vgrp && vlan_tx_tag_present(skb)) {
2164 swqe->tx_control |= EHEA_SWQE_VLAN_INSERT;
2165 swqe->vlan_tag = vlan_tx_tag_get(skb);
2166 }
2167
2168 if (netif_msg_tx_queued(port)) {
2169 ehea_info("post swqe on QP %d", pr->qp->init_attr.qp_nr);
Jan-Bernd Themannbff0a552006-10-05 16:53:14 +02002170 ehea_dump(swqe, 512, "swqe");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002171 }
2172
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002173 if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
2174 netif_stop_queue(dev);
2175 swqe->tx_control |= EHEA_SWQE_PURGE;
2176 }
Thomas Klein44c82152007-07-11 16:32:00 +02002177
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002178 ehea_post_swqe(pr->qp, swqe);
Thomas Klein7393b872007-11-21 17:37:58 +01002179 pr->tx_packets++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002180
2181 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
2182 spin_lock_irqsave(&pr->netif_queue, flags);
2183 if (unlikely(atomic_read(&pr->swqe_avail) <= 1)) {
Jan-Bernd Themannacbddb52007-03-23 17:18:53 +01002184 pr->p_stats.queue_stopped++;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002185 netif_stop_queue(dev);
2186 pr->queue_stopped = 1;
2187 }
2188 spin_unlock_irqrestore(&pr->netif_queue, flags);
2189 }
2190 dev->trans_start = jiffies;
2191 spin_unlock(&pr->xmit_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002192
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002193 return NETDEV_TX_OK;
2194}
2195
2196static void ehea_vlan_rx_register(struct net_device *dev,
2197 struct vlan_group *grp)
2198{
2199 struct ehea_port *port = netdev_priv(dev);
2200 struct ehea_adapter *adapter = port->adapter;
2201 struct hcp_ehea_port_cb1 *cb1;
2202 u64 hret;
2203
2204 port->vgrp = grp;
2205
Thomas Kleina1d261c2006-11-03 17:48:23 +01002206 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002207 if (!cb1) {
2208 ehea_error("no mem for cb1");
2209 goto out;
2210 }
2211
Thomas Kleindec590c2007-06-06 20:53:16 +02002212 memset(cb1->vlan_filter, 0, sizeof(cb1->vlan_filter));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002213
2214 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2215 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2216 if (hret != H_SUCCESS)
2217 ehea_error("modify_ehea_port failed");
2218
2219 kfree(cb1);
2220out:
2221 return;
2222}
2223
2224static void ehea_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
2225{
2226 struct ehea_port *port = netdev_priv(dev);
2227 struct ehea_adapter *adapter = port->adapter;
2228 struct hcp_ehea_port_cb1 *cb1;
2229 int index;
2230 u64 hret;
2231
Thomas Kleina1d261c2006-11-03 17:48:23 +01002232 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002233 if (!cb1) {
2234 ehea_error("no mem for cb1");
2235 goto out;
2236 }
2237
2238 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2239 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2240 if (hret != H_SUCCESS) {
2241 ehea_error("query_ehea_port failed");
2242 goto out;
2243 }
2244
2245 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002246 cb1->vlan_filter[index] |= ((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002247
2248 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2249 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2250 if (hret != H_SUCCESS)
2251 ehea_error("modify_ehea_port failed");
2252out:
2253 kfree(cb1);
2254 return;
2255}
2256
2257static void ehea_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
2258{
2259 struct ehea_port *port = netdev_priv(dev);
2260 struct ehea_adapter *adapter = port->adapter;
2261 struct hcp_ehea_port_cb1 *cb1;
2262 int index;
2263 u64 hret;
2264
Dan Aloni5c15bde2007-03-02 20:44:51 -08002265 vlan_group_set_device(port->vgrp, vid, NULL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002266
Thomas Kleina1d261c2006-11-03 17:48:23 +01002267 cb1 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002268 if (!cb1) {
2269 ehea_error("no mem for cb1");
2270 goto out;
2271 }
2272
2273 hret = ehea_h_query_ehea_port(adapter->handle, port->logical_port_id,
2274 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2275 if (hret != H_SUCCESS) {
2276 ehea_error("query_ehea_port failed");
2277 goto out;
2278 }
2279
2280 index = (vid / 64);
Thomas Kleindec590c2007-06-06 20:53:16 +02002281 cb1->vlan_filter[index] &= ~((u64)(0x8000000000000000 >> (vid & 0x3F)));
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002282
2283 hret = ehea_h_modify_ehea_port(adapter->handle, port->logical_port_id,
2284 H_PORT_CB1, H_PORT_CB1_ALL, cb1);
2285 if (hret != H_SUCCESS)
2286 ehea_error("modify_ehea_port failed");
2287out:
2288 kfree(cb1);
2289 return;
2290}
2291
2292int ehea_activate_qp(struct ehea_adapter *adapter, struct ehea_qp *qp)
2293{
2294 int ret = -EIO;
2295 u64 hret;
2296 u16 dummy16 = 0;
2297 u64 dummy64 = 0;
Doug Maxey508d2b52008-01-31 20:20:49 -06002298 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002299
Thomas Kleina1d261c2006-11-03 17:48:23 +01002300 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002301 if (!cb0) {
2302 ret = -ENOMEM;
2303 goto out;
2304 }
2305
2306 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2307 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2308 if (hret != H_SUCCESS) {
2309 ehea_error("query_ehea_qp failed (1)");
2310 goto out;
2311 }
2312
2313 cb0->qp_ctl_reg = H_QP_CR_STATE_INITIALIZED;
2314 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2315 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2316 &dummy64, &dummy64, &dummy16, &dummy16);
2317 if (hret != H_SUCCESS) {
2318 ehea_error("modify_ehea_qp failed (1)");
2319 goto out;
2320 }
2321
2322 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2323 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2324 if (hret != H_SUCCESS) {
2325 ehea_error("query_ehea_qp failed (2)");
2326 goto out;
2327 }
2328
2329 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_INITIALIZED;
2330 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2331 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2332 &dummy64, &dummy64, &dummy16, &dummy16);
2333 if (hret != H_SUCCESS) {
2334 ehea_error("modify_ehea_qp failed (2)");
2335 goto out;
2336 }
2337
2338 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2339 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2340 if (hret != H_SUCCESS) {
2341 ehea_error("query_ehea_qp failed (3)");
2342 goto out;
2343 }
2344
2345 cb0->qp_ctl_reg = H_QP_CR_ENABLED | H_QP_CR_STATE_RDY2SND;
2346 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2347 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG, 1), cb0,
2348 &dummy64, &dummy64, &dummy16, &dummy16);
2349 if (hret != H_SUCCESS) {
2350 ehea_error("modify_ehea_qp failed (3)");
2351 goto out;
2352 }
2353
2354 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2355 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF), cb0);
2356 if (hret != H_SUCCESS) {
2357 ehea_error("query_ehea_qp failed (4)");
2358 goto out;
2359 }
2360
2361 ret = 0;
2362out:
2363 kfree(cb0);
2364 return ret;
2365}
2366
2367static int ehea_port_res_setup(struct ehea_port *port, int def_qps,
2368 int add_tx_qps)
2369{
2370 int ret, i;
2371 struct port_res_cfg pr_cfg, pr_cfg_small_rx;
2372 enum ehea_eq_type eq_type = EHEA_EQ;
2373
2374 port->qp_eq = ehea_create_eq(port->adapter, eq_type,
2375 EHEA_MAX_ENTRIES_EQ, 1);
2376 if (!port->qp_eq) {
2377 ret = -EINVAL;
2378 ehea_error("ehea_create_eq failed (qp_eq)");
2379 goto out_kill_eq;
2380 }
2381
2382 pr_cfg.max_entries_rcq = rq1_entries + rq2_entries + rq3_entries;
Jan-Bernd Themann18604c52007-02-28 18:34:10 +01002383 pr_cfg.max_entries_scq = sq_entries * 2;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002384 pr_cfg.max_entries_sq = sq_entries;
2385 pr_cfg.max_entries_rq1 = rq1_entries;
2386 pr_cfg.max_entries_rq2 = rq2_entries;
2387 pr_cfg.max_entries_rq3 = rq3_entries;
2388
2389 pr_cfg_small_rx.max_entries_rcq = 1;
2390 pr_cfg_small_rx.max_entries_scq = sq_entries;
2391 pr_cfg_small_rx.max_entries_sq = sq_entries;
2392 pr_cfg_small_rx.max_entries_rq1 = 1;
2393 pr_cfg_small_rx.max_entries_rq2 = 1;
2394 pr_cfg_small_rx.max_entries_rq3 = 1;
2395
2396 for (i = 0; i < def_qps; i++) {
2397 ret = ehea_init_port_res(port, &port->port_res[i], &pr_cfg, i);
2398 if (ret)
2399 goto out_clean_pr;
2400 }
2401 for (i = def_qps; i < def_qps + add_tx_qps; i++) {
2402 ret = ehea_init_port_res(port, &port->port_res[i],
2403 &pr_cfg_small_rx, i);
2404 if (ret)
2405 goto out_clean_pr;
2406 }
2407
2408 return 0;
2409
2410out_clean_pr:
2411 while (--i >= 0)
2412 ehea_clean_portres(port, &port->port_res[i]);
2413
2414out_kill_eq:
2415 ehea_destroy_eq(port->qp_eq);
2416 return ret;
2417}
2418
2419static int ehea_clean_all_portres(struct ehea_port *port)
2420{
2421 int ret = 0;
2422 int i;
2423
Doug Maxey508d2b52008-01-31 20:20:49 -06002424 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002425 ret |= ehea_clean_portres(port, &port->port_res[i]);
2426
2427 ret |= ehea_destroy_eq(port->qp_eq);
2428
2429 return ret;
2430}
2431
Thomas Klein35cf2e22007-08-06 13:55:14 +02002432static void ehea_remove_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002433{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002434 if (adapter->active_ports)
2435 return;
Thomas Klein1211bb62007-04-26 11:56:43 +02002436
2437 ehea_rem_mr(&adapter->mr);
2438}
2439
Thomas Klein35cf2e22007-08-06 13:55:14 +02002440static int ehea_add_adapter_mr(struct ehea_adapter *adapter)
Thomas Klein1211bb62007-04-26 11:56:43 +02002441{
Thomas Klein35cf2e22007-08-06 13:55:14 +02002442 if (adapter->active_ports)
2443 return 0;
Thomas Klein1211bb62007-04-26 11:56:43 +02002444
2445 return ehea_reg_kernel_mr(adapter, &adapter->mr);
2446}
2447
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002448static int ehea_up(struct net_device *dev)
2449{
2450 int ret, i;
2451 struct ehea_port *port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002452
2453 if (port->state == EHEA_PORT_UP)
2454 return 0;
2455
Daniel Walker9f71a562008-03-28 14:41:26 -07002456 mutex_lock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002457
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002458 ret = ehea_port_res_setup(port, port->num_def_qps,
2459 port->num_add_tx_qps);
2460 if (ret) {
2461 ehea_error("port_res_failed");
2462 goto out;
2463 }
2464
2465 /* Set default QP for this port */
2466 ret = ehea_configure_port(port);
2467 if (ret) {
2468 ehea_error("ehea_configure_port failed. ret:%d", ret);
2469 goto out_clean_pr;
2470 }
2471
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002472 ret = ehea_reg_interrupts(dev);
2473 if (ret) {
Thomas Kleinf9e29222007-07-18 17:34:09 +02002474 ehea_error("reg_interrupts failed. ret:%d", ret);
2475 goto out_clean_pr;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002476 }
2477
Doug Maxey508d2b52008-01-31 20:20:49 -06002478 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002479 ret = ehea_activate_qp(port->adapter, port->port_res[i].qp);
2480 if (ret) {
2481 ehea_error("activate_qp failed");
2482 goto out_free_irqs;
2483 }
2484 }
2485
Doug Maxey508d2b52008-01-31 20:20:49 -06002486 for (i = 0; i < port->num_def_qps; i++) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002487 ret = ehea_fill_port_res(&port->port_res[i]);
2488 if (ret) {
2489 ehea_error("out_free_irqs");
2490 goto out_free_irqs;
2491 }
2492 }
2493
Thomas Klein21eee2d2008-02-13 16:18:33 +01002494 down(&ehea_bcmc_regs.lock);
2495
2496 ret = ehea_broadcast_reg_helper(port, H_REG_BCMC);
2497 if (ret) {
2498 ret = -EIO;
2499 goto out_free_irqs;
2500 }
2501
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002502 port->state = EHEA_PORT_UP;
Thomas Klein21eee2d2008-02-13 16:18:33 +01002503
2504 ret = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002505 goto out;
2506
2507out_free_irqs:
2508 ehea_free_interrupts(dev);
2509
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002510out_clean_pr:
2511 ehea_clean_all_portres(port);
2512out:
Thomas Klein44c82152007-07-11 16:32:00 +02002513 if (ret)
2514 ehea_info("Failed starting %s. ret=%i", dev->name, ret);
2515
Thomas Klein21eee2d2008-02-13 16:18:33 +01002516 ehea_update_bcmc_registrations();
2517 up(&ehea_bcmc_regs.lock);
2518
2519 ehea_update_firmware_handles();
Daniel Walker9f71a562008-03-28 14:41:26 -07002520 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002521
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002522 return ret;
2523}
2524
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002525static void port_napi_disable(struct ehea_port *port)
2526{
2527 int i;
2528
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002529 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002530 napi_disable(&port->port_res[i].napi);
2531}
2532
2533static void port_napi_enable(struct ehea_port *port)
2534{
2535 int i;
2536
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002537 for (i = 0; i < port->num_def_qps + port->num_add_tx_qps; i++)
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002538 napi_enable(&port->port_res[i].napi);
2539}
2540
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002541static int ehea_open(struct net_device *dev)
2542{
2543 int ret;
2544 struct ehea_port *port = netdev_priv(dev);
2545
2546 down(&port->port_lock);
2547
2548 if (netif_msg_ifup(port))
2549 ehea_info("enabling port %s", dev->name);
2550
2551 ret = ehea_up(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002552 if (!ret) {
2553 port_napi_enable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002554 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002555 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002556
2557 up(&port->port_lock);
2558
2559 return ret;
2560}
2561
2562static int ehea_down(struct net_device *dev)
2563{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002564 int ret;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002565 struct ehea_port *port = netdev_priv(dev);
2566
2567 if (port->state == EHEA_PORT_DOWN)
2568 return 0;
2569
Thomas Klein21eee2d2008-02-13 16:18:33 +01002570 down(&ehea_bcmc_regs.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002571 ehea_drop_multicast_list(dev);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002572 ehea_broadcast_reg_helper(port, H_DEREG_BCMC);
2573
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002574 ehea_free_interrupts(dev);
2575
Daniel Walker9f71a562008-03-28 14:41:26 -07002576 mutex_lock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002577
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002578 port->state = EHEA_PORT_DOWN;
Thomas Klein44c82152007-07-11 16:32:00 +02002579
Thomas Klein21eee2d2008-02-13 16:18:33 +01002580 ehea_update_bcmc_registrations();
2581 up(&ehea_bcmc_regs.lock);
2582
Thomas Klein44c82152007-07-11 16:32:00 +02002583 ret = ehea_clean_all_portres(port);
2584 if (ret)
2585 ehea_info("Failed freeing resources for %s. ret=%i",
2586 dev->name, ret);
2587
Thomas Klein21eee2d2008-02-13 16:18:33 +01002588 ehea_update_firmware_handles();
Daniel Walker9f71a562008-03-28 14:41:26 -07002589 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01002590
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002591 return ret;
2592}
2593
2594static int ehea_stop(struct net_device *dev)
2595{
2596 int ret;
2597 struct ehea_port *port = netdev_priv(dev);
2598
2599 if (netif_msg_ifdown(port))
2600 ehea_info("disabling port %s", dev->name);
2601
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02002602 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002603 down(&port->port_lock);
2604 netif_stop_queue(dev);
Jan-Bernd Themann0173b792007-10-24 11:53:34 +02002605 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002606 ret = ehea_down(dev);
2607 up(&port->port_lock);
2608 return ret;
2609}
2610
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002611void ehea_purge_sq(struct ehea_qp *orig_qp)
2612{
2613 struct ehea_qp qp = *orig_qp;
2614 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2615 struct ehea_swqe *swqe;
2616 int wqe_index;
2617 int i;
2618
2619 for (i = 0; i < init_attr->act_nr_send_wqes; i++) {
2620 swqe = ehea_get_swqe(&qp, &wqe_index);
2621 swqe->tx_control |= EHEA_SWQE_PURGE;
2622 }
2623}
2624
2625int ehea_stop_qps(struct net_device *dev)
2626{
2627 struct ehea_port *port = netdev_priv(dev);
2628 struct ehea_adapter *adapter = port->adapter;
Doug Maxey508d2b52008-01-31 20:20:49 -06002629 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002630 int ret = -EIO;
2631 int dret;
2632 int i;
2633 u64 hret;
2634 u64 dummy64 = 0;
2635 u16 dummy16 = 0;
2636
2637 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2638 if (!cb0) {
2639 ret = -ENOMEM;
2640 goto out;
2641 }
2642
2643 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2644 struct ehea_port_res *pr = &port->port_res[i];
2645 struct ehea_qp *qp = pr->qp;
2646
2647 /* Purge send queue */
2648 ehea_purge_sq(qp);
2649
2650 /* Disable queue pair */
2651 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2652 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2653 cb0);
2654 if (hret != H_SUCCESS) {
2655 ehea_error("query_ehea_qp failed (1)");
2656 goto out;
2657 }
2658
2659 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2660 cb0->qp_ctl_reg &= ~H_QP_CR_ENABLED;
2661
2662 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2663 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2664 1), cb0, &dummy64,
2665 &dummy64, &dummy16, &dummy16);
2666 if (hret != H_SUCCESS) {
2667 ehea_error("modify_ehea_qp failed (1)");
2668 goto out;
2669 }
2670
2671 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2672 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2673 cb0);
2674 if (hret != H_SUCCESS) {
2675 ehea_error("query_ehea_qp failed (2)");
2676 goto out;
2677 }
2678
2679 /* deregister shared memory regions */
2680 dret = ehea_rem_smrs(pr);
2681 if (dret) {
2682 ehea_error("unreg shared memory region failed");
2683 goto out;
2684 }
2685 }
2686
2687 ret = 0;
2688out:
2689 kfree(cb0);
2690
2691 return ret;
2692}
2693
Doug Maxey508d2b52008-01-31 20:20:49 -06002694void ehea_update_rqs(struct ehea_qp *orig_qp, struct ehea_port_res *pr)
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002695{
2696 struct ehea_qp qp = *orig_qp;
2697 struct ehea_qp_init_attr *init_attr = &qp.init_attr;
2698 struct ehea_rwqe *rwqe;
2699 struct sk_buff **skba_rq2 = pr->rq2_skba.arr;
2700 struct sk_buff **skba_rq3 = pr->rq3_skba.arr;
2701 struct sk_buff *skb;
2702 u32 lkey = pr->recv_mr.lkey;
2703
2704
2705 int i;
2706 int index;
2707
2708 for (i = 0; i < init_attr->act_nr_rwqes_rq2 + 1; i++) {
2709 rwqe = ehea_get_next_rwqe(&qp, 2);
2710 rwqe->sg_list[0].l_key = lkey;
2711 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2712 skb = skba_rq2[index];
2713 if (skb)
2714 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2715 }
2716
2717 for (i = 0; i < init_attr->act_nr_rwqes_rq3 + 1; i++) {
2718 rwqe = ehea_get_next_rwqe(&qp, 3);
2719 rwqe->sg_list[0].l_key = lkey;
2720 index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, rwqe->wr_id);
2721 skb = skba_rq3[index];
2722 if (skb)
2723 rwqe->sg_list[0].vaddr = ehea_map_vaddr(skb->data);
2724 }
2725}
2726
2727int ehea_restart_qps(struct net_device *dev)
2728{
2729 struct ehea_port *port = netdev_priv(dev);
2730 struct ehea_adapter *adapter = port->adapter;
2731 int ret = 0;
2732 int i;
2733
Doug Maxey508d2b52008-01-31 20:20:49 -06002734 struct hcp_modify_qp_cb0 *cb0;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002735 u64 hret;
2736 u64 dummy64 = 0;
2737 u16 dummy16 = 0;
2738
2739 cb0 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2740 if (!cb0) {
2741 ret = -ENOMEM;
2742 goto out;
2743 }
2744
2745 for (i = 0; i < (port->num_def_qps + port->num_add_tx_qps); i++) {
2746 struct ehea_port_res *pr = &port->port_res[i];
2747 struct ehea_qp *qp = pr->qp;
2748
2749 ret = ehea_gen_smrs(pr);
2750 if (ret) {
2751 ehea_error("creation of shared memory regions failed");
2752 goto out;
2753 }
2754
2755 ehea_update_rqs(qp, pr);
2756
2757 /* Enable queue pair */
2758 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2759 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2760 cb0);
2761 if (hret != H_SUCCESS) {
2762 ehea_error("query_ehea_qp failed (1)");
2763 goto out;
2764 }
2765
2766 cb0->qp_ctl_reg = (cb0->qp_ctl_reg & H_QP_CR_RES_STATE) << 8;
2767 cb0->qp_ctl_reg |= H_QP_CR_ENABLED;
2768
2769 hret = ehea_h_modify_ehea_qp(adapter->handle, 0, qp->fw_handle,
2770 EHEA_BMASK_SET(H_QPCB0_QP_CTL_REG,
2771 1), cb0, &dummy64,
2772 &dummy64, &dummy16, &dummy16);
2773 if (hret != H_SUCCESS) {
2774 ehea_error("modify_ehea_qp failed (1)");
2775 goto out;
2776 }
2777
2778 hret = ehea_h_query_ehea_qp(adapter->handle, 0, qp->fw_handle,
2779 EHEA_BMASK_SET(H_QPCB0_ALL, 0xFFFF),
2780 cb0);
2781 if (hret != H_SUCCESS) {
2782 ehea_error("query_ehea_qp failed (2)");
2783 goto out;
2784 }
2785
2786 /* refill entire queue */
2787 ehea_refill_rq1(pr, pr->rq1_skba.index, 0);
2788 ehea_refill_rq2(pr, 0);
2789 ehea_refill_rq3(pr, 0);
2790 }
2791out:
2792 kfree(cb0);
2793
2794 return ret;
2795}
2796
David Howellsc4028952006-11-22 14:57:56 +00002797static void ehea_reset_port(struct work_struct *work)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002798{
2799 int ret;
David Howellsc4028952006-11-22 14:57:56 +00002800 struct ehea_port *port =
2801 container_of(work, struct ehea_port, reset_task);
2802 struct net_device *dev = port->netdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002803
2804 port->resets++;
2805 down(&port->port_lock);
2806 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002807
2808 port_napi_disable(port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002809
Thomas Klein44c82152007-07-11 16:32:00 +02002810 ehea_down(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002811
2812 ret = ehea_up(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002813 if (ret)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002814 goto out;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002815
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002816 ehea_set_multicast_list(dev);
2817
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002818 if (netif_msg_timer(port))
2819 ehea_info("Device %s resetted successfully", dev->name);
2820
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002821 port_napi_enable(port);
2822
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002823 netif_wake_queue(dev);
2824out:
2825 up(&port->port_lock);
2826 return;
2827}
2828
Thomas Klein44c82152007-07-11 16:32:00 +02002829static void ehea_rereg_mrs(struct work_struct *work)
2830{
2831 int ret, i;
2832 struct ehea_adapter *adapter;
2833
Daniel Walker06f89ed2008-03-28 14:41:26 -07002834 mutex_lock(&dlpar_mem_lock);
Thomas Klein44c82152007-07-11 16:32:00 +02002835 ehea_info("LPAR memory enlarged - re-initializing driver");
2836
2837 list_for_each_entry(adapter, &adapter_list, list)
2838 if (adapter->active_ports) {
2839 /* Shutdown all ports */
2840 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2841 struct ehea_port *port = adapter->port[i];
2842
2843 if (port) {
2844 struct net_device *dev = port->netdev;
2845
2846 if (dev->flags & IFF_UP) {
Thomas Klein44c82152007-07-11 16:32:00 +02002847 down(&port->port_lock);
2848 netif_stop_queue(dev);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002849 ret = ehea_stop_qps(dev);
2850 if (ret) {
2851 up(&port->port_lock);
2852 goto out;
2853 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07002854 port_napi_disable(port);
Thomas Klein44c82152007-07-11 16:32:00 +02002855 up(&port->port_lock);
2856 }
2857 }
2858 }
2859
2860 /* Unregister old memory region */
2861 ret = ehea_rem_mr(&adapter->mr);
2862 if (ret) {
2863 ehea_error("unregister MR failed - driver"
2864 " inoperable!");
2865 goto out;
2866 }
2867 }
2868
2869 ehea_destroy_busmap();
Thomas Klein44c82152007-07-11 16:32:00 +02002870 ret = ehea_create_busmap();
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002871 if (ret) {
2872 ehea_error("creating ehea busmap failed");
Thomas Klein44c82152007-07-11 16:32:00 +02002873 goto out;
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002874 }
Thomas Klein44c82152007-07-11 16:32:00 +02002875
2876 clear_bit(__EHEA_STOP_XFER, &ehea_driver_flags);
2877
2878 list_for_each_entry(adapter, &adapter_list, list)
2879 if (adapter->active_ports) {
2880 /* Register new memory region */
2881 ret = ehea_reg_kernel_mr(adapter, &adapter->mr);
2882 if (ret) {
2883 ehea_error("register MR failed - driver"
2884 " inoperable!");
2885 goto out;
2886 }
2887
2888 /* Restart all ports */
2889 for (i = 0; i < EHEA_MAX_PORTS; i++) {
2890 struct ehea_port *port = adapter->port[i];
2891
2892 if (port) {
2893 struct net_device *dev = port->netdev;
2894
2895 if (dev->flags & IFF_UP) {
Thomas Klein44c82152007-07-11 16:32:00 +02002896 down(&port->port_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002897 port_napi_enable(port);
2898 ret = ehea_restart_qps(dev);
2899 if (!ret)
Thomas Klein44c82152007-07-11 16:32:00 +02002900 netif_wake_queue(dev);
Thomas Klein44c82152007-07-11 16:32:00 +02002901 up(&port->port_lock);
2902 }
2903 }
2904 }
2905 }
Daniel Walker06f89ed2008-03-28 14:41:26 -07002906 mutex_unlock(&dlpar_mem_lock);
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002907 ehea_info("re-initializing driver complete");
Thomas Klein44c82152007-07-11 16:32:00 +02002908out:
2909 return;
2910}
2911
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002912static void ehea_tx_watchdog(struct net_device *dev)
2913{
2914 struct ehea_port *port = netdev_priv(dev);
2915
Jan-Bernd Themann2c694482007-10-01 16:33:18 +02002916 if (netif_carrier_ok(dev) &&
2917 !test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02002918 schedule_work(&port->reset_task);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002919}
2920
2921int ehea_sense_adapter_attr(struct ehea_adapter *adapter)
2922{
2923 struct hcp_query_ehea *cb;
2924 u64 hret;
2925 int ret;
2926
Thomas Kleina1d261c2006-11-03 17:48:23 +01002927 cb = kzalloc(PAGE_SIZE, GFP_KERNEL);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002928 if (!cb) {
2929 ret = -ENOMEM;
2930 goto out;
2931 }
2932
2933 hret = ehea_h_query_ehea(adapter->handle, cb);
2934
2935 if (hret != H_SUCCESS) {
2936 ret = -EIO;
2937 goto out_herr;
2938 }
2939
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02002940 adapter->max_mc_mac = cb->max_mc_mac - 1;
2941 ret = 0;
2942
2943out_herr:
2944 kfree(cb);
2945out:
2946 return ret;
2947}
2948
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002949int ehea_get_jumboframe_status(struct ehea_port *port, int *jumbo)
2950{
2951 struct hcp_ehea_port_cb4 *cb4;
2952 u64 hret;
2953 int ret = 0;
2954
2955 *jumbo = 0;
2956
2957 /* (Try to) enable *jumbo frames */
2958 cb4 = kzalloc(PAGE_SIZE, GFP_KERNEL);
2959 if (!cb4) {
2960 ehea_error("no mem for cb4");
2961 ret = -ENOMEM;
2962 goto out;
2963 } else {
2964 hret = ehea_h_query_ehea_port(port->adapter->handle,
2965 port->logical_port_id,
2966 H_PORT_CB4,
2967 H_PORT_CB4_JUMBO, cb4);
2968 if (hret == H_SUCCESS) {
2969 if (cb4->jumbo_frame)
2970 *jumbo = 1;
2971 else {
2972 cb4->jumbo_frame = 1;
2973 hret = ehea_h_modify_ehea_port(port->adapter->
2974 handle,
2975 port->
2976 logical_port_id,
2977 H_PORT_CB4,
2978 H_PORT_CB4_JUMBO,
2979 cb4);
2980 if (hret == H_SUCCESS)
2981 *jumbo = 1;
2982 }
2983 } else
2984 ret = -EINVAL;
2985
2986 kfree(cb4);
2987 }
2988out:
2989 return ret;
2990}
2991
2992static ssize_t ehea_show_port_id(struct device *dev,
2993 struct device_attribute *attr, char *buf)
2994{
2995 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02002996 return sprintf(buf, "%d", port->logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01002997}
2998
2999static DEVICE_ATTR(log_port_id, S_IRUSR | S_IRGRP | S_IROTH, ehea_show_port_id,
3000 NULL);
3001
3002static void __devinit logical_port_release(struct device *dev)
3003{
3004 struct ehea_port *port = container_of(dev, struct ehea_port, ofdev.dev);
3005 of_node_put(port->ofdev.node);
3006}
3007
3008static struct device *ehea_register_port(struct ehea_port *port,
3009 struct device_node *dn)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003010{
3011 int ret;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003012
3013 port->ofdev.node = of_node_get(dn);
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003014 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
Thomas Kleind1dea382007-04-26 11:56:13 +02003015 port->ofdev.dev.bus = &ibmebus_bus_type;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003016
Thomas Kleind1dea382007-04-26 11:56:13 +02003017 sprintf(port->ofdev.dev.bus_id, "port%d", port_name_cnt++);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003018 port->ofdev.dev.release = logical_port_release;
3019
3020 ret = of_device_register(&port->ofdev);
3021 if (ret) {
3022 ehea_error("failed to register device. ret=%d", ret);
3023 goto out;
3024 }
3025
3026 ret = device_create_file(&port->ofdev.dev, &dev_attr_log_port_id);
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003027 if (ret) {
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003028 ehea_error("failed to register attributes, ret=%d", ret);
3029 goto out_unreg_of_dev;
3030 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003031
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003032 return &port->ofdev.dev;
3033
3034out_unreg_of_dev:
3035 of_device_unregister(&port->ofdev);
3036out:
3037 return NULL;
3038}
3039
3040static void ehea_unregister_port(struct ehea_port *port)
3041{
3042 device_remove_file(&port->ofdev.dev, &dev_attr_log_port_id);
3043 of_device_unregister(&port->ofdev);
3044}
3045
3046struct ehea_port *ehea_setup_single_port(struct ehea_adapter *adapter,
3047 u32 logical_port_id,
3048 struct device_node *dn)
3049{
3050 int ret;
3051 struct net_device *dev;
3052 struct ehea_port *port;
3053 struct device *port_dev;
3054 int jumbo;
3055
3056 /* allocate memory for the port structures */
3057 dev = alloc_etherdev(sizeof(struct ehea_port));
3058
3059 if (!dev) {
3060 ehea_error("no mem for net_device");
3061 ret = -ENOMEM;
3062 goto out_err;
3063 }
3064
3065 port = netdev_priv(dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003066
3067 sema_init(&port->port_lock, 1);
3068 port->state = EHEA_PORT_DOWN;
3069 port->sig_comp_iv = sq_entries / 10;
3070
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003071 port->adapter = adapter;
3072 port->netdev = dev;
3073 port->logical_port_id = logical_port_id;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003074
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003075 port->msg_enable = netif_msg_init(msg_level, EHEA_MSG_DEFAULT);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003076
3077 port->mc_list = kzalloc(sizeof(struct ehea_mc_list), GFP_KERNEL);
3078 if (!port->mc_list) {
3079 ret = -ENOMEM;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003080 goto out_free_ethdev;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003081 }
3082
3083 INIT_LIST_HEAD(&port->mc_list->list);
3084
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003085 ret = ehea_sense_port_attr(port);
3086 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003087 goto out_free_mc_list;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003088
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003089 port_dev = ehea_register_port(port, dn);
3090 if (!port_dev)
3091 goto out_free_mc_list;
Thomas Klein9c750b72007-01-29 18:44:01 +01003092
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003093 SET_NETDEV_DEV(dev, port_dev);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003094
3095 /* initialize net_device structure */
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003096 memcpy(dev->dev_addr, &port->mac_addr, ETH_ALEN);
3097
3098 dev->open = ehea_open;
Jan-Bernd Themann8d22c972007-07-23 16:05:03 +02003099#ifdef CONFIG_NET_POLL_CONTROLLER
3100 dev->poll_controller = ehea_netpoll;
3101#endif
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003102 dev->stop = ehea_stop;
3103 dev->hard_start_xmit = ehea_start_xmit;
3104 dev->get_stats = ehea_get_stats;
3105 dev->set_multicast_list = ehea_set_multicast_list;
3106 dev->set_mac_address = ehea_set_mac_addr;
3107 dev->change_mtu = ehea_change_mtu;
3108 dev->vlan_rx_register = ehea_vlan_rx_register;
3109 dev->vlan_rx_add_vid = ehea_vlan_rx_add_vid;
3110 dev->vlan_rx_kill_vid = ehea_vlan_rx_kill_vid;
3111 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO
Thomas Kleindc01c442008-03-19 13:55:43 +01003112 | NETIF_F_HIGHDMA | NETIF_F_IP_CSUM | NETIF_F_HW_VLAN_TX
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003113 | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER
3114 | NETIF_F_LLTX;
3115 dev->tx_timeout = &ehea_tx_watchdog;
3116 dev->watchdog_timeo = EHEA_WATCH_DOG_TIMEOUT;
3117
David Howellsc4028952006-11-22 14:57:56 +00003118 INIT_WORK(&port->reset_task, ehea_reset_port);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003119 ehea_set_ethtool_ops(dev);
3120
3121 ret = register_netdev(dev);
3122 if (ret) {
3123 ehea_error("register_netdev failed. ret=%d", ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003124 goto out_unreg_port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003125 }
3126
Jan-Bernd Themannd4dc4ec2007-09-25 16:16:34 -07003127 port->lro_max_aggr = lro_max_aggr;
3128
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003129 ret = ehea_get_jumboframe_status(port, &jumbo);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003130 if (ret)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003131 ehea_error("failed determining jumbo frame status for %s",
3132 port->netdev->name);
3133
Thomas Klein9c750b72007-01-29 18:44:01 +01003134 ehea_info("%s: Jumbo frames are %sabled", dev->name,
3135 jumbo == 1 ? "en" : "dis");
3136
Thomas Klein44c82152007-07-11 16:32:00 +02003137 adapter->active_ports++;
3138
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003139 return port;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003140
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003141out_unreg_port:
3142 ehea_unregister_port(port);
3143
3144out_free_mc_list:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003145 kfree(port->mc_list);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003146
3147out_free_ethdev:
3148 free_netdev(dev);
3149
3150out_err:
3151 ehea_error("setting up logical port with id=%d failed, ret=%d",
3152 logical_port_id, ret);
3153 return NULL;
3154}
3155
3156static void ehea_shutdown_single_port(struct ehea_port *port)
3157{
3158 unregister_netdev(port->netdev);
3159 ehea_unregister_port(port);
3160 kfree(port->mc_list);
3161 free_netdev(port->netdev);
Thomas Klein44c82152007-07-11 16:32:00 +02003162 port->adapter->active_ports--;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003163}
3164
3165static int ehea_setup_ports(struct ehea_adapter *adapter)
3166{
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003167 struct device_node *lhea_dn;
3168 struct device_node *eth_dn = NULL;
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003169
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003170 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003171 int i = 0;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003172
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003173 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003174 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003175
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003176 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003177 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003178 if (!dn_log_port_id) {
3179 ehea_error("bad device node: eth_dn name=%s",
3180 eth_dn->full_name);
3181 continue;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003182 }
3183
Thomas Klein1211bb62007-04-26 11:56:43 +02003184 if (ehea_add_adapter_mr(adapter)) {
3185 ehea_error("creating MR failed");
3186 of_node_put(eth_dn);
3187 return -EIO;
3188 }
3189
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003190 adapter->port[i] = ehea_setup_single_port(adapter,
3191 *dn_log_port_id,
3192 eth_dn);
3193 if (adapter->port[i])
3194 ehea_info("%s -> logical port id #%d",
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003195 adapter->port[i]->netdev->name,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003196 *dn_log_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003197 else
3198 ehea_remove_adapter_mr(adapter);
3199
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003200 i++;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003201 };
Thomas Klein1211bb62007-04-26 11:56:43 +02003202 return 0;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003203}
3204
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003205static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
3206 u32 logical_port_id)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003207{
3208 struct device_node *lhea_dn;
3209 struct device_node *eth_dn = NULL;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003210 const u32 *dn_log_port_id;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003211
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003212 lhea_dn = adapter->ofdev->node;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003213 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003214
Stephen Rothwell40cd3a42007-05-01 13:54:02 +10003215 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003216 NULL);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003217 if (dn_log_port_id)
3218 if (*dn_log_port_id == logical_port_id)
3219 return eth_dn;
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003220 };
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003221
3222 return NULL;
3223}
3224
3225static ssize_t ehea_probe_port(struct device *dev,
3226 struct device_attribute *attr,
3227 const char *buf, size_t count)
3228{
3229 struct ehea_adapter *adapter = dev->driver_data;
3230 struct ehea_port *port;
3231 struct device_node *eth_dn = NULL;
3232 int i;
3233
3234 u32 logical_port_id;
3235
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003236 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003237
3238 port = ehea_get_port(adapter, logical_port_id);
3239
3240 if (port) {
3241 ehea_info("adding port with logical port id=%d failed. port "
3242 "already configured as %s.", logical_port_id,
3243 port->netdev->name);
3244 return -EINVAL;
3245 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003246
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003247 eth_dn = ehea_get_eth_dn(adapter, logical_port_id);
3248
3249 if (!eth_dn) {
3250 ehea_info("no logical port with id %d found", logical_port_id);
3251 return -EINVAL;
3252 }
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003253
Thomas Klein1211bb62007-04-26 11:56:43 +02003254 if (ehea_add_adapter_mr(adapter)) {
3255 ehea_error("creating MR failed");
3256 return -EIO;
3257 }
3258
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003259 port = ehea_setup_single_port(adapter, logical_port_id, eth_dn);
3260
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003261 of_node_put(eth_dn);
3262
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003263 if (port) {
Doug Maxey508d2b52008-01-31 20:20:49 -06003264 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003265 if (!adapter->port[i]) {
3266 adapter->port[i] = port;
3267 break;
3268 }
3269
3270 ehea_info("added %s (logical port id=%d)", port->netdev->name,
3271 logical_port_id);
Thomas Klein1211bb62007-04-26 11:56:43 +02003272 } else {
3273 ehea_remove_adapter_mr(adapter);
Jan-Bernd Themanne542aa62007-03-22 17:50:24 +01003274 return -EIO;
Thomas Klein1211bb62007-04-26 11:56:43 +02003275 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003276
3277 return (ssize_t) count;
3278}
3279
3280static ssize_t ehea_remove_port(struct device *dev,
3281 struct device_attribute *attr,
3282 const char *buf, size_t count)
3283{
3284 struct ehea_adapter *adapter = dev->driver_data;
3285 struct ehea_port *port;
3286 int i;
3287 u32 logical_port_id;
3288
Jan-Bernd Themanna8e34fd2007-08-22 16:20:58 +02003289 sscanf(buf, "%d", &logical_port_id);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003290
3291 port = ehea_get_port(adapter, logical_port_id);
3292
3293 if (port) {
3294 ehea_info("removed %s (logical port id=%d)", port->netdev->name,
3295 logical_port_id);
3296
3297 ehea_shutdown_single_port(port);
3298
Doug Maxey508d2b52008-01-31 20:20:49 -06003299 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003300 if (adapter->port[i] == port) {
3301 adapter->port[i] = NULL;
3302 break;
3303 }
3304 } else {
3305 ehea_error("removing port with logical port id=%d failed. port "
3306 "not configured.", logical_port_id);
3307 return -EINVAL;
3308 }
3309
Thomas Klein1211bb62007-04-26 11:56:43 +02003310 ehea_remove_adapter_mr(adapter);
3311
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003312 return (ssize_t) count;
3313}
3314
3315static DEVICE_ATTR(probe_port, S_IWUSR, NULL, ehea_probe_port);
3316static DEVICE_ATTR(remove_port, S_IWUSR, NULL, ehea_remove_port);
3317
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003318int ehea_create_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003319{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003320 int ret = device_create_file(&dev->dev, &dev_attr_probe_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003321 if (ret)
3322 goto out;
3323
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003324 ret = device_create_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003325out:
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003326 return ret;
3327}
3328
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003329void ehea_remove_device_sysfs(struct of_device *dev)
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003330{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003331 device_remove_file(&dev->dev, &dev_attr_probe_port);
3332 device_remove_file(&dev->dev, &dev_attr_remove_port);
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003333}
3334
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003335static int __devinit ehea_probe_adapter(struct of_device *dev,
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003336 const struct of_device_id *id)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003337{
3338 struct ehea_adapter *adapter;
Stephen Rothwell9f9a3b82007-05-01 13:51:32 +10003339 const u64 *adapter_handle;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003340 int ret;
3341
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003342 if (!dev || !dev->node) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003343 ehea_error("Invalid ibmebus device probed");
3344 return -EINVAL;
3345 }
Daniel Walker9f71a562008-03-28 14:41:26 -07003346 mutex_lock(&ehea_fw_handles.lock);
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003347
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003348 adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
3349 if (!adapter) {
3350 ret = -ENOMEM;
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003351 dev_err(&dev->dev, "no mem for ehea_adapter\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003352 goto out;
3353 }
3354
Thomas Klein44c82152007-07-11 16:32:00 +02003355 list_add(&adapter->list, &adapter_list);
3356
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003357 adapter->ofdev = dev;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003358
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003359 adapter_handle = of_get_property(dev->node, "ibm,hea-handle",
Jan-Bernd Themannd1d25aa2007-07-02 13:00:46 +02003360 NULL);
Thomas Klein061bf3c2007-01-22 12:52:20 +01003361 if (adapter_handle)
3362 adapter->handle = *adapter_handle;
3363
3364 if (!adapter->handle) {
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003365 dev_err(&dev->dev, "failed getting handle for adapter"
3366 " '%s'\n", dev->node->full_name);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003367 ret = -ENODEV;
3368 goto out_free_ad;
3369 }
3370
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003371 adapter->pd = EHEA_PD_ID;
3372
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003373 dev->dev.driver_data = adapter;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003374
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003375
3376 /* initialize adapter and ports */
3377 /* get adapter properties */
3378 ret = ehea_sense_adapter_attr(adapter);
3379 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003380 dev_err(&dev->dev, "sense_adapter_attr failed: %d\n", ret);
Thomas Klein1211bb62007-04-26 11:56:43 +02003381 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003382 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003383
3384 adapter->neq = ehea_create_eq(adapter,
3385 EHEA_NEQ, EHEA_MAX_ENTRIES_EQ, 1);
3386 if (!adapter->neq) {
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003387 ret = -EIO;
Joe Perches898eb712007-10-18 03:06:30 -07003388 dev_err(&dev->dev, "NEQ creation failed\n");
Thomas Klein1211bb62007-04-26 11:56:43 +02003389 goto out_free_ad;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003390 }
3391
3392 tasklet_init(&adapter->neq_tasklet, ehea_neq_tasklet,
3393 (unsigned long)adapter);
3394
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003395 ret = ibmebus_request_irq(adapter->neq->attr.ist1,
Thomas Gleixner38515e92007-02-14 00:33:16 -08003396 ehea_interrupt_neq, IRQF_DISABLED,
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003397 "ehea_neq", adapter);
3398 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003399 dev_err(&dev->dev, "requesting NEQ IRQ failed\n");
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003400 goto out_kill_eq;
3401 }
3402
Jan-Bernd Themann1eef4e02007-03-22 17:49:42 +01003403 ret = ehea_create_device_sysfs(dev);
3404 if (ret)
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003405 goto out_free_irq;
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003406
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003407 ret = ehea_setup_ports(adapter);
3408 if (ret) {
Joe Perches898eb712007-10-18 03:06:30 -07003409 dev_err(&dev->dev, "setup_ports failed\n");
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003410 goto out_rem_dev_sysfs;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003411 }
3412
3413 ret = 0;
3414 goto out;
3415
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003416out_rem_dev_sysfs:
3417 ehea_remove_device_sysfs(dev);
3418
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003419out_free_irq:
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003420 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003421
3422out_kill_eq:
3423 ehea_destroy_eq(adapter->neq);
3424
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003425out_free_ad:
3426 kfree(adapter);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003427
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003428out:
Thomas Klein21eee2d2008-02-13 16:18:33 +01003429 ehea_update_firmware_handles();
Daniel Walker9f71a562008-03-28 14:41:26 -07003430 mutex_unlock(&ehea_fw_handles.lock);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003431 return ret;
3432}
3433
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003434static int __devexit ehea_remove(struct of_device *dev)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003435{
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003436 struct ehea_adapter *adapter = dev->dev.driver_data;
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003437 int i;
3438
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003439 for (i = 0; i < EHEA_MAX_PORTS; i++)
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003440 if (adapter->port[i]) {
3441 ehea_shutdown_single_port(adapter->port[i]);
3442 adapter->port[i] = NULL;
3443 }
Jan-Bernd Themann1acf2312007-02-28 18:34:02 +01003444
3445 ehea_remove_device_sysfs(dev);
3446
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003447 flush_scheduled_work();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003448
Daniel Walker9f71a562008-03-28 14:41:26 -07003449 mutex_lock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003450
Joachim Fenkes6b08f3a2007-09-26 19:45:51 +10003451 ibmebus_free_irq(adapter->neq->attr.ist1, adapter);
Thomas Kleind4150a22007-01-29 18:44:41 +01003452 tasklet_kill(&adapter->neq_tasklet);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003453
3454 ehea_destroy_eq(adapter->neq);
Thomas Klein1211bb62007-04-26 11:56:43 +02003455 ehea_remove_adapter_mr(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003456 list_del(&adapter->list);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003457 kfree(adapter);
Thomas Klein44c82152007-07-11 16:32:00 +02003458
Thomas Klein21eee2d2008-02-13 16:18:33 +01003459 ehea_update_firmware_handles();
Daniel Walker9f71a562008-03-28 14:41:26 -07003460 mutex_unlock(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003461
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003462 return 0;
3463}
3464
Thomas Klein21eee2d2008-02-13 16:18:33 +01003465void ehea_crash_handler(void)
3466{
3467 int i;
3468
3469 if (ehea_fw_handles.arr)
3470 for (i = 0; i < ehea_fw_handles.num_entries; i++)
3471 ehea_h_free_resource(ehea_fw_handles.arr[i].adh,
3472 ehea_fw_handles.arr[i].fwh,
3473 FORCE_FREE);
3474
3475 if (ehea_bcmc_regs.arr)
3476 for (i = 0; i < ehea_bcmc_regs.num_entries; i++)
3477 ehea_h_reg_dereg_bcmc(ehea_bcmc_regs.arr[i].adh,
3478 ehea_bcmc_regs.arr[i].port_id,
3479 ehea_bcmc_regs.arr[i].reg_type,
3480 ehea_bcmc_regs.arr[i].macaddr,
3481 0, H_DEREG_BCMC);
3482}
3483
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003484static int ehea_reboot_notifier(struct notifier_block *nb,
3485 unsigned long action, void *unused)
3486{
3487 if (action == SYS_RESTART) {
3488 ehea_info("Reboot: freeing all eHEA resources");
3489 ibmebus_unregister_driver(&ehea_driver);
3490 }
3491 return NOTIFY_DONE;
3492}
3493
3494static struct notifier_block ehea_reboot_nb = {
Doug Maxey508d2b52008-01-31 20:20:49 -06003495 .notifier_call = ehea_reboot_notifier,
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003496};
3497
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003498static int check_module_parm(void)
3499{
3500 int ret = 0;
3501
3502 if ((rq1_entries < EHEA_MIN_ENTRIES_QP) ||
3503 (rq1_entries > EHEA_MAX_ENTRIES_RQ1)) {
3504 ehea_info("Bad parameter: rq1_entries");
3505 ret = -EINVAL;
3506 }
3507 if ((rq2_entries < EHEA_MIN_ENTRIES_QP) ||
3508 (rq2_entries > EHEA_MAX_ENTRIES_RQ2)) {
3509 ehea_info("Bad parameter: rq2_entries");
3510 ret = -EINVAL;
3511 }
3512 if ((rq3_entries < EHEA_MIN_ENTRIES_QP) ||
3513 (rq3_entries > EHEA_MAX_ENTRIES_RQ3)) {
3514 ehea_info("Bad parameter: rq3_entries");
3515 ret = -EINVAL;
3516 }
3517 if ((sq_entries < EHEA_MIN_ENTRIES_QP) ||
3518 (sq_entries > EHEA_MAX_ENTRIES_SQ)) {
3519 ehea_info("Bad parameter: sq_entries");
3520 ret = -EINVAL;
3521 }
3522
3523 return ret;
3524}
3525
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003526static ssize_t ehea_show_capabilities(struct device_driver *drv,
3527 char *buf)
3528{
3529 return sprintf(buf, "%d", EHEA_CAPABILITIES);
3530}
3531
3532static DRIVER_ATTR(capabilities, S_IRUSR | S_IRGRP | S_IROTH,
3533 ehea_show_capabilities, NULL);
3534
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003535int __init ehea_module_init(void)
3536{
3537 int ret;
3538
3539 printk(KERN_INFO "IBM eHEA ethernet device driver (Release %s)\n",
3540 DRV_VERSION);
3541
Thomas Klein44c82152007-07-11 16:32:00 +02003542
3543 INIT_WORK(&ehea_rereg_mr_task, ehea_rereg_mrs);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003544 memset(&ehea_fw_handles, 0, sizeof(ehea_fw_handles));
3545 memset(&ehea_bcmc_regs, 0, sizeof(ehea_bcmc_regs));
3546
Daniel Walker9f71a562008-03-28 14:41:26 -07003547 mutex_init(&ehea_fw_handles.lock);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003548 sema_init(&ehea_bcmc_regs.lock, 1);
Thomas Klein44c82152007-07-11 16:32:00 +02003549
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003550 ret = check_module_parm();
3551 if (ret)
3552 goto out;
Thomas Klein44c82152007-07-11 16:32:00 +02003553
3554 ret = ehea_create_busmap();
3555 if (ret)
3556 goto out;
3557
Thomas Klein21eee2d2008-02-13 16:18:33 +01003558 ret = register_reboot_notifier(&ehea_reboot_nb);
3559 if (ret)
3560 ehea_info("failed registering reboot notifier");
3561
3562 ret = crash_shutdown_register(&ehea_crash_handler);
3563 if (ret)
3564 ehea_info("failed registering crash handler");
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003565
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003566 ret = ibmebus_register_driver(&ehea_driver);
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003567 if (ret) {
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003568 ehea_error("failed registering eHEA device driver on ebus");
Thomas Klein21eee2d2008-02-13 16:18:33 +01003569 goto out2;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003570 }
3571
3572 ret = driver_create_file(&ehea_driver.driver,
3573 &driver_attr_capabilities);
3574 if (ret) {
3575 ehea_error("failed to register capabilities attribute, ret=%d",
3576 ret);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003577 goto out3;
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003578 }
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003579
Thomas Klein21eee2d2008-02-13 16:18:33 +01003580 return ret;
3581
3582out3:
3583 ibmebus_unregister_driver(&ehea_driver);
3584out2:
3585 unregister_reboot_notifier(&ehea_reboot_nb);
3586 crash_shutdown_unregister(&ehea_crash_handler);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003587out:
3588 return ret;
3589}
3590
3591static void __exit ehea_module_exit(void)
3592{
Thomas Klein21eee2d2008-02-13 16:18:33 +01003593 int ret;
3594
Jan-Bernd Themann3bf76b82007-10-08 16:01:33 +02003595 flush_scheduled_work();
Jan-Bernd Themann4c3ca4d2007-07-05 09:26:25 +02003596 driver_remove_file(&ehea_driver.driver, &driver_attr_capabilities);
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003597 ibmebus_unregister_driver(&ehea_driver);
Jan-Bernd Themann2a6f4e42007-10-26 14:37:28 +02003598 unregister_reboot_notifier(&ehea_reboot_nb);
Thomas Klein21eee2d2008-02-13 16:18:33 +01003599 ret = crash_shutdown_unregister(&ehea_crash_handler);
3600 if (ret)
3601 ehea_info("failed unregistering crash handler");
3602 kfree(ehea_fw_handles.arr);
3603 kfree(ehea_bcmc_regs.arr);
Thomas Klein44c82152007-07-11 16:32:00 +02003604 ehea_destroy_busmap();
Jan-Bernd Themann7a291082006-09-13 17:44:31 +02003605}
3606
3607module_init(ehea_module_init);
3608module_exit(ehea_module_exit);