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 int qeth_l2_set_offline(struct ccwgroup_device
*);
28 static void qeth_bridgeport_query_support(struct qeth_card
*card
);
29 static void qeth_bridge_state_change(struct qeth_card
*card
,
30 struct qeth_ipa_cmd
*cmd
);
31 static void qeth_bridge_host_event(struct qeth_card
*card
,
32 struct qeth_ipa_cmd
*cmd
);
33 static void qeth_l2_vnicc_set_defaults(struct qeth_card
*card
);
34 static void qeth_l2_vnicc_init(struct qeth_card
*card
);
35 static bool qeth_l2_vnicc_recover_timeout(struct qeth_card
*card
, u32 vnicc
,
38 static int qeth_l2_setdelmac_makerc(struct qeth_card
*card
, u16 retcode
)
43 QETH_CARD_TEXT_(card
, 2, "err%04x", retcode
);
48 case IPA_RC_L2_UNSUPPORTED_CMD
:
51 case IPA_RC_L2_ADDR_TABLE_FULL
:
54 case IPA_RC_L2_DUP_MAC
:
55 case IPA_RC_L2_DUP_LAYER3_MAC
:
58 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP
:
59 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP
:
62 case IPA_RC_L2_MAC_NOT_FOUND
:
72 static int qeth_l2_send_setdelmac_cb(struct qeth_card
*card
,
73 struct qeth_reply
*reply
,
76 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
78 return qeth_l2_setdelmac_makerc(card
, cmd
->hdr
.return_code
);
81 static int qeth_l2_send_setdelmac(struct qeth_card
*card
, __u8
*mac
,
82 enum qeth_ipa_cmds ipacmd
)
84 struct qeth_ipa_cmd
*cmd
;
85 struct qeth_cmd_buffer
*iob
;
87 QETH_CARD_TEXT(card
, 2, "L2sdmac");
88 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, QETH_PROT_IPV4
);
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_del_all_macs(struct qeth_card
*card
)
154 struct qeth_mac
*mac
;
155 struct hlist_node
*tmp
;
158 spin_lock_bh(&card
->mclock
);
159 hash_for_each_safe(card
->mac_htable
, i
, tmp
, mac
, hnode
) {
160 hash_del(&mac
->hnode
);
163 spin_unlock_bh(&card
->mclock
);
166 static int qeth_l2_get_cast_type(struct qeth_card
*card
, struct sk_buff
*skb
)
168 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
170 if (is_broadcast_ether_addr(skb
->data
))
171 return RTN_BROADCAST
;
172 if (is_multicast_ether_addr(skb
->data
))
173 return RTN_MULTICAST
;
177 static void qeth_l2_fill_header(struct qeth_qdio_out_q
*queue
,
178 struct qeth_hdr
*hdr
, struct sk_buff
*skb
,
179 int ipv
, int cast_type
, unsigned int data_len
)
181 struct vlan_ethhdr
*veth
= vlan_eth_hdr(skb
);
183 hdr
->hdr
.l2
.pkt_length
= data_len
;
185 if (skb_is_gso(skb
)) {
186 hdr
->hdr
.l2
.id
= QETH_HEADER_TYPE_L2_TSO
;
188 hdr
->hdr
.l2
.id
= QETH_HEADER_TYPE_LAYER2
;
189 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
190 qeth_tx_csum(skb
, &hdr
->hdr
.l2
.flags
[1], ipv
);
191 QETH_TXQ_STAT_INC(queue
, skbs_csum
);
195 /* set byte byte 3 to casting flags */
196 if (cast_type
== RTN_MULTICAST
)
197 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_MULTICAST
;
198 else if (cast_type
== RTN_BROADCAST
)
199 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_BROADCAST
;
201 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_UNICAST
;
203 /* VSWITCH relies on the VLAN
204 * information to be present in
206 if (veth
->h_vlan_proto
== __constant_htons(ETH_P_8021Q
)) {
207 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_VLAN
;
208 hdr
->hdr
.l2
.vlan_id
= ntohs(veth
->h_vlan_TCI
);
212 static int qeth_l2_setdelvlan_makerc(struct qeth_card
*card
, u16 retcode
)
215 QETH_CARD_TEXT_(card
, 2, "err%04x", retcode
);
220 case IPA_RC_L2_INVALID_VLAN_ID
:
222 case IPA_RC_L2_DUP_VLAN_ID
:
224 case IPA_RC_L2_VLAN_ID_NOT_FOUND
:
226 case IPA_RC_L2_VLAN_ID_NOT_ALLOWED
:
233 static int qeth_l2_send_setdelvlan_cb(struct qeth_card
*card
,
234 struct qeth_reply
*reply
,
237 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
239 QETH_CARD_TEXT(card
, 2, "L2sdvcb");
240 if (cmd
->hdr
.return_code
) {
241 QETH_DBF_MESSAGE(2, "Error in processing VLAN %u on device %x: %#x.\n",
242 cmd
->data
.setdelvlan
.vlan_id
,
243 CARD_DEVID(card
), cmd
->hdr
.return_code
);
244 QETH_CARD_TEXT_(card
, 2, "L2VL%4x", cmd
->hdr
.command
);
246 return qeth_l2_setdelvlan_makerc(card
, cmd
->hdr
.return_code
);
249 static int qeth_l2_send_setdelvlan(struct qeth_card
*card
, __u16 i
,
250 enum qeth_ipa_cmds ipacmd
)
252 struct qeth_ipa_cmd
*cmd
;
253 struct qeth_cmd_buffer
*iob
;
255 QETH_CARD_TEXT_(card
, 4, "L2sdv%x", ipacmd
);
256 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, QETH_PROT_IPV4
);
259 cmd
= __ipa_cmd(iob
);
260 cmd
->data
.setdelvlan
.vlan_id
= i
;
261 return qeth_send_ipa_cmd(card
, iob
, qeth_l2_send_setdelvlan_cb
, NULL
);
264 static int qeth_l2_vlan_rx_add_vid(struct net_device
*dev
,
265 __be16 proto
, u16 vid
)
267 struct qeth_card
*card
= dev
->ml_priv
;
269 QETH_CARD_TEXT_(card
, 4, "aid:%d", vid
);
273 return qeth_l2_send_setdelvlan(card
, vid
, IPA_CMD_SETVLAN
);
276 static int qeth_l2_vlan_rx_kill_vid(struct net_device
*dev
,
277 __be16 proto
, u16 vid
)
279 struct qeth_card
*card
= dev
->ml_priv
;
281 QETH_CARD_TEXT_(card
, 4, "kid:%d", vid
);
285 return qeth_l2_send_setdelvlan(card
, vid
, IPA_CMD_DELVLAN
);
288 static void qeth_l2_stop_card(struct qeth_card
*card
)
290 QETH_DBF_TEXT(SETUP
, 2, "stopcard");
291 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
293 qeth_set_allowed_threads(card
, 0, 1);
295 if (card
->state
== CARD_STATE_SOFTSETUP
) {
296 qeth_l2_del_all_macs(card
);
297 qeth_clear_ipacmd_list(card
);
298 card
->state
= CARD_STATE_HARDSETUP
;
300 if (card
->state
== CARD_STATE_HARDSETUP
) {
301 qeth_qdio_clear_card(card
, 0);
302 qeth_clear_qdio_buffers(card
);
303 qeth_clear_working_pool_list(card
);
304 card
->state
= CARD_STATE_DOWN
;
306 if (card
->state
== CARD_STATE_DOWN
) {
307 qeth_clear_cmd_buffers(&card
->read
);
308 qeth_clear_cmd_buffers(&card
->write
);
311 flush_workqueue(card
->event_wq
);
312 card
->info
.mac_bits
&= ~QETH_LAYER2_MAC_REGISTERED
;
315 static int qeth_l2_process_inbound_buffer(struct qeth_card
*card
,
316 int budget
, int *done
)
320 struct qeth_hdr
*hdr
;
324 WARN_ON_ONCE(!budget
);
326 skb
= qeth_core_get_next_skb(card
,
327 &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
],
328 &card
->rx
.b_element
, &card
->rx
.e_offset
, &hdr
);
333 switch (hdr
->hdr
.l2
.id
) {
334 case QETH_HEADER_TYPE_LAYER2
:
335 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
336 qeth_rx_csum(card
, skb
, hdr
->hdr
.l2
.flags
[1]);
337 if (skb
->protocol
== htons(ETH_P_802_2
))
338 *((__u32
*)skb
->cb
) = ++card
->seqno
.pkt_seqno
;
340 napi_gro_receive(&card
->napi
, skb
);
342 case QETH_HEADER_TYPE_OSN
:
343 if (card
->info
.type
== QETH_CARD_TYPE_OSN
) {
344 skb_push(skb
, sizeof(struct qeth_hdr
));
345 skb_copy_to_linear_data(skb
, hdr
,
346 sizeof(struct qeth_hdr
));
348 card
->osn_info
.data_cb(skb
);
353 dev_kfree_skb_any(skb
);
354 QETH_CARD_TEXT(card
, 3, "inbunkno");
355 QETH_DBF_HEX(CTRL
, 3, hdr
, sizeof(*hdr
));
360 QETH_CARD_STAT_INC(card
, rx_packets
);
361 QETH_CARD_STAT_ADD(card
, rx_bytes
, len
);
366 static int qeth_l2_request_initial_mac(struct qeth_card
*card
)
370 QETH_DBF_TEXT(SETUP
, 2, "l2reqmac");
371 QETH_DBF_TEXT_(SETUP
, 2, "doL2%s", CARD_BUS_ID(card
));
374 rc
= qeth_vm_request_mac(card
);
377 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %x: %#x\n",
378 CARD_DEVID(card
), rc
);
379 QETH_DBF_TEXT_(SETUP
, 2, "err%04x", rc
);
380 /* fall back to alternative mechanism: */
384 rc
= qeth_setadpparms_change_macaddr(card
);
387 QETH_DBF_MESSAGE(2, "READ_MAC Assist failed on device %x: %#x\n",
388 CARD_DEVID(card
), rc
);
389 QETH_DBF_TEXT_(SETUP
, 2, "1err%04x", rc
);
390 /* fall back once more: */
393 /* some devices don't support a custom MAC address: */
394 if (card
->info
.type
== QETH_CARD_TYPE_OSM
||
395 card
->info
.type
== QETH_CARD_TYPE_OSX
)
396 return (rc
) ? rc
: -EADDRNOTAVAIL
;
397 eth_hw_addr_random(card
->dev
);
400 QETH_DBF_HEX(SETUP
, 2, card
->dev
->dev_addr
, card
->dev
->addr_len
);
404 static void qeth_l2_register_dev_addr(struct qeth_card
*card
)
406 if (!is_valid_ether_addr(card
->dev
->dev_addr
))
407 qeth_l2_request_initial_mac(card
);
409 if (!IS_OSN(card
) && !qeth_l2_send_setmac(card
, card
->dev
->dev_addr
))
410 card
->info
.mac_bits
|= QETH_LAYER2_MAC_REGISTERED
;
413 static int qeth_l2_validate_addr(struct net_device
*dev
)
415 struct qeth_card
*card
= dev
->ml_priv
;
417 if (card
->info
.mac_bits
& QETH_LAYER2_MAC_REGISTERED
)
418 return eth_validate_addr(dev
);
420 QETH_CARD_TEXT(card
, 4, "nomacadr");
424 static int qeth_l2_set_mac_address(struct net_device
*dev
, void *p
)
426 struct sockaddr
*addr
= p
;
427 struct qeth_card
*card
= dev
->ml_priv
;
428 u8 old_addr
[ETH_ALEN
];
431 QETH_CARD_TEXT(card
, 3, "setmac");
433 if (IS_OSM(card
) || IS_OSX(card
)) {
434 QETH_CARD_TEXT(card
, 3, "setmcTYP");
437 QETH_CARD_HEX(card
, 3, addr
->sa_data
, ETH_ALEN
);
438 if (!is_valid_ether_addr(addr
->sa_data
))
439 return -EADDRNOTAVAIL
;
441 /* don't register the same address twice */
442 if (ether_addr_equal_64bits(dev
->dev_addr
, addr
->sa_data
) &&
443 (card
->info
.mac_bits
& QETH_LAYER2_MAC_REGISTERED
))
446 /* add the new address, switch over, drop the old */
447 rc
= qeth_l2_send_setmac(card
, addr
->sa_data
);
450 ether_addr_copy(old_addr
, dev
->dev_addr
);
451 ether_addr_copy(dev
->dev_addr
, addr
->sa_data
);
453 if (card
->info
.mac_bits
& QETH_LAYER2_MAC_REGISTERED
)
454 qeth_l2_remove_mac(card
, old_addr
);
455 card
->info
.mac_bits
|= QETH_LAYER2_MAC_REGISTERED
;
459 static void qeth_promisc_to_bridge(struct qeth_card
*card
)
461 struct net_device
*dev
= card
->dev
;
462 enum qeth_ipa_promisc_modes promisc_mode
;
466 QETH_CARD_TEXT(card
, 3, "pmisc2br");
468 if (!card
->options
.sbp
.reflect_promisc
)
470 promisc_mode
= (dev
->flags
& IFF_PROMISC
) ? SET_PROMISC_MODE_ON
471 : SET_PROMISC_MODE_OFF
;
472 if (promisc_mode
== card
->info
.promisc_mode
)
475 if (promisc_mode
== SET_PROMISC_MODE_ON
) {
476 if (card
->options
.sbp
.reflect_promisc_primary
)
477 role
= QETH_SBP_ROLE_PRIMARY
;
479 role
= QETH_SBP_ROLE_SECONDARY
;
481 role
= QETH_SBP_ROLE_NONE
;
483 rc
= qeth_bridgeport_setrole(card
, role
);
484 QETH_DBF_TEXT_(SETUP
, 2, "bpm%c%04x",
485 (promisc_mode
== SET_PROMISC_MODE_ON
) ? '+' : '-', rc
);
487 card
->options
.sbp
.role
= role
;
488 card
->info
.promisc_mode
= promisc_mode
;
492 /* New MAC address is added to the hash table and marked to be written on card
493 * only if there is not in the hash table storage already
496 static void qeth_l2_add_mac(struct qeth_card
*card
, struct netdev_hw_addr
*ha
)
498 u32 mac_hash
= get_unaligned((u32
*)(&ha
->addr
[2]));
499 struct qeth_mac
*mac
;
501 hash_for_each_possible(card
->mac_htable
, mac
, hnode
, mac_hash
) {
502 if (ether_addr_equal_64bits(ha
->addr
, mac
->mac_addr
)) {
503 mac
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
508 mac
= kzalloc(sizeof(struct qeth_mac
), GFP_ATOMIC
);
512 ether_addr_copy(mac
->mac_addr
, ha
->addr
);
513 mac
->disp_flag
= QETH_DISP_ADDR_ADD
;
515 hash_add(card
->mac_htable
, &mac
->hnode
, mac_hash
);
518 static void qeth_l2_set_rx_mode(struct net_device
*dev
)
520 struct qeth_card
*card
= dev
->ml_priv
;
521 struct netdev_hw_addr
*ha
;
522 struct qeth_mac
*mac
;
523 struct hlist_node
*tmp
;
527 QETH_CARD_TEXT(card
, 3, "setmulti");
529 spin_lock_bh(&card
->mclock
);
531 netdev_for_each_mc_addr(ha
, dev
)
532 qeth_l2_add_mac(card
, ha
);
533 netdev_for_each_uc_addr(ha
, dev
)
534 qeth_l2_add_mac(card
, ha
);
536 hash_for_each_safe(card
->mac_htable
, i
, tmp
, mac
, hnode
) {
537 switch (mac
->disp_flag
) {
538 case QETH_DISP_ADDR_DELETE
:
539 qeth_l2_remove_mac(card
, mac
->mac_addr
);
540 hash_del(&mac
->hnode
);
543 case QETH_DISP_ADDR_ADD
:
544 rc
= qeth_l2_write_mac(card
, mac
->mac_addr
);
546 hash_del(&mac
->hnode
);
552 /* for next call to set_rx_mode(): */
553 mac
->disp_flag
= QETH_DISP_ADDR_DELETE
;
557 spin_unlock_bh(&card
->mclock
);
559 if (qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
560 qeth_setadp_promisc_mode(card
);
562 qeth_promisc_to_bridge(card
);
565 static int qeth_l2_xmit_osn(struct qeth_card
*card
, struct sk_buff
*skb
,
566 struct qeth_qdio_out_q
*queue
)
568 struct qeth_hdr
*hdr
= (struct qeth_hdr
*)skb
->data
;
569 addr_t end
= (addr_t
)(skb
->data
+ sizeof(*hdr
));
570 addr_t start
= (addr_t
)skb
->data
;
571 unsigned int elements
= 0;
572 unsigned int hd_len
= 0;
575 if (skb
->protocol
== htons(ETH_P_IPV6
))
576 return -EPROTONOSUPPORT
;
578 if (qeth_get_elements_for_range(start
, end
) > 1) {
579 /* Misaligned HW header, move it to its own buffer element. */
580 hdr
= kmem_cache_alloc(qeth_core_header_cache
, GFP_ATOMIC
);
583 hd_len
= sizeof(*hdr
);
584 skb_copy_from_linear_data(skb
, (char *)hdr
, hd_len
);
588 elements
+= qeth_count_elements(skb
, hd_len
);
589 if (elements
> QETH_MAX_BUFFER_ELEMENTS(card
)) {
594 rc
= qeth_do_send_packet(card
, queue
, skb
, hdr
, hd_len
, hd_len
,
598 kmem_cache_free(qeth_core_header_cache
, hdr
);
602 static netdev_tx_t
qeth_l2_hard_start_xmit(struct sk_buff
*skb
,
603 struct net_device
*dev
)
605 struct qeth_card
*card
= dev
->ml_priv
;
606 int cast_type
= qeth_l2_get_cast_type(card
, skb
);
607 int ipv
= qeth_get_ip_version(skb
);
608 struct qeth_qdio_out_q
*queue
;
609 int tx_bytes
= skb
->len
;
612 queue
= qeth_get_tx_queue(card
, skb
, ipv
, cast_type
);
614 netif_stop_queue(dev
);
617 rc
= qeth_l2_xmit_osn(card
, skb
, queue
);
619 rc
= qeth_xmit(card
, skb
, queue
, ipv
, cast_type
,
620 qeth_l2_fill_header
);
623 QETH_TXQ_STAT_INC(queue
, tx_packets
);
624 QETH_TXQ_STAT_ADD(queue
, tx_bytes
, tx_bytes
);
625 netif_wake_queue(dev
);
627 } else if (rc
== -EBUSY
) {
628 return NETDEV_TX_BUSY
;
629 } /* else fall through */
631 QETH_TXQ_STAT_INC(queue
, tx_dropped
);
633 netif_wake_queue(dev
);
637 static const struct device_type qeth_l2_devtype
= {
638 .name
= "qeth_layer2",
639 .groups
= qeth_l2_attr_groups
,
642 static int qeth_l2_probe_device(struct ccwgroup_device
*gdev
)
644 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
647 qeth_l2_vnicc_set_defaults(card
);
649 if (gdev
->dev
.type
== &qeth_generic_devtype
) {
650 rc
= qeth_l2_create_device_attributes(&gdev
->dev
);
655 hash_init(card
->mac_htable
);
659 static void qeth_l2_remove_device(struct ccwgroup_device
*cgdev
)
661 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
663 if (cgdev
->dev
.type
== &qeth_generic_devtype
)
664 qeth_l2_remove_device_attributes(&cgdev
->dev
);
665 qeth_set_allowed_threads(card
, 0, 1);
666 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
668 if (cgdev
->state
== CCWGROUP_ONLINE
)
669 qeth_l2_set_offline(cgdev
);
671 cancel_work_sync(&card
->close_dev_work
);
672 if (qeth_netdev_is_registered(card
->dev
))
673 unregister_netdev(card
->dev
);
676 static const struct net_device_ops qeth_l2_netdev_ops
= {
677 .ndo_open
= qeth_open
,
678 .ndo_stop
= qeth_stop
,
679 .ndo_get_stats64
= qeth_get_stats64
,
680 .ndo_start_xmit
= qeth_l2_hard_start_xmit
,
681 .ndo_features_check
= qeth_features_check
,
682 .ndo_validate_addr
= qeth_l2_validate_addr
,
683 .ndo_set_rx_mode
= qeth_l2_set_rx_mode
,
684 .ndo_do_ioctl
= qeth_do_ioctl
,
685 .ndo_set_mac_address
= qeth_l2_set_mac_address
,
686 .ndo_vlan_rx_add_vid
= qeth_l2_vlan_rx_add_vid
,
687 .ndo_vlan_rx_kill_vid
= qeth_l2_vlan_rx_kill_vid
,
688 .ndo_tx_timeout
= qeth_tx_timeout
,
689 .ndo_fix_features
= qeth_fix_features
,
690 .ndo_set_features
= qeth_set_features
693 static const struct net_device_ops qeth_osn_netdev_ops
= {
694 .ndo_open
= qeth_open
,
695 .ndo_stop
= qeth_stop
,
696 .ndo_get_stats64
= qeth_get_stats64
,
697 .ndo_start_xmit
= qeth_l2_hard_start_xmit
,
698 .ndo_validate_addr
= eth_validate_addr
,
699 .ndo_tx_timeout
= qeth_tx_timeout
,
702 static int qeth_l2_setup_netdev(struct qeth_card
*card
, bool carrier_ok
)
707 card
->dev
->netdev_ops
= &qeth_osn_netdev_ops
;
708 card
->dev
->flags
|= IFF_NOARP
;
712 card
->dev
->needed_headroom
= sizeof(struct qeth_hdr
);
713 card
->dev
->netdev_ops
= &qeth_l2_netdev_ops
;
714 card
->dev
->priv_flags
|= IFF_UNICAST_FLT
;
717 card
->dev
->features
|= NETIF_F_VLAN_CHALLENGED
;
719 if (!IS_VM_NIC(card
))
720 card
->dev
->hw_features
|= NETIF_F_HW_VLAN_CTAG_FILTER
;
721 card
->dev
->features
|= NETIF_F_HW_VLAN_CTAG_FILTER
;
724 if (card
->info
.type
== QETH_CARD_TYPE_OSD
&& !card
->info
.guestlan
) {
725 card
->dev
->features
|= NETIF_F_SG
;
726 /* OSA 3S and earlier has no RX/TX support */
727 if (qeth_is_supported(card
, IPA_OUTBOUND_CHECKSUM
)) {
728 card
->dev
->hw_features
|= NETIF_F_IP_CSUM
;
729 card
->dev
->vlan_features
|= NETIF_F_IP_CSUM
;
732 if (qeth_is_supported6(card
, IPA_OUTBOUND_CHECKSUM_V6
)) {
733 card
->dev
->hw_features
|= NETIF_F_IPV6_CSUM
;
734 card
->dev
->vlan_features
|= NETIF_F_IPV6_CSUM
;
736 if (qeth_is_supported(card
, IPA_INBOUND_CHECKSUM
) ||
737 qeth_is_supported6(card
, IPA_INBOUND_CHECKSUM_V6
)) {
738 card
->dev
->hw_features
|= NETIF_F_RXCSUM
;
739 card
->dev
->vlan_features
|= NETIF_F_RXCSUM
;
741 if (qeth_is_supported(card
, IPA_OUTBOUND_TSO
)) {
742 card
->dev
->hw_features
|= NETIF_F_TSO
;
743 card
->dev
->vlan_features
|= NETIF_F_TSO
;
745 if (qeth_is_supported6(card
, IPA_OUTBOUND_TSO
)) {
746 card
->dev
->hw_features
|= NETIF_F_TSO6
;
747 card
->dev
->vlan_features
|= NETIF_F_TSO6
;
750 if (card
->dev
->hw_features
& (NETIF_F_TSO
| NETIF_F_TSO6
)) {
751 card
->dev
->needed_headroom
= sizeof(struct qeth_hdr_tso
);
752 netif_set_gso_max_size(card
->dev
,
753 PAGE_SIZE
* (QDIO_MAX_ELEMENTS_PER_BUFFER
- 1));
757 netif_napi_add(card
->dev
, &card
->napi
, qeth_poll
, QETH_NAPI_WEIGHT
);
758 rc
= register_netdev(card
->dev
);
759 if (!rc
&& carrier_ok
)
760 netif_carrier_on(card
->dev
);
763 card
->dev
->netdev_ops
= NULL
;
767 static int qeth_l2_start_ipassists(struct qeth_card
*card
)
769 /* configure isolation level */
770 if (qeth_set_access_ctrl_online(card
, 0))
775 static void qeth_l2_trace_features(struct qeth_card
*card
)
777 /* Set BridgePort features */
778 QETH_CARD_TEXT(card
, 2, "featuSBP");
779 QETH_CARD_HEX(card
, 2, &card
->options
.sbp
.supported_funcs
,
780 sizeof(card
->options
.sbp
.supported_funcs
));
781 /* VNIC Characteristics features */
782 QETH_CARD_TEXT(card
, 2, "feaVNICC");
783 QETH_CARD_HEX(card
, 2, &card
->options
.vnicc
.sup_chars
,
784 sizeof(card
->options
.vnicc
.sup_chars
));
787 static int qeth_l2_set_online(struct ccwgroup_device
*gdev
)
789 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
790 struct net_device
*dev
= card
->dev
;
794 mutex_lock(&card
->discipline_mutex
);
795 mutex_lock(&card
->conf_mutex
);
796 QETH_DBF_TEXT(SETUP
, 2, "setonlin");
797 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
799 rc
= qeth_core_hardsetup_card(card
, &carrier_ok
);
801 QETH_DBF_TEXT_(SETUP
, 2, "2err%04x", rc
);
806 if (qeth_is_diagass_supported(card
, QETH_DIAGS_CMD_TRAP
)) {
807 if (card
->info
.hwtrap
&&
808 qeth_hw_trap(card
, QETH_DIAGS_TRAP_ARM
))
809 card
->info
.hwtrap
= 0;
811 card
->info
.hwtrap
= 0;
813 qeth_bridgeport_query_support(card
);
814 if (card
->options
.sbp
.supported_funcs
)
815 dev_info(&card
->gdev
->dev
,
816 "The device represents a Bridge Capable Port\n");
818 qeth_l2_register_dev_addr(card
);
820 /* for the rx_bcast characteristic, init VNICC after setmac */
821 qeth_l2_vnicc_init(card
);
823 qeth_trace_features(card
);
824 qeth_l2_trace_features(card
);
826 qeth_l2_setup_bridgeport_attrs(card
);
828 card
->state
= CARD_STATE_HARDSETUP
;
829 qeth_print_status_message(card
);
832 QETH_DBF_TEXT(SETUP
, 2, "softsetp");
834 if ((card
->info
.type
== QETH_CARD_TYPE_OSD
) ||
835 (card
->info
.type
== QETH_CARD_TYPE_OSX
)) {
836 rc
= qeth_l2_start_ipassists(card
);
841 rc
= qeth_init_qdio_queues(card
);
843 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
847 card
->state
= CARD_STATE_SOFTSETUP
;
849 qeth_set_allowed_threads(card
, 0xffffffff, 0);
851 if (!qeth_netdev_is_registered(dev
)) {
852 rc
= qeth_l2_setup_netdev(card
, carrier_ok
);
858 netif_carrier_on(dev
);
860 netif_carrier_off(dev
);
862 netif_device_attach(dev
);
863 qeth_enable_hw_features(dev
);
865 if (card
->info
.open_when_online
) {
866 card
->info
.open_when_online
= 0;
871 /* let user_space know that device is online */
872 kobject_uevent(&gdev
->dev
.kobj
, KOBJ_CHANGE
);
873 mutex_unlock(&card
->conf_mutex
);
874 mutex_unlock(&card
->discipline_mutex
);
878 qeth_l2_stop_card(card
);
879 ccw_device_set_offline(CARD_DDEV(card
));
880 ccw_device_set_offline(CARD_WDEV(card
));
881 ccw_device_set_offline(CARD_RDEV(card
));
882 qdio_free(CARD_DDEV(card
));
883 card
->state
= CARD_STATE_DOWN
;
885 mutex_unlock(&card
->conf_mutex
);
886 mutex_unlock(&card
->discipline_mutex
);
890 static int __qeth_l2_set_offline(struct ccwgroup_device
*cgdev
,
893 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
894 int rc
= 0, rc2
= 0, rc3
= 0;
896 mutex_lock(&card
->discipline_mutex
);
897 mutex_lock(&card
->conf_mutex
);
898 QETH_DBF_TEXT(SETUP
, 3, "setoffl");
899 QETH_DBF_HEX(SETUP
, 3, &card
, sizeof(void *));
901 if ((!recovery_mode
&& card
->info
.hwtrap
) || card
->info
.hwtrap
== 2) {
902 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
903 card
->info
.hwtrap
= 1;
907 card
->info
.open_when_online
= card
->dev
->flags
& IFF_UP
;
908 dev_close(card
->dev
);
909 netif_device_detach(card
->dev
);
910 netif_carrier_off(card
->dev
);
913 qeth_l2_stop_card(card
);
914 rc
= ccw_device_set_offline(CARD_DDEV(card
));
915 rc2
= ccw_device_set_offline(CARD_WDEV(card
));
916 rc3
= ccw_device_set_offline(CARD_RDEV(card
));
918 rc
= (rc2
) ? rc2
: rc3
;
920 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
921 qdio_free(CARD_DDEV(card
));
923 /* let user_space know that device is offline */
924 kobject_uevent(&cgdev
->dev
.kobj
, KOBJ_CHANGE
);
925 mutex_unlock(&card
->conf_mutex
);
926 mutex_unlock(&card
->discipline_mutex
);
930 static int qeth_l2_set_offline(struct ccwgroup_device
*cgdev
)
932 return __qeth_l2_set_offline(cgdev
, 0);
935 static int qeth_l2_recover(void *ptr
)
937 struct qeth_card
*card
;
940 card
= (struct qeth_card
*) ptr
;
941 QETH_CARD_TEXT(card
, 2, "recover1");
942 if (!qeth_do_run_thread(card
, QETH_RECOVER_THREAD
))
944 QETH_CARD_TEXT(card
, 2, "recover2");
945 dev_warn(&card
->gdev
->dev
,
946 "A recovery process has been started for the device\n");
947 __qeth_l2_set_offline(card
->gdev
, 1);
948 rc
= qeth_l2_set_online(card
->gdev
);
950 dev_info(&card
->gdev
->dev
,
951 "Device successfully recovered!\n");
953 ccwgroup_set_offline(card
->gdev
);
954 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
955 "failed to recover an error on the device\n");
957 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
958 qeth_clear_thread_running_bit(card
, QETH_RECOVER_THREAD
);
962 static int __init
qeth_l2_init(void)
964 pr_info("register layer 2 discipline\n");
968 static void __exit
qeth_l2_exit(void)
970 pr_info("unregister layer 2 discipline\n");
973 static int qeth_l2_pm_suspend(struct ccwgroup_device
*gdev
)
975 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
977 qeth_set_allowed_threads(card
, 0, 1);
978 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
979 if (gdev
->state
== CCWGROUP_OFFLINE
)
982 qeth_l2_set_offline(gdev
);
986 static int qeth_l2_pm_resume(struct ccwgroup_device
*gdev
)
988 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
991 rc
= qeth_l2_set_online(gdev
);
993 qeth_set_allowed_threads(card
, 0xffffffff, 0);
995 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
996 "failed to recover an error on the device\n");
1000 /* Returns zero if the command is successfully "consumed" */
1001 static int qeth_l2_control_event(struct qeth_card
*card
,
1002 struct qeth_ipa_cmd
*cmd
)
1004 switch (cmd
->hdr
.command
) {
1005 case IPA_CMD_SETBRIDGEPORT_OSA
:
1006 case IPA_CMD_SETBRIDGEPORT_IQD
:
1007 if (cmd
->data
.sbp
.hdr
.command_code
==
1008 IPA_SBP_BRIDGE_PORT_STATE_CHANGE
) {
1009 qeth_bridge_state_change(card
, cmd
);
1013 case IPA_CMD_ADDRESS_CHANGE_NOTIF
:
1014 qeth_bridge_host_event(card
, cmd
);
1021 struct qeth_discipline qeth_l2_discipline
= {
1022 .devtype
= &qeth_l2_devtype
,
1023 .process_rx_buffer
= qeth_l2_process_inbound_buffer
,
1024 .recover
= qeth_l2_recover
,
1025 .setup
= qeth_l2_probe_device
,
1026 .remove
= qeth_l2_remove_device
,
1027 .set_online
= qeth_l2_set_online
,
1028 .set_offline
= qeth_l2_set_offline
,
1029 .freeze
= qeth_l2_pm_suspend
,
1030 .thaw
= qeth_l2_pm_resume
,
1031 .restore
= qeth_l2_pm_resume
,
1033 .control_event_handler
= qeth_l2_control_event
,
1035 EXPORT_SYMBOL_GPL(qeth_l2_discipline
);
1037 static int qeth_osn_send_control_data(struct qeth_card
*card
, int len
,
1038 struct qeth_cmd_buffer
*iob
)
1040 struct qeth_channel
*channel
= iob
->channel
;
1043 QETH_CARD_TEXT(card
, 5, "osndctrd");
1045 wait_event(card
->wait_q
,
1046 atomic_cmpxchg(&channel
->irq_pending
, 0, 1) == 0);
1047 qeth_prepare_control_data(card
, len
, iob
);
1048 QETH_CARD_TEXT(card
, 6, "osnoirqp");
1049 spin_lock_irq(get_ccwdev_lock(channel
->ccwdev
));
1050 rc
= ccw_device_start_timeout(channel
->ccwdev
, channel
->ccw
,
1051 (addr_t
) iob
, 0, 0, QETH_IPA_TIMEOUT
);
1052 spin_unlock_irq(get_ccwdev_lock(channel
->ccwdev
));
1054 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
1055 "ccw_device_start rc = %i\n", rc
);
1056 QETH_CARD_TEXT_(card
, 2, " err%d", rc
);
1057 qeth_release_buffer(channel
, iob
);
1058 atomic_set(&channel
->irq_pending
, 0);
1059 wake_up(&card
->wait_q
);
1064 static int qeth_osn_send_ipa_cmd(struct qeth_card
*card
,
1065 struct qeth_cmd_buffer
*iob
)
1069 QETH_CARD_TEXT(card
, 4, "osndipa");
1071 memcpy(&length
, QETH_IPA_PDU_LEN_TOTAL(iob
->data
), 2);
1072 return qeth_osn_send_control_data(card
, length
, iob
);
1075 int qeth_osn_assist(struct net_device
*dev
, void *data
, int data_len
)
1077 struct qeth_cmd_buffer
*iob
;
1078 struct qeth_card
*card
;
1082 card
= dev
->ml_priv
;
1085 QETH_CARD_TEXT(card
, 2, "osnsdmc");
1086 if (!qeth_card_hw_is_reachable(card
))
1088 iob
= qeth_wait_for_buffer(&card
->write
);
1089 qeth_prepare_ipa_cmd(card
, iob
, (u16
) data_len
);
1090 memcpy(__ipa_cmd(iob
), data
, data_len
);
1091 return qeth_osn_send_ipa_cmd(card
, iob
);
1093 EXPORT_SYMBOL(qeth_osn_assist
);
1095 int qeth_osn_register(unsigned char *read_dev_no
, struct net_device
**dev
,
1096 int (*assist_cb
)(struct net_device
*, void *),
1097 int (*data_cb
)(struct sk_buff
*))
1099 struct qeth_card
*card
;
1103 memcpy(&devno
, read_dev_no
, 2);
1104 sprintf(bus_id
, "0.0.%04x", devno
);
1105 card
= qeth_get_card_by_busid(bus_id
);
1106 if (!card
|| !IS_OSN(card
))
1110 QETH_CARD_TEXT(card
, 2, "osnreg");
1111 if ((assist_cb
== NULL
) || (data_cb
== NULL
))
1113 card
->osn_info
.assist_cb
= assist_cb
;
1114 card
->osn_info
.data_cb
= data_cb
;
1117 EXPORT_SYMBOL(qeth_osn_register
);
1119 void qeth_osn_deregister(struct net_device
*dev
)
1121 struct qeth_card
*card
;
1125 card
= dev
->ml_priv
;
1128 QETH_CARD_TEXT(card
, 2, "osndereg");
1129 card
->osn_info
.assist_cb
= NULL
;
1130 card
->osn_info
.data_cb
= NULL
;
1133 EXPORT_SYMBOL(qeth_osn_deregister
);
1135 /* SETBRIDGEPORT support, async notifications */
1137 enum qeth_an_event_type
{anev_reg_unreg
, anev_abort
, anev_reset
};
1140 * qeth_bridge_emit_host_event() - bridgeport address change notification
1141 * @card: qeth_card structure pointer, for udev events.
1142 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1143 * and reset token and addr_lnid are unused and may be NULL.
1144 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1145 * object, 0 - addition of an object.
1146 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1147 * @token: "network token" structure identifying physical address of the port.
1148 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1150 * This function is called when registrations and deregistrations are
1151 * reported by the hardware, and also when notifications are enabled -
1152 * for all currently registered addresses.
1154 static void qeth_bridge_emit_host_event(struct qeth_card
*card
,
1155 enum qeth_an_event_type evtype
,
1156 u8 code
, struct net_if_token
*token
, struct mac_addr_lnid
*addr_lnid
)
1163 case anev_reg_unreg
:
1164 snprintf(str
[i
], sizeof(str
[i
]), "BRIDGEDHOST=%s",
1165 (code
& IPA_ADDR_CHANGE_CODE_REMOVAL
)
1166 ? "deregister" : "register");
1167 env
[i
] = str
[i
]; i
++;
1168 if (code
& IPA_ADDR_CHANGE_CODE_VLANID
) {
1169 snprintf(str
[i
], sizeof(str
[i
]), "VLAN=%d",
1171 env
[i
] = str
[i
]; i
++;
1173 if (code
& IPA_ADDR_CHANGE_CODE_MACADDR
) {
1174 snprintf(str
[i
], sizeof(str
[i
]), "MAC=%pM",
1176 env
[i
] = str
[i
]; i
++;
1178 snprintf(str
[i
], sizeof(str
[i
]), "NTOK_BUSID=%x.%x.%04x",
1179 token
->cssid
, token
->ssid
, token
->devnum
);
1180 env
[i
] = str
[i
]; i
++;
1181 snprintf(str
[i
], sizeof(str
[i
]), "NTOK_IID=%02x", token
->iid
);
1182 env
[i
] = str
[i
]; i
++;
1183 snprintf(str
[i
], sizeof(str
[i
]), "NTOK_CHPID=%02x",
1185 env
[i
] = str
[i
]; i
++;
1186 snprintf(str
[i
], sizeof(str
[i
]), "NTOK_CHID=%04x", token
->chid
);
1187 env
[i
] = str
[i
]; i
++;
1190 snprintf(str
[i
], sizeof(str
[i
]), "BRIDGEDHOST=abort");
1191 env
[i
] = str
[i
]; i
++;
1194 snprintf(str
[i
], sizeof(str
[i
]), "BRIDGEDHOST=reset");
1195 env
[i
] = str
[i
]; i
++;
1199 kobject_uevent_env(&card
->gdev
->dev
.kobj
, KOBJ_CHANGE
, env
);
1202 struct qeth_bridge_state_data
{
1203 struct work_struct worker
;
1204 struct qeth_card
*card
;
1205 struct qeth_sbp_state_change qports
;
1208 static void qeth_bridge_state_change_worker(struct work_struct
*work
)
1210 struct qeth_bridge_state_data
*data
=
1211 container_of(work
, struct qeth_bridge_state_data
, worker
);
1212 /* We are only interested in the first entry - local port */
1213 struct qeth_sbp_port_entry
*entry
= &data
->qports
.entry
[0];
1214 char env_locrem
[32];
1224 /* Role should not change by itself, but if it did, */
1225 /* information from the hardware is authoritative. */
1226 mutex_lock(&data
->card
->conf_mutex
);
1227 data
->card
->options
.sbp
.role
= entry
->role
;
1228 mutex_unlock(&data
->card
->conf_mutex
);
1230 snprintf(env_locrem
, sizeof(env_locrem
), "BRIDGEPORT=statechange");
1231 snprintf(env_role
, sizeof(env_role
), "ROLE=%s",
1232 (entry
->role
== QETH_SBP_ROLE_NONE
) ? "none" :
1233 (entry
->role
== QETH_SBP_ROLE_PRIMARY
) ? "primary" :
1234 (entry
->role
== QETH_SBP_ROLE_SECONDARY
) ? "secondary" :
1236 snprintf(env_state
, sizeof(env_state
), "STATE=%s",
1237 (entry
->state
== QETH_SBP_STATE_INACTIVE
) ? "inactive" :
1238 (entry
->state
== QETH_SBP_STATE_STANDBY
) ? "standby" :
1239 (entry
->state
== QETH_SBP_STATE_ACTIVE
) ? "active" :
1241 kobject_uevent_env(&data
->card
->gdev
->dev
.kobj
,
1246 static void qeth_bridge_state_change(struct qeth_card
*card
,
1247 struct qeth_ipa_cmd
*cmd
)
1249 struct qeth_sbp_state_change
*qports
=
1250 &cmd
->data
.sbp
.data
.state_change
;
1251 struct qeth_bridge_state_data
*data
;
1254 QETH_CARD_TEXT(card
, 2, "brstchng");
1255 if (qports
->entry_length
!= sizeof(struct qeth_sbp_port_entry
)) {
1256 QETH_CARD_TEXT_(card
, 2, "BPsz%04x", qports
->entry_length
);
1259 extrasize
= sizeof(struct qeth_sbp_port_entry
) * qports
->num_entries
;
1260 data
= kzalloc(sizeof(struct qeth_bridge_state_data
) + extrasize
,
1263 QETH_CARD_TEXT(card
, 2, "BPSalloc");
1266 INIT_WORK(&data
->worker
, qeth_bridge_state_change_worker
);
1268 memcpy(&data
->qports
, qports
,
1269 sizeof(struct qeth_sbp_state_change
) + extrasize
);
1270 queue_work(card
->event_wq
, &data
->worker
);
1273 struct qeth_bridge_host_data
{
1274 struct work_struct worker
;
1275 struct qeth_card
*card
;
1276 struct qeth_ipacmd_addr_change hostevs
;
1279 static void qeth_bridge_host_event_worker(struct work_struct
*work
)
1281 struct qeth_bridge_host_data
*data
=
1282 container_of(work
, struct qeth_bridge_host_data
, worker
);
1285 if (data
->hostevs
.lost_event_mask
) {
1286 dev_info(&data
->card
->gdev
->dev
,
1287 "Address notification from the Bridge Port stopped %s (%s)\n",
1288 data
->card
->dev
->name
,
1289 (data
->hostevs
.lost_event_mask
== 0x01)
1291 : (data
->hostevs
.lost_event_mask
== 0x02)
1292 ? "Bridge port state change"
1293 : "Unknown reason");
1294 mutex_lock(&data
->card
->conf_mutex
);
1295 data
->card
->options
.sbp
.hostnotification
= 0;
1296 mutex_unlock(&data
->card
->conf_mutex
);
1297 qeth_bridge_emit_host_event(data
->card
, anev_abort
,
1300 for (i
= 0; i
< data
->hostevs
.num_entries
; i
++) {
1301 struct qeth_ipacmd_addr_change_entry
*entry
=
1302 &data
->hostevs
.entry
[i
];
1303 qeth_bridge_emit_host_event(data
->card
,
1306 &entry
->token
, &entry
->addr_lnid
);
1311 static void qeth_bridge_host_event(struct qeth_card
*card
,
1312 struct qeth_ipa_cmd
*cmd
)
1314 struct qeth_ipacmd_addr_change
*hostevs
=
1315 &cmd
->data
.addrchange
;
1316 struct qeth_bridge_host_data
*data
;
1319 QETH_CARD_TEXT(card
, 2, "brhostev");
1320 if (cmd
->hdr
.return_code
!= 0x0000) {
1321 if (cmd
->hdr
.return_code
== 0x0010) {
1322 if (hostevs
->lost_event_mask
== 0x00)
1323 hostevs
->lost_event_mask
= 0xff;
1325 QETH_CARD_TEXT_(card
, 2, "BPHe%04x",
1326 cmd
->hdr
.return_code
);
1330 extrasize
= sizeof(struct qeth_ipacmd_addr_change_entry
) *
1331 hostevs
->num_entries
;
1332 data
= kzalloc(sizeof(struct qeth_bridge_host_data
) + extrasize
,
1335 QETH_CARD_TEXT(card
, 2, "BPHalloc");
1338 INIT_WORK(&data
->worker
, qeth_bridge_host_event_worker
);
1340 memcpy(&data
->hostevs
, hostevs
,
1341 sizeof(struct qeth_ipacmd_addr_change
) + extrasize
);
1342 queue_work(card
->event_wq
, &data
->worker
);
1345 /* SETBRIDGEPORT support; sending commands */
1347 struct _qeth_sbp_cbctl
{
1351 enum qeth_sbp_roles
*role
;
1352 enum qeth_sbp_states
*state
;
1357 static int qeth_bridgeport_makerc(struct qeth_card
*card
,
1358 struct qeth_ipa_cmd
*cmd
)
1360 struct qeth_ipacmd_setbridgeport
*sbp
= &cmd
->data
.sbp
;
1361 enum qeth_ipa_sbp_cmd setcmd
= sbp
->hdr
.command_code
;
1362 u16 ipa_rc
= cmd
->hdr
.return_code
;
1363 u16 sbp_rc
= sbp
->hdr
.return_code
;
1366 if (ipa_rc
== IPA_RC_SUCCESS
&& sbp_rc
== IPA_RC_SUCCESS
)
1369 if ((IS_IQD(card
) && ipa_rc
== IPA_RC_SUCCESS
) ||
1370 (!IS_IQD(card
) && ipa_rc
== sbp_rc
)) {
1372 case IPA_RC_SUCCESS
:
1375 case IPA_RC_L2_UNSUPPORTED_CMD
:
1376 case IPA_RC_UNSUPPORTED_COMMAND
:
1379 case IPA_RC_SBP_OSA_NOT_CONFIGURED
:
1380 case IPA_RC_SBP_IQD_NOT_CONFIGURED
:
1381 rc
= -ENODEV
; /* maybe not the best code here? */
1382 dev_err(&card
->gdev
->dev
,
1383 "The device is not configured as a Bridge Port\n");
1385 case IPA_RC_SBP_OSA_OS_MISMATCH
:
1386 case IPA_RC_SBP_IQD_OS_MISMATCH
:
1388 dev_err(&card
->gdev
->dev
,
1389 "A Bridge Port is already configured by a different operating system\n");
1391 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY
:
1392 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY
:
1394 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT
:
1396 dev_err(&card
->gdev
->dev
,
1397 "The LAN already has a primary Bridge Port\n");
1399 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT
:
1401 dev_err(&card
->gdev
->dev
,
1402 "The device is already a primary Bridge Port\n");
1408 case IPA_RC_SBP_OSA_CURRENT_SECOND
:
1409 case IPA_RC_SBP_IQD_CURRENT_SECOND
:
1411 dev_err(&card
->gdev
->dev
,
1412 "The device is already a secondary Bridge Port\n");
1414 case IPA_RC_SBP_OSA_LIMIT_SECOND
:
1415 case IPA_RC_SBP_IQD_LIMIT_SECOND
:
1417 dev_err(&card
->gdev
->dev
,
1418 "The LAN cannot have more secondary Bridge Ports\n");
1420 case IPA_RC_SBP_OSA_CURRENT_PRIMARY
:
1421 case IPA_RC_SBP_IQD_CURRENT_PRIMARY
:
1423 dev_err(&card
->gdev
->dev
,
1424 "The device is already a primary Bridge Port\n");
1426 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN
:
1427 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN
:
1429 dev_err(&card
->gdev
->dev
,
1430 "The device is not authorized to be a Bridge Port\n");
1437 case IPA_RC_NOTSUPP
:
1440 case IPA_RC_UNSUPPORTED_COMMAND
:
1449 QETH_CARD_TEXT_(card
, 2, "SBPi%04x", ipa_rc
);
1450 QETH_CARD_TEXT_(card
, 2, "SBPc%04x", sbp_rc
);
1455 static struct qeth_cmd_buffer
*qeth_sbp_build_cmd(struct qeth_card
*card
,
1456 enum qeth_ipa_sbp_cmd sbp_cmd
,
1457 unsigned int cmd_length
)
1459 enum qeth_ipa_cmds ipa_cmd
= (card
->info
.type
== QETH_CARD_TYPE_IQD
) ?
1460 IPA_CMD_SETBRIDGEPORT_IQD
:
1461 IPA_CMD_SETBRIDGEPORT_OSA
;
1462 struct qeth_cmd_buffer
*iob
;
1463 struct qeth_ipa_cmd
*cmd
;
1465 iob
= qeth_get_ipacmd_buffer(card
, ipa_cmd
, 0);
1468 cmd
= __ipa_cmd(iob
);
1469 cmd
->data
.sbp
.hdr
.cmdlength
= sizeof(struct qeth_ipacmd_sbp_hdr
) +
1471 cmd
->data
.sbp
.hdr
.command_code
= sbp_cmd
;
1472 cmd
->data
.sbp
.hdr
.used_total
= 1;
1473 cmd
->data
.sbp
.hdr
.seq_no
= 1;
1477 static int qeth_bridgeport_query_support_cb(struct qeth_card
*card
,
1478 struct qeth_reply
*reply
, unsigned long data
)
1480 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
1481 struct _qeth_sbp_cbctl
*cbctl
= (struct _qeth_sbp_cbctl
*)reply
->param
;
1484 QETH_CARD_TEXT(card
, 2, "brqsupcb");
1485 rc
= qeth_bridgeport_makerc(card
, cmd
);
1489 cbctl
->data
.supported
=
1490 cmd
->data
.sbp
.data
.query_cmds_supp
.supported_cmds
;
1495 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1496 * @card: qeth_card structure pointer.
1498 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1499 * strucutre: card->options.sbp.supported_funcs.
1501 static void qeth_bridgeport_query_support(struct qeth_card
*card
)
1503 struct qeth_cmd_buffer
*iob
;
1504 struct _qeth_sbp_cbctl cbctl
;
1506 QETH_CARD_TEXT(card
, 2, "brqsuppo");
1507 iob
= qeth_sbp_build_cmd(card
, IPA_SBP_QUERY_COMMANDS_SUPPORTED
,
1508 sizeof(struct qeth_sbp_query_cmds_supp
));
1512 if (qeth_send_ipa_cmd(card
, iob
, qeth_bridgeport_query_support_cb
,
1514 card
->options
.sbp
.role
= QETH_SBP_ROLE_NONE
;
1515 card
->options
.sbp
.supported_funcs
= 0;
1518 card
->options
.sbp
.supported_funcs
= cbctl
.data
.supported
;
1521 static int qeth_bridgeport_query_ports_cb(struct qeth_card
*card
,
1522 struct qeth_reply
*reply
, unsigned long data
)
1524 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
1525 struct qeth_sbp_query_ports
*qports
= &cmd
->data
.sbp
.data
.query_ports
;
1526 struct _qeth_sbp_cbctl
*cbctl
= (struct _qeth_sbp_cbctl
*)reply
->param
;
1529 QETH_CARD_TEXT(card
, 2, "brqprtcb");
1530 rc
= qeth_bridgeport_makerc(card
, cmd
);
1534 if (qports
->entry_length
!= sizeof(struct qeth_sbp_port_entry
)) {
1535 QETH_CARD_TEXT_(card
, 2, "SBPs%04x", qports
->entry_length
);
1538 /* first entry contains the state of the local port */
1539 if (qports
->num_entries
> 0) {
1540 if (cbctl
->data
.qports
.role
)
1541 *cbctl
->data
.qports
.role
= qports
->entry
[0].role
;
1542 if (cbctl
->data
.qports
.state
)
1543 *cbctl
->data
.qports
.state
= qports
->entry
[0].state
;
1549 * qeth_bridgeport_query_ports() - query local bridgeport status.
1550 * @card: qeth_card structure pointer.
1551 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1552 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1554 * Returns negative errno-compatible error indication or 0 on success.
1556 * 'role' and 'state' are not updated in case of hardware operation failure.
1558 int qeth_bridgeport_query_ports(struct qeth_card
*card
,
1559 enum qeth_sbp_roles
*role
, enum qeth_sbp_states
*state
)
1561 struct qeth_cmd_buffer
*iob
;
1562 struct _qeth_sbp_cbctl cbctl
= {
1571 QETH_CARD_TEXT(card
, 2, "brqports");
1572 if (!(card
->options
.sbp
.supported_funcs
& IPA_SBP_QUERY_BRIDGE_PORTS
))
1574 iob
= qeth_sbp_build_cmd(card
, IPA_SBP_QUERY_BRIDGE_PORTS
, 0);
1578 return qeth_send_ipa_cmd(card
, iob
, qeth_bridgeport_query_ports_cb
,
1582 static int qeth_bridgeport_set_cb(struct qeth_card
*card
,
1583 struct qeth_reply
*reply
, unsigned long data
)
1585 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*)data
;
1587 QETH_CARD_TEXT(card
, 2, "brsetrcb");
1588 return qeth_bridgeport_makerc(card
, cmd
);
1592 * qeth_bridgeport_setrole() - Assign primary role to the port.
1593 * @card: qeth_card structure pointer.
1594 * @role: Role to assign.
1596 * Returns negative errno-compatible error indication or 0 on success.
1598 int qeth_bridgeport_setrole(struct qeth_card
*card
, enum qeth_sbp_roles role
)
1601 struct qeth_cmd_buffer
*iob
;
1602 enum qeth_ipa_sbp_cmd setcmd
;
1604 QETH_CARD_TEXT(card
, 2, "brsetrol");
1606 case QETH_SBP_ROLE_NONE
:
1607 setcmd
= IPA_SBP_RESET_BRIDGE_PORT_ROLE
;
1608 cmdlength
= sizeof(struct qeth_sbp_reset_role
);
1610 case QETH_SBP_ROLE_PRIMARY
:
1611 setcmd
= IPA_SBP_SET_PRIMARY_BRIDGE_PORT
;
1612 cmdlength
= sizeof(struct qeth_sbp_set_primary
);
1614 case QETH_SBP_ROLE_SECONDARY
:
1615 setcmd
= IPA_SBP_SET_SECONDARY_BRIDGE_PORT
;
1616 cmdlength
= sizeof(struct qeth_sbp_set_secondary
);
1621 if (!(card
->options
.sbp
.supported_funcs
& setcmd
))
1623 iob
= qeth_sbp_build_cmd(card
, setcmd
, cmdlength
);
1627 return qeth_send_ipa_cmd(card
, iob
, qeth_bridgeport_set_cb
, NULL
);
1631 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1632 * @card: qeth_card structure pointer, for debug messages.
1634 * Returns negative errno-compatible error indication or 0 on success.
1636 static int qeth_anset_makerc(struct qeth_card
*card
, int pnso_rc
, u16 response
)
1649 dev_err(&card
->gdev
->dev
,
1650 "Setting address notification failed\n");
1662 QETH_CARD_TEXT_(card
, 2, "SBPp%04x", pnso_rc
);
1663 QETH_CARD_TEXT_(card
, 2, "SBPr%04x", response
);
1668 static void qeth_bridgeport_an_set_cb(void *priv
,
1669 enum qdio_brinfo_entry_type type
, void *entry
)
1671 struct qeth_card
*card
= (struct qeth_card
*)priv
;
1672 struct qdio_brinfo_entry_l2
*l2entry
;
1675 if (type
!= l2_addr_lnid
) {
1680 l2entry
= (struct qdio_brinfo_entry_l2
*)entry
;
1681 code
= IPA_ADDR_CHANGE_CODE_MACADDR
;
1682 if (l2entry
->addr_lnid
.lnid
)
1683 code
|= IPA_ADDR_CHANGE_CODE_VLANID
;
1684 qeth_bridge_emit_host_event(card
, anev_reg_unreg
, code
,
1685 (struct net_if_token
*)&l2entry
->nit
,
1686 (struct mac_addr_lnid
*)&l2entry
->addr_lnid
);
1690 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1691 * @card: qeth_card structure pointer.
1692 * @enable: 0 - disable, non-zero - enable notifications
1694 * Returns negative errno-compatible error indication or 0 on success.
1696 * On enable, emits a series of address notifications udev events for all
1697 * currently registered hosts.
1699 int qeth_bridgeport_an_set(struct qeth_card
*card
, int enable
)
1703 struct ccw_device
*ddev
;
1704 struct subchannel_id schid
;
1708 if (!card
->options
.sbp
.supported_funcs
)
1710 ddev
= CARD_DDEV(card
);
1711 ccw_device_get_schid(ddev
, &schid
);
1714 qeth_bridge_emit_host_event(card
, anev_reset
, 0, NULL
, NULL
);
1715 rc
= qdio_pnso_brinfo(schid
, 1, &response
,
1716 qeth_bridgeport_an_set_cb
, card
);
1718 rc
= qdio_pnso_brinfo(schid
, 0, &response
, NULL
, NULL
);
1719 return qeth_anset_makerc(card
, rc
, response
);
1722 static bool qeth_bridgeport_is_in_use(struct qeth_card
*card
)
1724 return (card
->options
.sbp
.role
|| card
->options
.sbp
.reflect_promisc
||
1725 card
->options
.sbp
.hostnotification
);
1728 /* VNIC Characteristics support */
1730 /* handle VNICC IPA command return codes; convert to error codes */
1731 static int qeth_l2_vnicc_makerc(struct qeth_card
*card
, u16 ipa_rc
)
1736 case IPA_RC_SUCCESS
:
1738 case IPA_RC_L2_UNSUPPORTED_CMD
:
1739 case IPA_RC_NOTSUPP
:
1742 case IPA_RC_VNICC_OOSEQ
:
1745 case IPA_RC_VNICC_VNICBP
:
1748 case IPA_RC_L2_ADDR_TABLE_FULL
:
1751 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP
:
1758 QETH_CARD_TEXT_(card
, 2, "err%04x", ipa_rc
);
1762 /* generic VNICC request call back control */
1763 struct _qeth_l2_vnicc_request_cbctl
{
1777 /* generic VNICC request call back */
1778 static int qeth_l2_vnicc_request_cb(struct qeth_card
*card
,
1779 struct qeth_reply
*reply
,
1782 struct _qeth_l2_vnicc_request_cbctl
*cbctl
=
1783 (struct _qeth_l2_vnicc_request_cbctl
*) reply
->param
;
1784 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
1785 struct qeth_ipacmd_vnicc
*rep
= &cmd
->data
.vnicc
;
1787 QETH_CARD_TEXT(card
, 2, "vniccrcb");
1788 if (cmd
->hdr
.return_code
)
1789 return qeth_l2_vnicc_makerc(card
, cmd
->hdr
.return_code
);
1790 /* return results to caller */
1791 card
->options
.vnicc
.sup_chars
= rep
->hdr
.sup
;
1792 card
->options
.vnicc
.cur_chars
= rep
->hdr
.cur
;
1794 if (cbctl
->sub_cmd
== IPA_VNICC_QUERY_CMDS
)
1795 *cbctl
->result
.sup_cmds
= rep
->query_cmds
.sup_cmds
;
1797 if (cbctl
->sub_cmd
== IPA_VNICC_GET_TIMEOUT
)
1798 *cbctl
->result
.timeout
= rep
->getset_timeout
.timeout
;
1803 /* generic VNICC request */
1804 static int qeth_l2_vnicc_request(struct qeth_card
*card
,
1805 struct _qeth_l2_vnicc_request_cbctl
*cbctl
)
1807 struct qeth_ipacmd_vnicc
*req
;
1808 struct qeth_cmd_buffer
*iob
;
1809 struct qeth_ipa_cmd
*cmd
;
1811 QETH_CARD_TEXT(card
, 2, "vniccreq");
1813 /* get new buffer for request */
1814 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_VNICC
, 0);
1818 /* create header for request */
1819 cmd
= __ipa_cmd(iob
);
1820 req
= &cmd
->data
.vnicc
;
1822 /* create sub command header for request */
1823 req
->sub_hdr
.data_length
= sizeof(req
->sub_hdr
);
1824 req
->sub_hdr
.sub_command
= cbctl
->sub_cmd
;
1826 /* create sub command specific request fields */
1827 switch (cbctl
->sub_cmd
) {
1828 case IPA_VNICC_QUERY_CHARS
:
1830 case IPA_VNICC_QUERY_CMDS
:
1831 req
->sub_hdr
.data_length
+= sizeof(req
->query_cmds
);
1832 req
->query_cmds
.vnic_char
= cbctl
->param
.vnic_char
;
1834 case IPA_VNICC_ENABLE
:
1835 case IPA_VNICC_DISABLE
:
1836 req
->sub_hdr
.data_length
+= sizeof(req
->set_char
);
1837 req
->set_char
.vnic_char
= cbctl
->param
.vnic_char
;
1839 case IPA_VNICC_SET_TIMEOUT
:
1840 req
->getset_timeout
.timeout
= cbctl
->param
.timeout
;
1842 case IPA_VNICC_GET_TIMEOUT
:
1843 req
->sub_hdr
.data_length
+= sizeof(req
->getset_timeout
);
1844 req
->getset_timeout
.vnic_char
= cbctl
->param
.vnic_char
;
1847 qeth_release_buffer(iob
->channel
, iob
);
1852 return qeth_send_ipa_cmd(card
, iob
, qeth_l2_vnicc_request_cb
, cbctl
);
1855 /* VNICC query VNIC characteristics request */
1856 static int qeth_l2_vnicc_query_chars(struct qeth_card
*card
)
1858 struct _qeth_l2_vnicc_request_cbctl cbctl
;
1860 /* prepare callback control */
1861 cbctl
.sub_cmd
= IPA_VNICC_QUERY_CHARS
;
1863 QETH_CARD_TEXT(card
, 2, "vniccqch");
1864 return qeth_l2_vnicc_request(card
, &cbctl
);
1867 /* VNICC query sub commands request */
1868 static int qeth_l2_vnicc_query_cmds(struct qeth_card
*card
, u32 vnic_char
,
1871 struct _qeth_l2_vnicc_request_cbctl cbctl
;
1873 /* prepare callback control */
1874 cbctl
.sub_cmd
= IPA_VNICC_QUERY_CMDS
;
1875 cbctl
.param
.vnic_char
= vnic_char
;
1876 cbctl
.result
.sup_cmds
= sup_cmds
;
1878 QETH_CARD_TEXT(card
, 2, "vniccqcm");
1879 return qeth_l2_vnicc_request(card
, &cbctl
);
1882 /* VNICC enable/disable characteristic request */
1883 static int qeth_l2_vnicc_set_char(struct qeth_card
*card
, u32 vnic_char
,
1886 struct _qeth_l2_vnicc_request_cbctl cbctl
;
1888 /* prepare callback control */
1889 cbctl
.sub_cmd
= cmd
;
1890 cbctl
.param
.vnic_char
= vnic_char
;
1892 QETH_CARD_TEXT(card
, 2, "vniccedc");
1893 return qeth_l2_vnicc_request(card
, &cbctl
);
1896 /* VNICC get/set timeout for characteristic request */
1897 static int qeth_l2_vnicc_getset_timeout(struct qeth_card
*card
, u32 vnicc
,
1898 u32 cmd
, u32
*timeout
)
1900 struct _qeth_l2_vnicc_request_cbctl cbctl
;
1902 /* prepare callback control */
1903 cbctl
.sub_cmd
= cmd
;
1904 cbctl
.param
.vnic_char
= vnicc
;
1905 if (cmd
== IPA_VNICC_SET_TIMEOUT
)
1906 cbctl
.param
.timeout
= *timeout
;
1907 if (cmd
== IPA_VNICC_GET_TIMEOUT
)
1908 cbctl
.result
.timeout
= timeout
;
1910 QETH_CARD_TEXT(card
, 2, "vniccgst");
1911 return qeth_l2_vnicc_request(card
, &cbctl
);
1914 /* set current VNICC flag state; called from sysfs store function */
1915 int qeth_l2_vnicc_set_state(struct qeth_card
*card
, u32 vnicc
, bool state
)
1920 QETH_CARD_TEXT(card
, 2, "vniccsch");
1922 /* do not change anything if BridgePort is enabled */
1923 if (qeth_bridgeport_is_in_use(card
))
1926 /* check if characteristic and enable/disable are supported */
1927 if (!(card
->options
.vnicc
.sup_chars
& vnicc
) ||
1928 !(card
->options
.vnicc
.set_char_sup
& vnicc
))
1931 /* set enable/disable command and store wanted characteristic */
1933 cmd
= IPA_VNICC_ENABLE
;
1934 card
->options
.vnicc
.wanted_chars
|= vnicc
;
1936 cmd
= IPA_VNICC_DISABLE
;
1937 card
->options
.vnicc
.wanted_chars
&= ~vnicc
;
1940 /* do we need to do anything? */
1941 if (card
->options
.vnicc
.cur_chars
== card
->options
.vnicc
.wanted_chars
)
1944 /* if card is not ready, simply stop here */
1945 if (!qeth_card_hw_is_reachable(card
)) {
1947 card
->options
.vnicc
.cur_chars
|= vnicc
;
1949 card
->options
.vnicc
.cur_chars
&= ~vnicc
;
1953 rc
= qeth_l2_vnicc_set_char(card
, vnicc
, cmd
);
1955 card
->options
.vnicc
.wanted_chars
=
1956 card
->options
.vnicc
.cur_chars
;
1958 /* successful online VNICC change; handle special cases */
1959 if (state
&& vnicc
== QETH_VNICC_RX_BCAST
)
1960 card
->options
.vnicc
.rx_bcast_enabled
= true;
1961 if (!state
&& vnicc
== QETH_VNICC_LEARNING
)
1962 qeth_l2_vnicc_recover_timeout(card
, vnicc
,
1963 &card
->options
.vnicc
.learning_timeout
);
1969 /* get current VNICC flag state; called from sysfs show function */
1970 int qeth_l2_vnicc_get_state(struct qeth_card
*card
, u32 vnicc
, bool *state
)
1974 QETH_CARD_TEXT(card
, 2, "vniccgch");
1976 /* do not get anything if BridgePort is enabled */
1977 if (qeth_bridgeport_is_in_use(card
))
1980 /* check if characteristic is supported */
1981 if (!(card
->options
.vnicc
.sup_chars
& vnicc
))
1984 /* if card is ready, query current VNICC state */
1985 if (qeth_card_hw_is_reachable(card
))
1986 rc
= qeth_l2_vnicc_query_chars(card
);
1988 *state
= (card
->options
.vnicc
.cur_chars
& vnicc
) ? true : false;
1992 /* set VNICC timeout; called from sysfs store function. Currently, only learning
1995 int qeth_l2_vnicc_set_timeout(struct qeth_card
*card
, u32 timeout
)
1999 QETH_CARD_TEXT(card
, 2, "vniccsto");
2001 /* do not change anything if BridgePort is enabled */
2002 if (qeth_bridgeport_is_in_use(card
))
2005 /* check if characteristic and set_timeout are supported */
2006 if (!(card
->options
.vnicc
.sup_chars
& QETH_VNICC_LEARNING
) ||
2007 !(card
->options
.vnicc
.getset_timeout_sup
& QETH_VNICC_LEARNING
))
2010 /* do we need to do anything? */
2011 if (card
->options
.vnicc
.learning_timeout
== timeout
)
2014 /* if card is not ready, simply store the value internally and return */
2015 if (!qeth_card_hw_is_reachable(card
)) {
2016 card
->options
.vnicc
.learning_timeout
= timeout
;
2020 /* send timeout value to card; if successful, store value internally */
2021 rc
= qeth_l2_vnicc_getset_timeout(card
, QETH_VNICC_LEARNING
,
2022 IPA_VNICC_SET_TIMEOUT
, &timeout
);
2024 card
->options
.vnicc
.learning_timeout
= timeout
;
2029 /* get current VNICC timeout; called from sysfs show function. Currently, only
2030 * learning supports timeout
2032 int qeth_l2_vnicc_get_timeout(struct qeth_card
*card
, u32
*timeout
)
2036 QETH_CARD_TEXT(card
, 2, "vniccgto");
2038 /* do not get anything if BridgePort is enabled */
2039 if (qeth_bridgeport_is_in_use(card
))
2042 /* check if characteristic and get_timeout are supported */
2043 if (!(card
->options
.vnicc
.sup_chars
& QETH_VNICC_LEARNING
) ||
2044 !(card
->options
.vnicc
.getset_timeout_sup
& QETH_VNICC_LEARNING
))
2046 /* if card is ready, get timeout. Otherwise, just return stored value */
2047 *timeout
= card
->options
.vnicc
.learning_timeout
;
2048 if (qeth_card_hw_is_reachable(card
))
2049 rc
= qeth_l2_vnicc_getset_timeout(card
, QETH_VNICC_LEARNING
,
2050 IPA_VNICC_GET_TIMEOUT
,
2056 /* check if VNICC is currently enabled */
2057 bool qeth_l2_vnicc_is_in_use(struct qeth_card
*card
)
2059 /* if everything is turned off, VNICC is not active */
2060 if (!card
->options
.vnicc
.cur_chars
)
2062 /* default values are only OK if rx_bcast was not enabled by user
2063 * or the card is offline.
2065 if (card
->options
.vnicc
.cur_chars
== QETH_VNICC_DEFAULT
) {
2066 if (!card
->options
.vnicc
.rx_bcast_enabled
||
2067 !qeth_card_hw_is_reachable(card
))
2073 /* recover user timeout setting */
2074 static bool qeth_l2_vnicc_recover_timeout(struct qeth_card
*card
, u32 vnicc
,
2077 if (card
->options
.vnicc
.sup_chars
& vnicc
&&
2078 card
->options
.vnicc
.getset_timeout_sup
& vnicc
&&
2079 !qeth_l2_vnicc_getset_timeout(card
, vnicc
, IPA_VNICC_SET_TIMEOUT
,
2082 *timeout
= QETH_VNICC_DEFAULT_TIMEOUT
;
2086 /* recover user characteristic setting */
2087 static bool qeth_l2_vnicc_recover_char(struct qeth_card
*card
, u32 vnicc
,
2090 u32 cmd
= enable
? IPA_VNICC_ENABLE
: IPA_VNICC_DISABLE
;
2092 if (card
->options
.vnicc
.sup_chars
& vnicc
&&
2093 card
->options
.vnicc
.set_char_sup
& vnicc
&&
2094 !qeth_l2_vnicc_set_char(card
, vnicc
, cmd
))
2096 card
->options
.vnicc
.wanted_chars
&= ~vnicc
;
2097 card
->options
.vnicc
.wanted_chars
|= QETH_VNICC_DEFAULT
& vnicc
;
2101 /* (re-)initialize VNICC */
2102 static void qeth_l2_vnicc_init(struct qeth_card
*card
)
2104 u32
*timeout
= &card
->options
.vnicc
.learning_timeout
;
2105 unsigned int chars_len
, i
;
2106 unsigned long chars_tmp
;
2107 u32 sup_cmds
, vnicc
;
2110 QETH_CARD_TEXT(card
, 2, "vniccini");
2111 /* reset rx_bcast */
2112 card
->options
.vnicc
.rx_bcast_enabled
= 0;
2113 /* initial query and storage of VNIC characteristics */
2114 if (qeth_l2_vnicc_query_chars(card
)) {
2115 if (card
->options
.vnicc
.wanted_chars
!= QETH_VNICC_DEFAULT
||
2116 *timeout
!= QETH_VNICC_DEFAULT_TIMEOUT
)
2117 dev_err(&card
->gdev
->dev
, "Configuring the VNIC characteristics failed\n");
2118 /* fail quietly if user didn't change the default config */
2119 card
->options
.vnicc
.sup_chars
= 0;
2120 card
->options
.vnicc
.cur_chars
= 0;
2121 card
->options
.vnicc
.wanted_chars
= QETH_VNICC_DEFAULT
;
2124 /* get supported commands for each supported characteristic */
2125 chars_tmp
= card
->options
.vnicc
.sup_chars
;
2126 chars_len
= sizeof(card
->options
.vnicc
.sup_chars
) * BITS_PER_BYTE
;
2127 for_each_set_bit(i
, &chars_tmp
, chars_len
) {
2129 qeth_l2_vnicc_query_cmds(card
, vnicc
, &sup_cmds
);
2130 if (!(sup_cmds
& IPA_VNICC_SET_TIMEOUT
) ||
2131 !(sup_cmds
& IPA_VNICC_GET_TIMEOUT
))
2132 card
->options
.vnicc
.getset_timeout_sup
&= ~vnicc
;
2133 if (!(sup_cmds
& IPA_VNICC_ENABLE
) ||
2134 !(sup_cmds
& IPA_VNICC_DISABLE
))
2135 card
->options
.vnicc
.set_char_sup
&= ~vnicc
;
2137 /* enforce assumed default values and recover settings, if changed */
2138 error
= qeth_l2_vnicc_recover_timeout(card
, QETH_VNICC_LEARNING
,
2140 chars_tmp
= card
->options
.vnicc
.wanted_chars
^ QETH_VNICC_DEFAULT
;
2141 chars_tmp
|= QETH_VNICC_BRIDGE_INVISIBLE
;
2142 chars_len
= sizeof(card
->options
.vnicc
.wanted_chars
) * BITS_PER_BYTE
;
2143 for_each_set_bit(i
, &chars_tmp
, chars_len
) {
2145 enable
= card
->options
.vnicc
.wanted_chars
& vnicc
;
2146 error
|= qeth_l2_vnicc_recover_char(card
, vnicc
, enable
);
2149 dev_err(&card
->gdev
->dev
, "Configuring the VNIC characteristics failed\n");
2152 /* configure default values of VNIC characteristics */
2153 static void qeth_l2_vnicc_set_defaults(struct qeth_card
*card
)
2155 /* characteristics values */
2156 card
->options
.vnicc
.sup_chars
= QETH_VNICC_ALL
;
2157 card
->options
.vnicc
.cur_chars
= QETH_VNICC_DEFAULT
;
2158 card
->options
.vnicc
.learning_timeout
= QETH_VNICC_DEFAULT_TIMEOUT
;
2159 /* supported commands */
2160 card
->options
.vnicc
.set_char_sup
= QETH_VNICC_ALL
;
2161 card
->options
.vnicc
.getset_timeout_sup
= QETH_VNICC_LEARNING
;
2162 /* settings wanted by users */
2163 card
->options
.vnicc
.wanted_chars
= QETH_VNICC_DEFAULT
;
2166 module_init(qeth_l2_init
);
2167 module_exit(qeth_l2_exit
);
2168 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2169 MODULE_DESCRIPTION("qeth layer 2 discipline");
2170 MODULE_LICENSE("GPL");