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
);
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 card
->state
= CARD_STATE_DOWN
;
290 qeth_qdio_clear_card(card
, 0);
291 qeth_clear_working_pool_list(card
);
292 flush_workqueue(card
->event_wq
);
293 card
->info
.mac_bits
&= ~QETH_LAYER2_MAC_REGISTERED
;
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
.mac_bits
|= QETH_LAYER2_MAC_REGISTERED
;
342 static int qeth_l2_validate_addr(struct net_device
*dev
)
344 struct qeth_card
*card
= dev
->ml_priv
;
346 if (card
->info
.mac_bits
& QETH_LAYER2_MAC_REGISTERED
)
347 return eth_validate_addr(dev
);
349 QETH_CARD_TEXT(card
, 4, "nomacadr");
353 static int qeth_l2_set_mac_address(struct net_device
*dev
, void *p
)
355 struct sockaddr
*addr
= p
;
356 struct qeth_card
*card
= dev
->ml_priv
;
357 u8 old_addr
[ETH_ALEN
];
360 QETH_CARD_TEXT(card
, 3, "setmac");
362 if (IS_OSM(card
) || IS_OSX(card
)) {
363 QETH_CARD_TEXT(card
, 3, "setmcTYP");
366 QETH_CARD_HEX(card
, 3, addr
->sa_data
, ETH_ALEN
);
367 if (!is_valid_ether_addr(addr
->sa_data
))
368 return -EADDRNOTAVAIL
;
370 /* don't register the same address twice */
371 if (ether_addr_equal_64bits(dev
->dev_addr
, addr
->sa_data
) &&
372 (card
->info
.mac_bits
& QETH_LAYER2_MAC_REGISTERED
))
375 /* add the new address, switch over, drop the old */
376 rc
= qeth_l2_send_setmac(card
, addr
->sa_data
);
379 ether_addr_copy(old_addr
, dev
->dev_addr
);
380 ether_addr_copy(dev
->dev_addr
, addr
->sa_data
);
382 if (card
->info
.mac_bits
& QETH_LAYER2_MAC_REGISTERED
)
383 qeth_l2_remove_mac(card
, old_addr
);
384 card
->info
.mac_bits
|= QETH_LAYER2_MAC_REGISTERED
;
388 static void qeth_l2_promisc_to_bridge(struct qeth_card
*card
, bool enable
)
393 QETH_CARD_TEXT(card
, 3, "pmisc2br");
396 if (card
->options
.sbp
.reflect_promisc_primary
)
397 role
= QETH_SBP_ROLE_PRIMARY
;
399 role
= QETH_SBP_ROLE_SECONDARY
;
401 role
= QETH_SBP_ROLE_NONE
;
403 rc
= qeth_bridgeport_setrole(card
, role
);
404 QETH_CARD_TEXT_(card
, 2, "bpm%c%04x", enable
? '+' : '-', rc
);
406 card
->options
.sbp
.role
= role
;
407 card
->info
.promisc_mode
= enable
;
411 static void qeth_l2_set_promisc_mode(struct qeth_card
*card
)
413 bool enable
= card
->dev
->flags
& IFF_PROMISC
;
415 if (card
->info
.promisc_mode
== enable
)
418 if (qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
)) {
419 qeth_setadp_promisc_mode(card
, enable
);
421 mutex_lock(&card
->sbp_lock
);
422 if (card
->options
.sbp
.reflect_promisc
)
423 qeth_l2_promisc_to_bridge(card
, enable
);
424 mutex_unlock(&card
->sbp_lock
);
428 /* New MAC address is added to the hash table and marked to be written on card
429 * only if there is not in the hash table storage already
432 static void qeth_l2_add_mac(struct qeth_card
*card
, struct netdev_hw_addr
*ha
)
434 u32 mac_hash
= get_unaligned((u32
*)(&ha
->addr
[2]));
435 struct qeth_mac
*mac
;
437 hash_for_each_possible(card
->mac_htable
, mac
, hnode
, mac_hash
) {
438 if (ether_addr_equal_64bits(ha
->addr
, mac
->mac_addr
)) {
439 mac
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
444 mac
= kzalloc(sizeof(struct qeth_mac
), GFP_ATOMIC
);
448 ether_addr_copy(mac
->mac_addr
, ha
->addr
);
449 mac
->disp_flag
= QETH_DISP_ADDR_ADD
;
451 hash_add(card
->mac_htable
, &mac
->hnode
, mac_hash
);
454 static void qeth_l2_rx_mode_work(struct work_struct
*work
)
456 struct qeth_card
*card
= container_of(work
, struct qeth_card
,
458 struct net_device
*dev
= card
->dev
;
459 struct netdev_hw_addr
*ha
;
460 struct qeth_mac
*mac
;
461 struct hlist_node
*tmp
;
465 QETH_CARD_TEXT(card
, 3, "setmulti");
467 netif_addr_lock_bh(dev
);
468 netdev_for_each_mc_addr(ha
, dev
)
469 qeth_l2_add_mac(card
, ha
);
470 netdev_for_each_uc_addr(ha
, dev
)
471 qeth_l2_add_mac(card
, ha
);
472 netif_addr_unlock_bh(dev
);
474 hash_for_each_safe(card
->mac_htable
, i
, tmp
, mac
, hnode
) {
475 switch (mac
->disp_flag
) {
476 case QETH_DISP_ADDR_DELETE
:
477 qeth_l2_remove_mac(card
, mac
->mac_addr
);
478 hash_del(&mac
->hnode
);
481 case QETH_DISP_ADDR_ADD
:
482 rc
= qeth_l2_write_mac(card
, mac
->mac_addr
);
484 hash_del(&mac
->hnode
);
490 /* for next call to set_rx_mode(): */
491 mac
->disp_flag
= QETH_DISP_ADDR_DELETE
;
495 qeth_l2_set_promisc_mode(card
);
498 static int qeth_l2_xmit_osn(struct qeth_card
*card
, struct sk_buff
*skb
,
499 struct qeth_qdio_out_q
*queue
)
501 struct qeth_hdr
*hdr
= (struct qeth_hdr
*)skb
->data
;
502 addr_t end
= (addr_t
)(skb
->data
+ sizeof(*hdr
));
503 addr_t start
= (addr_t
)skb
->data
;
504 unsigned int elements
= 0;
505 unsigned int hd_len
= 0;
508 if (skb
->protocol
== htons(ETH_P_IPV6
))
509 return -EPROTONOSUPPORT
;
511 if (qeth_get_elements_for_range(start
, end
) > 1) {
512 /* Misaligned HW header, move it to its own buffer element. */
513 hdr
= kmem_cache_alloc(qeth_core_header_cache
, GFP_ATOMIC
);
516 hd_len
= sizeof(*hdr
);
517 skb_copy_from_linear_data(skb
, (char *)hdr
, hd_len
);
521 elements
+= qeth_count_elements(skb
, hd_len
);
522 if (elements
> queue
->max_elements
) {
527 rc
= qeth_do_send_packet(card
, queue
, skb
, hdr
, hd_len
, hd_len
,
531 kmem_cache_free(qeth_core_header_cache
, hdr
);
535 static netdev_tx_t
qeth_l2_hard_start_xmit(struct sk_buff
*skb
,
536 struct net_device
*dev
)
538 struct qeth_card
*card
= dev
->ml_priv
;
539 u16 txq
= skb_get_queue_mapping(skb
);
540 struct qeth_qdio_out_q
*queue
;
543 if (!skb_is_gso(skb
))
544 qdisc_skb_cb(skb
)->pkt_len
= skb
->len
;
546 txq
= qeth_iqd_translate_txq(dev
, txq
);
547 queue
= card
->qdio
.out_qs
[txq
];
550 rc
= qeth_l2_xmit_osn(card
, skb
, queue
);
552 rc
= qeth_xmit(card
, skb
, queue
, qeth_get_ip_version(skb
),
553 qeth_l2_fill_header
);
558 QETH_TXQ_STAT_INC(queue
, tx_dropped
);
563 static u16
qeth_l2_select_queue(struct net_device
*dev
, struct sk_buff
*skb
,
564 struct net_device
*sb_dev
)
566 struct qeth_card
*card
= dev
->ml_priv
;
569 return qeth_iqd_select_queue(dev
, skb
,
570 qeth_get_ether_cast_type(skb
),
572 return qeth_get_priority_queue(card
, skb
);
575 static const struct device_type qeth_l2_devtype
= {
576 .name
= "qeth_layer2",
577 .groups
= qeth_l2_attr_groups
,
580 static int qeth_l2_probe_device(struct ccwgroup_device
*gdev
)
582 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
585 qeth_l2_vnicc_set_defaults(card
);
586 mutex_init(&card
->sbp_lock
);
588 if (gdev
->dev
.type
== &qeth_generic_devtype
) {
589 rc
= qeth_l2_create_device_attributes(&gdev
->dev
);
594 hash_init(card
->mac_htable
);
595 INIT_WORK(&card
->rx_mode_work
, qeth_l2_rx_mode_work
);
599 static void qeth_l2_remove_device(struct ccwgroup_device
*cgdev
)
601 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
603 if (cgdev
->dev
.type
== &qeth_generic_devtype
)
604 qeth_l2_remove_device_attributes(&cgdev
->dev
);
605 qeth_set_allowed_threads(card
, 0, 1);
606 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
608 if (cgdev
->state
== CCWGROUP_ONLINE
)
609 qeth_set_offline(card
, false);
611 cancel_work_sync(&card
->close_dev_work
);
612 if (qeth_netdev_is_registered(card
->dev
))
613 unregister_netdev(card
->dev
);
616 static void qeth_l2_set_rx_mode(struct net_device
*dev
)
618 struct qeth_card
*card
= dev
->ml_priv
;
620 schedule_work(&card
->rx_mode_work
);
623 static const struct net_device_ops qeth_l2_netdev_ops
= {
624 .ndo_open
= qeth_open
,
625 .ndo_stop
= qeth_stop
,
626 .ndo_get_stats64
= qeth_get_stats64
,
627 .ndo_start_xmit
= qeth_l2_hard_start_xmit
,
628 .ndo_features_check
= qeth_features_check
,
629 .ndo_select_queue
= qeth_l2_select_queue
,
630 .ndo_validate_addr
= qeth_l2_validate_addr
,
631 .ndo_set_rx_mode
= qeth_l2_set_rx_mode
,
632 .ndo_do_ioctl
= qeth_do_ioctl
,
633 .ndo_set_mac_address
= qeth_l2_set_mac_address
,
634 .ndo_vlan_rx_add_vid
= qeth_l2_vlan_rx_add_vid
,
635 .ndo_vlan_rx_kill_vid
= qeth_l2_vlan_rx_kill_vid
,
636 .ndo_tx_timeout
= qeth_tx_timeout
,
637 .ndo_fix_features
= qeth_fix_features
,
638 .ndo_set_features
= qeth_set_features
641 static const struct net_device_ops qeth_osn_netdev_ops
= {
642 .ndo_open
= qeth_open
,
643 .ndo_stop
= qeth_stop
,
644 .ndo_get_stats64
= qeth_get_stats64
,
645 .ndo_start_xmit
= qeth_l2_hard_start_xmit
,
646 .ndo_validate_addr
= eth_validate_addr
,
647 .ndo_tx_timeout
= qeth_tx_timeout
,
650 static int qeth_l2_setup_netdev(struct qeth_card
*card
, bool carrier_ok
)
655 card
->dev
->netdev_ops
= &qeth_osn_netdev_ops
;
656 card
->dev
->flags
|= IFF_NOARP
;
660 card
->dev
->needed_headroom
= sizeof(struct qeth_hdr
);
661 card
->dev
->netdev_ops
= &qeth_l2_netdev_ops
;
662 card
->dev
->priv_flags
|= IFF_UNICAST_FLT
;
665 card
->dev
->features
|= NETIF_F_VLAN_CHALLENGED
;
667 if (!IS_VM_NIC(card
))
668 card
->dev
->hw_features
|= NETIF_F_HW_VLAN_CTAG_FILTER
;
669 card
->dev
->features
|= NETIF_F_HW_VLAN_CTAG_FILTER
;
672 if (IS_OSD(card
) && !IS_VM_NIC(card
)) {
673 card
->dev
->features
|= NETIF_F_SG
;
674 /* OSA 3S and earlier has no RX/TX support */
675 if (qeth_is_supported(card
, IPA_OUTBOUND_CHECKSUM
)) {
676 card
->dev
->hw_features
|= NETIF_F_IP_CSUM
;
677 card
->dev
->vlan_features
|= NETIF_F_IP_CSUM
;
680 if (qeth_is_supported6(card
, IPA_OUTBOUND_CHECKSUM_V6
)) {
681 card
->dev
->hw_features
|= NETIF_F_IPV6_CSUM
;
682 card
->dev
->vlan_features
|= NETIF_F_IPV6_CSUM
;
684 if (qeth_is_supported(card
, IPA_INBOUND_CHECKSUM
) ||
685 qeth_is_supported6(card
, IPA_INBOUND_CHECKSUM_V6
)) {
686 card
->dev
->hw_features
|= NETIF_F_RXCSUM
;
687 card
->dev
->vlan_features
|= NETIF_F_RXCSUM
;
689 if (qeth_is_supported(card
, IPA_OUTBOUND_TSO
)) {
690 card
->dev
->hw_features
|= NETIF_F_TSO
;
691 card
->dev
->vlan_features
|= NETIF_F_TSO
;
693 if (qeth_is_supported6(card
, IPA_OUTBOUND_TSO
)) {
694 card
->dev
->hw_features
|= NETIF_F_TSO6
;
695 card
->dev
->vlan_features
|= NETIF_F_TSO6
;
698 if (card
->dev
->hw_features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) {
699 card
->dev
->needed_headroom
= sizeof(struct qeth_hdr_tso
);
700 netif_set_gso_max_size(card
->dev
,
701 PAGE_SIZE
* (QDIO_MAX_ELEMENTS_PER_BUFFER
- 1));
705 netif_napi_add(card
->dev
, &card
->napi
, qeth_poll
, QETH_NAPI_WEIGHT
);
706 rc
= register_netdev(card
->dev
);
707 if (!rc
&& carrier_ok
)
708 netif_carrier_on(card
->dev
);
711 card
->dev
->netdev_ops
= NULL
;
715 static void qeth_l2_trace_features(struct qeth_card
*card
)
717 /* Set BridgePort features */
718 QETH_CARD_TEXT(card
, 2, "featuSBP");
719 QETH_CARD_HEX(card
, 2, &card
->options
.sbp
.supported_funcs
,
720 sizeof(card
->options
.sbp
.supported_funcs
));
721 /* VNIC Characteristics features */
722 QETH_CARD_TEXT(card
, 2, "feaVNICC");
723 QETH_CARD_HEX(card
, 2, &card
->options
.vnicc
.sup_chars
,
724 sizeof(card
->options
.vnicc
.sup_chars
));
727 static void qeth_l2_setup_bridgeport_attrs(struct qeth_card
*card
)
729 if (!card
->options
.sbp
.reflect_promisc
&&
730 card
->options
.sbp
.role
!= QETH_SBP_ROLE_NONE
) {
731 /* Conditional to avoid spurious error messages */
732 qeth_bridgeport_setrole(card
, card
->options
.sbp
.role
);
733 /* Let the callback function refresh the stored role value. */
734 qeth_bridgeport_query_ports(card
, &card
->options
.sbp
.role
,
737 if (card
->options
.sbp
.hostnotification
) {
738 if (qeth_bridgeport_an_set(card
, 1))
739 card
->options
.sbp
.hostnotification
= 0;
741 qeth_bridgeport_an_set(card
, 0);
745 static int qeth_l2_set_online(struct qeth_card
*card
)
747 struct ccwgroup_device
*gdev
= card
->gdev
;
748 struct net_device
*dev
= card
->dev
;
752 rc
= qeth_core_hardsetup_card(card
, &carrier_ok
);
754 QETH_CARD_TEXT_(card
, 2, "2err%04x", rc
);
759 mutex_lock(&card
->sbp_lock
);
760 qeth_bridgeport_query_support(card
);
761 if (card
->options
.sbp
.supported_funcs
) {
762 qeth_l2_setup_bridgeport_attrs(card
);
763 dev_info(&card
->gdev
->dev
,
764 "The device represents a Bridge Capable Port\n");
766 mutex_unlock(&card
->sbp_lock
);
768 qeth_l2_register_dev_addr(card
);
770 /* for the rx_bcast characteristic, init VNICC after setmac */
771 qeth_l2_vnicc_init(card
);
773 qeth_trace_features(card
);
774 qeth_l2_trace_features(card
);
776 qeth_print_status_message(card
);
779 QETH_CARD_TEXT(card
, 2, "softsetp");
781 card
->state
= CARD_STATE_SOFTSETUP
;
783 qeth_set_allowed_threads(card
, 0xffffffff, 0);
785 if (!qeth_netdev_is_registered(dev
)) {
786 rc
= qeth_l2_setup_netdev(card
, carrier_ok
);
792 netif_carrier_on(dev
);
794 netif_carrier_off(dev
);
796 netif_device_attach(dev
);
797 qeth_enable_hw_features(dev
);
799 if (card
->info
.open_when_online
) {
800 card
->info
.open_when_online
= 0;
805 /* let user_space know that device is online */
806 kobject_uevent(&gdev
->dev
.kobj
, KOBJ_CHANGE
);
810 qeth_l2_stop_card(card
);
811 qeth_stop_channel(&card
->data
);
812 qeth_stop_channel(&card
->write
);
813 qeth_stop_channel(&card
->read
);
814 qdio_free(CARD_DDEV(card
));
818 static void qeth_l2_set_offline(struct qeth_card
*card
)
820 qeth_l2_stop_card(card
);
823 static int __init
qeth_l2_init(void)
825 pr_info("register layer 2 discipline\n");
829 static void __exit
qeth_l2_exit(void)
831 pr_info("unregister layer 2 discipline\n");
834 /* Returns zero if the command is successfully "consumed" */
835 static int qeth_l2_control_event(struct qeth_card
*card
,
836 struct qeth_ipa_cmd
*cmd
)
838 switch (cmd
->hdr
.command
) {
839 case IPA_CMD_SETBRIDGEPORT_OSA
:
840 case IPA_CMD_SETBRIDGEPORT_IQD
:
841 if (cmd
->data
.sbp
.hdr
.command_code
==
842 IPA_SBP_BRIDGE_PORT_STATE_CHANGE
) {
843 qeth_bridge_state_change(card
, cmd
);
847 case IPA_CMD_ADDRESS_CHANGE_NOTIF
:
848 qeth_bridge_host_event(card
, cmd
);
855 struct qeth_discipline qeth_l2_discipline
= {
856 .devtype
= &qeth_l2_devtype
,
857 .setup
= qeth_l2_probe_device
,
858 .remove
= qeth_l2_remove_device
,
859 .set_online
= qeth_l2_set_online
,
860 .set_offline
= qeth_l2_set_offline
,
862 .control_event_handler
= qeth_l2_control_event
,
864 EXPORT_SYMBOL_GPL(qeth_l2_discipline
);
866 static void qeth_osn_assist_cb(struct qeth_card
*card
,
867 struct qeth_cmd_buffer
*iob
,
868 unsigned int data_length
)
870 qeth_notify_cmd(iob
, 0);
874 int qeth_osn_assist(struct net_device
*dev
, void *data
, int data_len
)
876 struct qeth_cmd_buffer
*iob
;
877 struct qeth_card
*card
;
886 QETH_CARD_TEXT(card
, 2, "osnsdmc");
887 if (!qeth_card_hw_is_reachable(card
))
890 iob
= qeth_alloc_cmd(&card
->write
, IPA_PDU_HEADER_SIZE
+ data_len
, 1,
895 qeth_prepare_ipa_cmd(card
, iob
, (u16
) data_len
, NULL
);
897 memcpy(__ipa_cmd(iob
), data
, data_len
);
898 iob
->callback
= qeth_osn_assist_cb
;
899 return qeth_send_ipa_cmd(card
, iob
, NULL
, NULL
);
901 EXPORT_SYMBOL(qeth_osn_assist
);
903 int qeth_osn_register(unsigned char *read_dev_no
, struct net_device
**dev
,
904 int (*assist_cb
)(struct net_device
*, void *),
905 int (*data_cb
)(struct sk_buff
*))
907 struct qeth_card
*card
;
911 memcpy(&devno
, read_dev_no
, 2);
912 sprintf(bus_id
, "0.0.%04x", devno
);
913 card
= qeth_get_card_by_busid(bus_id
);
914 if (!card
|| !IS_OSN(card
))
918 QETH_CARD_TEXT(card
, 2, "osnreg");
919 if ((assist_cb
== NULL
) || (data_cb
== NULL
))
921 card
->osn_info
.assist_cb
= assist_cb
;
922 card
->osn_info
.data_cb
= data_cb
;
925 EXPORT_SYMBOL(qeth_osn_register
);
927 void qeth_osn_deregister(struct net_device
*dev
)
929 struct qeth_card
*card
;
936 QETH_CARD_TEXT(card
, 2, "osndereg");
937 card
->osn_info
.assist_cb
= NULL
;
938 card
->osn_info
.data_cb
= NULL
;
941 EXPORT_SYMBOL(qeth_osn_deregister
);
943 /* SETBRIDGEPORT support, async notifications */
945 enum qeth_an_event_type
{anev_reg_unreg
, anev_abort
, anev_reset
};
948 * qeth_bridge_emit_host_event() - bridgeport address change notification
949 * @card: qeth_card structure pointer, for udev events.
950 * @evtype: "normal" register/unregister, or abort, or reset. For abort
951 * and reset token and addr_lnid are unused and may be NULL.
952 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
953 * object, 0 - addition of an object.
954 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
955 * @token: "network token" structure identifying physical address of the port.
956 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
958 * This function is called when registrations and deregistrations are
959 * reported by the hardware, and also when notifications are enabled -
960 * for all currently registered addresses.
962 static void qeth_bridge_emit_host_event(struct qeth_card
*card
,
963 enum qeth_an_event_type evtype
,
964 u8 code
, struct net_if_token
*token
, struct mac_addr_lnid
*addr_lnid
)
972 snprintf(str
[i
], sizeof(str
[i
]), "BRIDGEDHOST=%s",
973 (code
& IPA_ADDR_CHANGE_CODE_REMOVAL
)
974 ? "deregister" : "register");
975 env
[i
] = str
[i
]; i
++;
976 if (code
& IPA_ADDR_CHANGE_CODE_VLANID
) {
977 snprintf(str
[i
], sizeof(str
[i
]), "VLAN=%d",
979 env
[i
] = str
[i
]; i
++;
981 if (code
& IPA_ADDR_CHANGE_CODE_MACADDR
) {
982 snprintf(str
[i
], sizeof(str
[i
]), "MAC=%pM",
984 env
[i
] = str
[i
]; i
++;
986 snprintf(str
[i
], sizeof(str
[i
]), "NTOK_BUSID=%x.%x.%04x",
987 token
->cssid
, token
->ssid
, token
->devnum
);
988 env
[i
] = str
[i
]; i
++;
989 snprintf(str
[i
], sizeof(str
[i
]), "NTOK_IID=%02x", token
->iid
);
990 env
[i
] = str
[i
]; i
++;
991 snprintf(str
[i
], sizeof(str
[i
]), "NTOK_CHPID=%02x",
993 env
[i
] = str
[i
]; i
++;
994 snprintf(str
[i
], sizeof(str
[i
]), "NTOK_CHID=%04x", token
->chid
);
995 env
[i
] = str
[i
]; i
++;
998 snprintf(str
[i
], sizeof(str
[i
]), "BRIDGEDHOST=abort");
999 env
[i
] = str
[i
]; i
++;
1002 snprintf(str
[i
], sizeof(str
[i
]), "BRIDGEDHOST=reset");
1003 env
[i
] = str
[i
]; i
++;
1007 kobject_uevent_env(&card
->gdev
->dev
.kobj
, KOBJ_CHANGE
, env
);
1010 struct qeth_bridge_state_data
{
1011 struct work_struct worker
;
1012 struct qeth_card
*card
;
1013 struct qeth_sbp_state_change qports
;
1016 static void qeth_bridge_state_change_worker(struct work_struct
*work
)
1018 struct qeth_bridge_state_data
*data
=
1019 container_of(work
, struct qeth_bridge_state_data
, worker
);
1020 /* We are only interested in the first entry - local port */
1021 struct qeth_sbp_port_entry
*entry
= &data
->qports
.entry
[0];
1022 char env_locrem
[32];
1032 /* Role should not change by itself, but if it did, */
1033 /* information from the hardware is authoritative. */
1034 mutex_lock(&data
->card
->sbp_lock
);
1035 data
->card
->options
.sbp
.role
= entry
->role
;
1036 mutex_unlock(&data
->card
->sbp_lock
);
1038 snprintf(env_locrem
, sizeof(env_locrem
), "BRIDGEPORT=statechange");
1039 snprintf(env_role
, sizeof(env_role
), "ROLE=%s",
1040 (entry
->role
== QETH_SBP_ROLE_NONE
) ? "none" :
1041 (entry
->role
== QETH_SBP_ROLE_PRIMARY
) ? "primary" :
1042 (entry
->role
== QETH_SBP_ROLE_SECONDARY
) ? "secondary" :
1044 snprintf(env_state
, sizeof(env_state
), "STATE=%s",
1045 (entry
->state
== QETH_SBP_STATE_INACTIVE
) ? "inactive" :
1046 (entry
->state
== QETH_SBP_STATE_STANDBY
) ? "standby" :
1047 (entry
->state
== QETH_SBP_STATE_ACTIVE
) ? "active" :
1049 kobject_uevent_env(&data
->card
->gdev
->dev
.kobj
,
1054 static void qeth_bridge_state_change(struct qeth_card
*card
,
1055 struct qeth_ipa_cmd
*cmd
)
1057 struct qeth_sbp_state_change
*qports
=
1058 &cmd
->data
.sbp
.data
.state_change
;
1059 struct qeth_bridge_state_data
*data
;
1062 QETH_CARD_TEXT(card
, 2, "brstchng");
1063 if (qports
->entry_length
!= sizeof(struct qeth_sbp_port_entry
)) {
1064 QETH_CARD_TEXT_(card
, 2, "BPsz%04x", qports
->entry_length
);
1067 extrasize
= sizeof(struct qeth_sbp_port_entry
) * qports
->num_entries
;
1068 data
= kzalloc(sizeof(struct qeth_bridge_state_data
) + extrasize
,
1071 QETH_CARD_TEXT(card
, 2, "BPSalloc");
1074 INIT_WORK(&data
->worker
, qeth_bridge_state_change_worker
);
1076 memcpy(&data
->qports
, qports
,
1077 sizeof(struct qeth_sbp_state_change
) + extrasize
);
1078 queue_work(card
->event_wq
, &data
->worker
);
1081 struct qeth_bridge_host_data
{
1082 struct work_struct worker
;
1083 struct qeth_card
*card
;
1084 struct qeth_ipacmd_addr_change hostevs
;
1087 static void qeth_bridge_host_event_worker(struct work_struct
*work
)
1089 struct qeth_bridge_host_data
*data
=
1090 container_of(work
, struct qeth_bridge_host_data
, worker
);
1093 if (data
->hostevs
.lost_event_mask
) {
1094 dev_info(&data
->card
->gdev
->dev
,
1095 "Address notification from the Bridge Port stopped %s (%s)\n",
1096 data
->card
->dev
->name
,
1097 (data
->hostevs
.lost_event_mask
== 0x01)
1099 : (data
->hostevs
.lost_event_mask
== 0x02)
1100 ? "Bridge port state change"
1101 : "Unknown reason");
1102 mutex_lock(&data
->card
->sbp_lock
);
1103 data
->card
->options
.sbp
.hostnotification
= 0;
1104 mutex_unlock(&data
->card
->sbp_lock
);
1105 qeth_bridge_emit_host_event(data
->card
, anev_abort
,
1108 for (i
= 0; i
< data
->hostevs
.num_entries
; i
++) {
1109 struct qeth_ipacmd_addr_change_entry
*entry
=
1110 &data
->hostevs
.entry
[i
];
1111 qeth_bridge_emit_host_event(data
->card
,
1114 &entry
->token
, &entry
->addr_lnid
);
1119 static void qeth_bridge_host_event(struct qeth_card
*card
,
1120 struct qeth_ipa_cmd
*cmd
)
1122 struct qeth_ipacmd_addr_change
*hostevs
=
1123 &cmd
->data
.addrchange
;
1124 struct qeth_bridge_host_data
*data
;
1127 QETH_CARD_TEXT(card
, 2, "brhostev");
1128 if (cmd
->hdr
.return_code
!= 0x0000) {
1129 if (cmd
->hdr
.return_code
== 0x0010) {
1130 if (hostevs
->lost_event_mask
== 0x00)
1131 hostevs
->lost_event_mask
= 0xff;
1133 QETH_CARD_TEXT_(card
, 2, "BPHe%04x",
1134 cmd
->hdr
.return_code
);
1138 extrasize
= sizeof(struct qeth_ipacmd_addr_change_entry
) *
1139 hostevs
->num_entries
;
1140 data
= kzalloc(sizeof(struct qeth_bridge_host_data
) + extrasize
,
1143 QETH_CARD_TEXT(card
, 2, "BPHalloc");
1146 INIT_WORK(&data
->worker
, qeth_bridge_host_event_worker
);
1148 memcpy(&data
->hostevs
, hostevs
,
1149 sizeof(struct qeth_ipacmd_addr_change
) + extrasize
);
1150 queue_work(card
->event_wq
, &data
->worker
);
1153 /* SETBRIDGEPORT support; sending commands */
1155 struct _qeth_sbp_cbctl
{
1159 enum qeth_sbp_roles
*role
;
1160 enum qeth_sbp_states
*state
;
1165 static int qeth_bridgeport_makerc(struct qeth_card
*card
,
1166 struct qeth_ipa_cmd
*cmd
)
1168 struct qeth_ipacmd_setbridgeport
*sbp
= &cmd
->data
.sbp
;
1169 enum qeth_ipa_sbp_cmd setcmd
= sbp
->hdr
.command_code
;
1170 u16 ipa_rc
= cmd
->hdr
.return_code
;
1171 u16 sbp_rc
= sbp
->hdr
.return_code
;
1174 if (ipa_rc
== IPA_RC_SUCCESS
&& sbp_rc
== IPA_RC_SUCCESS
)
1177 if ((IS_IQD(card
) && ipa_rc
== IPA_RC_SUCCESS
) ||
1178 (!IS_IQD(card
) && ipa_rc
== sbp_rc
)) {
1180 case IPA_RC_SUCCESS
:
1183 case IPA_RC_L2_UNSUPPORTED_CMD
:
1184 case IPA_RC_UNSUPPORTED_COMMAND
:
1187 case IPA_RC_SBP_OSA_NOT_CONFIGURED
:
1188 case IPA_RC_SBP_IQD_NOT_CONFIGURED
:
1189 rc
= -ENODEV
; /* maybe not the best code here? */
1190 dev_err(&card
->gdev
->dev
,
1191 "The device is not configured as a Bridge Port\n");
1193 case IPA_RC_SBP_OSA_OS_MISMATCH
:
1194 case IPA_RC_SBP_IQD_OS_MISMATCH
:
1196 dev_err(&card
->gdev
->dev
,
1197 "A Bridge Port is already configured by a different operating system\n");
1199 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY
:
1200 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY
:
1202 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT
:
1204 dev_err(&card
->gdev
->dev
,
1205 "The LAN already has a primary Bridge Port\n");
1207 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT
:
1209 dev_err(&card
->gdev
->dev
,
1210 "The device is already a primary Bridge Port\n");
1216 case IPA_RC_SBP_OSA_CURRENT_SECOND
:
1217 case IPA_RC_SBP_IQD_CURRENT_SECOND
:
1219 dev_err(&card
->gdev
->dev
,
1220 "The device is already a secondary Bridge Port\n");
1222 case IPA_RC_SBP_OSA_LIMIT_SECOND
:
1223 case IPA_RC_SBP_IQD_LIMIT_SECOND
:
1225 dev_err(&card
->gdev
->dev
,
1226 "The LAN cannot have more secondary Bridge Ports\n");
1228 case IPA_RC_SBP_OSA_CURRENT_PRIMARY
:
1229 case IPA_RC_SBP_IQD_CURRENT_PRIMARY
:
1231 dev_err(&card
->gdev
->dev
,
1232 "The device is already a primary Bridge Port\n");
1234 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN
:
1235 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN
:
1237 dev_err(&card
->gdev
->dev
,
1238 "The device is not authorized to be a Bridge Port\n");
1245 case IPA_RC_NOTSUPP
:
1248 case IPA_RC_UNSUPPORTED_COMMAND
:
1257 QETH_CARD_TEXT_(card
, 2, "SBPi%04x", ipa_rc
);
1258 QETH_CARD_TEXT_(card
, 2, "SBPc%04x", sbp_rc
);
1263 static struct qeth_cmd_buffer
*qeth_sbp_build_cmd(struct qeth_card
*card
,
1264 enum qeth_ipa_sbp_cmd sbp_cmd
,
1265 unsigned int data_length
)
1267 enum qeth_ipa_cmds ipa_cmd
= IS_IQD(card
) ? IPA_CMD_SETBRIDGEPORT_IQD
:
1268 IPA_CMD_SETBRIDGEPORT_OSA
;
1269 struct qeth_ipacmd_sbp_hdr
*hdr
;
1270 struct qeth_cmd_buffer
*iob
;
1272 iob
= qeth_ipa_alloc_cmd(card
, ipa_cmd
, QETH_PROT_NONE
,
1274 offsetof(struct qeth_ipacmd_setbridgeport
,
1279 hdr
= &__ipa_cmd(iob
)->data
.sbp
.hdr
;
1280 hdr
->cmdlength
= sizeof(*hdr
) + data_length
;
1281 hdr
->command_code
= sbp_cmd
;
1282 hdr
->used_total
= 1;
1287 static int qeth_bridgeport_query_support_cb(struct qeth_card
*card
,
1288 struct qeth_reply
*reply
, unsigned long data
)
1290 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
1291 struct _qeth_sbp_cbctl
*cbctl
= (struct _qeth_sbp_cbctl
*)reply
->param
;
1294 QETH_CARD_TEXT(card
, 2, "brqsupcb");
1295 rc
= qeth_bridgeport_makerc(card
, cmd
);
1299 cbctl
->data
.supported
=
1300 cmd
->data
.sbp
.data
.query_cmds_supp
.supported_cmds
;
1305 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1306 * @card: qeth_card structure pointer.
1308 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1309 * strucutre: card->options.sbp.supported_funcs.
1311 static void qeth_bridgeport_query_support(struct qeth_card
*card
)
1313 struct qeth_cmd_buffer
*iob
;
1314 struct _qeth_sbp_cbctl cbctl
;
1316 QETH_CARD_TEXT(card
, 2, "brqsuppo");
1317 iob
= qeth_sbp_build_cmd(card
, IPA_SBP_QUERY_COMMANDS_SUPPORTED
,
1318 SBP_DATA_SIZEOF(query_cmds_supp
));
1322 if (qeth_send_ipa_cmd(card
, iob
, qeth_bridgeport_query_support_cb
,
1324 card
->options
.sbp
.role
= QETH_SBP_ROLE_NONE
;
1325 card
->options
.sbp
.supported_funcs
= 0;
1328 card
->options
.sbp
.supported_funcs
= cbctl
.data
.supported
;
1331 static int qeth_bridgeport_query_ports_cb(struct qeth_card
*card
,
1332 struct qeth_reply
*reply
, unsigned long data
)
1334 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
1335 struct qeth_sbp_query_ports
*qports
= &cmd
->data
.sbp
.data
.query_ports
;
1336 struct _qeth_sbp_cbctl
*cbctl
= (struct _qeth_sbp_cbctl
*)reply
->param
;
1339 QETH_CARD_TEXT(card
, 2, "brqprtcb");
1340 rc
= qeth_bridgeport_makerc(card
, cmd
);
1344 if (qports
->entry_length
!= sizeof(struct qeth_sbp_port_entry
)) {
1345 QETH_CARD_TEXT_(card
, 2, "SBPs%04x", qports
->entry_length
);
1348 /* first entry contains the state of the local port */
1349 if (qports
->num_entries
> 0) {
1350 if (cbctl
->data
.qports
.role
)
1351 *cbctl
->data
.qports
.role
= qports
->entry
[0].role
;
1352 if (cbctl
->data
.qports
.state
)
1353 *cbctl
->data
.qports
.state
= qports
->entry
[0].state
;
1359 * qeth_bridgeport_query_ports() - query local bridgeport status.
1360 * @card: qeth_card structure pointer.
1361 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1362 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1364 * Returns negative errno-compatible error indication or 0 on success.
1366 * 'role' and 'state' are not updated in case of hardware operation failure.
1368 int qeth_bridgeport_query_ports(struct qeth_card
*card
,
1369 enum qeth_sbp_roles
*role
, enum qeth_sbp_states
*state
)
1371 struct qeth_cmd_buffer
*iob
;
1372 struct _qeth_sbp_cbctl cbctl
= {
1381 QETH_CARD_TEXT(card
, 2, "brqports");
1382 if (!(card
->options
.sbp
.supported_funcs
& IPA_SBP_QUERY_BRIDGE_PORTS
))
1384 iob
= qeth_sbp_build_cmd(card
, IPA_SBP_QUERY_BRIDGE_PORTS
, 0);
1388 return qeth_send_ipa_cmd(card
, iob
, qeth_bridgeport_query_ports_cb
,
1392 static int qeth_bridgeport_set_cb(struct qeth_card
*card
,
1393 struct qeth_reply
*reply
, unsigned long data
)
1395 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*)data
;
1397 QETH_CARD_TEXT(card
, 2, "brsetrcb");
1398 return qeth_bridgeport_makerc(card
, cmd
);
1402 * qeth_bridgeport_setrole() - Assign primary role to the port.
1403 * @card: qeth_card structure pointer.
1404 * @role: Role to assign.
1406 * Returns negative errno-compatible error indication or 0 on success.
1408 int qeth_bridgeport_setrole(struct qeth_card
*card
, enum qeth_sbp_roles role
)
1410 struct qeth_cmd_buffer
*iob
;
1411 enum qeth_ipa_sbp_cmd setcmd
;
1412 unsigned int cmdlength
= 0;
1414 QETH_CARD_TEXT(card
, 2, "brsetrol");
1416 case QETH_SBP_ROLE_NONE
:
1417 setcmd
= IPA_SBP_RESET_BRIDGE_PORT_ROLE
;
1419 case QETH_SBP_ROLE_PRIMARY
:
1420 setcmd
= IPA_SBP_SET_PRIMARY_BRIDGE_PORT
;
1421 cmdlength
= SBP_DATA_SIZEOF(set_primary
);
1423 case QETH_SBP_ROLE_SECONDARY
:
1424 setcmd
= IPA_SBP_SET_SECONDARY_BRIDGE_PORT
;
1429 if (!(card
->options
.sbp
.supported_funcs
& setcmd
))
1431 iob
= qeth_sbp_build_cmd(card
, setcmd
, cmdlength
);
1435 return qeth_send_ipa_cmd(card
, iob
, qeth_bridgeport_set_cb
, NULL
);
1439 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1440 * @card: qeth_card structure pointer, for debug messages.
1442 * Returns negative errno-compatible error indication or 0 on success.
1444 static int qeth_anset_makerc(struct qeth_card
*card
, int pnso_rc
, u16 response
)
1457 dev_err(&card
->gdev
->dev
,
1458 "Setting address notification failed\n");
1470 QETH_CARD_TEXT_(card
, 2, "SBPp%04x", pnso_rc
);
1471 QETH_CARD_TEXT_(card
, 2, "SBPr%04x", response
);
1476 static void qeth_bridgeport_an_set_cb(void *priv
,
1477 enum qdio_brinfo_entry_type type
, void *entry
)
1479 struct qeth_card
*card
= (struct qeth_card
*)priv
;
1480 struct qdio_brinfo_entry_l2
*l2entry
;
1483 if (type
!= l2_addr_lnid
) {
1488 l2entry
= (struct qdio_brinfo_entry_l2
*)entry
;
1489 code
= IPA_ADDR_CHANGE_CODE_MACADDR
;
1490 if (l2entry
->addr_lnid
.lnid
< VLAN_N_VID
)
1491 code
|= IPA_ADDR_CHANGE_CODE_VLANID
;
1492 qeth_bridge_emit_host_event(card
, anev_reg_unreg
, code
,
1493 (struct net_if_token
*)&l2entry
->nit
,
1494 (struct mac_addr_lnid
*)&l2entry
->addr_lnid
);
1498 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1499 * @card: qeth_card structure pointer.
1500 * @enable: 0 - disable, non-zero - enable notifications
1502 * Returns negative errno-compatible error indication or 0 on success.
1504 * On enable, emits a series of address notifications udev events for all
1505 * currently registered hosts.
1507 int qeth_bridgeport_an_set(struct qeth_card
*card
, int enable
)
1511 struct ccw_device
*ddev
;
1512 struct subchannel_id schid
;
1516 if (!card
->options
.sbp
.supported_funcs
)
1518 ddev
= CARD_DDEV(card
);
1519 ccw_device_get_schid(ddev
, &schid
);
1522 qeth_bridge_emit_host_event(card
, anev_reset
, 0, NULL
, NULL
);
1523 rc
= qdio_pnso_brinfo(schid
, 1, &response
,
1524 qeth_bridgeport_an_set_cb
, card
);
1526 rc
= qdio_pnso_brinfo(schid
, 0, &response
, NULL
, NULL
);
1527 return qeth_anset_makerc(card
, rc
, response
);
1530 static bool qeth_bridgeport_is_in_use(struct qeth_card
*card
)
1532 return (card
->options
.sbp
.role
|| card
->options
.sbp
.reflect_promisc
||
1533 card
->options
.sbp
.hostnotification
);
1536 /* VNIC Characteristics support */
1538 /* handle VNICC IPA command return codes; convert to error codes */
1539 static int qeth_l2_vnicc_makerc(struct qeth_card
*card
, u16 ipa_rc
)
1544 case IPA_RC_SUCCESS
:
1546 case IPA_RC_L2_UNSUPPORTED_CMD
:
1547 case IPA_RC_NOTSUPP
:
1550 case IPA_RC_VNICC_OOSEQ
:
1553 case IPA_RC_VNICC_VNICBP
:
1556 case IPA_RC_L2_ADDR_TABLE_FULL
:
1559 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP
:
1566 QETH_CARD_TEXT_(card
, 2, "err%04x", ipa_rc
);
1570 /* generic VNICC request call back control */
1571 struct _qeth_l2_vnicc_request_cbctl
{
1580 /* generic VNICC request call back */
1581 static int qeth_l2_vnicc_request_cb(struct qeth_card
*card
,
1582 struct qeth_reply
*reply
,
1585 struct _qeth_l2_vnicc_request_cbctl
*cbctl
=
1586 (struct _qeth_l2_vnicc_request_cbctl
*) reply
->param
;
1587 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
1588 struct qeth_ipacmd_vnicc
*rep
= &cmd
->data
.vnicc
;
1589 u32 sub_cmd
= cmd
->data
.vnicc
.hdr
.sub_command
;
1591 QETH_CARD_TEXT(card
, 2, "vniccrcb");
1592 if (cmd
->hdr
.return_code
)
1593 return qeth_l2_vnicc_makerc(card
, cmd
->hdr
.return_code
);
1594 /* return results to caller */
1595 card
->options
.vnicc
.sup_chars
= rep
->vnicc_cmds
.supported
;
1596 card
->options
.vnicc
.cur_chars
= rep
->vnicc_cmds
.enabled
;
1598 if (sub_cmd
== IPA_VNICC_QUERY_CMDS
)
1599 *cbctl
->result
.sup_cmds
= rep
->data
.query_cmds
.sup_cmds
;
1600 else if (sub_cmd
== IPA_VNICC_GET_TIMEOUT
)
1601 *cbctl
->result
.timeout
= rep
->data
.getset_timeout
.timeout
;
1606 static struct qeth_cmd_buffer
*qeth_l2_vnicc_build_cmd(struct qeth_card
*card
,
1608 unsigned int data_length
)
1610 struct qeth_ipacmd_vnicc_hdr
*hdr
;
1611 struct qeth_cmd_buffer
*iob
;
1613 iob
= qeth_ipa_alloc_cmd(card
, IPA_CMD_VNICC
, QETH_PROT_NONE
,
1615 offsetof(struct qeth_ipacmd_vnicc
, data
));
1619 hdr
= &__ipa_cmd(iob
)->data
.vnicc
.hdr
;
1620 hdr
->data_length
= sizeof(*hdr
) + data_length
;
1621 hdr
->sub_command
= vnicc_cmd
;
1625 /* VNICC query VNIC characteristics request */
1626 static int qeth_l2_vnicc_query_chars(struct qeth_card
*card
)
1628 struct qeth_cmd_buffer
*iob
;
1630 QETH_CARD_TEXT(card
, 2, "vniccqch");
1631 iob
= qeth_l2_vnicc_build_cmd(card
, IPA_VNICC_QUERY_CHARS
, 0);
1635 return qeth_send_ipa_cmd(card
, iob
, qeth_l2_vnicc_request_cb
, NULL
);
1638 /* VNICC query sub commands request */
1639 static int qeth_l2_vnicc_query_cmds(struct qeth_card
*card
, u32 vnic_char
,
1642 struct _qeth_l2_vnicc_request_cbctl cbctl
;
1643 struct qeth_cmd_buffer
*iob
;
1645 QETH_CARD_TEXT(card
, 2, "vniccqcm");
1646 iob
= qeth_l2_vnicc_build_cmd(card
, IPA_VNICC_QUERY_CMDS
,
1647 VNICC_DATA_SIZEOF(query_cmds
));
1651 __ipa_cmd(iob
)->data
.vnicc
.data
.query_cmds
.vnic_char
= vnic_char
;
1653 /* prepare callback control */
1654 cbctl
.result
.sup_cmds
= sup_cmds
;
1656 return qeth_send_ipa_cmd(card
, iob
, qeth_l2_vnicc_request_cb
, &cbctl
);
1659 /* VNICC enable/disable characteristic request */
1660 static int qeth_l2_vnicc_set_char(struct qeth_card
*card
, u32 vnic_char
,
1663 struct qeth_cmd_buffer
*iob
;
1665 QETH_CARD_TEXT(card
, 2, "vniccedc");
1666 iob
= qeth_l2_vnicc_build_cmd(card
, cmd
, VNICC_DATA_SIZEOF(set_char
));
1670 __ipa_cmd(iob
)->data
.vnicc
.data
.set_char
.vnic_char
= vnic_char
;
1672 return qeth_send_ipa_cmd(card
, iob
, qeth_l2_vnicc_request_cb
, NULL
);
1675 /* VNICC get/set timeout for characteristic request */
1676 static int qeth_l2_vnicc_getset_timeout(struct qeth_card
*card
, u32 vnicc
,
1677 u32 cmd
, u32
*timeout
)
1679 struct qeth_vnicc_getset_timeout
*getset_timeout
;
1680 struct _qeth_l2_vnicc_request_cbctl cbctl
;
1681 struct qeth_cmd_buffer
*iob
;
1683 QETH_CARD_TEXT(card
, 2, "vniccgst");
1684 iob
= qeth_l2_vnicc_build_cmd(card
, cmd
,
1685 VNICC_DATA_SIZEOF(getset_timeout
));
1689 getset_timeout
= &__ipa_cmd(iob
)->data
.vnicc
.data
.getset_timeout
;
1690 getset_timeout
->vnic_char
= vnicc
;
1692 if (cmd
== IPA_VNICC_SET_TIMEOUT
)
1693 getset_timeout
->timeout
= *timeout
;
1695 /* prepare callback control */
1696 if (cmd
== IPA_VNICC_GET_TIMEOUT
)
1697 cbctl
.result
.timeout
= timeout
;
1699 return qeth_send_ipa_cmd(card
, iob
, qeth_l2_vnicc_request_cb
, &cbctl
);
1702 /* set current VNICC flag state; called from sysfs store function */
1703 int qeth_l2_vnicc_set_state(struct qeth_card
*card
, u32 vnicc
, bool state
)
1708 QETH_CARD_TEXT(card
, 2, "vniccsch");
1710 /* do not change anything if BridgePort is enabled */
1711 if (qeth_bridgeport_is_in_use(card
))
1714 /* check if characteristic and enable/disable are supported */
1715 if (!(card
->options
.vnicc
.sup_chars
& vnicc
) ||
1716 !(card
->options
.vnicc
.set_char_sup
& vnicc
))
1719 /* set enable/disable command and store wanted characteristic */
1721 cmd
= IPA_VNICC_ENABLE
;
1722 card
->options
.vnicc
.wanted_chars
|= vnicc
;
1724 cmd
= IPA_VNICC_DISABLE
;
1725 card
->options
.vnicc
.wanted_chars
&= ~vnicc
;
1728 /* do we need to do anything? */
1729 if (card
->options
.vnicc
.cur_chars
== card
->options
.vnicc
.wanted_chars
)
1732 /* if card is not ready, simply stop here */
1733 if (!qeth_card_hw_is_reachable(card
)) {
1735 card
->options
.vnicc
.cur_chars
|= vnicc
;
1737 card
->options
.vnicc
.cur_chars
&= ~vnicc
;
1741 rc
= qeth_l2_vnicc_set_char(card
, vnicc
, cmd
);
1743 card
->options
.vnicc
.wanted_chars
=
1744 card
->options
.vnicc
.cur_chars
;
1746 /* successful online VNICC change; handle special cases */
1747 if (state
&& vnicc
== QETH_VNICC_RX_BCAST
)
1748 card
->options
.vnicc
.rx_bcast_enabled
= true;
1749 if (!state
&& vnicc
== QETH_VNICC_LEARNING
)
1750 qeth_l2_vnicc_recover_timeout(card
, vnicc
,
1751 &card
->options
.vnicc
.learning_timeout
);
1757 /* get current VNICC flag state; called from sysfs show function */
1758 int qeth_l2_vnicc_get_state(struct qeth_card
*card
, u32 vnicc
, bool *state
)
1762 QETH_CARD_TEXT(card
, 2, "vniccgch");
1764 /* do not get anything if BridgePort is enabled */
1765 if (qeth_bridgeport_is_in_use(card
))
1768 /* check if characteristic is supported */
1769 if (!(card
->options
.vnicc
.sup_chars
& vnicc
))
1772 /* if card is ready, query current VNICC state */
1773 if (qeth_card_hw_is_reachable(card
))
1774 rc
= qeth_l2_vnicc_query_chars(card
);
1776 *state
= (card
->options
.vnicc
.cur_chars
& vnicc
) ? true : false;
1780 /* set VNICC timeout; called from sysfs store function. Currently, only learning
1783 int qeth_l2_vnicc_set_timeout(struct qeth_card
*card
, u32 timeout
)
1787 QETH_CARD_TEXT(card
, 2, "vniccsto");
1789 /* do not change anything if BridgePort is enabled */
1790 if (qeth_bridgeport_is_in_use(card
))
1793 /* check if characteristic and set_timeout are supported */
1794 if (!(card
->options
.vnicc
.sup_chars
& QETH_VNICC_LEARNING
) ||
1795 !(card
->options
.vnicc
.getset_timeout_sup
& QETH_VNICC_LEARNING
))
1798 /* do we need to do anything? */
1799 if (card
->options
.vnicc
.learning_timeout
== timeout
)
1802 /* if card is not ready, simply store the value internally and return */
1803 if (!qeth_card_hw_is_reachable(card
)) {
1804 card
->options
.vnicc
.learning_timeout
= timeout
;
1808 /* send timeout value to card; if successful, store value internally */
1809 rc
= qeth_l2_vnicc_getset_timeout(card
, QETH_VNICC_LEARNING
,
1810 IPA_VNICC_SET_TIMEOUT
, &timeout
);
1812 card
->options
.vnicc
.learning_timeout
= timeout
;
1817 /* get current VNICC timeout; called from sysfs show function. Currently, only
1818 * learning supports timeout
1820 int qeth_l2_vnicc_get_timeout(struct qeth_card
*card
, u32
*timeout
)
1824 QETH_CARD_TEXT(card
, 2, "vniccgto");
1826 /* do not get anything if BridgePort is enabled */
1827 if (qeth_bridgeport_is_in_use(card
))
1830 /* check if characteristic and get_timeout are supported */
1831 if (!(card
->options
.vnicc
.sup_chars
& QETH_VNICC_LEARNING
) ||
1832 !(card
->options
.vnicc
.getset_timeout_sup
& QETH_VNICC_LEARNING
))
1834 /* if card is ready, get timeout. Otherwise, just return stored value */
1835 *timeout
= card
->options
.vnicc
.learning_timeout
;
1836 if (qeth_card_hw_is_reachable(card
))
1837 rc
= qeth_l2_vnicc_getset_timeout(card
, QETH_VNICC_LEARNING
,
1838 IPA_VNICC_GET_TIMEOUT
,
1844 /* check if VNICC is currently enabled */
1845 bool qeth_l2_vnicc_is_in_use(struct qeth_card
*card
)
1847 if (!card
->options
.vnicc
.sup_chars
)
1849 /* default values are only OK if rx_bcast was not enabled by user
1850 * or the card is offline.
1852 if (card
->options
.vnicc
.cur_chars
== QETH_VNICC_DEFAULT
) {
1853 if (!card
->options
.vnicc
.rx_bcast_enabled
||
1854 !qeth_card_hw_is_reachable(card
))
1860 /* recover user timeout setting */
1861 static bool qeth_l2_vnicc_recover_timeout(struct qeth_card
*card
, u32 vnicc
,
1864 if (card
->options
.vnicc
.sup_chars
& vnicc
&&
1865 card
->options
.vnicc
.getset_timeout_sup
& vnicc
&&
1866 !qeth_l2_vnicc_getset_timeout(card
, vnicc
, IPA_VNICC_SET_TIMEOUT
,
1869 *timeout
= QETH_VNICC_DEFAULT_TIMEOUT
;
1873 /* recover user characteristic setting */
1874 static bool qeth_l2_vnicc_recover_char(struct qeth_card
*card
, u32 vnicc
,
1877 u32 cmd
= enable
? IPA_VNICC_ENABLE
: IPA_VNICC_DISABLE
;
1879 if (card
->options
.vnicc
.sup_chars
& vnicc
&&
1880 card
->options
.vnicc
.set_char_sup
& vnicc
&&
1881 !qeth_l2_vnicc_set_char(card
, vnicc
, cmd
))
1883 card
->options
.vnicc
.wanted_chars
&= ~vnicc
;
1884 card
->options
.vnicc
.wanted_chars
|= QETH_VNICC_DEFAULT
& vnicc
;
1888 /* (re-)initialize VNICC */
1889 static void qeth_l2_vnicc_init(struct qeth_card
*card
)
1891 u32
*timeout
= &card
->options
.vnicc
.learning_timeout
;
1892 bool enable
, error
= false;
1893 unsigned int chars_len
, i
;
1894 unsigned long chars_tmp
;
1895 u32 sup_cmds
, vnicc
;
1897 QETH_CARD_TEXT(card
, 2, "vniccini");
1898 /* reset rx_bcast */
1899 card
->options
.vnicc
.rx_bcast_enabled
= 0;
1900 /* initial query and storage of VNIC characteristics */
1901 if (qeth_l2_vnicc_query_chars(card
)) {
1902 if (card
->options
.vnicc
.wanted_chars
!= QETH_VNICC_DEFAULT
||
1903 *timeout
!= QETH_VNICC_DEFAULT_TIMEOUT
)
1904 dev_err(&card
->gdev
->dev
, "Configuring the VNIC characteristics failed\n");
1905 /* fail quietly if user didn't change the default config */
1906 card
->options
.vnicc
.sup_chars
= 0;
1907 card
->options
.vnicc
.cur_chars
= 0;
1908 card
->options
.vnicc
.wanted_chars
= QETH_VNICC_DEFAULT
;
1911 /* get supported commands for each supported characteristic */
1912 chars_tmp
= card
->options
.vnicc
.sup_chars
;
1913 chars_len
= sizeof(card
->options
.vnicc
.sup_chars
) * BITS_PER_BYTE
;
1914 for_each_set_bit(i
, &chars_tmp
, chars_len
) {
1916 if (qeth_l2_vnicc_query_cmds(card
, vnicc
, &sup_cmds
)) {
1920 if ((sup_cmds
& IPA_VNICC_SET_TIMEOUT
) &&
1921 (sup_cmds
& IPA_VNICC_GET_TIMEOUT
))
1922 card
->options
.vnicc
.getset_timeout_sup
|= vnicc
;
1924 card
->options
.vnicc
.getset_timeout_sup
&= ~vnicc
;
1925 if ((sup_cmds
& IPA_VNICC_ENABLE
) &&
1926 (sup_cmds
& IPA_VNICC_DISABLE
))
1927 card
->options
.vnicc
.set_char_sup
|= vnicc
;
1929 card
->options
.vnicc
.set_char_sup
&= ~vnicc
;
1931 /* enforce assumed default values and recover settings, if changed */
1932 error
|= qeth_l2_vnicc_recover_timeout(card
, QETH_VNICC_LEARNING
,
1934 /* Change chars, if necessary */
1935 chars_tmp
= card
->options
.vnicc
.wanted_chars
^
1936 card
->options
.vnicc
.cur_chars
;
1937 chars_len
= sizeof(card
->options
.vnicc
.wanted_chars
) * BITS_PER_BYTE
;
1938 for_each_set_bit(i
, &chars_tmp
, chars_len
) {
1940 enable
= card
->options
.vnicc
.wanted_chars
& vnicc
;
1941 error
|= qeth_l2_vnicc_recover_char(card
, vnicc
, enable
);
1944 dev_err(&card
->gdev
->dev
, "Configuring the VNIC characteristics failed\n");
1947 /* configure default values of VNIC characteristics */
1948 static void qeth_l2_vnicc_set_defaults(struct qeth_card
*card
)
1950 /* characteristics values */
1951 card
->options
.vnicc
.sup_chars
= QETH_VNICC_ALL
;
1952 card
->options
.vnicc
.cur_chars
= QETH_VNICC_DEFAULT
;
1953 card
->options
.vnicc
.learning_timeout
= QETH_VNICC_DEFAULT_TIMEOUT
;
1954 /* supported commands */
1955 card
->options
.vnicc
.set_char_sup
= QETH_VNICC_ALL
;
1956 card
->options
.vnicc
.getset_timeout_sup
= QETH_VNICC_LEARNING
;
1957 /* settings wanted by users */
1958 card
->options
.vnicc
.wanted_chars
= QETH_VNICC_DEFAULT
;
1961 module_init(qeth_l2_init
);
1962 module_exit(qeth_l2_exit
);
1963 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1964 MODULE_DESCRIPTION("qeth layer 2 discipline");
1965 MODULE_LICENSE("GPL");