1 // SPDX-License-Identifier: GPL-2.0
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>
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"
27 static void qeth_bridgeport_query_support(struct qeth_card *card);
28 static void qeth_bridge_state_change(struct qeth_card *card,
29 struct qeth_ipa_cmd *cmd);
30 static void qeth_bridge_host_event(struct qeth_card *card,
31 struct qeth_ipa_cmd *cmd);
32 static void qeth_l2_vnicc_set_defaults(struct qeth_card *card);
33 static void qeth_l2_vnicc_init(struct qeth_card *card);
34 static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
37 static int qeth_l2_setdelmac_makerc(struct qeth_card *card, u16 retcode)
42 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
47 case IPA_RC_L2_UNSUPPORTED_CMD:
50 case IPA_RC_L2_ADDR_TABLE_FULL:
53 case IPA_RC_L2_DUP_MAC:
54 case IPA_RC_L2_DUP_LAYER3_MAC:
57 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
58 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
61 case IPA_RC_L2_MAC_NOT_FOUND:
71 static int qeth_l2_send_setdelmac_cb(struct qeth_card *card,
72 struct qeth_reply *reply,
75 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
77 return qeth_l2_setdelmac_makerc(card, cmd->hdr.return_code);
80 static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
81 enum qeth_ipa_cmds ipacmd)
83 struct qeth_ipa_cmd *cmd;
84 struct qeth_cmd_buffer *iob;
86 QETH_CARD_TEXT(card, 2, "L2sdmac");
87 iob = qeth_ipa_alloc_cmd(card, ipacmd, QETH_PROT_IPV4,
88 IPA_DATA_SIZEOF(setdelmac));
92 cmd->data.setdelmac.mac_length = ETH_ALEN;
93 ether_addr_copy(cmd->data.setdelmac.mac, mac);
94 return qeth_send_ipa_cmd(card, iob, qeth_l2_send_setdelmac_cb, NULL);
97 static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
101 QETH_CARD_TEXT(card, 2, "L2Setmac");
102 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC);
104 dev_info(&card->gdev->dev,
105 "MAC address %pM successfully registered\n", mac);
109 dev_warn(&card->gdev->dev,
110 "MAC address %pM already exists\n", mac);
113 dev_warn(&card->gdev->dev,
114 "MAC address %pM is not authorized\n", mac);
121 static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac)
123 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
124 IPA_CMD_SETGMAC : IPA_CMD_SETVMAC;
127 QETH_CARD_TEXT(card, 2, "L2Wmac");
128 rc = qeth_l2_send_setdelmac(card, mac, cmd);
129 if (rc == -EADDRINUSE)
130 QETH_DBF_MESSAGE(2, "MAC already registered on device %x\n",
133 QETH_DBF_MESSAGE(2, "Failed to register MAC on device %x: %d\n",
134 CARD_DEVID(card), rc);
138 static int qeth_l2_remove_mac(struct qeth_card *card, u8 *mac)
140 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
141 IPA_CMD_DELGMAC : IPA_CMD_DELVMAC;
144 QETH_CARD_TEXT(card, 2, "L2Rmac");
145 rc = qeth_l2_send_setdelmac(card, mac, cmd);
147 QETH_DBF_MESSAGE(2, "Failed to delete MAC on device %u: %d\n",
148 CARD_DEVID(card), rc);
152 static void qeth_l2_drain_rx_mode_cache(struct qeth_card *card)
154 struct qeth_mac *mac;
155 struct hlist_node *tmp;
158 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
159 hash_del(&mac->hnode);
164 static void qeth_l2_fill_header(struct qeth_qdio_out_q *queue,
165 struct qeth_hdr *hdr, struct sk_buff *skb,
166 int ipv, unsigned int data_len)
168 int cast_type = qeth_get_ether_cast_type(skb);
169 struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
171 hdr->hdr.l2.pkt_length = data_len;
173 if (skb_is_gso(skb)) {
174 hdr->hdr.l2.id = QETH_HEADER_TYPE_L2_TSO;
176 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
177 if (skb->ip_summed == CHECKSUM_PARTIAL)
178 qeth_tx_csum(skb, &hdr->hdr.l2.flags[1], ipv);
181 /* set byte byte 3 to casting flags */
182 if (cast_type == RTN_MULTICAST)
183 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
184 else if (cast_type == RTN_BROADCAST)
185 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
187 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
189 /* VSWITCH relies on the VLAN
190 * information to be present in
192 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
193 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
194 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
198 static int qeth_l2_setdelvlan_makerc(struct qeth_card *card, u16 retcode)
201 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
206 case IPA_RC_L2_INVALID_VLAN_ID:
208 case IPA_RC_L2_DUP_VLAN_ID:
210 case IPA_RC_L2_VLAN_ID_NOT_FOUND:
212 case IPA_RC_L2_VLAN_ID_NOT_ALLOWED:
219 static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
220 struct qeth_reply *reply,
223 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
225 QETH_CARD_TEXT(card, 2, "L2sdvcb");
226 if (cmd->hdr.return_code) {
227 QETH_DBF_MESSAGE(2, "Error in processing VLAN %u on device %x: %#x.\n",
228 cmd->data.setdelvlan.vlan_id,
229 CARD_DEVID(card), cmd->hdr.return_code);
230 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
232 return qeth_l2_setdelvlan_makerc(card, cmd->hdr.return_code);
235 static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
236 enum qeth_ipa_cmds ipacmd)
238 struct qeth_ipa_cmd *cmd;
239 struct qeth_cmd_buffer *iob;
241 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
242 iob = qeth_ipa_alloc_cmd(card, ipacmd, QETH_PROT_IPV4,
243 IPA_DATA_SIZEOF(setdelvlan));
246 cmd = __ipa_cmd(iob);
247 cmd->data.setdelvlan.vlan_id = i;
248 return qeth_send_ipa_cmd(card, iob, qeth_l2_send_setdelvlan_cb, NULL);
251 static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
252 __be16 proto, u16 vid)
254 struct qeth_card *card = dev->ml_priv;
256 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
260 return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
263 static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
264 __be16 proto, u16 vid)
266 struct qeth_card *card = dev->ml_priv;
268 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
272 return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
275 static void qeth_l2_stop_card(struct qeth_card *card)
277 QETH_CARD_TEXT(card, 2, "stopcard");
279 qeth_set_allowed_threads(card, 0, 1);
281 cancel_work_sync(&card->rx_mode_work);
282 qeth_l2_drain_rx_mode_cache(card);
284 if (card->state == CARD_STATE_SOFTSETUP) {
285 qeth_clear_ipacmd_list(card);
286 qeth_drain_output_queues(card);
287 cancel_delayed_work_sync(&card->buffer_reclaim_work);
288 card->state = CARD_STATE_DOWN;
291 qeth_qdio_clear_card(card, 0);
292 qeth_clear_working_pool_list(card);
293 flush_workqueue(card->event_wq);
294 card->info.promisc_mode = 0;
297 static int qeth_l2_request_initial_mac(struct qeth_card *card)
301 QETH_CARD_TEXT(card, 2, "l2reqmac");
304 rc = qeth_vm_request_mac(card);
307 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %x: %#x\n",
308 CARD_DEVID(card), rc);
309 QETH_CARD_TEXT_(card, 2, "err%04x", rc);
310 /* fall back to alternative mechanism: */
314 rc = qeth_setadpparms_change_macaddr(card);
317 QETH_DBF_MESSAGE(2, "READ_MAC Assist failed on device %x: %#x\n",
318 CARD_DEVID(card), rc);
319 QETH_CARD_TEXT_(card, 2, "1err%04x", rc);
320 /* fall back once more: */
323 /* some devices don't support a custom MAC address: */
324 if (IS_OSM(card) || IS_OSX(card))
325 return (rc) ? rc : -EADDRNOTAVAIL;
326 eth_hw_addr_random(card->dev);
329 QETH_CARD_HEX(card, 2, card->dev->dev_addr, card->dev->addr_len);
333 static void qeth_l2_register_dev_addr(struct qeth_card *card)
335 if (!is_valid_ether_addr(card->dev->dev_addr))
336 qeth_l2_request_initial_mac(card);
338 if (!IS_OSN(card) && !qeth_l2_send_setmac(card, card->dev->dev_addr))
339 card->info.dev_addr_is_registered = 1;
341 card->info.dev_addr_is_registered = 0;
344 static int qeth_l2_validate_addr(struct net_device *dev)
346 struct qeth_card *card = dev->ml_priv;
348 if (card->info.dev_addr_is_registered)
349 return eth_validate_addr(dev);
351 QETH_CARD_TEXT(card, 4, "nomacadr");
355 static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
357 struct sockaddr *addr = p;
358 struct qeth_card *card = dev->ml_priv;
359 u8 old_addr[ETH_ALEN];
362 QETH_CARD_TEXT(card, 3, "setmac");
364 if (IS_OSM(card) || IS_OSX(card)) {
365 QETH_CARD_TEXT(card, 3, "setmcTYP");
368 QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN);
369 if (!is_valid_ether_addr(addr->sa_data))
370 return -EADDRNOTAVAIL;
372 /* don't register the same address twice */
373 if (ether_addr_equal_64bits(dev->dev_addr, addr->sa_data) &&
374 card->info.dev_addr_is_registered)
377 /* add the new address, switch over, drop the old */
378 rc = qeth_l2_send_setmac(card, addr->sa_data);
381 ether_addr_copy(old_addr, dev->dev_addr);
382 ether_addr_copy(dev->dev_addr, addr->sa_data);
384 if (card->info.dev_addr_is_registered)
385 qeth_l2_remove_mac(card, old_addr);
386 card->info.dev_addr_is_registered = 1;
390 static void qeth_l2_promisc_to_bridge(struct qeth_card *card, bool enable)
395 QETH_CARD_TEXT(card, 3, "pmisc2br");
398 if (card->options.sbp.reflect_promisc_primary)
399 role = QETH_SBP_ROLE_PRIMARY;
401 role = QETH_SBP_ROLE_SECONDARY;
403 role = QETH_SBP_ROLE_NONE;
405 rc = qeth_bridgeport_setrole(card, role);
406 QETH_CARD_TEXT_(card, 2, "bpm%c%04x", enable ? '+' : '-', rc);
408 card->options.sbp.role = role;
409 card->info.promisc_mode = enable;
413 static void qeth_l2_set_promisc_mode(struct qeth_card *card)
415 bool enable = card->dev->flags & IFF_PROMISC;
417 if (card->info.promisc_mode == enable)
420 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) {
421 qeth_setadp_promisc_mode(card, enable);
423 mutex_lock(&card->sbp_lock);
424 if (card->options.sbp.reflect_promisc)
425 qeth_l2_promisc_to_bridge(card, enable);
426 mutex_unlock(&card->sbp_lock);
430 /* New MAC address is added to the hash table and marked to be written on card
431 * only if there is not in the hash table storage already
434 static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha)
436 u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2]));
437 struct qeth_mac *mac;
439 hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) {
440 if (ether_addr_equal_64bits(ha->addr, mac->mac_addr)) {
441 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
446 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
450 ether_addr_copy(mac->mac_addr, ha->addr);
451 mac->disp_flag = QETH_DISP_ADDR_ADD;
453 hash_add(card->mac_htable, &mac->hnode, mac_hash);
456 static void qeth_l2_rx_mode_work(struct work_struct *work)
458 struct qeth_card *card = container_of(work, struct qeth_card,
460 struct net_device *dev = card->dev;
461 struct netdev_hw_addr *ha;
462 struct qeth_mac *mac;
463 struct hlist_node *tmp;
467 QETH_CARD_TEXT(card, 3, "setmulti");
469 netif_addr_lock_bh(dev);
470 netdev_for_each_mc_addr(ha, dev)
471 qeth_l2_add_mac(card, ha);
472 netdev_for_each_uc_addr(ha, dev)
473 qeth_l2_add_mac(card, ha);
474 netif_addr_unlock_bh(dev);
476 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
477 switch (mac->disp_flag) {
478 case QETH_DISP_ADDR_DELETE:
479 qeth_l2_remove_mac(card, mac->mac_addr);
480 hash_del(&mac->hnode);
483 case QETH_DISP_ADDR_ADD:
484 rc = qeth_l2_write_mac(card, mac->mac_addr);
486 hash_del(&mac->hnode);
492 /* for next call to set_rx_mode(): */
493 mac->disp_flag = QETH_DISP_ADDR_DELETE;
497 qeth_l2_set_promisc_mode(card);
500 static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb,
501 struct qeth_qdio_out_q *queue)
503 gfp_t gfp = GFP_ATOMIC | (skb_pfmemalloc(skb) ? __GFP_MEMALLOC : 0);
504 struct qeth_hdr *hdr = (struct qeth_hdr *)skb->data;
505 addr_t end = (addr_t)(skb->data + sizeof(*hdr));
506 addr_t start = (addr_t)skb->data;
507 unsigned int elements = 0;
508 unsigned int hd_len = 0;
511 if (skb->protocol == htons(ETH_P_IPV6))
512 return -EPROTONOSUPPORT;
514 if (qeth_get_elements_for_range(start, end) > 1) {
515 /* Misaligned HW header, move it to its own buffer element. */
516 hdr = kmem_cache_alloc(qeth_core_header_cache, gfp);
519 hd_len = sizeof(*hdr);
520 skb_copy_from_linear_data(skb, (char *)hdr, hd_len);
524 elements += qeth_count_elements(skb, hd_len);
525 if (elements > queue->max_elements) {
530 rc = qeth_do_send_packet(card, queue, skb, hdr, hd_len, hd_len,
534 kmem_cache_free(qeth_core_header_cache, hdr);
538 static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb,
539 struct net_device *dev)
541 struct qeth_card *card = dev->ml_priv;
542 u16 txq = skb_get_queue_mapping(skb);
543 struct qeth_qdio_out_q *queue;
546 if (!skb_is_gso(skb))
547 qdisc_skb_cb(skb)->pkt_len = skb->len;
549 txq = qeth_iqd_translate_txq(dev, txq);
550 queue = card->qdio.out_qs[txq];
553 rc = qeth_l2_xmit_osn(card, skb, queue);
555 rc = qeth_xmit(card, skb, queue, qeth_get_ip_version(skb),
556 qeth_l2_fill_header);
561 QETH_TXQ_STAT_INC(queue, tx_dropped);
566 static u16 qeth_l2_select_queue(struct net_device *dev, struct sk_buff *skb,
567 struct net_device *sb_dev)
569 struct qeth_card *card = dev->ml_priv;
572 return qeth_iqd_select_queue(dev, skb,
573 qeth_get_ether_cast_type(skb),
576 return IS_VM_NIC(card) ? netdev_pick_tx(dev, skb, sb_dev) :
577 qeth_get_priority_queue(card, skb);
580 static const struct device_type qeth_l2_devtype = {
581 .name = "qeth_layer2",
582 .groups = qeth_l2_attr_groups,
585 static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
587 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
591 dev_notice(&gdev->dev, "OSN support will be dropped in 2021\n");
593 qeth_l2_vnicc_set_defaults(card);
594 mutex_init(&card->sbp_lock);
596 if (gdev->dev.type == &qeth_generic_devtype) {
597 rc = qeth_l2_create_device_attributes(&gdev->dev);
602 hash_init(card->mac_htable);
603 INIT_WORK(&card->rx_mode_work, qeth_l2_rx_mode_work);
607 static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
609 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
611 if (cgdev->dev.type == &qeth_generic_devtype)
612 qeth_l2_remove_device_attributes(&cgdev->dev);
613 qeth_set_allowed_threads(card, 0, 1);
614 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
616 if (cgdev->state == CCWGROUP_ONLINE)
617 qeth_set_offline(card, false);
619 cancel_work_sync(&card->close_dev_work);
620 if (card->dev->reg_state == NETREG_REGISTERED)
621 unregister_netdev(card->dev);
624 static void qeth_l2_set_rx_mode(struct net_device *dev)
626 struct qeth_card *card = dev->ml_priv;
628 schedule_work(&card->rx_mode_work);
631 static const struct net_device_ops qeth_l2_netdev_ops = {
632 .ndo_open = qeth_open,
633 .ndo_stop = qeth_stop,
634 .ndo_get_stats64 = qeth_get_stats64,
635 .ndo_start_xmit = qeth_l2_hard_start_xmit,
636 .ndo_features_check = qeth_features_check,
637 .ndo_select_queue = qeth_l2_select_queue,
638 .ndo_validate_addr = qeth_l2_validate_addr,
639 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
640 .ndo_do_ioctl = qeth_do_ioctl,
641 .ndo_set_mac_address = qeth_l2_set_mac_address,
642 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
643 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
644 .ndo_tx_timeout = qeth_tx_timeout,
645 .ndo_fix_features = qeth_fix_features,
646 .ndo_set_features = qeth_set_features
649 static const struct net_device_ops qeth_osn_netdev_ops = {
650 .ndo_open = qeth_open,
651 .ndo_stop = qeth_stop,
652 .ndo_get_stats64 = qeth_get_stats64,
653 .ndo_start_xmit = qeth_l2_hard_start_xmit,
654 .ndo_validate_addr = eth_validate_addr,
655 .ndo_tx_timeout = qeth_tx_timeout,
658 static int qeth_l2_setup_netdev(struct qeth_card *card)
663 card->dev->netdev_ops = &qeth_osn_netdev_ops;
664 card->dev->flags |= IFF_NOARP;
668 rc = qeth_setup_netdev(card);
672 card->dev->needed_headroom = sizeof(struct qeth_hdr);
673 card->dev->netdev_ops = &qeth_l2_netdev_ops;
674 card->dev->priv_flags |= IFF_UNICAST_FLT;
677 card->dev->features |= NETIF_F_VLAN_CHALLENGED;
679 if (!IS_VM_NIC(card))
680 card->dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
681 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
684 if (IS_OSD(card) && !IS_VM_NIC(card)) {
685 card->dev->features |= NETIF_F_SG;
686 /* OSA 3S and earlier has no RX/TX support */
687 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
688 card->dev->hw_features |= NETIF_F_IP_CSUM;
689 card->dev->vlan_features |= NETIF_F_IP_CSUM;
692 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
693 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
694 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
696 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM) ||
697 qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6)) {
698 card->dev->hw_features |= NETIF_F_RXCSUM;
699 card->dev->vlan_features |= NETIF_F_RXCSUM;
701 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
702 card->dev->hw_features |= NETIF_F_TSO;
703 card->dev->vlan_features |= NETIF_F_TSO;
705 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) {
706 card->dev->hw_features |= NETIF_F_TSO6;
707 card->dev->vlan_features |= NETIF_F_TSO6;
710 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6)) {
711 card->dev->needed_headroom = sizeof(struct qeth_hdr_tso);
712 netif_set_gso_max_size(card->dev,
713 PAGE_SIZE * (QDIO_MAX_ELEMENTS_PER_BUFFER - 1));
717 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
718 return register_netdev(card->dev);
721 static void qeth_l2_trace_features(struct qeth_card *card)
723 /* Set BridgePort features */
724 QETH_CARD_TEXT(card, 2, "featuSBP");
725 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs,
726 sizeof(card->options.sbp.supported_funcs));
727 /* VNIC Characteristics features */
728 QETH_CARD_TEXT(card, 2, "feaVNICC");
729 QETH_CARD_HEX(card, 2, &card->options.vnicc.sup_chars,
730 sizeof(card->options.vnicc.sup_chars));
733 static void qeth_l2_setup_bridgeport_attrs(struct qeth_card *card)
735 if (!card->options.sbp.reflect_promisc &&
736 card->options.sbp.role != QETH_SBP_ROLE_NONE) {
737 /* Conditional to avoid spurious error messages */
738 qeth_bridgeport_setrole(card, card->options.sbp.role);
739 /* Let the callback function refresh the stored role value. */
740 qeth_bridgeport_query_ports(card, &card->options.sbp.role,
743 if (card->options.sbp.hostnotification) {
744 if (qeth_bridgeport_an_set(card, 1))
745 card->options.sbp.hostnotification = 0;
747 qeth_bridgeport_an_set(card, 0);
751 static int qeth_l2_set_online(struct qeth_card *card)
753 struct ccwgroup_device *gdev = card->gdev;
754 struct net_device *dev = card->dev;
758 rc = qeth_core_hardsetup_card(card, &carrier_ok);
760 QETH_CARD_TEXT_(card, 2, "2err%04x", rc);
765 mutex_lock(&card->sbp_lock);
766 qeth_bridgeport_query_support(card);
767 if (card->options.sbp.supported_funcs) {
768 qeth_l2_setup_bridgeport_attrs(card);
769 dev_info(&card->gdev->dev,
770 "The device represents a Bridge Capable Port\n");
772 mutex_unlock(&card->sbp_lock);
774 qeth_l2_register_dev_addr(card);
776 /* for the rx_bcast characteristic, init VNICC after setmac */
777 qeth_l2_vnicc_init(card);
779 qeth_trace_features(card);
780 qeth_l2_trace_features(card);
782 qeth_print_status_message(card);
785 QETH_CARD_TEXT(card, 2, "softsetp");
787 card->state = CARD_STATE_SOFTSETUP;
789 qeth_set_allowed_threads(card, 0xffffffff, 0);
791 if (dev->reg_state != NETREG_REGISTERED) {
792 rc = qeth_l2_setup_netdev(card);
797 netif_carrier_on(dev);
801 netif_carrier_on(dev);
803 netif_carrier_off(dev);
805 netif_device_attach(dev);
806 qeth_enable_hw_features(dev);
808 if (card->info.open_when_online) {
809 card->info.open_when_online = 0;
814 /* let user_space know that device is online */
815 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
819 qeth_l2_stop_card(card);
820 qeth_stop_channel(&card->data);
821 qeth_stop_channel(&card->write);
822 qeth_stop_channel(&card->read);
823 qdio_free(CARD_DDEV(card));
827 static void qeth_l2_set_offline(struct qeth_card *card)
829 qeth_l2_stop_card(card);
832 static int __init qeth_l2_init(void)
834 pr_info("register layer 2 discipline\n");
838 static void __exit qeth_l2_exit(void)
840 pr_info("unregister layer 2 discipline\n");
843 /* Returns zero if the command is successfully "consumed" */
844 static int qeth_l2_control_event(struct qeth_card *card,
845 struct qeth_ipa_cmd *cmd)
847 switch (cmd->hdr.command) {
848 case IPA_CMD_SETBRIDGEPORT_OSA:
849 case IPA_CMD_SETBRIDGEPORT_IQD:
850 if (cmd->data.sbp.hdr.command_code ==
851 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
852 qeth_bridge_state_change(card, cmd);
856 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
857 qeth_bridge_host_event(card, cmd);
864 struct qeth_discipline qeth_l2_discipline = {
865 .devtype = &qeth_l2_devtype,
866 .setup = qeth_l2_probe_device,
867 .remove = qeth_l2_remove_device,
868 .set_online = qeth_l2_set_online,
869 .set_offline = qeth_l2_set_offline,
871 .control_event_handler = qeth_l2_control_event,
873 EXPORT_SYMBOL_GPL(qeth_l2_discipline);
875 #ifdef CONFIG_QETH_OSN
876 static void qeth_osn_assist_cb(struct qeth_card *card,
877 struct qeth_cmd_buffer *iob,
878 unsigned int data_length)
880 qeth_notify_cmd(iob, 0);
884 int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
886 struct qeth_cmd_buffer *iob;
887 struct qeth_card *card;
896 QETH_CARD_TEXT(card, 2, "osnsdmc");
897 if (!qeth_card_hw_is_reachable(card))
900 iob = qeth_alloc_cmd(&card->write, IPA_PDU_HEADER_SIZE + data_len, 1,
905 qeth_prepare_ipa_cmd(card, iob, (u16) data_len, NULL);
907 memcpy(__ipa_cmd(iob), data, data_len);
908 iob->callback = qeth_osn_assist_cb;
909 return qeth_send_ipa_cmd(card, iob, NULL, NULL);
911 EXPORT_SYMBOL(qeth_osn_assist);
913 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
914 int (*assist_cb)(struct net_device *, void *),
915 int (*data_cb)(struct sk_buff *))
917 struct qeth_card *card;
921 memcpy(&devno, read_dev_no, 2);
922 sprintf(bus_id, "0.0.%04x", devno);
923 card = qeth_get_card_by_busid(bus_id);
924 if (!card || !IS_OSN(card))
928 QETH_CARD_TEXT(card, 2, "osnreg");
929 if ((assist_cb == NULL) || (data_cb == NULL))
931 card->osn_info.assist_cb = assist_cb;
932 card->osn_info.data_cb = data_cb;
935 EXPORT_SYMBOL(qeth_osn_register);
937 void qeth_osn_deregister(struct net_device *dev)
939 struct qeth_card *card;
946 QETH_CARD_TEXT(card, 2, "osndereg");
947 card->osn_info.assist_cb = NULL;
948 card->osn_info.data_cb = NULL;
951 EXPORT_SYMBOL(qeth_osn_deregister);
954 /* SETBRIDGEPORT support, async notifications */
956 enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
959 * qeth_bridge_emit_host_event() - bridgeport address change notification
960 * @card: qeth_card structure pointer, for udev events.
961 * @evtype: "normal" register/unregister, or abort, or reset. For abort
962 * and reset token and addr_lnid are unused and may be NULL.
963 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
964 * object, 0 - addition of an object.
965 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
966 * @token: "network token" structure identifying physical address of the port.
967 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
969 * This function is called when registrations and deregistrations are
970 * reported by the hardware, and also when notifications are enabled -
971 * for all currently registered addresses.
973 static void qeth_bridge_emit_host_event(struct qeth_card *card,
974 enum qeth_an_event_type evtype,
975 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
983 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
984 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
985 ? "deregister" : "register");
986 env[i] = str[i]; i++;
987 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
988 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
990 env[i] = str[i]; i++;
992 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
993 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
995 env[i] = str[i]; i++;
997 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
998 token->cssid, token->ssid, token->devnum);
999 env[i] = str[i]; i++;
1000 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1001 env[i] = str[i]; i++;
1002 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1004 env[i] = str[i]; i++;
1005 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1006 env[i] = str[i]; i++;
1009 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1010 env[i] = str[i]; i++;
1013 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1014 env[i] = str[i]; i++;
1018 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1021 struct qeth_bridge_state_data {
1022 struct work_struct worker;
1023 struct qeth_card *card;
1024 struct qeth_sbp_state_change qports;
1027 static void qeth_bridge_state_change_worker(struct work_struct *work)
1029 struct qeth_bridge_state_data *data =
1030 container_of(work, struct qeth_bridge_state_data, worker);
1031 /* We are only interested in the first entry - local port */
1032 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1033 char env_locrem[32];
1043 /* Role should not change by itself, but if it did, */
1044 /* information from the hardware is authoritative. */
1045 mutex_lock(&data->card->sbp_lock);
1046 data->card->options.sbp.role = entry->role;
1047 mutex_unlock(&data->card->sbp_lock);
1049 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1050 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1051 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1052 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1053 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1055 snprintf(env_state, sizeof(env_state), "STATE=%s",
1056 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1057 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1058 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1060 kobject_uevent_env(&data->card->gdev->dev.kobj,
1065 static void qeth_bridge_state_change(struct qeth_card *card,
1066 struct qeth_ipa_cmd *cmd)
1068 struct qeth_sbp_state_change *qports =
1069 &cmd->data.sbp.data.state_change;
1070 struct qeth_bridge_state_data *data;
1073 QETH_CARD_TEXT(card, 2, "brstchng");
1074 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1075 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
1078 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1079 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1082 QETH_CARD_TEXT(card, 2, "BPSalloc");
1085 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1087 memcpy(&data->qports, qports,
1088 sizeof(struct qeth_sbp_state_change) + extrasize);
1089 queue_work(card->event_wq, &data->worker);
1092 struct qeth_bridge_host_data {
1093 struct work_struct worker;
1094 struct qeth_card *card;
1095 struct qeth_ipacmd_addr_change hostevs;
1098 static void qeth_bridge_host_event_worker(struct work_struct *work)
1100 struct qeth_bridge_host_data *data =
1101 container_of(work, struct qeth_bridge_host_data, worker);
1104 if (data->hostevs.lost_event_mask) {
1105 dev_info(&data->card->gdev->dev,
1106 "Address notification from the Bridge Port stopped %s (%s)\n",
1107 data->card->dev->name,
1108 (data->hostevs.lost_event_mask == 0x01)
1110 : (data->hostevs.lost_event_mask == 0x02)
1111 ? "Bridge port state change"
1112 : "Unknown reason");
1113 mutex_lock(&data->card->sbp_lock);
1114 data->card->options.sbp.hostnotification = 0;
1115 mutex_unlock(&data->card->sbp_lock);
1116 qeth_bridge_emit_host_event(data->card, anev_abort,
1119 for (i = 0; i < data->hostevs.num_entries; i++) {
1120 struct qeth_ipacmd_addr_change_entry *entry =
1121 &data->hostevs.entry[i];
1122 qeth_bridge_emit_host_event(data->card,
1125 &entry->token, &entry->addr_lnid);
1130 static void qeth_bridge_host_event(struct qeth_card *card,
1131 struct qeth_ipa_cmd *cmd)
1133 struct qeth_ipacmd_addr_change *hostevs =
1134 &cmd->data.addrchange;
1135 struct qeth_bridge_host_data *data;
1138 QETH_CARD_TEXT(card, 2, "brhostev");
1139 if (cmd->hdr.return_code != 0x0000) {
1140 if (cmd->hdr.return_code == 0x0010) {
1141 if (hostevs->lost_event_mask == 0x00)
1142 hostevs->lost_event_mask = 0xff;
1144 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1145 cmd->hdr.return_code);
1149 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1150 hostevs->num_entries;
1151 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1154 QETH_CARD_TEXT(card, 2, "BPHalloc");
1157 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1159 memcpy(&data->hostevs, hostevs,
1160 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1161 queue_work(card->event_wq, &data->worker);
1164 /* SETBRIDGEPORT support; sending commands */
1166 struct _qeth_sbp_cbctl {
1170 enum qeth_sbp_roles *role;
1171 enum qeth_sbp_states *state;
1176 static int qeth_bridgeport_makerc(struct qeth_card *card,
1177 struct qeth_ipa_cmd *cmd)
1179 struct qeth_ipacmd_setbridgeport *sbp = &cmd->data.sbp;
1180 enum qeth_ipa_sbp_cmd setcmd = sbp->hdr.command_code;
1181 u16 ipa_rc = cmd->hdr.return_code;
1182 u16 sbp_rc = sbp->hdr.return_code;
1185 if (ipa_rc == IPA_RC_SUCCESS && sbp_rc == IPA_RC_SUCCESS)
1188 if ((IS_IQD(card) && ipa_rc == IPA_RC_SUCCESS) ||
1189 (!IS_IQD(card) && ipa_rc == sbp_rc)) {
1191 case IPA_RC_SUCCESS:
1194 case IPA_RC_L2_UNSUPPORTED_CMD:
1195 case IPA_RC_UNSUPPORTED_COMMAND:
1198 case IPA_RC_SBP_OSA_NOT_CONFIGURED:
1199 case IPA_RC_SBP_IQD_NOT_CONFIGURED:
1200 rc = -ENODEV; /* maybe not the best code here? */
1201 dev_err(&card->gdev->dev,
1202 "The device is not configured as a Bridge Port\n");
1204 case IPA_RC_SBP_OSA_OS_MISMATCH:
1205 case IPA_RC_SBP_IQD_OS_MISMATCH:
1207 dev_err(&card->gdev->dev,
1208 "A Bridge Port is already configured by a different operating system\n");
1210 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY:
1211 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY:
1213 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1215 dev_err(&card->gdev->dev,
1216 "The LAN already has a primary Bridge Port\n");
1218 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1220 dev_err(&card->gdev->dev,
1221 "The device is already a primary Bridge Port\n");
1227 case IPA_RC_SBP_OSA_CURRENT_SECOND:
1228 case IPA_RC_SBP_IQD_CURRENT_SECOND:
1230 dev_err(&card->gdev->dev,
1231 "The device is already a secondary Bridge Port\n");
1233 case IPA_RC_SBP_OSA_LIMIT_SECOND:
1234 case IPA_RC_SBP_IQD_LIMIT_SECOND:
1236 dev_err(&card->gdev->dev,
1237 "The LAN cannot have more secondary Bridge Ports\n");
1239 case IPA_RC_SBP_OSA_CURRENT_PRIMARY:
1240 case IPA_RC_SBP_IQD_CURRENT_PRIMARY:
1242 dev_err(&card->gdev->dev,
1243 "The device is already a primary Bridge Port\n");
1245 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN:
1246 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN:
1248 dev_err(&card->gdev->dev,
1249 "The device is not authorized to be a Bridge Port\n");
1256 case IPA_RC_NOTSUPP:
1259 case IPA_RC_UNSUPPORTED_COMMAND:
1268 QETH_CARD_TEXT_(card, 2, "SBPi%04x", ipa_rc);
1269 QETH_CARD_TEXT_(card, 2, "SBPc%04x", sbp_rc);
1274 static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card,
1275 enum qeth_ipa_sbp_cmd sbp_cmd,
1276 unsigned int data_length)
1278 enum qeth_ipa_cmds ipa_cmd = IS_IQD(card) ? IPA_CMD_SETBRIDGEPORT_IQD :
1279 IPA_CMD_SETBRIDGEPORT_OSA;
1280 struct qeth_ipacmd_sbp_hdr *hdr;
1281 struct qeth_cmd_buffer *iob;
1283 iob = qeth_ipa_alloc_cmd(card, ipa_cmd, QETH_PROT_NONE,
1285 offsetof(struct qeth_ipacmd_setbridgeport,
1290 hdr = &__ipa_cmd(iob)->data.sbp.hdr;
1291 hdr->cmdlength = sizeof(*hdr) + data_length;
1292 hdr->command_code = sbp_cmd;
1293 hdr->used_total = 1;
1298 static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1299 struct qeth_reply *reply, unsigned long data)
1301 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1302 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1305 QETH_CARD_TEXT(card, 2, "brqsupcb");
1306 rc = qeth_bridgeport_makerc(card, cmd);
1310 cbctl->data.supported =
1311 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1316 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1317 * @card: qeth_card structure pointer.
1319 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1320 * strucutre: card->options.sbp.supported_funcs.
1322 static void qeth_bridgeport_query_support(struct qeth_card *card)
1324 struct qeth_cmd_buffer *iob;
1325 struct _qeth_sbp_cbctl cbctl;
1327 QETH_CARD_TEXT(card, 2, "brqsuppo");
1328 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED,
1329 SBP_DATA_SIZEOF(query_cmds_supp));
1333 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1335 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1336 card->options.sbp.supported_funcs = 0;
1339 card->options.sbp.supported_funcs = cbctl.data.supported;
1342 static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1343 struct qeth_reply *reply, unsigned long data)
1345 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1346 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1347 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1350 QETH_CARD_TEXT(card, 2, "brqprtcb");
1351 rc = qeth_bridgeport_makerc(card, cmd);
1355 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1356 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1359 /* first entry contains the state of the local port */
1360 if (qports->num_entries > 0) {
1361 if (cbctl->data.qports.role)
1362 *cbctl->data.qports.role = qports->entry[0].role;
1363 if (cbctl->data.qports.state)
1364 *cbctl->data.qports.state = qports->entry[0].state;
1370 * qeth_bridgeport_query_ports() - query local bridgeport status.
1371 * @card: qeth_card structure pointer.
1372 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1373 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1375 * Returns negative errno-compatible error indication or 0 on success.
1377 * 'role' and 'state' are not updated in case of hardware operation failure.
1379 int qeth_bridgeport_query_ports(struct qeth_card *card,
1380 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1382 struct qeth_cmd_buffer *iob;
1383 struct _qeth_sbp_cbctl cbctl = {
1392 QETH_CARD_TEXT(card, 2, "brqports");
1393 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1395 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0);
1399 return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1403 static int qeth_bridgeport_set_cb(struct qeth_card *card,
1404 struct qeth_reply *reply, unsigned long data)
1406 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
1408 QETH_CARD_TEXT(card, 2, "brsetrcb");
1409 return qeth_bridgeport_makerc(card, cmd);
1413 * qeth_bridgeport_setrole() - Assign primary role to the port.
1414 * @card: qeth_card structure pointer.
1415 * @role: Role to assign.
1417 * Returns negative errno-compatible error indication or 0 on success.
1419 int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1421 struct qeth_cmd_buffer *iob;
1422 enum qeth_ipa_sbp_cmd setcmd;
1423 unsigned int cmdlength = 0;
1425 QETH_CARD_TEXT(card, 2, "brsetrol");
1427 case QETH_SBP_ROLE_NONE:
1428 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
1430 case QETH_SBP_ROLE_PRIMARY:
1431 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
1432 cmdlength = SBP_DATA_SIZEOF(set_primary);
1434 case QETH_SBP_ROLE_SECONDARY:
1435 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
1440 if (!(card->options.sbp.supported_funcs & setcmd))
1442 iob = qeth_sbp_build_cmd(card, setcmd, cmdlength);
1446 return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb, NULL);
1450 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1451 * @card: qeth_card structure pointer, for debug messages.
1453 * Returns negative errno-compatible error indication or 0 on success.
1455 static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
1468 dev_err(&card->gdev->dev,
1469 "Setting address notification failed\n");
1481 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
1482 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
1487 static void qeth_bridgeport_an_set_cb(void *priv,
1488 enum qdio_brinfo_entry_type type, void *entry)
1490 struct qeth_card *card = (struct qeth_card *)priv;
1491 struct qdio_brinfo_entry_l2 *l2entry;
1494 if (type != l2_addr_lnid) {
1499 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
1500 code = IPA_ADDR_CHANGE_CODE_MACADDR;
1501 if (l2entry->addr_lnid.lnid < VLAN_N_VID)
1502 code |= IPA_ADDR_CHANGE_CODE_VLANID;
1503 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
1504 (struct net_if_token *)&l2entry->nit,
1505 (struct mac_addr_lnid *)&l2entry->addr_lnid);
1509 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1510 * @card: qeth_card structure pointer.
1511 * @enable: 0 - disable, non-zero - enable notifications
1513 * Returns negative errno-compatible error indication or 0 on success.
1515 * On enable, emits a series of address notifications udev events for all
1516 * currently registered hosts.
1518 int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
1522 struct ccw_device *ddev;
1523 struct subchannel_id schid;
1525 if (!card->options.sbp.supported_funcs)
1527 ddev = CARD_DDEV(card);
1528 ccw_device_get_schid(ddev, &schid);
1531 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
1532 rc = qdio_pnso_brinfo(schid, 1, &response,
1533 qeth_bridgeport_an_set_cb, card);
1535 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
1536 return qeth_anset_makerc(card, rc, response);
1539 static bool qeth_bridgeport_is_in_use(struct qeth_card *card)
1541 return (card->options.sbp.role || card->options.sbp.reflect_promisc ||
1542 card->options.sbp.hostnotification);
1545 /* VNIC Characteristics support */
1547 /* handle VNICC IPA command return codes; convert to error codes */
1548 static int qeth_l2_vnicc_makerc(struct qeth_card *card, u16 ipa_rc)
1553 case IPA_RC_SUCCESS:
1555 case IPA_RC_L2_UNSUPPORTED_CMD:
1556 case IPA_RC_NOTSUPP:
1559 case IPA_RC_VNICC_OOSEQ:
1562 case IPA_RC_VNICC_VNICBP:
1565 case IPA_RC_L2_ADDR_TABLE_FULL:
1568 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
1575 QETH_CARD_TEXT_(card, 2, "err%04x", ipa_rc);
1579 /* generic VNICC request call back */
1580 static int qeth_l2_vnicc_request_cb(struct qeth_card *card,
1581 struct qeth_reply *reply,
1584 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1585 struct qeth_ipacmd_vnicc *rep = &cmd->data.vnicc;
1586 u32 sub_cmd = cmd->data.vnicc.hdr.sub_command;
1588 QETH_CARD_TEXT(card, 2, "vniccrcb");
1589 if (cmd->hdr.return_code)
1590 return qeth_l2_vnicc_makerc(card, cmd->hdr.return_code);
1591 /* return results to caller */
1592 card->options.vnicc.sup_chars = rep->vnicc_cmds.supported;
1593 card->options.vnicc.cur_chars = rep->vnicc_cmds.enabled;
1595 if (sub_cmd == IPA_VNICC_QUERY_CMDS)
1596 *(u32 *)reply->param = rep->data.query_cmds.sup_cmds;
1597 else if (sub_cmd == IPA_VNICC_GET_TIMEOUT)
1598 *(u32 *)reply->param = rep->data.getset_timeout.timeout;
1603 static struct qeth_cmd_buffer *qeth_l2_vnicc_build_cmd(struct qeth_card *card,
1605 unsigned int data_length)
1607 struct qeth_ipacmd_vnicc_hdr *hdr;
1608 struct qeth_cmd_buffer *iob;
1610 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_VNICC, QETH_PROT_NONE,
1612 offsetof(struct qeth_ipacmd_vnicc, data));
1616 hdr = &__ipa_cmd(iob)->data.vnicc.hdr;
1617 hdr->data_length = sizeof(*hdr) + data_length;
1618 hdr->sub_command = vnicc_cmd;
1622 /* VNICC query VNIC characteristics request */
1623 static int qeth_l2_vnicc_query_chars(struct qeth_card *card)
1625 struct qeth_cmd_buffer *iob;
1627 QETH_CARD_TEXT(card, 2, "vniccqch");
1628 iob = qeth_l2_vnicc_build_cmd(card, IPA_VNICC_QUERY_CHARS, 0);
1632 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, NULL);
1635 /* VNICC query sub commands request */
1636 static int qeth_l2_vnicc_query_cmds(struct qeth_card *card, u32 vnic_char,
1639 struct qeth_cmd_buffer *iob;
1641 QETH_CARD_TEXT(card, 2, "vniccqcm");
1642 iob = qeth_l2_vnicc_build_cmd(card, IPA_VNICC_QUERY_CMDS,
1643 VNICC_DATA_SIZEOF(query_cmds));
1647 __ipa_cmd(iob)->data.vnicc.data.query_cmds.vnic_char = vnic_char;
1649 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, sup_cmds);
1652 /* VNICC enable/disable characteristic request */
1653 static int qeth_l2_vnicc_set_char(struct qeth_card *card, u32 vnic_char,
1656 struct qeth_cmd_buffer *iob;
1658 QETH_CARD_TEXT(card, 2, "vniccedc");
1659 iob = qeth_l2_vnicc_build_cmd(card, cmd, VNICC_DATA_SIZEOF(set_char));
1663 __ipa_cmd(iob)->data.vnicc.data.set_char.vnic_char = vnic_char;
1665 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, NULL);
1668 /* VNICC get/set timeout for characteristic request */
1669 static int qeth_l2_vnicc_getset_timeout(struct qeth_card *card, u32 vnicc,
1670 u32 cmd, u32 *timeout)
1672 struct qeth_vnicc_getset_timeout *getset_timeout;
1673 struct qeth_cmd_buffer *iob;
1675 QETH_CARD_TEXT(card, 2, "vniccgst");
1676 iob = qeth_l2_vnicc_build_cmd(card, cmd,
1677 VNICC_DATA_SIZEOF(getset_timeout));
1681 getset_timeout = &__ipa_cmd(iob)->data.vnicc.data.getset_timeout;
1682 getset_timeout->vnic_char = vnicc;
1684 if (cmd == IPA_VNICC_SET_TIMEOUT)
1685 getset_timeout->timeout = *timeout;
1687 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, timeout);
1690 /* set current VNICC flag state; called from sysfs store function */
1691 int qeth_l2_vnicc_set_state(struct qeth_card *card, u32 vnicc, bool state)
1696 QETH_CARD_TEXT(card, 2, "vniccsch");
1698 /* check if characteristic and enable/disable are supported */
1699 if (!(card->options.vnicc.sup_chars & vnicc) ||
1700 !(card->options.vnicc.set_char_sup & vnicc))
1703 if (qeth_bridgeport_is_in_use(card))
1706 /* set enable/disable command and store wanted characteristic */
1708 cmd = IPA_VNICC_ENABLE;
1709 card->options.vnicc.wanted_chars |= vnicc;
1711 cmd = IPA_VNICC_DISABLE;
1712 card->options.vnicc.wanted_chars &= ~vnicc;
1715 /* do we need to do anything? */
1716 if (card->options.vnicc.cur_chars == card->options.vnicc.wanted_chars)
1719 /* if card is not ready, simply stop here */
1720 if (!qeth_card_hw_is_reachable(card)) {
1722 card->options.vnicc.cur_chars |= vnicc;
1724 card->options.vnicc.cur_chars &= ~vnicc;
1728 rc = qeth_l2_vnicc_set_char(card, vnicc, cmd);
1730 card->options.vnicc.wanted_chars =
1731 card->options.vnicc.cur_chars;
1733 /* successful online VNICC change; handle special cases */
1734 if (state && vnicc == QETH_VNICC_RX_BCAST)
1735 card->options.vnicc.rx_bcast_enabled = true;
1736 if (!state && vnicc == QETH_VNICC_LEARNING)
1737 qeth_l2_vnicc_recover_timeout(card, vnicc,
1738 &card->options.vnicc.learning_timeout);
1744 /* get current VNICC flag state; called from sysfs show function */
1745 int qeth_l2_vnicc_get_state(struct qeth_card *card, u32 vnicc, bool *state)
1749 QETH_CARD_TEXT(card, 2, "vniccgch");
1751 /* check if characteristic is supported */
1752 if (!(card->options.vnicc.sup_chars & vnicc))
1755 if (qeth_bridgeport_is_in_use(card))
1758 /* if card is ready, query current VNICC state */
1759 if (qeth_card_hw_is_reachable(card))
1760 rc = qeth_l2_vnicc_query_chars(card);
1762 *state = (card->options.vnicc.cur_chars & vnicc) ? true : false;
1766 /* set VNICC timeout; called from sysfs store function. Currently, only learning
1769 int qeth_l2_vnicc_set_timeout(struct qeth_card *card, u32 timeout)
1773 QETH_CARD_TEXT(card, 2, "vniccsto");
1775 /* check if characteristic and set_timeout are supported */
1776 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
1777 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
1780 if (qeth_bridgeport_is_in_use(card))
1783 /* do we need to do anything? */
1784 if (card->options.vnicc.learning_timeout == timeout)
1787 /* if card is not ready, simply store the value internally and return */
1788 if (!qeth_card_hw_is_reachable(card)) {
1789 card->options.vnicc.learning_timeout = timeout;
1793 /* send timeout value to card; if successful, store value internally */
1794 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
1795 IPA_VNICC_SET_TIMEOUT, &timeout);
1797 card->options.vnicc.learning_timeout = timeout;
1802 /* get current VNICC timeout; called from sysfs show function. Currently, only
1803 * learning supports timeout
1805 int qeth_l2_vnicc_get_timeout(struct qeth_card *card, u32 *timeout)
1809 QETH_CARD_TEXT(card, 2, "vniccgto");
1811 /* check if characteristic and get_timeout are supported */
1812 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
1813 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
1816 if (qeth_bridgeport_is_in_use(card))
1819 /* if card is ready, get timeout. Otherwise, just return stored value */
1820 *timeout = card->options.vnicc.learning_timeout;
1821 if (qeth_card_hw_is_reachable(card))
1822 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
1823 IPA_VNICC_GET_TIMEOUT,
1829 /* check if VNICC is currently enabled */
1830 bool qeth_l2_vnicc_is_in_use(struct qeth_card *card)
1832 if (!card->options.vnicc.sup_chars)
1834 /* default values are only OK if rx_bcast was not enabled by user
1835 * or the card is offline.
1837 if (card->options.vnicc.cur_chars == QETH_VNICC_DEFAULT) {
1838 if (!card->options.vnicc.rx_bcast_enabled ||
1839 !qeth_card_hw_is_reachable(card))
1845 /* recover user timeout setting */
1846 static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
1849 if (card->options.vnicc.sup_chars & vnicc &&
1850 card->options.vnicc.getset_timeout_sup & vnicc &&
1851 !qeth_l2_vnicc_getset_timeout(card, vnicc, IPA_VNICC_SET_TIMEOUT,
1854 *timeout = QETH_VNICC_DEFAULT_TIMEOUT;
1858 /* recover user characteristic setting */
1859 static bool qeth_l2_vnicc_recover_char(struct qeth_card *card, u32 vnicc,
1862 u32 cmd = enable ? IPA_VNICC_ENABLE : IPA_VNICC_DISABLE;
1864 if (card->options.vnicc.sup_chars & vnicc &&
1865 card->options.vnicc.set_char_sup & vnicc &&
1866 !qeth_l2_vnicc_set_char(card, vnicc, cmd))
1868 card->options.vnicc.wanted_chars &= ~vnicc;
1869 card->options.vnicc.wanted_chars |= QETH_VNICC_DEFAULT & vnicc;
1873 /* (re-)initialize VNICC */
1874 static void qeth_l2_vnicc_init(struct qeth_card *card)
1876 u32 *timeout = &card->options.vnicc.learning_timeout;
1877 bool enable, error = false;
1878 unsigned int chars_len, i;
1879 unsigned long chars_tmp;
1880 u32 sup_cmds, vnicc;
1882 QETH_CARD_TEXT(card, 2, "vniccini");
1883 /* reset rx_bcast */
1884 card->options.vnicc.rx_bcast_enabled = 0;
1885 /* initial query and storage of VNIC characteristics */
1886 if (qeth_l2_vnicc_query_chars(card)) {
1887 if (card->options.vnicc.wanted_chars != QETH_VNICC_DEFAULT ||
1888 *timeout != QETH_VNICC_DEFAULT_TIMEOUT)
1889 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
1890 /* fail quietly if user didn't change the default config */
1891 card->options.vnicc.sup_chars = 0;
1892 card->options.vnicc.cur_chars = 0;
1893 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
1896 /* get supported commands for each supported characteristic */
1897 chars_tmp = card->options.vnicc.sup_chars;
1898 chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE;
1899 for_each_set_bit(i, &chars_tmp, chars_len) {
1901 if (qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds)) {
1905 if ((sup_cmds & IPA_VNICC_SET_TIMEOUT) &&
1906 (sup_cmds & IPA_VNICC_GET_TIMEOUT))
1907 card->options.vnicc.getset_timeout_sup |= vnicc;
1909 card->options.vnicc.getset_timeout_sup &= ~vnicc;
1910 if ((sup_cmds & IPA_VNICC_ENABLE) &&
1911 (sup_cmds & IPA_VNICC_DISABLE))
1912 card->options.vnicc.set_char_sup |= vnicc;
1914 card->options.vnicc.set_char_sup &= ~vnicc;
1916 /* enforce assumed default values and recover settings, if changed */
1917 error |= qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING,
1919 /* Change chars, if necessary */
1920 chars_tmp = card->options.vnicc.wanted_chars ^
1921 card->options.vnicc.cur_chars;
1922 chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE;
1923 for_each_set_bit(i, &chars_tmp, chars_len) {
1925 enable = card->options.vnicc.wanted_chars & vnicc;
1926 error |= qeth_l2_vnicc_recover_char(card, vnicc, enable);
1929 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
1932 /* configure default values of VNIC characteristics */
1933 static void qeth_l2_vnicc_set_defaults(struct qeth_card *card)
1935 /* characteristics values */
1936 card->options.vnicc.sup_chars = QETH_VNICC_ALL;
1937 card->options.vnicc.cur_chars = QETH_VNICC_DEFAULT;
1938 card->options.vnicc.learning_timeout = QETH_VNICC_DEFAULT_TIMEOUT;
1939 /* supported commands */
1940 card->options.vnicc.set_char_sup = QETH_VNICC_ALL;
1941 card->options.vnicc.getset_timeout_sup = QETH_VNICC_LEARNING;
1942 /* settings wanted by users */
1943 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
1946 module_init(qeth_l2_init);
1947 module_exit(qeth_l2_exit);
1948 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1949 MODULE_DESCRIPTION("qeth layer 2 discipline");
1950 MODULE_LICENSE("GPL");