media: stv06xx: add missing descriptor sanity checks
[linux/fpc-iii.git] / drivers / s390 / net / qeth_l2_main.c
blobe26ad80ddfa39cf5f67075fa414b1a9ca0838697
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright IBM Corp. 2007, 2009
4 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
5 * Frank Pavlic <fpavlic@de.ibm.com>,
6 * Thomas Spatzier <tspat@de.ibm.com>,
7 * Frank Blaschka <frank.blaschka@de.ibm.com>
8 */
10 #define KMSG_COMPONENT "qeth"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
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"
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);
38 static int qeth_l2_setdelmac_makerc(struct qeth_card *card, u16 retcode)
40 int rc;
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;
69 return rc;
72 static int qeth_l2_send_setdelmac_cb(struct qeth_card *card,
73 struct qeth_reply *reply,
74 unsigned long data)
76 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
78 return qeth_l2_setdelmac_makerc(card, cmd->hdr.return_code);
81 static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
82 enum qeth_ipa_cmds ipacmd)
84 struct qeth_ipa_cmd *cmd;
85 struct qeth_cmd_buffer *iob;
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);
98 static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
100 int rc;
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;
119 return rc;
122 static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac)
124 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
125 IPA_CMD_SETGMAC : IPA_CMD_SETVMAC;
126 int rc;
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;
139 static int qeth_l2_remove_mac(struct qeth_card *card, u8 *mac)
141 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
142 IPA_CMD_DELGMAC : IPA_CMD_DELVMAC;
143 int rc;
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;
153 static void qeth_l2_drain_rx_mode_cache(struct qeth_card *card)
155 struct qeth_mac *mac;
156 struct hlist_node *tmp;
157 int i;
159 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
160 hash_del(&mac->hnode);
161 kfree(mac);
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)
169 int cast_type = qeth_get_ether_cast_type(skb);
170 struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
172 hdr->hdr.l2.pkt_length = data_len;
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);
182 /* set byte byte 3 to casting flags */
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;
190 /* VSWITCH relies on the VLAN
191 * information to be present in
192 * the QDIO header */
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);
199 static int qeth_l2_setdelvlan_makerc(struct qeth_card *card, u16 retcode)
201 if (retcode)
202 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
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;
220 static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
221 struct qeth_reply *reply,
222 unsigned long data)
224 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
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);
233 return qeth_l2_setdelvlan_makerc(card, cmd->hdr.return_code);
236 static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
237 enum qeth_ipa_cmds ipacmd)
239 struct qeth_ipa_cmd *cmd;
240 struct qeth_cmd_buffer *iob;
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);
252 static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
253 __be16 proto, u16 vid)
255 struct qeth_card *card = dev->ml_priv;
257 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
258 if (!vid)
259 return 0;
261 return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
264 static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
265 __be16 proto, u16 vid)
267 struct qeth_card *card = dev->ml_priv;
269 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
270 if (!vid)
271 return 0;
273 return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
276 static void qeth_l2_stop_card(struct qeth_card *card)
278 QETH_CARD_TEXT(card, 2, "stopcard");
280 qeth_set_allowed_threads(card, 0, 1);
282 cancel_work_sync(&card->rx_mode_work);
283 qeth_l2_drain_rx_mode_cache(card);
285 if (card->state == CARD_STATE_SOFTSETUP) {
286 qeth_clear_ipacmd_list(card);
287 card->state = CARD_STATE_HARDSETUP;
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;
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;
301 static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
302 int budget, int *done)
304 int work_done = 0;
305 struct sk_buff *skb;
306 struct qeth_hdr *hdr;
307 unsigned int len;
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;
320 if (hdr->hdr.l2.id == 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 } else {
326 skb_push(skb, sizeof(*hdr));
327 skb_copy_to_linear_data(skb, hdr, sizeof(*hdr));
328 len = skb->len;
329 card->osn_info.data_cb(skb);
332 work_done++;
333 budget--;
334 QETH_CARD_STAT_INC(card, rx_packets);
335 QETH_CARD_STAT_ADD(card, rx_bytes, len);
337 return work_done;
340 static int qeth_l2_request_initial_mac(struct qeth_card *card)
342 int rc = 0;
344 QETH_CARD_TEXT(card, 2, "l2reqmac");
346 if (MACHINE_IS_VM) {
347 rc = qeth_vm_request_mac(card);
348 if (!rc)
349 goto out;
350 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %x: %#x\n",
351 CARD_DEVID(card), rc);
352 QETH_CARD_TEXT_(card, 2, "err%04x", rc);
353 /* fall back to alternative mechanism: */
356 if (!IS_OSN(card)) {
357 rc = qeth_setadpparms_change_macaddr(card);
358 if (!rc)
359 goto out;
360 QETH_DBF_MESSAGE(2, "READ_MAC Assist failed on device %x: %#x\n",
361 CARD_DEVID(card), rc);
362 QETH_CARD_TEXT_(card, 2, "1err%04x", rc);
363 /* fall back once more: */
366 /* some devices don't support a custom MAC address: */
367 if (IS_OSM(card) || IS_OSX(card))
368 return (rc) ? rc : -EADDRNOTAVAIL;
369 eth_hw_addr_random(card->dev);
371 out:
372 QETH_CARD_HEX(card, 2, card->dev->dev_addr, card->dev->addr_len);
373 return 0;
376 static void qeth_l2_register_dev_addr(struct qeth_card *card)
378 if (!is_valid_ether_addr(card->dev->dev_addr))
379 qeth_l2_request_initial_mac(card);
381 if (!IS_OSN(card) && !qeth_l2_send_setmac(card, card->dev->dev_addr))
382 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
385 static int qeth_l2_validate_addr(struct net_device *dev)
387 struct qeth_card *card = dev->ml_priv;
389 if (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)
390 return eth_validate_addr(dev);
392 QETH_CARD_TEXT(card, 4, "nomacadr");
393 return -EPERM;
396 static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
398 struct sockaddr *addr = p;
399 struct qeth_card *card = dev->ml_priv;
400 u8 old_addr[ETH_ALEN];
401 int rc = 0;
403 QETH_CARD_TEXT(card, 3, "setmac");
405 if (IS_OSM(card) || IS_OSX(card)) {
406 QETH_CARD_TEXT(card, 3, "setmcTYP");
407 return -EOPNOTSUPP;
409 QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN);
410 if (!is_valid_ether_addr(addr->sa_data))
411 return -EADDRNOTAVAIL;
413 /* don't register the same address twice */
414 if (ether_addr_equal_64bits(dev->dev_addr, addr->sa_data) &&
415 (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
416 return 0;
418 /* add the new address, switch over, drop the old */
419 rc = qeth_l2_send_setmac(card, addr->sa_data);
420 if (rc)
421 return rc;
422 ether_addr_copy(old_addr, dev->dev_addr);
423 ether_addr_copy(dev->dev_addr, addr->sa_data);
425 if (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)
426 qeth_l2_remove_mac(card, old_addr);
427 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
428 return 0;
431 static void qeth_l2_promisc_to_bridge(struct qeth_card *card, bool enable)
433 int role;
434 int rc;
436 QETH_CARD_TEXT(card, 3, "pmisc2br");
438 if (enable) {
439 if (card->options.sbp.reflect_promisc_primary)
440 role = QETH_SBP_ROLE_PRIMARY;
441 else
442 role = QETH_SBP_ROLE_SECONDARY;
443 } else
444 role = QETH_SBP_ROLE_NONE;
446 rc = qeth_bridgeport_setrole(card, role);
447 QETH_CARD_TEXT_(card, 2, "bpm%c%04x", enable ? '+' : '-', rc);
448 if (!rc) {
449 card->options.sbp.role = role;
450 card->info.promisc_mode = enable;
454 static void qeth_l2_set_promisc_mode(struct qeth_card *card)
456 bool enable = card->dev->flags & IFF_PROMISC;
458 if (card->info.promisc_mode == enable)
459 return;
461 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) {
462 qeth_setadp_promisc_mode(card, enable);
463 } else {
464 mutex_lock(&card->sbp_lock);
465 if (card->options.sbp.reflect_promisc)
466 qeth_l2_promisc_to_bridge(card, enable);
467 mutex_unlock(&card->sbp_lock);
471 /* New MAC address is added to the hash table and marked to be written on card
472 * only if there is not in the hash table storage already
475 static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha)
477 u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2]));
478 struct qeth_mac *mac;
480 hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) {
481 if (ether_addr_equal_64bits(ha->addr, mac->mac_addr)) {
482 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
483 return;
487 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
488 if (!mac)
489 return;
491 ether_addr_copy(mac->mac_addr, ha->addr);
492 mac->disp_flag = QETH_DISP_ADDR_ADD;
494 hash_add(card->mac_htable, &mac->hnode, mac_hash);
497 static void qeth_l2_rx_mode_work(struct work_struct *work)
499 struct qeth_card *card = container_of(work, struct qeth_card,
500 rx_mode_work);
501 struct net_device *dev = card->dev;
502 struct netdev_hw_addr *ha;
503 struct qeth_mac *mac;
504 struct hlist_node *tmp;
505 int i;
506 int rc;
508 QETH_CARD_TEXT(card, 3, "setmulti");
510 netif_addr_lock_bh(dev);
511 netdev_for_each_mc_addr(ha, dev)
512 qeth_l2_add_mac(card, ha);
513 netdev_for_each_uc_addr(ha, dev)
514 qeth_l2_add_mac(card, ha);
515 netif_addr_unlock_bh(dev);
517 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
518 switch (mac->disp_flag) {
519 case QETH_DISP_ADDR_DELETE:
520 qeth_l2_remove_mac(card, mac->mac_addr);
521 hash_del(&mac->hnode);
522 kfree(mac);
523 break;
524 case QETH_DISP_ADDR_ADD:
525 rc = qeth_l2_write_mac(card, mac->mac_addr);
526 if (rc) {
527 hash_del(&mac->hnode);
528 kfree(mac);
529 break;
531 /* fall through */
532 default:
533 /* for next call to set_rx_mode(): */
534 mac->disp_flag = QETH_DISP_ADDR_DELETE;
538 qeth_l2_set_promisc_mode(card);
541 static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb,
542 struct qeth_qdio_out_q *queue)
544 struct qeth_hdr *hdr = (struct qeth_hdr *)skb->data;
545 addr_t end = (addr_t)(skb->data + sizeof(*hdr));
546 addr_t start = (addr_t)skb->data;
547 unsigned int elements = 0;
548 unsigned int hd_len = 0;
549 int rc;
551 if (skb->protocol == htons(ETH_P_IPV6))
552 return -EPROTONOSUPPORT;
554 if (qeth_get_elements_for_range(start, end) > 1) {
555 /* Misaligned HW header, move it to its own buffer element. */
556 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
557 if (!hdr)
558 return -ENOMEM;
559 hd_len = sizeof(*hdr);
560 skb_copy_from_linear_data(skb, (char *)hdr, hd_len);
561 elements++;
564 elements += qeth_count_elements(skb, hd_len);
565 if (elements > queue->max_elements) {
566 rc = -E2BIG;
567 goto out;
570 rc = qeth_do_send_packet(card, queue, skb, hdr, hd_len, hd_len,
571 elements);
572 out:
573 if (rc && hd_len)
574 kmem_cache_free(qeth_core_header_cache, hdr);
575 return rc;
578 static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb,
579 struct net_device *dev)
581 struct qeth_card *card = dev->ml_priv;
582 u16 txq = skb_get_queue_mapping(skb);
583 struct qeth_qdio_out_q *queue;
584 int rc;
586 if (!skb_is_gso(skb))
587 qdisc_skb_cb(skb)->pkt_len = skb->len;
588 if (IS_IQD(card))
589 txq = qeth_iqd_translate_txq(dev, txq);
590 queue = card->qdio.out_qs[txq];
592 if (IS_OSN(card))
593 rc = qeth_l2_xmit_osn(card, skb, queue);
594 else
595 rc = qeth_xmit(card, skb, queue, qeth_get_ip_version(skb),
596 qeth_l2_fill_header);
598 if (!rc)
599 return NETDEV_TX_OK;
601 QETH_TXQ_STAT_INC(queue, tx_dropped);
602 kfree_skb(skb);
603 return NETDEV_TX_OK;
606 static u16 qeth_l2_select_queue(struct net_device *dev, struct sk_buff *skb,
607 struct net_device *sb_dev)
609 struct qeth_card *card = dev->ml_priv;
611 if (IS_IQD(card))
612 return qeth_iqd_select_queue(dev, skb,
613 qeth_get_ether_cast_type(skb),
614 sb_dev);
615 return qeth_get_priority_queue(card, skb);
618 static const struct device_type qeth_l2_devtype = {
619 .name = "qeth_layer2",
620 .groups = qeth_l2_attr_groups,
623 static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
625 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
626 int rc;
628 qeth_l2_vnicc_set_defaults(card);
629 mutex_init(&card->sbp_lock);
631 if (gdev->dev.type == &qeth_generic_devtype) {
632 rc = qeth_l2_create_device_attributes(&gdev->dev);
633 if (rc)
634 return rc;
637 hash_init(card->mac_htable);
638 INIT_WORK(&card->rx_mode_work, qeth_l2_rx_mode_work);
639 return 0;
642 static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
644 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
646 if (cgdev->dev.type == &qeth_generic_devtype)
647 qeth_l2_remove_device_attributes(&cgdev->dev);
648 qeth_set_allowed_threads(card, 0, 1);
649 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
651 if (cgdev->state == CCWGROUP_ONLINE)
652 qeth_l2_set_offline(cgdev);
654 cancel_work_sync(&card->close_dev_work);
655 if (qeth_netdev_is_registered(card->dev))
656 unregister_netdev(card->dev);
659 static void qeth_l2_set_rx_mode(struct net_device *dev)
661 struct qeth_card *card = dev->ml_priv;
663 schedule_work(&card->rx_mode_work);
666 static const struct net_device_ops qeth_l2_netdev_ops = {
667 .ndo_open = qeth_open,
668 .ndo_stop = qeth_stop,
669 .ndo_get_stats64 = qeth_get_stats64,
670 .ndo_start_xmit = qeth_l2_hard_start_xmit,
671 .ndo_features_check = qeth_features_check,
672 .ndo_select_queue = qeth_l2_select_queue,
673 .ndo_validate_addr = qeth_l2_validate_addr,
674 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
675 .ndo_do_ioctl = qeth_do_ioctl,
676 .ndo_set_mac_address = qeth_l2_set_mac_address,
677 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
678 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
679 .ndo_tx_timeout = qeth_tx_timeout,
680 .ndo_fix_features = qeth_fix_features,
681 .ndo_set_features = qeth_set_features
684 static const struct net_device_ops qeth_osn_netdev_ops = {
685 .ndo_open = qeth_open,
686 .ndo_stop = qeth_stop,
687 .ndo_get_stats64 = qeth_get_stats64,
688 .ndo_start_xmit = qeth_l2_hard_start_xmit,
689 .ndo_validate_addr = eth_validate_addr,
690 .ndo_tx_timeout = qeth_tx_timeout,
693 static int qeth_l2_setup_netdev(struct qeth_card *card, bool carrier_ok)
695 int rc;
697 if (IS_OSN(card)) {
698 card->dev->netdev_ops = &qeth_osn_netdev_ops;
699 card->dev->flags |= IFF_NOARP;
700 goto add_napi;
703 card->dev->needed_headroom = sizeof(struct qeth_hdr);
704 card->dev->netdev_ops = &qeth_l2_netdev_ops;
705 card->dev->priv_flags |= IFF_UNICAST_FLT;
707 if (IS_OSM(card)) {
708 card->dev->features |= NETIF_F_VLAN_CHALLENGED;
709 } else {
710 if (!IS_VM_NIC(card))
711 card->dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
712 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
715 if (IS_OSD(card) && !IS_VM_NIC(card)) {
716 card->dev->features |= NETIF_F_SG;
717 /* OSA 3S and earlier has no RX/TX support */
718 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
719 card->dev->hw_features |= NETIF_F_IP_CSUM;
720 card->dev->vlan_features |= NETIF_F_IP_CSUM;
723 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
724 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
725 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
727 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM) ||
728 qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6)) {
729 card->dev->hw_features |= NETIF_F_RXCSUM;
730 card->dev->vlan_features |= NETIF_F_RXCSUM;
732 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
733 card->dev->hw_features |= NETIF_F_TSO;
734 card->dev->vlan_features |= NETIF_F_TSO;
736 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) {
737 card->dev->hw_features |= NETIF_F_TSO6;
738 card->dev->vlan_features |= NETIF_F_TSO6;
741 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6)) {
742 card->dev->needed_headroom = sizeof(struct qeth_hdr_tso);
743 netif_set_gso_max_size(card->dev,
744 PAGE_SIZE * (QDIO_MAX_ELEMENTS_PER_BUFFER - 1));
747 add_napi:
748 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
749 rc = register_netdev(card->dev);
750 if (!rc && carrier_ok)
751 netif_carrier_on(card->dev);
753 if (rc)
754 card->dev->netdev_ops = NULL;
755 return rc;
758 static void qeth_l2_trace_features(struct qeth_card *card)
760 /* Set BridgePort features */
761 QETH_CARD_TEXT(card, 2, "featuSBP");
762 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs,
763 sizeof(card->options.sbp.supported_funcs));
764 /* VNIC Characteristics features */
765 QETH_CARD_TEXT(card, 2, "feaVNICC");
766 QETH_CARD_HEX(card, 2, &card->options.vnicc.sup_chars,
767 sizeof(card->options.vnicc.sup_chars));
770 static int qeth_l2_set_online(struct ccwgroup_device *gdev)
772 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
773 struct net_device *dev = card->dev;
774 int rc = 0;
775 bool carrier_ok;
777 mutex_lock(&card->discipline_mutex);
778 mutex_lock(&card->conf_mutex);
779 QETH_CARD_TEXT(card, 2, "setonlin");
781 rc = qeth_core_hardsetup_card(card, &carrier_ok);
782 if (rc) {
783 QETH_CARD_TEXT_(card, 2, "2err%04x", rc);
784 rc = -ENODEV;
785 goto out_remove;
788 mutex_lock(&card->sbp_lock);
789 qeth_bridgeport_query_support(card);
790 if (card->options.sbp.supported_funcs)
791 dev_info(&card->gdev->dev,
792 "The device represents a Bridge Capable Port\n");
793 mutex_unlock(&card->sbp_lock);
795 qeth_l2_register_dev_addr(card);
797 /* for the rx_bcast characteristic, init VNICC after setmac */
798 qeth_l2_vnicc_init(card);
800 qeth_trace_features(card);
801 qeth_l2_trace_features(card);
803 qeth_l2_setup_bridgeport_attrs(card);
805 card->state = CARD_STATE_HARDSETUP;
806 qeth_print_status_message(card);
808 /* softsetup */
809 QETH_CARD_TEXT(card, 2, "softsetp");
811 rc = qeth_init_qdio_queues(card);
812 if (rc) {
813 QETH_CARD_TEXT_(card, 2, "6err%d", rc);
814 rc = -ENODEV;
815 goto out_remove;
817 card->state = CARD_STATE_SOFTSETUP;
819 qeth_set_allowed_threads(card, 0xffffffff, 0);
821 if (!qeth_netdev_is_registered(dev)) {
822 rc = qeth_l2_setup_netdev(card, carrier_ok);
823 if (rc)
824 goto out_remove;
825 } else {
826 rtnl_lock();
827 if (carrier_ok)
828 netif_carrier_on(dev);
829 else
830 netif_carrier_off(dev);
832 netif_device_attach(dev);
833 qeth_enable_hw_features(dev);
835 if (card->info.open_when_online) {
836 card->info.open_when_online = 0;
837 dev_open(dev, NULL);
839 rtnl_unlock();
841 /* let user_space know that device is online */
842 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
843 mutex_unlock(&card->conf_mutex);
844 mutex_unlock(&card->discipline_mutex);
845 return 0;
847 out_remove:
848 qeth_l2_stop_card(card);
849 qeth_stop_channel(&card->data);
850 qeth_stop_channel(&card->write);
851 qeth_stop_channel(&card->read);
852 qdio_free(CARD_DDEV(card));
854 mutex_unlock(&card->conf_mutex);
855 mutex_unlock(&card->discipline_mutex);
856 return rc;
859 static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
860 int recovery_mode)
862 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
863 int rc = 0, rc2 = 0, rc3 = 0;
865 mutex_lock(&card->discipline_mutex);
866 mutex_lock(&card->conf_mutex);
867 QETH_CARD_TEXT(card, 3, "setoffl");
869 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
870 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
871 card->info.hwtrap = 1;
874 rtnl_lock();
875 card->info.open_when_online = card->dev->flags & IFF_UP;
876 dev_close(card->dev);
877 netif_device_detach(card->dev);
878 netif_carrier_off(card->dev);
879 rtnl_unlock();
881 qeth_l2_stop_card(card);
882 rc = qeth_stop_channel(&card->data);
883 rc2 = qeth_stop_channel(&card->write);
884 rc3 = qeth_stop_channel(&card->read);
885 if (!rc)
886 rc = (rc2) ? rc2 : rc3;
887 if (rc)
888 QETH_CARD_TEXT_(card, 2, "1err%d", rc);
889 qdio_free(CARD_DDEV(card));
891 /* let user_space know that device is offline */
892 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
893 mutex_unlock(&card->conf_mutex);
894 mutex_unlock(&card->discipline_mutex);
895 return 0;
898 static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
900 return __qeth_l2_set_offline(cgdev, 0);
903 static int qeth_l2_recover(void *ptr)
905 struct qeth_card *card;
906 int rc = 0;
908 card = (struct qeth_card *) ptr;
909 QETH_CARD_TEXT(card, 2, "recover1");
910 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
911 return 0;
912 QETH_CARD_TEXT(card, 2, "recover2");
913 dev_warn(&card->gdev->dev,
914 "A recovery process has been started for the device\n");
915 __qeth_l2_set_offline(card->gdev, 1);
916 rc = qeth_l2_set_online(card->gdev);
917 if (!rc)
918 dev_info(&card->gdev->dev,
919 "Device successfully recovered!\n");
920 else {
921 ccwgroup_set_offline(card->gdev);
922 dev_warn(&card->gdev->dev, "The qeth device driver "
923 "failed to recover an error on the device\n");
925 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
926 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
927 return 0;
930 static int __init qeth_l2_init(void)
932 pr_info("register layer 2 discipline\n");
933 return 0;
936 static void __exit qeth_l2_exit(void)
938 pr_info("unregister layer 2 discipline\n");
941 /* Returns zero if the command is successfully "consumed" */
942 static int qeth_l2_control_event(struct qeth_card *card,
943 struct qeth_ipa_cmd *cmd)
945 switch (cmd->hdr.command) {
946 case IPA_CMD_SETBRIDGEPORT_OSA:
947 case IPA_CMD_SETBRIDGEPORT_IQD:
948 if (cmd->data.sbp.hdr.command_code ==
949 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
950 qeth_bridge_state_change(card, cmd);
951 return 0;
952 } else
953 return 1;
954 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
955 qeth_bridge_host_event(card, cmd);
956 return 0;
957 default:
958 return 1;
962 struct qeth_discipline qeth_l2_discipline = {
963 .devtype = &qeth_l2_devtype,
964 .process_rx_buffer = qeth_l2_process_inbound_buffer,
965 .recover = qeth_l2_recover,
966 .setup = qeth_l2_probe_device,
967 .remove = qeth_l2_remove_device,
968 .set_online = qeth_l2_set_online,
969 .set_offline = qeth_l2_set_offline,
970 .do_ioctl = NULL,
971 .control_event_handler = qeth_l2_control_event,
973 EXPORT_SYMBOL_GPL(qeth_l2_discipline);
975 static void qeth_osn_assist_cb(struct qeth_card *card,
976 struct qeth_cmd_buffer *iob,
977 unsigned int data_length)
979 qeth_notify_cmd(iob, 0);
980 qeth_put_cmd(iob);
983 int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
985 struct qeth_cmd_buffer *iob;
986 struct qeth_card *card;
988 if (data_len < 0)
989 return -EINVAL;
990 if (!dev)
991 return -ENODEV;
992 card = dev->ml_priv;
993 if (!card)
994 return -ENODEV;
995 QETH_CARD_TEXT(card, 2, "osnsdmc");
996 if (!qeth_card_hw_is_reachable(card))
997 return -ENODEV;
999 iob = qeth_alloc_cmd(&card->write, IPA_PDU_HEADER_SIZE + data_len, 1,
1000 QETH_IPA_TIMEOUT);
1001 if (!iob)
1002 return -ENOMEM;
1004 qeth_prepare_ipa_cmd(card, iob, (u16) data_len);
1005 memcpy(__ipa_cmd(iob), data, data_len);
1006 iob->callback = qeth_osn_assist_cb;
1007 return qeth_send_ipa_cmd(card, iob, NULL, NULL);
1009 EXPORT_SYMBOL(qeth_osn_assist);
1011 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1012 int (*assist_cb)(struct net_device *, void *),
1013 int (*data_cb)(struct sk_buff *))
1015 struct qeth_card *card;
1016 char bus_id[16];
1017 u16 devno;
1019 memcpy(&devno, read_dev_no, 2);
1020 sprintf(bus_id, "0.0.%04x", devno);
1021 card = qeth_get_card_by_busid(bus_id);
1022 if (!card || !IS_OSN(card))
1023 return -ENODEV;
1024 *dev = card->dev;
1026 QETH_CARD_TEXT(card, 2, "osnreg");
1027 if ((assist_cb == NULL) || (data_cb == NULL))
1028 return -EINVAL;
1029 card->osn_info.assist_cb = assist_cb;
1030 card->osn_info.data_cb = data_cb;
1031 return 0;
1033 EXPORT_SYMBOL(qeth_osn_register);
1035 void qeth_osn_deregister(struct net_device *dev)
1037 struct qeth_card *card;
1039 if (!dev)
1040 return;
1041 card = dev->ml_priv;
1042 if (!card)
1043 return;
1044 QETH_CARD_TEXT(card, 2, "osndereg");
1045 card->osn_info.assist_cb = NULL;
1046 card->osn_info.data_cb = NULL;
1047 return;
1049 EXPORT_SYMBOL(qeth_osn_deregister);
1051 /* SETBRIDGEPORT support, async notifications */
1053 enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1056 * qeth_bridge_emit_host_event() - bridgeport address change notification
1057 * @card: qeth_card structure pointer, for udev events.
1058 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1059 * and reset token and addr_lnid are unused and may be NULL.
1060 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1061 * object, 0 - addition of an object.
1062 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1063 * @token: "network token" structure identifying physical address of the port.
1064 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1066 * This function is called when registrations and deregistrations are
1067 * reported by the hardware, and also when notifications are enabled -
1068 * for all currently registered addresses.
1070 static void qeth_bridge_emit_host_event(struct qeth_card *card,
1071 enum qeth_an_event_type evtype,
1072 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1074 char str[7][32];
1075 char *env[8];
1076 int i = 0;
1078 switch (evtype) {
1079 case anev_reg_unreg:
1080 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1081 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1082 ? "deregister" : "register");
1083 env[i] = str[i]; i++;
1084 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1085 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1086 addr_lnid->lnid);
1087 env[i] = str[i]; i++;
1089 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
1090 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
1091 addr_lnid->mac);
1092 env[i] = str[i]; i++;
1094 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1095 token->cssid, token->ssid, token->devnum);
1096 env[i] = str[i]; i++;
1097 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1098 env[i] = str[i]; i++;
1099 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1100 token->chpid);
1101 env[i] = str[i]; i++;
1102 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1103 env[i] = str[i]; i++;
1104 break;
1105 case anev_abort:
1106 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1107 env[i] = str[i]; i++;
1108 break;
1109 case anev_reset:
1110 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1111 env[i] = str[i]; i++;
1112 break;
1114 env[i] = NULL;
1115 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1118 struct qeth_bridge_state_data {
1119 struct work_struct worker;
1120 struct qeth_card *card;
1121 struct qeth_sbp_state_change qports;
1124 static void qeth_bridge_state_change_worker(struct work_struct *work)
1126 struct qeth_bridge_state_data *data =
1127 container_of(work, struct qeth_bridge_state_data, worker);
1128 /* We are only interested in the first entry - local port */
1129 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1130 char env_locrem[32];
1131 char env_role[32];
1132 char env_state[32];
1133 char *env[] = {
1134 env_locrem,
1135 env_role,
1136 env_state,
1137 NULL
1140 /* Role should not change by itself, but if it did, */
1141 /* information from the hardware is authoritative. */
1142 mutex_lock(&data->card->sbp_lock);
1143 data->card->options.sbp.role = entry->role;
1144 mutex_unlock(&data->card->sbp_lock);
1146 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1147 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1148 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1149 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1150 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1151 "<INVALID>");
1152 snprintf(env_state, sizeof(env_state), "STATE=%s",
1153 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1154 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1155 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1156 "<INVALID>");
1157 kobject_uevent_env(&data->card->gdev->dev.kobj,
1158 KOBJ_CHANGE, env);
1159 kfree(data);
1162 static void qeth_bridge_state_change(struct qeth_card *card,
1163 struct qeth_ipa_cmd *cmd)
1165 struct qeth_sbp_state_change *qports =
1166 &cmd->data.sbp.data.state_change;
1167 struct qeth_bridge_state_data *data;
1168 int extrasize;
1170 QETH_CARD_TEXT(card, 2, "brstchng");
1171 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1172 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
1173 return;
1175 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1176 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1177 GFP_ATOMIC);
1178 if (!data) {
1179 QETH_CARD_TEXT(card, 2, "BPSalloc");
1180 return;
1182 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1183 data->card = card;
1184 memcpy(&data->qports, qports,
1185 sizeof(struct qeth_sbp_state_change) + extrasize);
1186 queue_work(card->event_wq, &data->worker);
1189 struct qeth_bridge_host_data {
1190 struct work_struct worker;
1191 struct qeth_card *card;
1192 struct qeth_ipacmd_addr_change hostevs;
1195 static void qeth_bridge_host_event_worker(struct work_struct *work)
1197 struct qeth_bridge_host_data *data =
1198 container_of(work, struct qeth_bridge_host_data, worker);
1199 int i;
1201 if (data->hostevs.lost_event_mask) {
1202 dev_info(&data->card->gdev->dev,
1203 "Address notification from the Bridge Port stopped %s (%s)\n",
1204 data->card->dev->name,
1205 (data->hostevs.lost_event_mask == 0x01)
1206 ? "Overflow"
1207 : (data->hostevs.lost_event_mask == 0x02)
1208 ? "Bridge port state change"
1209 : "Unknown reason");
1210 mutex_lock(&data->card->sbp_lock);
1211 data->card->options.sbp.hostnotification = 0;
1212 mutex_unlock(&data->card->sbp_lock);
1213 qeth_bridge_emit_host_event(data->card, anev_abort,
1214 0, NULL, NULL);
1215 } else
1216 for (i = 0; i < data->hostevs.num_entries; i++) {
1217 struct qeth_ipacmd_addr_change_entry *entry =
1218 &data->hostevs.entry[i];
1219 qeth_bridge_emit_host_event(data->card,
1220 anev_reg_unreg,
1221 entry->change_code,
1222 &entry->token, &entry->addr_lnid);
1224 kfree(data);
1227 static void qeth_bridge_host_event(struct qeth_card *card,
1228 struct qeth_ipa_cmd *cmd)
1230 struct qeth_ipacmd_addr_change *hostevs =
1231 &cmd->data.addrchange;
1232 struct qeth_bridge_host_data *data;
1233 int extrasize;
1235 QETH_CARD_TEXT(card, 2, "brhostev");
1236 if (cmd->hdr.return_code != 0x0000) {
1237 if (cmd->hdr.return_code == 0x0010) {
1238 if (hostevs->lost_event_mask == 0x00)
1239 hostevs->lost_event_mask = 0xff;
1240 } else {
1241 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1242 cmd->hdr.return_code);
1243 return;
1246 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1247 hostevs->num_entries;
1248 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1249 GFP_ATOMIC);
1250 if (!data) {
1251 QETH_CARD_TEXT(card, 2, "BPHalloc");
1252 return;
1254 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1255 data->card = card;
1256 memcpy(&data->hostevs, hostevs,
1257 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1258 queue_work(card->event_wq, &data->worker);
1261 /* SETBRIDGEPORT support; sending commands */
1263 struct _qeth_sbp_cbctl {
1264 union {
1265 u32 supported;
1266 struct {
1267 enum qeth_sbp_roles *role;
1268 enum qeth_sbp_states *state;
1269 } qports;
1270 } data;
1273 static int qeth_bridgeport_makerc(struct qeth_card *card,
1274 struct qeth_ipa_cmd *cmd)
1276 struct qeth_ipacmd_setbridgeport *sbp = &cmd->data.sbp;
1277 enum qeth_ipa_sbp_cmd setcmd = sbp->hdr.command_code;
1278 u16 ipa_rc = cmd->hdr.return_code;
1279 u16 sbp_rc = sbp->hdr.return_code;
1280 int rc;
1282 if (ipa_rc == IPA_RC_SUCCESS && sbp_rc == IPA_RC_SUCCESS)
1283 return 0;
1285 if ((IS_IQD(card) && ipa_rc == IPA_RC_SUCCESS) ||
1286 (!IS_IQD(card) && ipa_rc == sbp_rc)) {
1287 switch (sbp_rc) {
1288 case IPA_RC_SUCCESS:
1289 rc = 0;
1290 break;
1291 case IPA_RC_L2_UNSUPPORTED_CMD:
1292 case IPA_RC_UNSUPPORTED_COMMAND:
1293 rc = -EOPNOTSUPP;
1294 break;
1295 case IPA_RC_SBP_OSA_NOT_CONFIGURED:
1296 case IPA_RC_SBP_IQD_NOT_CONFIGURED:
1297 rc = -ENODEV; /* maybe not the best code here? */
1298 dev_err(&card->gdev->dev,
1299 "The device is not configured as a Bridge Port\n");
1300 break;
1301 case IPA_RC_SBP_OSA_OS_MISMATCH:
1302 case IPA_RC_SBP_IQD_OS_MISMATCH:
1303 rc = -EPERM;
1304 dev_err(&card->gdev->dev,
1305 "A Bridge Port is already configured by a different operating system\n");
1306 break;
1307 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY:
1308 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY:
1309 switch (setcmd) {
1310 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1311 rc = -EEXIST;
1312 dev_err(&card->gdev->dev,
1313 "The LAN already has a primary Bridge Port\n");
1314 break;
1315 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1316 rc = -EBUSY;
1317 dev_err(&card->gdev->dev,
1318 "The device is already a primary Bridge Port\n");
1319 break;
1320 default:
1321 rc = -EIO;
1323 break;
1324 case IPA_RC_SBP_OSA_CURRENT_SECOND:
1325 case IPA_RC_SBP_IQD_CURRENT_SECOND:
1326 rc = -EBUSY;
1327 dev_err(&card->gdev->dev,
1328 "The device is already a secondary Bridge Port\n");
1329 break;
1330 case IPA_RC_SBP_OSA_LIMIT_SECOND:
1331 case IPA_RC_SBP_IQD_LIMIT_SECOND:
1332 rc = -EEXIST;
1333 dev_err(&card->gdev->dev,
1334 "The LAN cannot have more secondary Bridge Ports\n");
1335 break;
1336 case IPA_RC_SBP_OSA_CURRENT_PRIMARY:
1337 case IPA_RC_SBP_IQD_CURRENT_PRIMARY:
1338 rc = -EBUSY;
1339 dev_err(&card->gdev->dev,
1340 "The device is already a primary Bridge Port\n");
1341 break;
1342 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN:
1343 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN:
1344 rc = -EACCES;
1345 dev_err(&card->gdev->dev,
1346 "The device is not authorized to be a Bridge Port\n");
1347 break;
1348 default:
1349 rc = -EIO;
1351 } else {
1352 switch (ipa_rc) {
1353 case IPA_RC_NOTSUPP:
1354 rc = -EOPNOTSUPP;
1355 break;
1356 case IPA_RC_UNSUPPORTED_COMMAND:
1357 rc = -EOPNOTSUPP;
1358 break;
1359 default:
1360 rc = -EIO;
1364 if (rc) {
1365 QETH_CARD_TEXT_(card, 2, "SBPi%04x", ipa_rc);
1366 QETH_CARD_TEXT_(card, 2, "SBPc%04x", sbp_rc);
1368 return rc;
1371 static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card,
1372 enum qeth_ipa_sbp_cmd sbp_cmd,
1373 unsigned int data_length)
1375 enum qeth_ipa_cmds ipa_cmd = IS_IQD(card) ? IPA_CMD_SETBRIDGEPORT_IQD :
1376 IPA_CMD_SETBRIDGEPORT_OSA;
1377 struct qeth_ipacmd_sbp_hdr *hdr;
1378 struct qeth_cmd_buffer *iob;
1380 iob = qeth_ipa_alloc_cmd(card, ipa_cmd, QETH_PROT_NONE,
1381 data_length +
1382 offsetof(struct qeth_ipacmd_setbridgeport,
1383 data));
1384 if (!iob)
1385 return iob;
1387 hdr = &__ipa_cmd(iob)->data.sbp.hdr;
1388 hdr->cmdlength = sizeof(*hdr) + data_length;
1389 hdr->command_code = sbp_cmd;
1390 hdr->used_total = 1;
1391 hdr->seq_no = 1;
1392 return iob;
1395 static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1396 struct qeth_reply *reply, unsigned long data)
1398 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1399 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1400 int rc;
1402 QETH_CARD_TEXT(card, 2, "brqsupcb");
1403 rc = qeth_bridgeport_makerc(card, cmd);
1404 if (rc)
1405 return rc;
1407 cbctl->data.supported =
1408 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1409 return 0;
1413 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1414 * @card: qeth_card structure pointer.
1416 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1417 * strucutre: card->options.sbp.supported_funcs.
1419 static void qeth_bridgeport_query_support(struct qeth_card *card)
1421 struct qeth_cmd_buffer *iob;
1422 struct _qeth_sbp_cbctl cbctl;
1424 QETH_CARD_TEXT(card, 2, "brqsuppo");
1425 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED,
1426 SBP_DATA_SIZEOF(query_cmds_supp));
1427 if (!iob)
1428 return;
1430 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1431 &cbctl)) {
1432 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1433 card->options.sbp.supported_funcs = 0;
1434 return;
1436 card->options.sbp.supported_funcs = cbctl.data.supported;
1439 static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1440 struct qeth_reply *reply, unsigned long data)
1442 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1443 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1444 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1445 int rc;
1447 QETH_CARD_TEXT(card, 2, "brqprtcb");
1448 rc = qeth_bridgeport_makerc(card, cmd);
1449 if (rc)
1450 return rc;
1452 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1453 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1454 return -EINVAL;
1456 /* first entry contains the state of the local port */
1457 if (qports->num_entries > 0) {
1458 if (cbctl->data.qports.role)
1459 *cbctl->data.qports.role = qports->entry[0].role;
1460 if (cbctl->data.qports.state)
1461 *cbctl->data.qports.state = qports->entry[0].state;
1463 return 0;
1467 * qeth_bridgeport_query_ports() - query local bridgeport status.
1468 * @card: qeth_card structure pointer.
1469 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1470 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1472 * Returns negative errno-compatible error indication or 0 on success.
1474 * 'role' and 'state' are not updated in case of hardware operation failure.
1476 int qeth_bridgeport_query_ports(struct qeth_card *card,
1477 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1479 struct qeth_cmd_buffer *iob;
1480 struct _qeth_sbp_cbctl cbctl = {
1481 .data = {
1482 .qports = {
1483 .role = role,
1484 .state = state,
1489 QETH_CARD_TEXT(card, 2, "brqports");
1490 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1491 return -EOPNOTSUPP;
1492 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0);
1493 if (!iob)
1494 return -ENOMEM;
1496 return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1497 &cbctl);
1500 static int qeth_bridgeport_set_cb(struct qeth_card *card,
1501 struct qeth_reply *reply, unsigned long data)
1503 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
1505 QETH_CARD_TEXT(card, 2, "brsetrcb");
1506 return qeth_bridgeport_makerc(card, cmd);
1510 * qeth_bridgeport_setrole() - Assign primary role to the port.
1511 * @card: qeth_card structure pointer.
1512 * @role: Role to assign.
1514 * Returns negative errno-compatible error indication or 0 on success.
1516 int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1518 struct qeth_cmd_buffer *iob;
1519 enum qeth_ipa_sbp_cmd setcmd;
1520 unsigned int cmdlength = 0;
1522 QETH_CARD_TEXT(card, 2, "brsetrol");
1523 switch (role) {
1524 case QETH_SBP_ROLE_NONE:
1525 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
1526 break;
1527 case QETH_SBP_ROLE_PRIMARY:
1528 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
1529 cmdlength = SBP_DATA_SIZEOF(set_primary);
1530 break;
1531 case QETH_SBP_ROLE_SECONDARY:
1532 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
1533 break;
1534 default:
1535 return -EINVAL;
1537 if (!(card->options.sbp.supported_funcs & setcmd))
1538 return -EOPNOTSUPP;
1539 iob = qeth_sbp_build_cmd(card, setcmd, cmdlength);
1540 if (!iob)
1541 return -ENOMEM;
1543 return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb, NULL);
1547 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1548 * @card: qeth_card structure pointer, for debug messages.
1550 * Returns negative errno-compatible error indication or 0 on success.
1552 static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
1554 int rc;
1556 if (pnso_rc == 0)
1557 switch (response) {
1558 case 0x0001:
1559 rc = 0;
1560 break;
1561 case 0x0004:
1562 case 0x0100:
1563 case 0x0106:
1564 rc = -EOPNOTSUPP;
1565 dev_err(&card->gdev->dev,
1566 "Setting address notification failed\n");
1567 break;
1568 case 0x0107:
1569 rc = -EAGAIN;
1570 break;
1571 default:
1572 rc = -EIO;
1574 else
1575 rc = -EIO;
1577 if (rc) {
1578 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
1579 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
1581 return rc;
1584 static void qeth_bridgeport_an_set_cb(void *priv,
1585 enum qdio_brinfo_entry_type type, void *entry)
1587 struct qeth_card *card = (struct qeth_card *)priv;
1588 struct qdio_brinfo_entry_l2 *l2entry;
1589 u8 code;
1591 if (type != l2_addr_lnid) {
1592 WARN_ON_ONCE(1);
1593 return;
1596 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
1597 code = IPA_ADDR_CHANGE_CODE_MACADDR;
1598 if (l2entry->addr_lnid.lnid < VLAN_N_VID)
1599 code |= IPA_ADDR_CHANGE_CODE_VLANID;
1600 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
1601 (struct net_if_token *)&l2entry->nit,
1602 (struct mac_addr_lnid *)&l2entry->addr_lnid);
1606 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1607 * @card: qeth_card structure pointer.
1608 * @enable: 0 - disable, non-zero - enable notifications
1610 * Returns negative errno-compatible error indication or 0 on success.
1612 * On enable, emits a series of address notifications udev events for all
1613 * currently registered hosts.
1615 int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
1617 int rc;
1618 u16 response;
1619 struct ccw_device *ddev;
1620 struct subchannel_id schid;
1622 if (!card)
1623 return -EINVAL;
1624 if (!card->options.sbp.supported_funcs)
1625 return -EOPNOTSUPP;
1626 ddev = CARD_DDEV(card);
1627 ccw_device_get_schid(ddev, &schid);
1629 if (enable) {
1630 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
1631 rc = qdio_pnso_brinfo(schid, 1, &response,
1632 qeth_bridgeport_an_set_cb, card);
1633 } else
1634 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
1635 return qeth_anset_makerc(card, rc, response);
1638 static bool qeth_bridgeport_is_in_use(struct qeth_card *card)
1640 return (card->options.sbp.role || card->options.sbp.reflect_promisc ||
1641 card->options.sbp.hostnotification);
1644 /* VNIC Characteristics support */
1646 /* handle VNICC IPA command return codes; convert to error codes */
1647 static int qeth_l2_vnicc_makerc(struct qeth_card *card, u16 ipa_rc)
1649 int rc;
1651 switch (ipa_rc) {
1652 case IPA_RC_SUCCESS:
1653 return ipa_rc;
1654 case IPA_RC_L2_UNSUPPORTED_CMD:
1655 case IPA_RC_NOTSUPP:
1656 rc = -EOPNOTSUPP;
1657 break;
1658 case IPA_RC_VNICC_OOSEQ:
1659 rc = -EALREADY;
1660 break;
1661 case IPA_RC_VNICC_VNICBP:
1662 rc = -EBUSY;
1663 break;
1664 case IPA_RC_L2_ADDR_TABLE_FULL:
1665 rc = -ENOSPC;
1666 break;
1667 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
1668 rc = -EACCES;
1669 break;
1670 default:
1671 rc = -EIO;
1674 QETH_CARD_TEXT_(card, 2, "err%04x", ipa_rc);
1675 return rc;
1678 /* generic VNICC request call back control */
1679 struct _qeth_l2_vnicc_request_cbctl {
1680 struct {
1681 union{
1682 u32 *sup_cmds;
1683 u32 *timeout;
1685 } result;
1688 /* generic VNICC request call back */
1689 static int qeth_l2_vnicc_request_cb(struct qeth_card *card,
1690 struct qeth_reply *reply,
1691 unsigned long data)
1693 struct _qeth_l2_vnicc_request_cbctl *cbctl =
1694 (struct _qeth_l2_vnicc_request_cbctl *) reply->param;
1695 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1696 struct qeth_ipacmd_vnicc *rep = &cmd->data.vnicc;
1697 u32 sub_cmd = cmd->data.vnicc.hdr.sub_command;
1699 QETH_CARD_TEXT(card, 2, "vniccrcb");
1700 if (cmd->hdr.return_code)
1701 return qeth_l2_vnicc_makerc(card, cmd->hdr.return_code);
1702 /* return results to caller */
1703 card->options.vnicc.sup_chars = rep->vnicc_cmds.supported;
1704 card->options.vnicc.cur_chars = rep->vnicc_cmds.enabled;
1706 if (sub_cmd == IPA_VNICC_QUERY_CMDS)
1707 *cbctl->result.sup_cmds = rep->data.query_cmds.sup_cmds;
1708 else if (sub_cmd == IPA_VNICC_GET_TIMEOUT)
1709 *cbctl->result.timeout = rep->data.getset_timeout.timeout;
1711 return 0;
1714 static struct qeth_cmd_buffer *qeth_l2_vnicc_build_cmd(struct qeth_card *card,
1715 u32 vnicc_cmd,
1716 unsigned int data_length)
1718 struct qeth_ipacmd_vnicc_hdr *hdr;
1719 struct qeth_cmd_buffer *iob;
1721 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_VNICC, QETH_PROT_NONE,
1722 data_length +
1723 offsetof(struct qeth_ipacmd_vnicc, data));
1724 if (!iob)
1725 return NULL;
1727 hdr = &__ipa_cmd(iob)->data.vnicc.hdr;
1728 hdr->data_length = sizeof(*hdr) + data_length;
1729 hdr->sub_command = vnicc_cmd;
1730 return iob;
1733 /* VNICC query VNIC characteristics request */
1734 static int qeth_l2_vnicc_query_chars(struct qeth_card *card)
1736 struct qeth_cmd_buffer *iob;
1738 QETH_CARD_TEXT(card, 2, "vniccqch");
1739 iob = qeth_l2_vnicc_build_cmd(card, IPA_VNICC_QUERY_CHARS, 0);
1740 if (!iob)
1741 return -ENOMEM;
1743 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, NULL);
1746 /* VNICC query sub commands request */
1747 static int qeth_l2_vnicc_query_cmds(struct qeth_card *card, u32 vnic_char,
1748 u32 *sup_cmds)
1750 struct _qeth_l2_vnicc_request_cbctl cbctl;
1751 struct qeth_cmd_buffer *iob;
1753 QETH_CARD_TEXT(card, 2, "vniccqcm");
1754 iob = qeth_l2_vnicc_build_cmd(card, IPA_VNICC_QUERY_CMDS,
1755 VNICC_DATA_SIZEOF(query_cmds));
1756 if (!iob)
1757 return -ENOMEM;
1759 __ipa_cmd(iob)->data.vnicc.data.query_cmds.vnic_char = vnic_char;
1761 /* prepare callback control */
1762 cbctl.result.sup_cmds = sup_cmds;
1764 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, &cbctl);
1767 /* VNICC enable/disable characteristic request */
1768 static int qeth_l2_vnicc_set_char(struct qeth_card *card, u32 vnic_char,
1769 u32 cmd)
1771 struct qeth_cmd_buffer *iob;
1773 QETH_CARD_TEXT(card, 2, "vniccedc");
1774 iob = qeth_l2_vnicc_build_cmd(card, cmd, VNICC_DATA_SIZEOF(set_char));
1775 if (!iob)
1776 return -ENOMEM;
1778 __ipa_cmd(iob)->data.vnicc.data.set_char.vnic_char = vnic_char;
1780 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, NULL);
1783 /* VNICC get/set timeout for characteristic request */
1784 static int qeth_l2_vnicc_getset_timeout(struct qeth_card *card, u32 vnicc,
1785 u32 cmd, u32 *timeout)
1787 struct qeth_vnicc_getset_timeout *getset_timeout;
1788 struct _qeth_l2_vnicc_request_cbctl cbctl;
1789 struct qeth_cmd_buffer *iob;
1791 QETH_CARD_TEXT(card, 2, "vniccgst");
1792 iob = qeth_l2_vnicc_build_cmd(card, cmd,
1793 VNICC_DATA_SIZEOF(getset_timeout));
1794 if (!iob)
1795 return -ENOMEM;
1797 getset_timeout = &__ipa_cmd(iob)->data.vnicc.data.getset_timeout;
1798 getset_timeout->vnic_char = vnicc;
1800 if (cmd == IPA_VNICC_SET_TIMEOUT)
1801 getset_timeout->timeout = *timeout;
1803 /* prepare callback control */
1804 if (cmd == IPA_VNICC_GET_TIMEOUT)
1805 cbctl.result.timeout = timeout;
1807 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, &cbctl);
1810 /* set current VNICC flag state; called from sysfs store function */
1811 int qeth_l2_vnicc_set_state(struct qeth_card *card, u32 vnicc, bool state)
1813 int rc = 0;
1814 u32 cmd;
1816 QETH_CARD_TEXT(card, 2, "vniccsch");
1818 /* check if characteristic and enable/disable are supported */
1819 if (!(card->options.vnicc.sup_chars & vnicc) ||
1820 !(card->options.vnicc.set_char_sup & vnicc))
1821 return -EOPNOTSUPP;
1823 if (qeth_bridgeport_is_in_use(card))
1824 return -EBUSY;
1826 /* set enable/disable command and store wanted characteristic */
1827 if (state) {
1828 cmd = IPA_VNICC_ENABLE;
1829 card->options.vnicc.wanted_chars |= vnicc;
1830 } else {
1831 cmd = IPA_VNICC_DISABLE;
1832 card->options.vnicc.wanted_chars &= ~vnicc;
1835 /* do we need to do anything? */
1836 if (card->options.vnicc.cur_chars == card->options.vnicc.wanted_chars)
1837 return rc;
1839 /* if card is not ready, simply stop here */
1840 if (!qeth_card_hw_is_reachable(card)) {
1841 if (state)
1842 card->options.vnicc.cur_chars |= vnicc;
1843 else
1844 card->options.vnicc.cur_chars &= ~vnicc;
1845 return rc;
1848 rc = qeth_l2_vnicc_set_char(card, vnicc, cmd);
1849 if (rc)
1850 card->options.vnicc.wanted_chars =
1851 card->options.vnicc.cur_chars;
1852 else {
1853 /* successful online VNICC change; handle special cases */
1854 if (state && vnicc == QETH_VNICC_RX_BCAST)
1855 card->options.vnicc.rx_bcast_enabled = true;
1856 if (!state && vnicc == QETH_VNICC_LEARNING)
1857 qeth_l2_vnicc_recover_timeout(card, vnicc,
1858 &card->options.vnicc.learning_timeout);
1861 return rc;
1864 /* get current VNICC flag state; called from sysfs show function */
1865 int qeth_l2_vnicc_get_state(struct qeth_card *card, u32 vnicc, bool *state)
1867 int rc = 0;
1869 QETH_CARD_TEXT(card, 2, "vniccgch");
1871 /* check if characteristic is supported */
1872 if (!(card->options.vnicc.sup_chars & vnicc))
1873 return -EOPNOTSUPP;
1875 if (qeth_bridgeport_is_in_use(card))
1876 return -EBUSY;
1878 /* if card is ready, query current VNICC state */
1879 if (qeth_card_hw_is_reachable(card))
1880 rc = qeth_l2_vnicc_query_chars(card);
1882 *state = (card->options.vnicc.cur_chars & vnicc) ? true : false;
1883 return rc;
1886 /* set VNICC timeout; called from sysfs store function. Currently, only learning
1887 * supports timeout
1889 int qeth_l2_vnicc_set_timeout(struct qeth_card *card, u32 timeout)
1891 int rc = 0;
1893 QETH_CARD_TEXT(card, 2, "vniccsto");
1895 /* check if characteristic and set_timeout are supported */
1896 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
1897 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
1898 return -EOPNOTSUPP;
1900 if (qeth_bridgeport_is_in_use(card))
1901 return -EBUSY;
1903 /* do we need to do anything? */
1904 if (card->options.vnicc.learning_timeout == timeout)
1905 return rc;
1907 /* if card is not ready, simply store the value internally and return */
1908 if (!qeth_card_hw_is_reachable(card)) {
1909 card->options.vnicc.learning_timeout = timeout;
1910 return rc;
1913 /* send timeout value to card; if successful, store value internally */
1914 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
1915 IPA_VNICC_SET_TIMEOUT, &timeout);
1916 if (!rc)
1917 card->options.vnicc.learning_timeout = timeout;
1919 return rc;
1922 /* get current VNICC timeout; called from sysfs show function. Currently, only
1923 * learning supports timeout
1925 int qeth_l2_vnicc_get_timeout(struct qeth_card *card, u32 *timeout)
1927 int rc = 0;
1929 QETH_CARD_TEXT(card, 2, "vniccgto");
1931 /* check if characteristic and get_timeout are supported */
1932 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
1933 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
1934 return -EOPNOTSUPP;
1936 if (qeth_bridgeport_is_in_use(card))
1937 return -EBUSY;
1939 /* if card is ready, get timeout. Otherwise, just return stored value */
1940 *timeout = card->options.vnicc.learning_timeout;
1941 if (qeth_card_hw_is_reachable(card))
1942 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
1943 IPA_VNICC_GET_TIMEOUT,
1944 timeout);
1946 return rc;
1949 /* check if VNICC is currently enabled */
1950 bool qeth_l2_vnicc_is_in_use(struct qeth_card *card)
1952 if (!card->options.vnicc.sup_chars)
1953 return false;
1954 /* default values are only OK if rx_bcast was not enabled by user
1955 * or the card is offline.
1957 if (card->options.vnicc.cur_chars == QETH_VNICC_DEFAULT) {
1958 if (!card->options.vnicc.rx_bcast_enabled ||
1959 !qeth_card_hw_is_reachable(card))
1960 return false;
1962 return true;
1965 /* recover user timeout setting */
1966 static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
1967 u32 *timeout)
1969 if (card->options.vnicc.sup_chars & vnicc &&
1970 card->options.vnicc.getset_timeout_sup & vnicc &&
1971 !qeth_l2_vnicc_getset_timeout(card, vnicc, IPA_VNICC_SET_TIMEOUT,
1972 timeout))
1973 return false;
1974 *timeout = QETH_VNICC_DEFAULT_TIMEOUT;
1975 return true;
1978 /* recover user characteristic setting */
1979 static bool qeth_l2_vnicc_recover_char(struct qeth_card *card, u32 vnicc,
1980 bool enable)
1982 u32 cmd = enable ? IPA_VNICC_ENABLE : IPA_VNICC_DISABLE;
1984 if (card->options.vnicc.sup_chars & vnicc &&
1985 card->options.vnicc.set_char_sup & vnicc &&
1986 !qeth_l2_vnicc_set_char(card, vnicc, cmd))
1987 return false;
1988 card->options.vnicc.wanted_chars &= ~vnicc;
1989 card->options.vnicc.wanted_chars |= QETH_VNICC_DEFAULT & vnicc;
1990 return true;
1993 /* (re-)initialize VNICC */
1994 static void qeth_l2_vnicc_init(struct qeth_card *card)
1996 u32 *timeout = &card->options.vnicc.learning_timeout;
1997 bool enable, error = false;
1998 unsigned int chars_len, i;
1999 unsigned long chars_tmp;
2000 u32 sup_cmds, vnicc;
2002 QETH_CARD_TEXT(card, 2, "vniccini");
2003 /* reset rx_bcast */
2004 card->options.vnicc.rx_bcast_enabled = 0;
2005 /* initial query and storage of VNIC characteristics */
2006 if (qeth_l2_vnicc_query_chars(card)) {
2007 if (card->options.vnicc.wanted_chars != QETH_VNICC_DEFAULT ||
2008 *timeout != QETH_VNICC_DEFAULT_TIMEOUT)
2009 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2010 /* fail quietly if user didn't change the default config */
2011 card->options.vnicc.sup_chars = 0;
2012 card->options.vnicc.cur_chars = 0;
2013 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
2014 return;
2016 /* get supported commands for each supported characteristic */
2017 chars_tmp = card->options.vnicc.sup_chars;
2018 chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE;
2019 for_each_set_bit(i, &chars_tmp, chars_len) {
2020 vnicc = BIT(i);
2021 if (qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds)) {
2022 sup_cmds = 0;
2023 error = true;
2025 if ((sup_cmds & IPA_VNICC_SET_TIMEOUT) &&
2026 (sup_cmds & IPA_VNICC_GET_TIMEOUT))
2027 card->options.vnicc.getset_timeout_sup |= vnicc;
2028 else
2029 card->options.vnicc.getset_timeout_sup &= ~vnicc;
2030 if ((sup_cmds & IPA_VNICC_ENABLE) &&
2031 (sup_cmds & IPA_VNICC_DISABLE))
2032 card->options.vnicc.set_char_sup |= vnicc;
2033 else
2034 card->options.vnicc.set_char_sup &= ~vnicc;
2036 /* enforce assumed default values and recover settings, if changed */
2037 error |= qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING,
2038 timeout);
2039 /* Change chars, if necessary */
2040 chars_tmp = card->options.vnicc.wanted_chars ^
2041 card->options.vnicc.cur_chars;
2042 chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE;
2043 for_each_set_bit(i, &chars_tmp, chars_len) {
2044 vnicc = BIT(i);
2045 enable = card->options.vnicc.wanted_chars & vnicc;
2046 error |= qeth_l2_vnicc_recover_char(card, vnicc, enable);
2048 if (error)
2049 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2052 /* configure default values of VNIC characteristics */
2053 static void qeth_l2_vnicc_set_defaults(struct qeth_card *card)
2055 /* characteristics values */
2056 card->options.vnicc.sup_chars = QETH_VNICC_ALL;
2057 card->options.vnicc.cur_chars = QETH_VNICC_DEFAULT;
2058 card->options.vnicc.learning_timeout = QETH_VNICC_DEFAULT_TIMEOUT;
2059 /* supported commands */
2060 card->options.vnicc.set_char_sup = QETH_VNICC_ALL;
2061 card->options.vnicc.getset_timeout_sup = QETH_VNICC_LEARNING;
2062 /* settings wanted by users */
2063 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
2066 module_init(qeth_l2_init);
2067 module_exit(qeth_l2_exit);
2068 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2069 MODULE_DESCRIPTION("qeth layer 2 discipline");
2070 MODULE_LICENSE("GPL");