This source file includes following definitions.
- qeth_l2_setdelmac_makerc
- qeth_l2_send_setdelmac_cb
- qeth_l2_send_setdelmac
- qeth_l2_send_setmac
- qeth_l2_write_mac
- qeth_l2_remove_mac
- qeth_l2_drain_rx_mode_cache
- qeth_l2_fill_header
- qeth_l2_setdelvlan_makerc
- qeth_l2_send_setdelvlan_cb
- qeth_l2_send_setdelvlan
- qeth_l2_vlan_rx_add_vid
- qeth_l2_vlan_rx_kill_vid
- qeth_l2_stop_card
- qeth_l2_process_inbound_buffer
- qeth_l2_request_initial_mac
- qeth_l2_register_dev_addr
- qeth_l2_validate_addr
- qeth_l2_set_mac_address
- qeth_l2_promisc_to_bridge
- qeth_l2_set_promisc_mode
- qeth_l2_add_mac
- qeth_l2_rx_mode_work
- qeth_l2_xmit_osn
- qeth_l2_hard_start_xmit
- qeth_l2_select_queue
- qeth_l2_probe_device
- qeth_l2_remove_device
- qeth_l2_set_rx_mode
- qeth_l2_setup_netdev
- qeth_l2_start_ipassists
- qeth_l2_trace_features
- qeth_l2_set_online
- __qeth_l2_set_offline
- qeth_l2_set_offline
- qeth_l2_recover
- qeth_l2_init
- qeth_l2_exit
- qeth_l2_control_event
- qeth_osn_assist_cb
- qeth_osn_assist
- qeth_osn_register
- qeth_osn_deregister
- qeth_bridge_emit_host_event
- qeth_bridge_state_change_worker
- qeth_bridge_state_change
- qeth_bridge_host_event_worker
- qeth_bridge_host_event
- qeth_bridgeport_makerc
- qeth_sbp_build_cmd
- qeth_bridgeport_query_support_cb
- qeth_bridgeport_query_support
- qeth_bridgeport_query_ports_cb
- qeth_bridgeport_query_ports
- qeth_bridgeport_set_cb
- qeth_bridgeport_setrole
- qeth_anset_makerc
- qeth_bridgeport_an_set_cb
- qeth_bridgeport_an_set
- qeth_bridgeport_is_in_use
- qeth_l2_vnicc_makerc
- qeth_l2_vnicc_request_cb
- qeth_l2_vnicc_build_cmd
- qeth_l2_vnicc_query_chars
- qeth_l2_vnicc_query_cmds
- qeth_l2_vnicc_set_char
- qeth_l2_vnicc_getset_timeout
- qeth_l2_vnicc_set_state
- qeth_l2_vnicc_get_state
- qeth_l2_vnicc_set_timeout
- qeth_l2_vnicc_get_timeout
- qeth_l2_vnicc_is_in_use
- qeth_l2_vnicc_recover_timeout
- qeth_l2_vnicc_recover_char
- qeth_l2_vnicc_init
- qeth_l2_vnicc_set_defaults
1
2
3
4
5
6
7
8
9
10 #define KMSG_COMPONENT "qeth"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
13 #include <linux/module.h>
14 #include <linux/moduleparam.h>
15 #include <linux/string.h>
16 #include <linux/errno.h>
17 #include <linux/kernel.h>
18 #include <linux/slab.h>
19 #include <linux/etherdevice.h>
20 #include <linux/list.h>
21 #include <linux/hash.h>
22 #include <linux/hashtable.h>
23 #include <asm/setup.h>
24 #include "qeth_core.h"
25 #include "qeth_l2.h"
26
27 static int qeth_l2_set_offline(struct ccwgroup_device *);
28 static void qeth_bridgeport_query_support(struct qeth_card *card);
29 static void qeth_bridge_state_change(struct qeth_card *card,
30 struct qeth_ipa_cmd *cmd);
31 static void qeth_bridge_host_event(struct qeth_card *card,
32 struct qeth_ipa_cmd *cmd);
33 static void qeth_l2_vnicc_set_defaults(struct qeth_card *card);
34 static void qeth_l2_vnicc_init(struct qeth_card *card);
35 static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
36 u32 *timeout);
37
38 static int qeth_l2_setdelmac_makerc(struct qeth_card *card, u16 retcode)
39 {
40 int rc;
41
42 if (retcode)
43 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
44 switch (retcode) {
45 case IPA_RC_SUCCESS:
46 rc = 0;
47 break;
48 case IPA_RC_L2_UNSUPPORTED_CMD:
49 rc = -EOPNOTSUPP;
50 break;
51 case IPA_RC_L2_ADDR_TABLE_FULL:
52 rc = -ENOSPC;
53 break;
54 case IPA_RC_L2_DUP_MAC:
55 case IPA_RC_L2_DUP_LAYER3_MAC:
56 rc = -EEXIST;
57 break;
58 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
59 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
60 rc = -EPERM;
61 break;
62 case IPA_RC_L2_MAC_NOT_FOUND:
63 rc = -ENOENT;
64 break;
65 default:
66 rc = -EIO;
67 break;
68 }
69 return rc;
70 }
71
72 static int qeth_l2_send_setdelmac_cb(struct qeth_card *card,
73 struct qeth_reply *reply,
74 unsigned long data)
75 {
76 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
77
78 return qeth_l2_setdelmac_makerc(card, cmd->hdr.return_code);
79 }
80
81 static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
82 enum qeth_ipa_cmds ipacmd)
83 {
84 struct qeth_ipa_cmd *cmd;
85 struct qeth_cmd_buffer *iob;
86
87 QETH_CARD_TEXT(card, 2, "L2sdmac");
88 iob = qeth_ipa_alloc_cmd(card, ipacmd, QETH_PROT_IPV4,
89 IPA_DATA_SIZEOF(setdelmac));
90 if (!iob)
91 return -ENOMEM;
92 cmd = __ipa_cmd(iob);
93 cmd->data.setdelmac.mac_length = ETH_ALEN;
94 ether_addr_copy(cmd->data.setdelmac.mac, mac);
95 return qeth_send_ipa_cmd(card, iob, qeth_l2_send_setdelmac_cb, NULL);
96 }
97
98 static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
99 {
100 int rc;
101
102 QETH_CARD_TEXT(card, 2, "L2Setmac");
103 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC);
104 if (rc == 0) {
105 dev_info(&card->gdev->dev,
106 "MAC address %pM successfully registered\n", mac);
107 } else {
108 switch (rc) {
109 case -EEXIST:
110 dev_warn(&card->gdev->dev,
111 "MAC address %pM already exists\n", mac);
112 break;
113 case -EPERM:
114 dev_warn(&card->gdev->dev,
115 "MAC address %pM is not authorized\n", mac);
116 break;
117 }
118 }
119 return rc;
120 }
121
122 static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac)
123 {
124 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
125 IPA_CMD_SETGMAC : IPA_CMD_SETVMAC;
126 int rc;
127
128 QETH_CARD_TEXT(card, 2, "L2Wmac");
129 rc = qeth_l2_send_setdelmac(card, mac, cmd);
130 if (rc == -EEXIST)
131 QETH_DBF_MESSAGE(2, "MAC already registered on device %x\n",
132 CARD_DEVID(card));
133 else if (rc)
134 QETH_DBF_MESSAGE(2, "Failed to register MAC on device %x: %d\n",
135 CARD_DEVID(card), rc);
136 return rc;
137 }
138
139 static int qeth_l2_remove_mac(struct qeth_card *card, u8 *mac)
140 {
141 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
142 IPA_CMD_DELGMAC : IPA_CMD_DELVMAC;
143 int rc;
144
145 QETH_CARD_TEXT(card, 2, "L2Rmac");
146 rc = qeth_l2_send_setdelmac(card, mac, cmd);
147 if (rc)
148 QETH_DBF_MESSAGE(2, "Failed to delete MAC on device %u: %d\n",
149 CARD_DEVID(card), rc);
150 return rc;
151 }
152
153 static void qeth_l2_drain_rx_mode_cache(struct qeth_card *card)
154 {
155 struct qeth_mac *mac;
156 struct hlist_node *tmp;
157 int i;
158
159 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
160 hash_del(&mac->hnode);
161 kfree(mac);
162 }
163 }
164
165 static void qeth_l2_fill_header(struct qeth_qdio_out_q *queue,
166 struct qeth_hdr *hdr, struct sk_buff *skb,
167 int ipv, unsigned int data_len)
168 {
169 int cast_type = qeth_get_ether_cast_type(skb);
170 struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
171
172 hdr->hdr.l2.pkt_length = data_len;
173
174 if (skb_is_gso(skb)) {
175 hdr->hdr.l2.id = QETH_HEADER_TYPE_L2_TSO;
176 } else {
177 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
178 if (skb->ip_summed == CHECKSUM_PARTIAL)
179 qeth_tx_csum(skb, &hdr->hdr.l2.flags[1], ipv);
180 }
181
182
183 if (cast_type == RTN_MULTICAST)
184 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
185 else if (cast_type == RTN_BROADCAST)
186 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
187 else
188 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
189
190
191
192
193 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
194 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
195 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
196 }
197 }
198
199 static int qeth_l2_setdelvlan_makerc(struct qeth_card *card, u16 retcode)
200 {
201 if (retcode)
202 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
203
204 switch (retcode) {
205 case IPA_RC_SUCCESS:
206 return 0;
207 case IPA_RC_L2_INVALID_VLAN_ID:
208 return -EINVAL;
209 case IPA_RC_L2_DUP_VLAN_ID:
210 return -EEXIST;
211 case IPA_RC_L2_VLAN_ID_NOT_FOUND:
212 return -ENOENT;
213 case IPA_RC_L2_VLAN_ID_NOT_ALLOWED:
214 return -EPERM;
215 default:
216 return -EIO;
217 }
218 }
219
220 static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
221 struct qeth_reply *reply,
222 unsigned long data)
223 {
224 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
225
226 QETH_CARD_TEXT(card, 2, "L2sdvcb");
227 if (cmd->hdr.return_code) {
228 QETH_DBF_MESSAGE(2, "Error in processing VLAN %u on device %x: %#x.\n",
229 cmd->data.setdelvlan.vlan_id,
230 CARD_DEVID(card), cmd->hdr.return_code);
231 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
232 }
233 return qeth_l2_setdelvlan_makerc(card, cmd->hdr.return_code);
234 }
235
236 static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
237 enum qeth_ipa_cmds ipacmd)
238 {
239 struct qeth_ipa_cmd *cmd;
240 struct qeth_cmd_buffer *iob;
241
242 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
243 iob = qeth_ipa_alloc_cmd(card, ipacmd, QETH_PROT_IPV4,
244 IPA_DATA_SIZEOF(setdelvlan));
245 if (!iob)
246 return -ENOMEM;
247 cmd = __ipa_cmd(iob);
248 cmd->data.setdelvlan.vlan_id = i;
249 return qeth_send_ipa_cmd(card, iob, qeth_l2_send_setdelvlan_cb, NULL);
250 }
251
252 static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
253 __be16 proto, u16 vid)
254 {
255 struct qeth_card *card = dev->ml_priv;
256
257 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
258 if (!vid)
259 return 0;
260
261 return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
262 }
263
264 static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
265 __be16 proto, u16 vid)
266 {
267 struct qeth_card *card = dev->ml_priv;
268
269 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
270 if (!vid)
271 return 0;
272
273 return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
274 }
275
276 static void qeth_l2_stop_card(struct qeth_card *card)
277 {
278 QETH_CARD_TEXT(card, 2, "stopcard");
279
280 qeth_set_allowed_threads(card, 0, 1);
281
282 cancel_work_sync(&card->rx_mode_work);
283 qeth_l2_drain_rx_mode_cache(card);
284
285 if (card->state == CARD_STATE_SOFTSETUP) {
286 qeth_clear_ipacmd_list(card);
287 card->state = CARD_STATE_HARDSETUP;
288 }
289 if (card->state == CARD_STATE_HARDSETUP) {
290 qeth_drain_output_queues(card);
291 qeth_clear_working_pool_list(card);
292 card->state = CARD_STATE_DOWN;
293 }
294
295 qeth_qdio_clear_card(card, 0);
296 flush_workqueue(card->event_wq);
297 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
298 card->info.promisc_mode = 0;
299 }
300
301 static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
302 int budget, int *done)
303 {
304 int work_done = 0;
305 struct sk_buff *skb;
306 struct qeth_hdr *hdr;
307 unsigned int len;
308
309 *done = 0;
310 WARN_ON_ONCE(!budget);
311 while (budget) {
312 skb = qeth_core_get_next_skb(card,
313 &card->qdio.in_q->bufs[card->rx.b_index],
314 &card->rx.b_element, &card->rx.e_offset, &hdr);
315 if (!skb) {
316 *done = 1;
317 break;
318 }
319 switch (hdr->hdr.l2.id) {
320 case QETH_HEADER_TYPE_LAYER2:
321 skb->protocol = eth_type_trans(skb, skb->dev);
322 qeth_rx_csum(card, skb, hdr->hdr.l2.flags[1]);
323 len = skb->len;
324 napi_gro_receive(&card->napi, skb);
325 break;
326 case QETH_HEADER_TYPE_OSN:
327 if (IS_OSN(card)) {
328 skb_push(skb, sizeof(struct qeth_hdr));
329 skb_copy_to_linear_data(skb, hdr,
330 sizeof(struct qeth_hdr));
331 len = skb->len;
332 card->osn_info.data_cb(skb);
333 break;
334 }
335
336 default:
337 dev_kfree_skb_any(skb);
338 QETH_CARD_TEXT(card, 3, "inbunkno");
339 QETH_DBF_HEX(CTRL, 3, hdr, sizeof(*hdr));
340 continue;
341 }
342 work_done++;
343 budget--;
344 QETH_CARD_STAT_INC(card, rx_packets);
345 QETH_CARD_STAT_ADD(card, rx_bytes, len);
346 }
347 return work_done;
348 }
349
350 static int qeth_l2_request_initial_mac(struct qeth_card *card)
351 {
352 int rc = 0;
353
354 QETH_CARD_TEXT(card, 2, "l2reqmac");
355
356 if (MACHINE_IS_VM) {
357 rc = qeth_vm_request_mac(card);
358 if (!rc)
359 goto out;
360 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %x: %#x\n",
361 CARD_DEVID(card), rc);
362 QETH_CARD_TEXT_(card, 2, "err%04x", rc);
363
364 }
365
366 if (!IS_OSN(card)) {
367 rc = qeth_setadpparms_change_macaddr(card);
368 if (!rc)
369 goto out;
370 QETH_DBF_MESSAGE(2, "READ_MAC Assist failed on device %x: %#x\n",
371 CARD_DEVID(card), rc);
372 QETH_CARD_TEXT_(card, 2, "1err%04x", rc);
373
374 }
375
376
377 if (IS_OSM(card) || IS_OSX(card))
378 return (rc) ? rc : -EADDRNOTAVAIL;
379 eth_hw_addr_random(card->dev);
380
381 out:
382 QETH_CARD_HEX(card, 2, card->dev->dev_addr, card->dev->addr_len);
383 return 0;
384 }
385
386 static void qeth_l2_register_dev_addr(struct qeth_card *card)
387 {
388 if (!is_valid_ether_addr(card->dev->dev_addr))
389 qeth_l2_request_initial_mac(card);
390
391 if (!IS_OSN(card) && !qeth_l2_send_setmac(card, card->dev->dev_addr))
392 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
393 }
394
395 static int qeth_l2_validate_addr(struct net_device *dev)
396 {
397 struct qeth_card *card = dev->ml_priv;
398
399 if (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)
400 return eth_validate_addr(dev);
401
402 QETH_CARD_TEXT(card, 4, "nomacadr");
403 return -EPERM;
404 }
405
406 static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
407 {
408 struct sockaddr *addr = p;
409 struct qeth_card *card = dev->ml_priv;
410 u8 old_addr[ETH_ALEN];
411 int rc = 0;
412
413 QETH_CARD_TEXT(card, 3, "setmac");
414
415 if (IS_OSM(card) || IS_OSX(card)) {
416 QETH_CARD_TEXT(card, 3, "setmcTYP");
417 return -EOPNOTSUPP;
418 }
419 QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN);
420 if (!is_valid_ether_addr(addr->sa_data))
421 return -EADDRNOTAVAIL;
422
423
424 if (ether_addr_equal_64bits(dev->dev_addr, addr->sa_data) &&
425 (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
426 return 0;
427
428
429 rc = qeth_l2_send_setmac(card, addr->sa_data);
430 if (rc)
431 return rc;
432 ether_addr_copy(old_addr, dev->dev_addr);
433 ether_addr_copy(dev->dev_addr, addr->sa_data);
434
435 if (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)
436 qeth_l2_remove_mac(card, old_addr);
437 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
438 return 0;
439 }
440
441 static void qeth_l2_promisc_to_bridge(struct qeth_card *card, bool enable)
442 {
443 int role;
444 int rc;
445
446 QETH_CARD_TEXT(card, 3, "pmisc2br");
447
448 if (enable) {
449 if (card->options.sbp.reflect_promisc_primary)
450 role = QETH_SBP_ROLE_PRIMARY;
451 else
452 role = QETH_SBP_ROLE_SECONDARY;
453 } else
454 role = QETH_SBP_ROLE_NONE;
455
456 rc = qeth_bridgeport_setrole(card, role);
457 QETH_CARD_TEXT_(card, 2, "bpm%c%04x", enable ? '+' : '-', rc);
458 if (!rc) {
459 card->options.sbp.role = role;
460 card->info.promisc_mode = enable;
461 }
462 }
463
464 static void qeth_l2_set_promisc_mode(struct qeth_card *card)
465 {
466 bool enable = card->dev->flags & IFF_PROMISC;
467
468 if (card->info.promisc_mode == enable)
469 return;
470
471 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) {
472 qeth_setadp_promisc_mode(card, enable);
473 } else {
474 mutex_lock(&card->sbp_lock);
475 if (card->options.sbp.reflect_promisc)
476 qeth_l2_promisc_to_bridge(card, enable);
477 mutex_unlock(&card->sbp_lock);
478 }
479 }
480
481
482
483
484
485 static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha)
486 {
487 u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2]));
488 struct qeth_mac *mac;
489
490 hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) {
491 if (ether_addr_equal_64bits(ha->addr, mac->mac_addr)) {
492 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
493 return;
494 }
495 }
496
497 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
498 if (!mac)
499 return;
500
501 ether_addr_copy(mac->mac_addr, ha->addr);
502 mac->disp_flag = QETH_DISP_ADDR_ADD;
503
504 hash_add(card->mac_htable, &mac->hnode, mac_hash);
505 }
506
507 static void qeth_l2_rx_mode_work(struct work_struct *work)
508 {
509 struct qeth_card *card = container_of(work, struct qeth_card,
510 rx_mode_work);
511 struct net_device *dev = card->dev;
512 struct netdev_hw_addr *ha;
513 struct qeth_mac *mac;
514 struct hlist_node *tmp;
515 int i;
516 int rc;
517
518 QETH_CARD_TEXT(card, 3, "setmulti");
519
520 netif_addr_lock_bh(dev);
521 netdev_for_each_mc_addr(ha, dev)
522 qeth_l2_add_mac(card, ha);
523 netdev_for_each_uc_addr(ha, dev)
524 qeth_l2_add_mac(card, ha);
525 netif_addr_unlock_bh(dev);
526
527 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
528 switch (mac->disp_flag) {
529 case QETH_DISP_ADDR_DELETE:
530 qeth_l2_remove_mac(card, mac->mac_addr);
531 hash_del(&mac->hnode);
532 kfree(mac);
533 break;
534 case QETH_DISP_ADDR_ADD:
535 rc = qeth_l2_write_mac(card, mac->mac_addr);
536 if (rc) {
537 hash_del(&mac->hnode);
538 kfree(mac);
539 break;
540 }
541
542 default:
543
544 mac->disp_flag = QETH_DISP_ADDR_DELETE;
545 }
546 }
547
548 qeth_l2_set_promisc_mode(card);
549 }
550
551 static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb,
552 struct qeth_qdio_out_q *queue)
553 {
554 struct qeth_hdr *hdr = (struct qeth_hdr *)skb->data;
555 addr_t end = (addr_t)(skb->data + sizeof(*hdr));
556 addr_t start = (addr_t)skb->data;
557 unsigned int elements = 0;
558 unsigned int hd_len = 0;
559 int rc;
560
561 if (skb->protocol == htons(ETH_P_IPV6))
562 return -EPROTONOSUPPORT;
563
564 if (qeth_get_elements_for_range(start, end) > 1) {
565
566 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
567 if (!hdr)
568 return -ENOMEM;
569 hd_len = sizeof(*hdr);
570 skb_copy_from_linear_data(skb, (char *)hdr, hd_len);
571 elements++;
572 }
573
574 elements += qeth_count_elements(skb, hd_len);
575 if (elements > queue->max_elements) {
576 rc = -E2BIG;
577 goto out;
578 }
579
580 rc = qeth_do_send_packet(card, queue, skb, hdr, hd_len, hd_len,
581 elements);
582 out:
583 if (rc && hd_len)
584 kmem_cache_free(qeth_core_header_cache, hdr);
585 return rc;
586 }
587
588 static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb,
589 struct net_device *dev)
590 {
591 struct qeth_card *card = dev->ml_priv;
592 u16 txq = skb_get_queue_mapping(skb);
593 struct qeth_qdio_out_q *queue;
594 int rc;
595
596 if (!skb_is_gso(skb))
597 qdisc_skb_cb(skb)->pkt_len = skb->len;
598 if (IS_IQD(card))
599 txq = qeth_iqd_translate_txq(dev, txq);
600 queue = card->qdio.out_qs[txq];
601
602 if (IS_OSN(card))
603 rc = qeth_l2_xmit_osn(card, skb, queue);
604 else
605 rc = qeth_xmit(card, skb, queue, qeth_get_ip_version(skb),
606 qeth_l2_fill_header);
607
608 if (!rc)
609 return NETDEV_TX_OK;
610
611 QETH_TXQ_STAT_INC(queue, tx_dropped);
612 kfree_skb(skb);
613 return NETDEV_TX_OK;
614 }
615
616 static u16 qeth_l2_select_queue(struct net_device *dev, struct sk_buff *skb,
617 struct net_device *sb_dev)
618 {
619 struct qeth_card *card = dev->ml_priv;
620
621 if (IS_IQD(card))
622 return qeth_iqd_select_queue(dev, skb,
623 qeth_get_ether_cast_type(skb),
624 sb_dev);
625 return qeth_get_priority_queue(card, skb);
626 }
627
628 static const struct device_type qeth_l2_devtype = {
629 .name = "qeth_layer2",
630 .groups = qeth_l2_attr_groups,
631 };
632
633 static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
634 {
635 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
636 int rc;
637
638 qeth_l2_vnicc_set_defaults(card);
639 mutex_init(&card->sbp_lock);
640
641 if (gdev->dev.type == &qeth_generic_devtype) {
642 rc = qeth_l2_create_device_attributes(&gdev->dev);
643 if (rc)
644 return rc;
645 }
646
647 hash_init(card->mac_htable);
648 INIT_WORK(&card->rx_mode_work, qeth_l2_rx_mode_work);
649 return 0;
650 }
651
652 static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
653 {
654 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
655
656 if (cgdev->dev.type == &qeth_generic_devtype)
657 qeth_l2_remove_device_attributes(&cgdev->dev);
658 qeth_set_allowed_threads(card, 0, 1);
659 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
660
661 if (cgdev->state == CCWGROUP_ONLINE)
662 qeth_l2_set_offline(cgdev);
663
664 cancel_work_sync(&card->close_dev_work);
665 if (qeth_netdev_is_registered(card->dev))
666 unregister_netdev(card->dev);
667 }
668
669 static void qeth_l2_set_rx_mode(struct net_device *dev)
670 {
671 struct qeth_card *card = dev->ml_priv;
672
673 schedule_work(&card->rx_mode_work);
674 }
675
676 static const struct net_device_ops qeth_l2_netdev_ops = {
677 .ndo_open = qeth_open,
678 .ndo_stop = qeth_stop,
679 .ndo_get_stats64 = qeth_get_stats64,
680 .ndo_start_xmit = qeth_l2_hard_start_xmit,
681 .ndo_features_check = qeth_features_check,
682 .ndo_select_queue = qeth_l2_select_queue,
683 .ndo_validate_addr = qeth_l2_validate_addr,
684 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
685 .ndo_do_ioctl = qeth_do_ioctl,
686 .ndo_set_mac_address = qeth_l2_set_mac_address,
687 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
688 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
689 .ndo_tx_timeout = qeth_tx_timeout,
690 .ndo_fix_features = qeth_fix_features,
691 .ndo_set_features = qeth_set_features
692 };
693
694 static const struct net_device_ops qeth_osn_netdev_ops = {
695 .ndo_open = qeth_open,
696 .ndo_stop = qeth_stop,
697 .ndo_get_stats64 = qeth_get_stats64,
698 .ndo_start_xmit = qeth_l2_hard_start_xmit,
699 .ndo_validate_addr = eth_validate_addr,
700 .ndo_tx_timeout = qeth_tx_timeout,
701 };
702
703 static int qeth_l2_setup_netdev(struct qeth_card *card, bool carrier_ok)
704 {
705 int rc;
706
707 if (IS_OSN(card)) {
708 card->dev->netdev_ops = &qeth_osn_netdev_ops;
709 card->dev->flags |= IFF_NOARP;
710 goto add_napi;
711 }
712
713 card->dev->needed_headroom = sizeof(struct qeth_hdr);
714 card->dev->netdev_ops = &qeth_l2_netdev_ops;
715 card->dev->priv_flags |= IFF_UNICAST_FLT;
716
717 if (IS_OSM(card)) {
718 card->dev->features |= NETIF_F_VLAN_CHALLENGED;
719 } else {
720 if (!IS_VM_NIC(card))
721 card->dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
722 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
723 }
724
725 if (IS_OSD(card) && !IS_VM_NIC(card)) {
726 card->dev->features |= NETIF_F_SG;
727
728 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
729 card->dev->hw_features |= NETIF_F_IP_CSUM;
730 card->dev->vlan_features |= NETIF_F_IP_CSUM;
731 }
732 }
733 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
734 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
735 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
736 }
737 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM) ||
738 qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6)) {
739 card->dev->hw_features |= NETIF_F_RXCSUM;
740 card->dev->vlan_features |= NETIF_F_RXCSUM;
741 }
742 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
743 card->dev->hw_features |= NETIF_F_TSO;
744 card->dev->vlan_features |= NETIF_F_TSO;
745 }
746 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) {
747 card->dev->hw_features |= NETIF_F_TSO6;
748 card->dev->vlan_features |= NETIF_F_TSO6;
749 }
750
751 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6)) {
752 card->dev->needed_headroom = sizeof(struct qeth_hdr_tso);
753 netif_set_gso_max_size(card->dev,
754 PAGE_SIZE * (QDIO_MAX_ELEMENTS_PER_BUFFER - 1));
755 }
756
757 add_napi:
758 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
759 rc = register_netdev(card->dev);
760 if (!rc && carrier_ok)
761 netif_carrier_on(card->dev);
762
763 if (rc)
764 card->dev->netdev_ops = NULL;
765 return rc;
766 }
767
768 static int qeth_l2_start_ipassists(struct qeth_card *card)
769 {
770
771 if (qeth_set_access_ctrl_online(card, 0))
772 return -ENODEV;
773 return 0;
774 }
775
776 static void qeth_l2_trace_features(struct qeth_card *card)
777 {
778
779 QETH_CARD_TEXT(card, 2, "featuSBP");
780 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs,
781 sizeof(card->options.sbp.supported_funcs));
782
783 QETH_CARD_TEXT(card, 2, "feaVNICC");
784 QETH_CARD_HEX(card, 2, &card->options.vnicc.sup_chars,
785 sizeof(card->options.vnicc.sup_chars));
786 }
787
788 static int qeth_l2_set_online(struct ccwgroup_device *gdev)
789 {
790 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
791 struct net_device *dev = card->dev;
792 int rc = 0;
793 bool carrier_ok;
794
795 mutex_lock(&card->discipline_mutex);
796 mutex_lock(&card->conf_mutex);
797 QETH_CARD_TEXT(card, 2, "setonlin");
798
799 rc = qeth_core_hardsetup_card(card, &carrier_ok);
800 if (rc) {
801 QETH_CARD_TEXT_(card, 2, "2err%04x", rc);
802 rc = -ENODEV;
803 goto out_remove;
804 }
805
806 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
807 if (card->info.hwtrap &&
808 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
809 card->info.hwtrap = 0;
810 } else
811 card->info.hwtrap = 0;
812
813 mutex_lock(&card->sbp_lock);
814 qeth_bridgeport_query_support(card);
815 if (card->options.sbp.supported_funcs)
816 dev_info(&card->gdev->dev,
817 "The device represents a Bridge Capable Port\n");
818 mutex_unlock(&card->sbp_lock);
819
820 qeth_l2_register_dev_addr(card);
821
822
823 qeth_l2_vnicc_init(card);
824
825 qeth_trace_features(card);
826 qeth_l2_trace_features(card);
827
828 qeth_l2_setup_bridgeport_attrs(card);
829
830 card->state = CARD_STATE_HARDSETUP;
831 qeth_print_status_message(card);
832
833
834 QETH_CARD_TEXT(card, 2, "softsetp");
835
836 if (IS_OSD(card) || IS_OSX(card)) {
837 rc = qeth_l2_start_ipassists(card);
838 if (rc)
839 goto out_remove;
840 }
841
842 rc = qeth_init_qdio_queues(card);
843 if (rc) {
844 QETH_CARD_TEXT_(card, 2, "6err%d", rc);
845 rc = -ENODEV;
846 goto out_remove;
847 }
848 card->state = CARD_STATE_SOFTSETUP;
849
850 qeth_set_allowed_threads(card, 0xffffffff, 0);
851
852 if (!qeth_netdev_is_registered(dev)) {
853 rc = qeth_l2_setup_netdev(card, carrier_ok);
854 if (rc)
855 goto out_remove;
856 } else {
857 rtnl_lock();
858 if (carrier_ok)
859 netif_carrier_on(dev);
860 else
861 netif_carrier_off(dev);
862
863 netif_device_attach(dev);
864 qeth_enable_hw_features(dev);
865
866 if (card->info.open_when_online) {
867 card->info.open_when_online = 0;
868 dev_open(dev, NULL);
869 }
870 rtnl_unlock();
871 }
872
873 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
874 mutex_unlock(&card->conf_mutex);
875 mutex_unlock(&card->discipline_mutex);
876 return 0;
877
878 out_remove:
879 qeth_l2_stop_card(card);
880 qeth_stop_channel(&card->data);
881 qeth_stop_channel(&card->write);
882 qeth_stop_channel(&card->read);
883 qdio_free(CARD_DDEV(card));
884
885 mutex_unlock(&card->conf_mutex);
886 mutex_unlock(&card->discipline_mutex);
887 return rc;
888 }
889
890 static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
891 int recovery_mode)
892 {
893 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
894 int rc = 0, rc2 = 0, rc3 = 0;
895
896 mutex_lock(&card->discipline_mutex);
897 mutex_lock(&card->conf_mutex);
898 QETH_CARD_TEXT(card, 3, "setoffl");
899
900 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
901 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
902 card->info.hwtrap = 1;
903 }
904
905 rtnl_lock();
906 card->info.open_when_online = card->dev->flags & IFF_UP;
907 dev_close(card->dev);
908 netif_device_detach(card->dev);
909 netif_carrier_off(card->dev);
910 rtnl_unlock();
911
912 qeth_l2_stop_card(card);
913 rc = qeth_stop_channel(&card->data);
914 rc2 = qeth_stop_channel(&card->write);
915 rc3 = qeth_stop_channel(&card->read);
916 if (!rc)
917 rc = (rc2) ? rc2 : rc3;
918 if (rc)
919 QETH_CARD_TEXT_(card, 2, "1err%d", rc);
920 qdio_free(CARD_DDEV(card));
921
922
923 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
924 mutex_unlock(&card->conf_mutex);
925 mutex_unlock(&card->discipline_mutex);
926 return 0;
927 }
928
929 static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
930 {
931 return __qeth_l2_set_offline(cgdev, 0);
932 }
933
934 static int qeth_l2_recover(void *ptr)
935 {
936 struct qeth_card *card;
937 int rc = 0;
938
939 card = (struct qeth_card *) ptr;
940 QETH_CARD_TEXT(card, 2, "recover1");
941 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
942 return 0;
943 QETH_CARD_TEXT(card, 2, "recover2");
944 dev_warn(&card->gdev->dev,
945 "A recovery process has been started for the device\n");
946 __qeth_l2_set_offline(card->gdev, 1);
947 rc = qeth_l2_set_online(card->gdev);
948 if (!rc)
949 dev_info(&card->gdev->dev,
950 "Device successfully recovered!\n");
951 else {
952 ccwgroup_set_offline(card->gdev);
953 dev_warn(&card->gdev->dev, "The qeth device driver "
954 "failed to recover an error on the device\n");
955 }
956 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
957 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
958 return 0;
959 }
960
961 static int __init qeth_l2_init(void)
962 {
963 pr_info("register layer 2 discipline\n");
964 return 0;
965 }
966
967 static void __exit qeth_l2_exit(void)
968 {
969 pr_info("unregister layer 2 discipline\n");
970 }
971
972
973 static int qeth_l2_control_event(struct qeth_card *card,
974 struct qeth_ipa_cmd *cmd)
975 {
976 switch (cmd->hdr.command) {
977 case IPA_CMD_SETBRIDGEPORT_OSA:
978 case IPA_CMD_SETBRIDGEPORT_IQD:
979 if (cmd->data.sbp.hdr.command_code ==
980 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
981 qeth_bridge_state_change(card, cmd);
982 return 0;
983 } else
984 return 1;
985 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
986 qeth_bridge_host_event(card, cmd);
987 return 0;
988 default:
989 return 1;
990 }
991 }
992
993 struct qeth_discipline qeth_l2_discipline = {
994 .devtype = &qeth_l2_devtype,
995 .process_rx_buffer = qeth_l2_process_inbound_buffer,
996 .recover = qeth_l2_recover,
997 .setup = qeth_l2_probe_device,
998 .remove = qeth_l2_remove_device,
999 .set_online = qeth_l2_set_online,
1000 .set_offline = qeth_l2_set_offline,
1001 .do_ioctl = NULL,
1002 .control_event_handler = qeth_l2_control_event,
1003 };
1004 EXPORT_SYMBOL_GPL(qeth_l2_discipline);
1005
1006 static void qeth_osn_assist_cb(struct qeth_card *card,
1007 struct qeth_cmd_buffer *iob,
1008 unsigned int data_length)
1009 {
1010 qeth_notify_cmd(iob, 0);
1011 qeth_put_cmd(iob);
1012 }
1013
1014 int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1015 {
1016 struct qeth_cmd_buffer *iob;
1017 struct qeth_card *card;
1018
1019 if (data_len < 0)
1020 return -EINVAL;
1021 if (!dev)
1022 return -ENODEV;
1023 card = dev->ml_priv;
1024 if (!card)
1025 return -ENODEV;
1026 QETH_CARD_TEXT(card, 2, "osnsdmc");
1027 if (!qeth_card_hw_is_reachable(card))
1028 return -ENODEV;
1029
1030 iob = qeth_alloc_cmd(&card->write, IPA_PDU_HEADER_SIZE + data_len, 1,
1031 QETH_IPA_TIMEOUT);
1032 if (!iob)
1033 return -ENOMEM;
1034
1035 qeth_prepare_ipa_cmd(card, iob, (u16) data_len);
1036 memcpy(__ipa_cmd(iob), data, data_len);
1037 iob->callback = qeth_osn_assist_cb;
1038 return qeth_send_ipa_cmd(card, iob, NULL, NULL);
1039 }
1040 EXPORT_SYMBOL(qeth_osn_assist);
1041
1042 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1043 int (*assist_cb)(struct net_device *, void *),
1044 int (*data_cb)(struct sk_buff *))
1045 {
1046 struct qeth_card *card;
1047 char bus_id[16];
1048 u16 devno;
1049
1050 memcpy(&devno, read_dev_no, 2);
1051 sprintf(bus_id, "0.0.%04x", devno);
1052 card = qeth_get_card_by_busid(bus_id);
1053 if (!card || !IS_OSN(card))
1054 return -ENODEV;
1055 *dev = card->dev;
1056
1057 QETH_CARD_TEXT(card, 2, "osnreg");
1058 if ((assist_cb == NULL) || (data_cb == NULL))
1059 return -EINVAL;
1060 card->osn_info.assist_cb = assist_cb;
1061 card->osn_info.data_cb = data_cb;
1062 return 0;
1063 }
1064 EXPORT_SYMBOL(qeth_osn_register);
1065
1066 void qeth_osn_deregister(struct net_device *dev)
1067 {
1068 struct qeth_card *card;
1069
1070 if (!dev)
1071 return;
1072 card = dev->ml_priv;
1073 if (!card)
1074 return;
1075 QETH_CARD_TEXT(card, 2, "osndereg");
1076 card->osn_info.assist_cb = NULL;
1077 card->osn_info.data_cb = NULL;
1078 return;
1079 }
1080 EXPORT_SYMBOL(qeth_osn_deregister);
1081
1082
1083
1084 enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101 static void qeth_bridge_emit_host_event(struct qeth_card *card,
1102 enum qeth_an_event_type evtype,
1103 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1104 {
1105 char str[7][32];
1106 char *env[8];
1107 int i = 0;
1108
1109 switch (evtype) {
1110 case anev_reg_unreg:
1111 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1112 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1113 ? "deregister" : "register");
1114 env[i] = str[i]; i++;
1115 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1116 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1117 addr_lnid->lnid);
1118 env[i] = str[i]; i++;
1119 }
1120 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
1121 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
1122 addr_lnid->mac);
1123 env[i] = str[i]; i++;
1124 }
1125 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1126 token->cssid, token->ssid, token->devnum);
1127 env[i] = str[i]; i++;
1128 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1129 env[i] = str[i]; i++;
1130 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1131 token->chpid);
1132 env[i] = str[i]; i++;
1133 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1134 env[i] = str[i]; i++;
1135 break;
1136 case anev_abort:
1137 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1138 env[i] = str[i]; i++;
1139 break;
1140 case anev_reset:
1141 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1142 env[i] = str[i]; i++;
1143 break;
1144 }
1145 env[i] = NULL;
1146 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1147 }
1148
1149 struct qeth_bridge_state_data {
1150 struct work_struct worker;
1151 struct qeth_card *card;
1152 struct qeth_sbp_state_change qports;
1153 };
1154
1155 static void qeth_bridge_state_change_worker(struct work_struct *work)
1156 {
1157 struct qeth_bridge_state_data *data =
1158 container_of(work, struct qeth_bridge_state_data, worker);
1159
1160 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1161 char env_locrem[32];
1162 char env_role[32];
1163 char env_state[32];
1164 char *env[] = {
1165 env_locrem,
1166 env_role,
1167 env_state,
1168 NULL
1169 };
1170
1171
1172
1173 mutex_lock(&data->card->sbp_lock);
1174 data->card->options.sbp.role = entry->role;
1175 mutex_unlock(&data->card->sbp_lock);
1176
1177 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1178 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1179 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1180 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1181 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1182 "<INVALID>");
1183 snprintf(env_state, sizeof(env_state), "STATE=%s",
1184 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1185 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1186 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1187 "<INVALID>");
1188 kobject_uevent_env(&data->card->gdev->dev.kobj,
1189 KOBJ_CHANGE, env);
1190 kfree(data);
1191 }
1192
1193 static void qeth_bridge_state_change(struct qeth_card *card,
1194 struct qeth_ipa_cmd *cmd)
1195 {
1196 struct qeth_sbp_state_change *qports =
1197 &cmd->data.sbp.data.state_change;
1198 struct qeth_bridge_state_data *data;
1199 int extrasize;
1200
1201 QETH_CARD_TEXT(card, 2, "brstchng");
1202 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1203 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
1204 return;
1205 }
1206 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1207 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1208 GFP_ATOMIC);
1209 if (!data) {
1210 QETH_CARD_TEXT(card, 2, "BPSalloc");
1211 return;
1212 }
1213 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1214 data->card = card;
1215 memcpy(&data->qports, qports,
1216 sizeof(struct qeth_sbp_state_change) + extrasize);
1217 queue_work(card->event_wq, &data->worker);
1218 }
1219
1220 struct qeth_bridge_host_data {
1221 struct work_struct worker;
1222 struct qeth_card *card;
1223 struct qeth_ipacmd_addr_change hostevs;
1224 };
1225
1226 static void qeth_bridge_host_event_worker(struct work_struct *work)
1227 {
1228 struct qeth_bridge_host_data *data =
1229 container_of(work, struct qeth_bridge_host_data, worker);
1230 int i;
1231
1232 if (data->hostevs.lost_event_mask) {
1233 dev_info(&data->card->gdev->dev,
1234 "Address notification from the Bridge Port stopped %s (%s)\n",
1235 data->card->dev->name,
1236 (data->hostevs.lost_event_mask == 0x01)
1237 ? "Overflow"
1238 : (data->hostevs.lost_event_mask == 0x02)
1239 ? "Bridge port state change"
1240 : "Unknown reason");
1241 mutex_lock(&data->card->sbp_lock);
1242 data->card->options.sbp.hostnotification = 0;
1243 mutex_unlock(&data->card->sbp_lock);
1244 qeth_bridge_emit_host_event(data->card, anev_abort,
1245 0, NULL, NULL);
1246 } else
1247 for (i = 0; i < data->hostevs.num_entries; i++) {
1248 struct qeth_ipacmd_addr_change_entry *entry =
1249 &data->hostevs.entry[i];
1250 qeth_bridge_emit_host_event(data->card,
1251 anev_reg_unreg,
1252 entry->change_code,
1253 &entry->token, &entry->addr_lnid);
1254 }
1255 kfree(data);
1256 }
1257
1258 static void qeth_bridge_host_event(struct qeth_card *card,
1259 struct qeth_ipa_cmd *cmd)
1260 {
1261 struct qeth_ipacmd_addr_change *hostevs =
1262 &cmd->data.addrchange;
1263 struct qeth_bridge_host_data *data;
1264 int extrasize;
1265
1266 QETH_CARD_TEXT(card, 2, "brhostev");
1267 if (cmd->hdr.return_code != 0x0000) {
1268 if (cmd->hdr.return_code == 0x0010) {
1269 if (hostevs->lost_event_mask == 0x00)
1270 hostevs->lost_event_mask = 0xff;
1271 } else {
1272 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1273 cmd->hdr.return_code);
1274 return;
1275 }
1276 }
1277 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1278 hostevs->num_entries;
1279 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1280 GFP_ATOMIC);
1281 if (!data) {
1282 QETH_CARD_TEXT(card, 2, "BPHalloc");
1283 return;
1284 }
1285 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1286 data->card = card;
1287 memcpy(&data->hostevs, hostevs,
1288 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1289 queue_work(card->event_wq, &data->worker);
1290 }
1291
1292
1293
1294 struct _qeth_sbp_cbctl {
1295 union {
1296 u32 supported;
1297 struct {
1298 enum qeth_sbp_roles *role;
1299 enum qeth_sbp_states *state;
1300 } qports;
1301 } data;
1302 };
1303
1304 static int qeth_bridgeport_makerc(struct qeth_card *card,
1305 struct qeth_ipa_cmd *cmd)
1306 {
1307 struct qeth_ipacmd_setbridgeport *sbp = &cmd->data.sbp;
1308 enum qeth_ipa_sbp_cmd setcmd = sbp->hdr.command_code;
1309 u16 ipa_rc = cmd->hdr.return_code;
1310 u16 sbp_rc = sbp->hdr.return_code;
1311 int rc;
1312
1313 if (ipa_rc == IPA_RC_SUCCESS && sbp_rc == IPA_RC_SUCCESS)
1314 return 0;
1315
1316 if ((IS_IQD(card) && ipa_rc == IPA_RC_SUCCESS) ||
1317 (!IS_IQD(card) && ipa_rc == sbp_rc)) {
1318 switch (sbp_rc) {
1319 case IPA_RC_SUCCESS:
1320 rc = 0;
1321 break;
1322 case IPA_RC_L2_UNSUPPORTED_CMD:
1323 case IPA_RC_UNSUPPORTED_COMMAND:
1324 rc = -EOPNOTSUPP;
1325 break;
1326 case IPA_RC_SBP_OSA_NOT_CONFIGURED:
1327 case IPA_RC_SBP_IQD_NOT_CONFIGURED:
1328 rc = -ENODEV;
1329 dev_err(&card->gdev->dev,
1330 "The device is not configured as a Bridge Port\n");
1331 break;
1332 case IPA_RC_SBP_OSA_OS_MISMATCH:
1333 case IPA_RC_SBP_IQD_OS_MISMATCH:
1334 rc = -EPERM;
1335 dev_err(&card->gdev->dev,
1336 "A Bridge Port is already configured by a different operating system\n");
1337 break;
1338 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY:
1339 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY:
1340 switch (setcmd) {
1341 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1342 rc = -EEXIST;
1343 dev_err(&card->gdev->dev,
1344 "The LAN already has a primary Bridge Port\n");
1345 break;
1346 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1347 rc = -EBUSY;
1348 dev_err(&card->gdev->dev,
1349 "The device is already a primary Bridge Port\n");
1350 break;
1351 default:
1352 rc = -EIO;
1353 }
1354 break;
1355 case IPA_RC_SBP_OSA_CURRENT_SECOND:
1356 case IPA_RC_SBP_IQD_CURRENT_SECOND:
1357 rc = -EBUSY;
1358 dev_err(&card->gdev->dev,
1359 "The device is already a secondary Bridge Port\n");
1360 break;
1361 case IPA_RC_SBP_OSA_LIMIT_SECOND:
1362 case IPA_RC_SBP_IQD_LIMIT_SECOND:
1363 rc = -EEXIST;
1364 dev_err(&card->gdev->dev,
1365 "The LAN cannot have more secondary Bridge Ports\n");
1366 break;
1367 case IPA_RC_SBP_OSA_CURRENT_PRIMARY:
1368 case IPA_RC_SBP_IQD_CURRENT_PRIMARY:
1369 rc = -EBUSY;
1370 dev_err(&card->gdev->dev,
1371 "The device is already a primary Bridge Port\n");
1372 break;
1373 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN:
1374 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN:
1375 rc = -EACCES;
1376 dev_err(&card->gdev->dev,
1377 "The device is not authorized to be a Bridge Port\n");
1378 break;
1379 default:
1380 rc = -EIO;
1381 }
1382 } else {
1383 switch (ipa_rc) {
1384 case IPA_RC_NOTSUPP:
1385 rc = -EOPNOTSUPP;
1386 break;
1387 case IPA_RC_UNSUPPORTED_COMMAND:
1388 rc = -EOPNOTSUPP;
1389 break;
1390 default:
1391 rc = -EIO;
1392 }
1393 }
1394
1395 if (rc) {
1396 QETH_CARD_TEXT_(card, 2, "SBPi%04x", ipa_rc);
1397 QETH_CARD_TEXT_(card, 2, "SBPc%04x", sbp_rc);
1398 }
1399 return rc;
1400 }
1401
1402 static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card,
1403 enum qeth_ipa_sbp_cmd sbp_cmd,
1404 unsigned int data_length)
1405 {
1406 enum qeth_ipa_cmds ipa_cmd = IS_IQD(card) ? IPA_CMD_SETBRIDGEPORT_IQD :
1407 IPA_CMD_SETBRIDGEPORT_OSA;
1408 struct qeth_ipacmd_sbp_hdr *hdr;
1409 struct qeth_cmd_buffer *iob;
1410
1411 iob = qeth_ipa_alloc_cmd(card, ipa_cmd, QETH_PROT_NONE,
1412 data_length +
1413 offsetof(struct qeth_ipacmd_setbridgeport,
1414 data));
1415 if (!iob)
1416 return iob;
1417
1418 hdr = &__ipa_cmd(iob)->data.sbp.hdr;
1419 hdr->cmdlength = sizeof(*hdr) + data_length;
1420 hdr->command_code = sbp_cmd;
1421 hdr->used_total = 1;
1422 hdr->seq_no = 1;
1423 return iob;
1424 }
1425
1426 static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1427 struct qeth_reply *reply, unsigned long data)
1428 {
1429 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1430 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1431 int rc;
1432
1433 QETH_CARD_TEXT(card, 2, "brqsupcb");
1434 rc = qeth_bridgeport_makerc(card, cmd);
1435 if (rc)
1436 return rc;
1437
1438 cbctl->data.supported =
1439 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1440 return 0;
1441 }
1442
1443
1444
1445
1446
1447
1448
1449
1450 static void qeth_bridgeport_query_support(struct qeth_card *card)
1451 {
1452 struct qeth_cmd_buffer *iob;
1453 struct _qeth_sbp_cbctl cbctl;
1454
1455 QETH_CARD_TEXT(card, 2, "brqsuppo");
1456 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED,
1457 SBP_DATA_SIZEOF(query_cmds_supp));
1458 if (!iob)
1459 return;
1460
1461 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1462 &cbctl)) {
1463 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1464 card->options.sbp.supported_funcs = 0;
1465 return;
1466 }
1467 card->options.sbp.supported_funcs = cbctl.data.supported;
1468 }
1469
1470 static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1471 struct qeth_reply *reply, unsigned long data)
1472 {
1473 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1474 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1475 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1476 int rc;
1477
1478 QETH_CARD_TEXT(card, 2, "brqprtcb");
1479 rc = qeth_bridgeport_makerc(card, cmd);
1480 if (rc)
1481 return rc;
1482
1483 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1484 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1485 return -EINVAL;
1486 }
1487
1488 if (qports->num_entries > 0) {
1489 if (cbctl->data.qports.role)
1490 *cbctl->data.qports.role = qports->entry[0].role;
1491 if (cbctl->data.qports.state)
1492 *cbctl->data.qports.state = qports->entry[0].state;
1493 }
1494 return 0;
1495 }
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507 int qeth_bridgeport_query_ports(struct qeth_card *card,
1508 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1509 {
1510 struct qeth_cmd_buffer *iob;
1511 struct _qeth_sbp_cbctl cbctl = {
1512 .data = {
1513 .qports = {
1514 .role = role,
1515 .state = state,
1516 },
1517 },
1518 };
1519
1520 QETH_CARD_TEXT(card, 2, "brqports");
1521 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1522 return -EOPNOTSUPP;
1523 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0);
1524 if (!iob)
1525 return -ENOMEM;
1526
1527 return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1528 &cbctl);
1529 }
1530
1531 static int qeth_bridgeport_set_cb(struct qeth_card *card,
1532 struct qeth_reply *reply, unsigned long data)
1533 {
1534 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
1535
1536 QETH_CARD_TEXT(card, 2, "brsetrcb");
1537 return qeth_bridgeport_makerc(card, cmd);
1538 }
1539
1540
1541
1542
1543
1544
1545
1546
1547 int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1548 {
1549 struct qeth_cmd_buffer *iob;
1550 enum qeth_ipa_sbp_cmd setcmd;
1551 unsigned int cmdlength = 0;
1552
1553 QETH_CARD_TEXT(card, 2, "brsetrol");
1554 switch (role) {
1555 case QETH_SBP_ROLE_NONE:
1556 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
1557 break;
1558 case QETH_SBP_ROLE_PRIMARY:
1559 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
1560 cmdlength = SBP_DATA_SIZEOF(set_primary);
1561 break;
1562 case QETH_SBP_ROLE_SECONDARY:
1563 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
1564 break;
1565 default:
1566 return -EINVAL;
1567 }
1568 if (!(card->options.sbp.supported_funcs & setcmd))
1569 return -EOPNOTSUPP;
1570 iob = qeth_sbp_build_cmd(card, setcmd, cmdlength);
1571 if (!iob)
1572 return -ENOMEM;
1573
1574 return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb, NULL);
1575 }
1576
1577
1578
1579
1580
1581
1582
1583 static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
1584 {
1585 int rc;
1586
1587 if (pnso_rc == 0)
1588 switch (response) {
1589 case 0x0001:
1590 rc = 0;
1591 break;
1592 case 0x0004:
1593 case 0x0100:
1594 case 0x0106:
1595 rc = -EOPNOTSUPP;
1596 dev_err(&card->gdev->dev,
1597 "Setting address notification failed\n");
1598 break;
1599 case 0x0107:
1600 rc = -EAGAIN;
1601 break;
1602 default:
1603 rc = -EIO;
1604 }
1605 else
1606 rc = -EIO;
1607
1608 if (rc) {
1609 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
1610 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
1611 }
1612 return rc;
1613 }
1614
1615 static void qeth_bridgeport_an_set_cb(void *priv,
1616 enum qdio_brinfo_entry_type type, void *entry)
1617 {
1618 struct qeth_card *card = (struct qeth_card *)priv;
1619 struct qdio_brinfo_entry_l2 *l2entry;
1620 u8 code;
1621
1622 if (type != l2_addr_lnid) {
1623 WARN_ON_ONCE(1);
1624 return;
1625 }
1626
1627 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
1628 code = IPA_ADDR_CHANGE_CODE_MACADDR;
1629 if (l2entry->addr_lnid.lnid < VLAN_N_VID)
1630 code |= IPA_ADDR_CHANGE_CODE_VLANID;
1631 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
1632 (struct net_if_token *)&l2entry->nit,
1633 (struct mac_addr_lnid *)&l2entry->addr_lnid);
1634 }
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646 int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
1647 {
1648 int rc;
1649 u16 response;
1650 struct ccw_device *ddev;
1651 struct subchannel_id schid;
1652
1653 if (!card)
1654 return -EINVAL;
1655 if (!card->options.sbp.supported_funcs)
1656 return -EOPNOTSUPP;
1657 ddev = CARD_DDEV(card);
1658 ccw_device_get_schid(ddev, &schid);
1659
1660 if (enable) {
1661 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
1662 rc = qdio_pnso_brinfo(schid, 1, &response,
1663 qeth_bridgeport_an_set_cb, card);
1664 } else
1665 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
1666 return qeth_anset_makerc(card, rc, response);
1667 }
1668
1669 static bool qeth_bridgeport_is_in_use(struct qeth_card *card)
1670 {
1671 return (card->options.sbp.role || card->options.sbp.reflect_promisc ||
1672 card->options.sbp.hostnotification);
1673 }
1674
1675
1676
1677
1678 static int qeth_l2_vnicc_makerc(struct qeth_card *card, u16 ipa_rc)
1679 {
1680 int rc;
1681
1682 switch (ipa_rc) {
1683 case IPA_RC_SUCCESS:
1684 return ipa_rc;
1685 case IPA_RC_L2_UNSUPPORTED_CMD:
1686 case IPA_RC_NOTSUPP:
1687 rc = -EOPNOTSUPP;
1688 break;
1689 case IPA_RC_VNICC_OOSEQ:
1690 rc = -EALREADY;
1691 break;
1692 case IPA_RC_VNICC_VNICBP:
1693 rc = -EBUSY;
1694 break;
1695 case IPA_RC_L2_ADDR_TABLE_FULL:
1696 rc = -ENOSPC;
1697 break;
1698 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
1699 rc = -EACCES;
1700 break;
1701 default:
1702 rc = -EIO;
1703 }
1704
1705 QETH_CARD_TEXT_(card, 2, "err%04x", ipa_rc);
1706 return rc;
1707 }
1708
1709
1710 struct _qeth_l2_vnicc_request_cbctl {
1711 struct {
1712 union{
1713 u32 *sup_cmds;
1714 u32 *timeout;
1715 };
1716 } result;
1717 };
1718
1719
1720 static int qeth_l2_vnicc_request_cb(struct qeth_card *card,
1721 struct qeth_reply *reply,
1722 unsigned long data)
1723 {
1724 struct _qeth_l2_vnicc_request_cbctl *cbctl =
1725 (struct _qeth_l2_vnicc_request_cbctl *) reply->param;
1726 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1727 struct qeth_ipacmd_vnicc *rep = &cmd->data.vnicc;
1728 u32 sub_cmd = cmd->data.vnicc.hdr.sub_command;
1729
1730 QETH_CARD_TEXT(card, 2, "vniccrcb");
1731 if (cmd->hdr.return_code)
1732 return qeth_l2_vnicc_makerc(card, cmd->hdr.return_code);
1733
1734 card->options.vnicc.sup_chars = rep->vnicc_cmds.supported;
1735 card->options.vnicc.cur_chars = rep->vnicc_cmds.enabled;
1736
1737 if (sub_cmd == IPA_VNICC_QUERY_CMDS)
1738 *cbctl->result.sup_cmds = rep->data.query_cmds.sup_cmds;
1739 else if (sub_cmd == IPA_VNICC_GET_TIMEOUT)
1740 *cbctl->result.timeout = rep->data.getset_timeout.timeout;
1741
1742 return 0;
1743 }
1744
1745 static struct qeth_cmd_buffer *qeth_l2_vnicc_build_cmd(struct qeth_card *card,
1746 u32 vnicc_cmd,
1747 unsigned int data_length)
1748 {
1749 struct qeth_ipacmd_vnicc_hdr *hdr;
1750 struct qeth_cmd_buffer *iob;
1751
1752 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_VNICC, QETH_PROT_NONE,
1753 data_length +
1754 offsetof(struct qeth_ipacmd_vnicc, data));
1755 if (!iob)
1756 return NULL;
1757
1758 hdr = &__ipa_cmd(iob)->data.vnicc.hdr;
1759 hdr->data_length = sizeof(*hdr) + data_length;
1760 hdr->sub_command = vnicc_cmd;
1761 return iob;
1762 }
1763
1764
1765 static int qeth_l2_vnicc_query_chars(struct qeth_card *card)
1766 {
1767 struct qeth_cmd_buffer *iob;
1768
1769 QETH_CARD_TEXT(card, 2, "vniccqch");
1770 iob = qeth_l2_vnicc_build_cmd(card, IPA_VNICC_QUERY_CHARS, 0);
1771 if (!iob)
1772 return -ENOMEM;
1773
1774 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, NULL);
1775 }
1776
1777
1778 static int qeth_l2_vnicc_query_cmds(struct qeth_card *card, u32 vnic_char,
1779 u32 *sup_cmds)
1780 {
1781 struct _qeth_l2_vnicc_request_cbctl cbctl;
1782 struct qeth_cmd_buffer *iob;
1783
1784 QETH_CARD_TEXT(card, 2, "vniccqcm");
1785 iob = qeth_l2_vnicc_build_cmd(card, IPA_VNICC_QUERY_CMDS,
1786 VNICC_DATA_SIZEOF(query_cmds));
1787 if (!iob)
1788 return -ENOMEM;
1789
1790 __ipa_cmd(iob)->data.vnicc.data.query_cmds.vnic_char = vnic_char;
1791
1792
1793 cbctl.result.sup_cmds = sup_cmds;
1794
1795 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, &cbctl);
1796 }
1797
1798
1799 static int qeth_l2_vnicc_set_char(struct qeth_card *card, u32 vnic_char,
1800 u32 cmd)
1801 {
1802 struct qeth_cmd_buffer *iob;
1803
1804 QETH_CARD_TEXT(card, 2, "vniccedc");
1805 iob = qeth_l2_vnicc_build_cmd(card, cmd, VNICC_DATA_SIZEOF(set_char));
1806 if (!iob)
1807 return -ENOMEM;
1808
1809 __ipa_cmd(iob)->data.vnicc.data.set_char.vnic_char = vnic_char;
1810
1811 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, NULL);
1812 }
1813
1814
1815 static int qeth_l2_vnicc_getset_timeout(struct qeth_card *card, u32 vnicc,
1816 u32 cmd, u32 *timeout)
1817 {
1818 struct qeth_vnicc_getset_timeout *getset_timeout;
1819 struct _qeth_l2_vnicc_request_cbctl cbctl;
1820 struct qeth_cmd_buffer *iob;
1821
1822 QETH_CARD_TEXT(card, 2, "vniccgst");
1823 iob = qeth_l2_vnicc_build_cmd(card, cmd,
1824 VNICC_DATA_SIZEOF(getset_timeout));
1825 if (!iob)
1826 return -ENOMEM;
1827
1828 getset_timeout = &__ipa_cmd(iob)->data.vnicc.data.getset_timeout;
1829 getset_timeout->vnic_char = vnicc;
1830
1831 if (cmd == IPA_VNICC_SET_TIMEOUT)
1832 getset_timeout->timeout = *timeout;
1833
1834
1835 if (cmd == IPA_VNICC_GET_TIMEOUT)
1836 cbctl.result.timeout = timeout;
1837
1838 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, &cbctl);
1839 }
1840
1841
1842 int qeth_l2_vnicc_set_state(struct qeth_card *card, u32 vnicc, bool state)
1843 {
1844 int rc = 0;
1845 u32 cmd;
1846
1847 QETH_CARD_TEXT(card, 2, "vniccsch");
1848
1849
1850 if (!(card->options.vnicc.sup_chars & vnicc) ||
1851 !(card->options.vnicc.set_char_sup & vnicc))
1852 return -EOPNOTSUPP;
1853
1854 if (qeth_bridgeport_is_in_use(card))
1855 return -EBUSY;
1856
1857
1858 if (state) {
1859 cmd = IPA_VNICC_ENABLE;
1860 card->options.vnicc.wanted_chars |= vnicc;
1861 } else {
1862 cmd = IPA_VNICC_DISABLE;
1863 card->options.vnicc.wanted_chars &= ~vnicc;
1864 }
1865
1866
1867 if (card->options.vnicc.cur_chars == card->options.vnicc.wanted_chars)
1868 return rc;
1869
1870
1871 if (!qeth_card_hw_is_reachable(card)) {
1872 if (state)
1873 card->options.vnicc.cur_chars |= vnicc;
1874 else
1875 card->options.vnicc.cur_chars &= ~vnicc;
1876 return rc;
1877 }
1878
1879 rc = qeth_l2_vnicc_set_char(card, vnicc, cmd);
1880 if (rc)
1881 card->options.vnicc.wanted_chars =
1882 card->options.vnicc.cur_chars;
1883 else {
1884
1885 if (state && vnicc == QETH_VNICC_RX_BCAST)
1886 card->options.vnicc.rx_bcast_enabled = true;
1887 if (!state && vnicc == QETH_VNICC_LEARNING)
1888 qeth_l2_vnicc_recover_timeout(card, vnicc,
1889 &card->options.vnicc.learning_timeout);
1890 }
1891
1892 return rc;
1893 }
1894
1895
1896 int qeth_l2_vnicc_get_state(struct qeth_card *card, u32 vnicc, bool *state)
1897 {
1898 int rc = 0;
1899
1900 QETH_CARD_TEXT(card, 2, "vniccgch");
1901
1902
1903 if (!(card->options.vnicc.sup_chars & vnicc))
1904 return -EOPNOTSUPP;
1905
1906 if (qeth_bridgeport_is_in_use(card))
1907 return -EBUSY;
1908
1909
1910 if (qeth_card_hw_is_reachable(card))
1911 rc = qeth_l2_vnicc_query_chars(card);
1912
1913 *state = (card->options.vnicc.cur_chars & vnicc) ? true : false;
1914 return rc;
1915 }
1916
1917
1918
1919
1920 int qeth_l2_vnicc_set_timeout(struct qeth_card *card, u32 timeout)
1921 {
1922 int rc = 0;
1923
1924 QETH_CARD_TEXT(card, 2, "vniccsto");
1925
1926
1927 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
1928 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
1929 return -EOPNOTSUPP;
1930
1931 if (qeth_bridgeport_is_in_use(card))
1932 return -EBUSY;
1933
1934
1935 if (card->options.vnicc.learning_timeout == timeout)
1936 return rc;
1937
1938
1939 if (!qeth_card_hw_is_reachable(card)) {
1940 card->options.vnicc.learning_timeout = timeout;
1941 return rc;
1942 }
1943
1944
1945 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
1946 IPA_VNICC_SET_TIMEOUT, &timeout);
1947 if (!rc)
1948 card->options.vnicc.learning_timeout = timeout;
1949
1950 return rc;
1951 }
1952
1953
1954
1955
1956 int qeth_l2_vnicc_get_timeout(struct qeth_card *card, u32 *timeout)
1957 {
1958 int rc = 0;
1959
1960 QETH_CARD_TEXT(card, 2, "vniccgto");
1961
1962
1963 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
1964 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
1965 return -EOPNOTSUPP;
1966
1967 if (qeth_bridgeport_is_in_use(card))
1968 return -EBUSY;
1969
1970
1971 *timeout = card->options.vnicc.learning_timeout;
1972 if (qeth_card_hw_is_reachable(card))
1973 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
1974 IPA_VNICC_GET_TIMEOUT,
1975 timeout);
1976
1977 return rc;
1978 }
1979
1980
1981 bool qeth_l2_vnicc_is_in_use(struct qeth_card *card)
1982 {
1983 if (!card->options.vnicc.sup_chars)
1984 return false;
1985
1986
1987
1988 if (card->options.vnicc.cur_chars == QETH_VNICC_DEFAULT) {
1989 if (!card->options.vnicc.rx_bcast_enabled ||
1990 !qeth_card_hw_is_reachable(card))
1991 return false;
1992 }
1993 return true;
1994 }
1995
1996
1997 static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
1998 u32 *timeout)
1999 {
2000 if (card->options.vnicc.sup_chars & vnicc &&
2001 card->options.vnicc.getset_timeout_sup & vnicc &&
2002 !qeth_l2_vnicc_getset_timeout(card, vnicc, IPA_VNICC_SET_TIMEOUT,
2003 timeout))
2004 return false;
2005 *timeout = QETH_VNICC_DEFAULT_TIMEOUT;
2006 return true;
2007 }
2008
2009
2010 static bool qeth_l2_vnicc_recover_char(struct qeth_card *card, u32 vnicc,
2011 bool enable)
2012 {
2013 u32 cmd = enable ? IPA_VNICC_ENABLE : IPA_VNICC_DISABLE;
2014
2015 if (card->options.vnicc.sup_chars & vnicc &&
2016 card->options.vnicc.set_char_sup & vnicc &&
2017 !qeth_l2_vnicc_set_char(card, vnicc, cmd))
2018 return false;
2019 card->options.vnicc.wanted_chars &= ~vnicc;
2020 card->options.vnicc.wanted_chars |= QETH_VNICC_DEFAULT & vnicc;
2021 return true;
2022 }
2023
2024
2025 static void qeth_l2_vnicc_init(struct qeth_card *card)
2026 {
2027 u32 *timeout = &card->options.vnicc.learning_timeout;
2028 bool enable, error = false;
2029 unsigned int chars_len, i;
2030 unsigned long chars_tmp;
2031 u32 sup_cmds, vnicc;
2032
2033 QETH_CARD_TEXT(card, 2, "vniccini");
2034
2035 card->options.vnicc.rx_bcast_enabled = 0;
2036
2037 if (qeth_l2_vnicc_query_chars(card)) {
2038 if (card->options.vnicc.wanted_chars != QETH_VNICC_DEFAULT ||
2039 *timeout != QETH_VNICC_DEFAULT_TIMEOUT)
2040 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2041
2042 card->options.vnicc.sup_chars = 0;
2043 card->options.vnicc.cur_chars = 0;
2044 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
2045 return;
2046 }
2047
2048 chars_tmp = card->options.vnicc.sup_chars;
2049 chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE;
2050 for_each_set_bit(i, &chars_tmp, chars_len) {
2051 vnicc = BIT(i);
2052 if (qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds)) {
2053 sup_cmds = 0;
2054 error = true;
2055 }
2056 if ((sup_cmds & IPA_VNICC_SET_TIMEOUT) &&
2057 (sup_cmds & IPA_VNICC_GET_TIMEOUT))
2058 card->options.vnicc.getset_timeout_sup |= vnicc;
2059 else
2060 card->options.vnicc.getset_timeout_sup &= ~vnicc;
2061 if ((sup_cmds & IPA_VNICC_ENABLE) &&
2062 (sup_cmds & IPA_VNICC_DISABLE))
2063 card->options.vnicc.set_char_sup |= vnicc;
2064 else
2065 card->options.vnicc.set_char_sup &= ~vnicc;
2066 }
2067
2068 error |= qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING,
2069 timeout);
2070
2071 chars_tmp = card->options.vnicc.wanted_chars ^
2072 card->options.vnicc.cur_chars;
2073 chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE;
2074 for_each_set_bit(i, &chars_tmp, chars_len) {
2075 vnicc = BIT(i);
2076 enable = card->options.vnicc.wanted_chars & vnicc;
2077 error |= qeth_l2_vnicc_recover_char(card, vnicc, enable);
2078 }
2079 if (error)
2080 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2081 }
2082
2083
2084 static void qeth_l2_vnicc_set_defaults(struct qeth_card *card)
2085 {
2086
2087 card->options.vnicc.sup_chars = QETH_VNICC_ALL;
2088 card->options.vnicc.cur_chars = QETH_VNICC_DEFAULT;
2089 card->options.vnicc.learning_timeout = QETH_VNICC_DEFAULT_TIMEOUT;
2090
2091 card->options.vnicc.set_char_sup = QETH_VNICC_ALL;
2092 card->options.vnicc.getset_timeout_sup = QETH_VNICC_LEARNING;
2093
2094 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
2095 }
2096
2097 module_init(qeth_l2_init);
2098 module_exit(qeth_l2_exit);
2099 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2100 MODULE_DESCRIPTION("qeth layer 2 discipline");
2101 MODULE_LICENSE("GPL");