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 int qeth_l2_stop(struct net_device
*);
29 static void qeth_l2_set_rx_mode(struct net_device
*);
30 static void qeth_bridgeport_query_support(struct qeth_card
*card
);
31 static void qeth_bridge_state_change(struct qeth_card
*card
,
32 struct qeth_ipa_cmd
*cmd
);
33 static void qeth_bridge_host_event(struct qeth_card
*card
,
34 struct qeth_ipa_cmd
*cmd
);
35 static void qeth_l2_vnicc_set_defaults(struct qeth_card
*card
);
36 static void qeth_l2_vnicc_init(struct qeth_card
*card
);
37 static bool qeth_l2_vnicc_recover_timeout(struct qeth_card
*card
, u32 vnicc
,
40 static struct net_device
*qeth_l2_netdev_by_devno(unsigned char *read_dev_no
)
42 struct qeth_card
*card
;
43 struct net_device
*ndev
;
46 struct ccw_dev_id read_devid
;
49 memcpy(&temp_dev_no
, read_dev_no
, 2);
50 read_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
51 list_for_each_entry(card
, &qeth_core_card_list
.list
, list
) {
52 ccw_device_get_id(CARD_RDEV(card
), &read_devid
);
53 if (read_devid
.devno
== temp_dev_no
) {
58 read_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
62 static int qeth_setdelmac_makerc(struct qeth_card
*card
, int retcode
)
67 QETH_CARD_TEXT_(card
, 2, "err%04x", retcode
);
72 case IPA_RC_L2_UNSUPPORTED_CMD
:
75 case IPA_RC_L2_ADDR_TABLE_FULL
:
78 case IPA_RC_L2_DUP_MAC
:
79 case IPA_RC_L2_DUP_LAYER3_MAC
:
82 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP
:
83 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP
:
86 case IPA_RC_L2_MAC_NOT_FOUND
:
99 static int qeth_l2_send_setdelmac(struct qeth_card
*card
, __u8
*mac
,
100 enum qeth_ipa_cmds ipacmd
)
102 struct qeth_ipa_cmd
*cmd
;
103 struct qeth_cmd_buffer
*iob
;
105 QETH_CARD_TEXT(card
, 2, "L2sdmac");
106 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, QETH_PROT_IPV4
);
109 cmd
= __ipa_cmd(iob
);
110 cmd
->data
.setdelmac
.mac_length
= ETH_ALEN
;
111 ether_addr_copy(cmd
->data
.setdelmac
.mac
, mac
);
112 return qeth_setdelmac_makerc(card
, qeth_send_ipa_cmd(card
, iob
,
116 static int qeth_l2_send_setmac(struct qeth_card
*card
, __u8
*mac
)
120 QETH_CARD_TEXT(card
, 2, "L2Setmac");
121 rc
= qeth_l2_send_setdelmac(card
, mac
, IPA_CMD_SETVMAC
);
123 dev_info(&card
->gdev
->dev
,
124 "MAC address %pM successfully registered on device %s\n",
125 mac
, card
->dev
->name
);
129 dev_warn(&card
->gdev
->dev
,
130 "MAC address %pM already exists\n", mac
);
133 dev_warn(&card
->gdev
->dev
,
134 "MAC address %pM is not authorized\n", mac
);
141 static int qeth_l2_write_mac(struct qeth_card
*card
, u8
*mac
)
143 enum qeth_ipa_cmds cmd
= is_multicast_ether_addr(mac
) ?
144 IPA_CMD_SETGMAC
: IPA_CMD_SETVMAC
;
147 QETH_CARD_TEXT(card
, 2, "L2Wmac");
148 rc
= qeth_l2_send_setdelmac(card
, mac
, cmd
);
150 QETH_DBF_MESSAGE(2, "MAC %pM already registered on %s\n",
151 mac
, QETH_CARD_IFNAME(card
));
153 QETH_DBF_MESSAGE(2, "Failed to register MAC %pM on %s: %d\n",
154 mac
, QETH_CARD_IFNAME(card
), rc
);
158 static int qeth_l2_remove_mac(struct qeth_card
*card
, u8
*mac
)
160 enum qeth_ipa_cmds cmd
= is_multicast_ether_addr(mac
) ?
161 IPA_CMD_DELGMAC
: IPA_CMD_DELVMAC
;
164 QETH_CARD_TEXT(card
, 2, "L2Rmac");
165 rc
= qeth_l2_send_setdelmac(card
, mac
, cmd
);
167 QETH_DBF_MESSAGE(2, "Failed to delete MAC %pM on %s: %d\n",
168 mac
, QETH_CARD_IFNAME(card
), rc
);
172 static void qeth_l2_del_all_macs(struct qeth_card
*card
)
174 struct qeth_mac
*mac
;
175 struct hlist_node
*tmp
;
178 spin_lock_bh(&card
->mclock
);
179 hash_for_each_safe(card
->mac_htable
, i
, tmp
, mac
, hnode
) {
180 hash_del(&mac
->hnode
);
183 spin_unlock_bh(&card
->mclock
);
186 static int qeth_l2_get_cast_type(struct qeth_card
*card
, struct sk_buff
*skb
)
188 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
190 if (is_broadcast_ether_addr(skb
->data
))
191 return RTN_BROADCAST
;
192 if (is_multicast_ether_addr(skb
->data
))
193 return RTN_MULTICAST
;
197 static void qeth_l2_fill_header(struct qeth_hdr
*hdr
, struct sk_buff
*skb
,
198 int cast_type
, unsigned int data_len
)
200 struct vlan_ethhdr
*veth
= (struct vlan_ethhdr
*)skb_mac_header(skb
);
202 memset(hdr
, 0, sizeof(struct qeth_hdr
));
203 hdr
->hdr
.l2
.id
= QETH_HEADER_TYPE_LAYER2
;
204 hdr
->hdr
.l2
.pkt_length
= data_len
;
206 /* set byte byte 3 to casting flags */
207 if (cast_type
== RTN_MULTICAST
)
208 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_MULTICAST
;
209 else if (cast_type
== RTN_BROADCAST
)
210 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_BROADCAST
;
212 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_UNICAST
;
214 /* VSWITCH relies on the VLAN
215 * information to be present in
217 if (veth
->h_vlan_proto
== __constant_htons(ETH_P_8021Q
)) {
218 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_VLAN
;
219 hdr
->hdr
.l2
.vlan_id
= ntohs(veth
->h_vlan_TCI
);
223 static int qeth_setdelvlan_makerc(struct qeth_card
*card
, int retcode
)
226 QETH_CARD_TEXT_(card
, 2, "err%04x", retcode
);
231 case IPA_RC_L2_INVALID_VLAN_ID
:
233 case IPA_RC_L2_DUP_VLAN_ID
:
235 case IPA_RC_L2_VLAN_ID_NOT_FOUND
:
237 case IPA_RC_L2_VLAN_ID_NOT_ALLOWED
:
246 static int qeth_l2_send_setdelvlan_cb(struct qeth_card
*card
,
247 struct qeth_reply
*reply
,
250 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
252 QETH_CARD_TEXT(card
, 2, "L2sdvcb");
253 if (cmd
->hdr
.return_code
) {
254 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x.\n",
255 cmd
->data
.setdelvlan
.vlan_id
,
256 QETH_CARD_IFNAME(card
), cmd
->hdr
.return_code
);
257 QETH_CARD_TEXT_(card
, 2, "L2VL%4x", cmd
->hdr
.command
);
258 QETH_CARD_TEXT_(card
, 2, "err%d", cmd
->hdr
.return_code
);
263 static int qeth_l2_send_setdelvlan(struct qeth_card
*card
, __u16 i
,
264 enum qeth_ipa_cmds ipacmd
)
266 struct qeth_ipa_cmd
*cmd
;
267 struct qeth_cmd_buffer
*iob
;
269 QETH_CARD_TEXT_(card
, 4, "L2sdv%x", ipacmd
);
270 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, QETH_PROT_IPV4
);
273 cmd
= __ipa_cmd(iob
);
274 cmd
->data
.setdelvlan
.vlan_id
= i
;
275 return qeth_setdelvlan_makerc(card
, qeth_send_ipa_cmd(card
, iob
,
276 qeth_l2_send_setdelvlan_cb
, NULL
));
279 static void qeth_l2_process_vlans(struct qeth_card
*card
)
281 struct qeth_vlan_vid
*id
;
283 QETH_CARD_TEXT(card
, 3, "L2prcvln");
284 mutex_lock(&card
->vid_list_mutex
);
285 list_for_each_entry(id
, &card
->vid_list
, list
) {
286 qeth_l2_send_setdelvlan(card
, id
->vid
, IPA_CMD_SETVLAN
);
288 mutex_unlock(&card
->vid_list_mutex
);
291 static int qeth_l2_vlan_rx_add_vid(struct net_device
*dev
,
292 __be16 proto
, u16 vid
)
294 struct qeth_card
*card
= dev
->ml_priv
;
295 struct qeth_vlan_vid
*id
;
298 QETH_CARD_TEXT_(card
, 4, "aid:%d", vid
);
301 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
302 QETH_CARD_TEXT(card
, 3, "aidREC");
305 id
= kmalloc(sizeof(*id
), GFP_KERNEL
);
308 rc
= qeth_l2_send_setdelvlan(card
, vid
, IPA_CMD_SETVLAN
);
313 mutex_lock(&card
->vid_list_mutex
);
314 list_add_tail(&id
->list
, &card
->vid_list
);
315 mutex_unlock(&card
->vid_list_mutex
);
322 static int qeth_l2_vlan_rx_kill_vid(struct net_device
*dev
,
323 __be16 proto
, u16 vid
)
325 struct qeth_vlan_vid
*id
, *tmpid
= NULL
;
326 struct qeth_card
*card
= dev
->ml_priv
;
329 QETH_CARD_TEXT_(card
, 4, "kid:%d", vid
);
330 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
331 QETH_CARD_TEXT(card
, 3, "kidREC");
334 mutex_lock(&card
->vid_list_mutex
);
335 list_for_each_entry(id
, &card
->vid_list
, list
) {
336 if (id
->vid
== vid
) {
342 mutex_unlock(&card
->vid_list_mutex
);
344 rc
= qeth_l2_send_setdelvlan(card
, vid
, IPA_CMD_DELVLAN
);
347 qeth_l2_set_rx_mode(card
->dev
);
351 static void qeth_l2_stop_card(struct qeth_card
*card
, int recovery_mode
)
353 QETH_DBF_TEXT(SETUP
, 2, "stopcard");
354 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
356 qeth_set_allowed_threads(card
, 0, 1);
357 if (card
->read
.state
== CH_STATE_UP
&&
358 card
->write
.state
== CH_STATE_UP
&&
359 (card
->state
== CARD_STATE_UP
)) {
361 card
->info
.type
!= QETH_CARD_TYPE_OSN
) {
362 qeth_l2_stop(card
->dev
);
365 dev_close(card
->dev
);
368 card
->info
.mac_bits
&= ~QETH_LAYER2_MAC_REGISTERED
;
369 card
->state
= CARD_STATE_SOFTSETUP
;
371 if (card
->state
== CARD_STATE_SOFTSETUP
) {
372 qeth_l2_del_all_macs(card
);
373 qeth_clear_ipacmd_list(card
);
374 card
->state
= CARD_STATE_HARDSETUP
;
376 if (card
->state
== CARD_STATE_HARDSETUP
) {
377 qeth_qdio_clear_card(card
, 0);
378 qeth_clear_qdio_buffers(card
);
379 qeth_clear_working_pool_list(card
);
380 card
->state
= CARD_STATE_DOWN
;
382 if (card
->state
== CARD_STATE_DOWN
) {
383 qeth_clear_cmd_buffers(&card
->read
);
384 qeth_clear_cmd_buffers(&card
->write
);
388 static int qeth_l2_process_inbound_buffer(struct qeth_card
*card
,
389 int budget
, int *done
)
393 struct qeth_hdr
*hdr
;
397 WARN_ON_ONCE(!budget
);
399 skb
= qeth_core_get_next_skb(card
,
400 &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
],
401 &card
->rx
.b_element
, &card
->rx
.e_offset
, &hdr
);
406 switch (hdr
->hdr
.l2
.id
) {
407 case QETH_HEADER_TYPE_LAYER2
:
408 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
409 qeth_rx_csum(card
, skb
, hdr
->hdr
.l2
.flags
[1]);
410 if (skb
->protocol
== htons(ETH_P_802_2
))
411 *((__u32
*)skb
->cb
) = ++card
->seqno
.pkt_seqno
;
413 napi_gro_receive(&card
->napi
, skb
);
415 case QETH_HEADER_TYPE_OSN
:
416 if (card
->info
.type
== QETH_CARD_TYPE_OSN
) {
417 skb_push(skb
, sizeof(struct qeth_hdr
));
418 skb_copy_to_linear_data(skb
, hdr
,
419 sizeof(struct qeth_hdr
));
421 card
->osn_info
.data_cb(skb
);
426 dev_kfree_skb_any(skb
);
427 QETH_CARD_TEXT(card
, 3, "inbunkno");
428 QETH_DBF_HEX(CTRL
, 3, hdr
, QETH_DBF_CTRL_LEN
);
433 card
->stats
.rx_packets
++;
434 card
->stats
.rx_bytes
+= len
;
439 static int qeth_l2_request_initial_mac(struct qeth_card
*card
)
443 QETH_DBF_TEXT(SETUP
, 2, "l2reqmac");
444 QETH_DBF_TEXT_(SETUP
, 2, "doL2%s", CARD_BUS_ID(card
));
447 rc
= qeth_vm_request_mac(card
);
450 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %s: x%x\n",
451 CARD_BUS_ID(card
), rc
);
452 QETH_DBF_TEXT_(SETUP
, 2, "err%04x", rc
);
453 /* fall back to alternative mechanism: */
456 if (card
->info
.type
== QETH_CARD_TYPE_IQD
||
457 card
->info
.type
== QETH_CARD_TYPE_OSM
||
458 card
->info
.type
== QETH_CARD_TYPE_OSX
||
459 card
->info
.guestlan
) {
460 rc
= qeth_setadpparms_change_macaddr(card
);
463 QETH_DBF_MESSAGE(2, "READ_MAC Assist failed on device %s: x%x\n",
464 CARD_BUS_ID(card
), rc
);
465 QETH_DBF_TEXT_(SETUP
, 2, "1err%04x", rc
);
466 /* fall back once more: */
469 /* some devices don't support a custom MAC address: */
470 if (card
->info
.type
== QETH_CARD_TYPE_OSM
||
471 card
->info
.type
== QETH_CARD_TYPE_OSX
)
472 return (rc
) ? rc
: -EADDRNOTAVAIL
;
473 eth_hw_addr_random(card
->dev
);
476 QETH_DBF_HEX(SETUP
, 2, card
->dev
->dev_addr
, card
->dev
->addr_len
);
480 static int qeth_l2_set_mac_address(struct net_device
*dev
, void *p
)
482 struct sockaddr
*addr
= p
;
483 struct qeth_card
*card
= dev
->ml_priv
;
484 u8 old_addr
[ETH_ALEN
];
487 QETH_CARD_TEXT(card
, 3, "setmac");
489 if (card
->info
.type
== QETH_CARD_TYPE_OSN
||
490 card
->info
.type
== QETH_CARD_TYPE_OSM
||
491 card
->info
.type
== QETH_CARD_TYPE_OSX
) {
492 QETH_CARD_TEXT(card
, 3, "setmcTYP");
495 QETH_CARD_HEX(card
, 3, addr
->sa_data
, ETH_ALEN
);
496 if (!is_valid_ether_addr(addr
->sa_data
))
497 return -EADDRNOTAVAIL
;
499 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
500 QETH_CARD_TEXT(card
, 3, "setmcREC");
504 /* avoid racing against concurrent state change: */
505 if (!mutex_trylock(&card
->conf_mutex
))
508 if (!qeth_card_hw_is_reachable(card
)) {
509 ether_addr_copy(dev
->dev_addr
, addr
->sa_data
);
513 /* don't register the same address twice */
514 if (ether_addr_equal_64bits(dev
->dev_addr
, addr
->sa_data
) &&
515 (card
->info
.mac_bits
& QETH_LAYER2_MAC_REGISTERED
))
518 /* add the new address, switch over, drop the old */
519 rc
= qeth_l2_send_setmac(card
, addr
->sa_data
);
522 ether_addr_copy(old_addr
, dev
->dev_addr
);
523 ether_addr_copy(dev
->dev_addr
, addr
->sa_data
);
525 if (card
->info
.mac_bits
& QETH_LAYER2_MAC_REGISTERED
)
526 qeth_l2_remove_mac(card
, old_addr
);
527 card
->info
.mac_bits
|= QETH_LAYER2_MAC_REGISTERED
;
530 mutex_unlock(&card
->conf_mutex
);
534 static void qeth_promisc_to_bridge(struct qeth_card
*card
)
536 struct net_device
*dev
= card
->dev
;
537 enum qeth_ipa_promisc_modes promisc_mode
;
541 QETH_CARD_TEXT(card
, 3, "pmisc2br");
543 if (!card
->options
.sbp
.reflect_promisc
)
545 promisc_mode
= (dev
->flags
& IFF_PROMISC
) ? SET_PROMISC_MODE_ON
546 : SET_PROMISC_MODE_OFF
;
547 if (promisc_mode
== card
->info
.promisc_mode
)
550 if (promisc_mode
== SET_PROMISC_MODE_ON
) {
551 if (card
->options
.sbp
.reflect_promisc_primary
)
552 role
= QETH_SBP_ROLE_PRIMARY
;
554 role
= QETH_SBP_ROLE_SECONDARY
;
556 role
= QETH_SBP_ROLE_NONE
;
558 rc
= qeth_bridgeport_setrole(card
, role
);
559 QETH_DBF_TEXT_(SETUP
, 2, "bpm%c%04x",
560 (promisc_mode
== SET_PROMISC_MODE_ON
) ? '+' : '-', rc
);
562 card
->options
.sbp
.role
= role
;
563 card
->info
.promisc_mode
= promisc_mode
;
567 /* New MAC address is added to the hash table and marked to be written on card
568 * only if there is not in the hash table storage already
571 static void qeth_l2_add_mac(struct qeth_card
*card
, struct netdev_hw_addr
*ha
)
573 u32 mac_hash
= get_unaligned((u32
*)(&ha
->addr
[2]));
574 struct qeth_mac
*mac
;
576 hash_for_each_possible(card
->mac_htable
, mac
, hnode
, mac_hash
) {
577 if (ether_addr_equal_64bits(ha
->addr
, mac
->mac_addr
)) {
578 mac
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
583 mac
= kzalloc(sizeof(struct qeth_mac
), GFP_ATOMIC
);
587 ether_addr_copy(mac
->mac_addr
, ha
->addr
);
588 mac
->disp_flag
= QETH_DISP_ADDR_ADD
;
590 hash_add(card
->mac_htable
, &mac
->hnode
, mac_hash
);
593 static void qeth_l2_set_rx_mode(struct net_device
*dev
)
595 struct qeth_card
*card
= dev
->ml_priv
;
596 struct netdev_hw_addr
*ha
;
597 struct qeth_mac
*mac
;
598 struct hlist_node
*tmp
;
602 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
605 QETH_CARD_TEXT(card
, 3, "setmulti");
606 if (qeth_threads_running(card
, QETH_RECOVER_THREAD
) &&
607 (card
->state
!= CARD_STATE_UP
))
610 spin_lock_bh(&card
->mclock
);
612 netdev_for_each_mc_addr(ha
, dev
)
613 qeth_l2_add_mac(card
, ha
);
614 netdev_for_each_uc_addr(ha
, dev
)
615 qeth_l2_add_mac(card
, ha
);
617 hash_for_each_safe(card
->mac_htable
, i
, tmp
, mac
, hnode
) {
618 switch (mac
->disp_flag
) {
619 case QETH_DISP_ADDR_DELETE
:
620 qeth_l2_remove_mac(card
, mac
->mac_addr
);
621 hash_del(&mac
->hnode
);
624 case QETH_DISP_ADDR_ADD
:
625 rc
= qeth_l2_write_mac(card
, mac
->mac_addr
);
627 hash_del(&mac
->hnode
);
633 /* for next call to set_rx_mode(): */
634 mac
->disp_flag
= QETH_DISP_ADDR_DELETE
;
638 spin_unlock_bh(&card
->mclock
);
640 if (qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
641 qeth_setadp_promisc_mode(card
);
643 qeth_promisc_to_bridge(card
);
646 static int qeth_l2_xmit_iqd(struct qeth_card
*card
, struct sk_buff
*skb
,
647 struct qeth_qdio_out_q
*queue
, int cast_type
)
649 unsigned int data_offset
= ETH_HLEN
;
650 struct qeth_hdr
*hdr
;
653 hdr
= kmem_cache_alloc(qeth_core_header_cache
, GFP_ATOMIC
);
656 qeth_l2_fill_header(hdr
, skb
, cast_type
, skb
->len
);
657 skb_copy_from_linear_data(skb
, ((char *)hdr
) + sizeof(*hdr
),
660 if (!qeth_get_elements_no(card
, skb
, 1, data_offset
)) {
664 rc
= qeth_do_send_packet_fast(queue
, skb
, hdr
, data_offset
,
665 sizeof(*hdr
) + data_offset
);
668 kmem_cache_free(qeth_core_header_cache
, hdr
);
672 static int qeth_l2_xmit_osa(struct qeth_card
*card
, struct sk_buff
*skb
,
673 struct qeth_qdio_out_q
*queue
, int cast_type
,
676 int push_len
= sizeof(struct qeth_hdr
);
677 unsigned int elements
, nr_frags
;
678 unsigned int hdr_elements
= 0;
679 struct qeth_hdr
*hdr
= NULL
;
680 unsigned int hd_len
= 0;
683 /* fix hardware limitation: as long as we do not have sbal
684 * chaining we can not send long frag lists
686 if (!qeth_get_elements_no(card
, skb
, 0, 0)) {
687 rc
= skb_linearize(skb
);
689 if (card
->options
.performance_stats
) {
691 card
->perf_stats
.tx_linfail
++;
693 card
->perf_stats
.tx_lin
++;
698 nr_frags
= skb_shinfo(skb
)->nr_frags
;
700 rc
= skb_cow_head(skb
, push_len
);
703 push_len
= qeth_push_hdr(skb
, &hdr
, push_len
);
707 /* hdr was allocated from cache */
708 hd_len
= sizeof(*hdr
);
711 qeth_l2_fill_header(hdr
, skb
, cast_type
, skb
->len
- push_len
);
712 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
713 qeth_tx_csum(skb
, &hdr
->hdr
.l2
.flags
[1], ipv
);
714 if (card
->options
.performance_stats
)
715 card
->perf_stats
.tx_csum
++;
718 elements
= qeth_get_elements_no(card
, skb
, hdr_elements
, 0);
723 elements
+= hdr_elements
;
725 /* TODO: remove the skb_orphan() once TX completion is fast enough */
727 rc
= qeth_do_send_packet(card
, queue
, skb
, hdr
, 0, hd_len
, elements
);
730 if (card
->options
.performance_stats
&& nr_frags
) {
731 card
->perf_stats
.sg_skbs_sent
++;
732 /* nr_frags + skb->data */
733 card
->perf_stats
.sg_frags_sent
+= nr_frags
+ 1;
737 kmem_cache_free(qeth_core_header_cache
, hdr
);
739 /* roll back to ETH header */
740 skb_pull(skb
, push_len
);
745 static int qeth_l2_xmit_osn(struct qeth_card
*card
, struct sk_buff
*skb
,
746 struct qeth_qdio_out_q
*queue
)
748 unsigned int elements
;
749 struct qeth_hdr
*hdr
;
751 if (skb
->protocol
== htons(ETH_P_IPV6
))
752 return -EPROTONOSUPPORT
;
754 hdr
= (struct qeth_hdr
*)skb
->data
;
755 elements
= qeth_get_elements_no(card
, skb
, 0, 0);
758 if (qeth_hdr_chk_and_bounce(skb
, &hdr
, sizeof(*hdr
)))
760 return qeth_do_send_packet(card
, queue
, skb
, hdr
, 0, 0, elements
);
763 static netdev_tx_t
qeth_l2_hard_start_xmit(struct sk_buff
*skb
,
764 struct net_device
*dev
)
766 struct qeth_card
*card
= dev
->ml_priv
;
767 int cast_type
= qeth_l2_get_cast_type(card
, skb
);
768 int ipv
= qeth_get_ip_version(skb
);
769 struct qeth_qdio_out_q
*queue
;
770 int tx_bytes
= skb
->len
;
773 if (card
->qdio
.do_prio_queueing
|| (cast_type
&&
774 card
->info
.is_multicast_different
))
775 queue
= card
->qdio
.out_qs
[qeth_get_priority_queue(card
, skb
,
778 queue
= card
->qdio
.out_qs
[card
->qdio
.default_out_queue
];
780 if ((card
->state
!= CARD_STATE_UP
) || !card
->lan_online
) {
781 card
->stats
.tx_carrier_errors
++;
785 if (card
->options
.performance_stats
) {
786 card
->perf_stats
.outbound_cnt
++;
787 card
->perf_stats
.outbound_start_time
= qeth_get_micros();
789 netif_stop_queue(dev
);
791 switch (card
->info
.type
) {
792 case QETH_CARD_TYPE_OSN
:
793 rc
= qeth_l2_xmit_osn(card
, skb
, queue
);
795 case QETH_CARD_TYPE_IQD
:
796 rc
= qeth_l2_xmit_iqd(card
, skb
, queue
, cast_type
);
799 rc
= qeth_l2_xmit_osa(card
, skb
, queue
, cast_type
, ipv
);
803 card
->stats
.tx_packets
++;
804 card
->stats
.tx_bytes
+= tx_bytes
;
805 if (card
->options
.performance_stats
)
806 card
->perf_stats
.outbound_time
+= qeth_get_micros() -
807 card
->perf_stats
.outbound_start_time
;
808 netif_wake_queue(dev
);
810 } else if (rc
== -EBUSY
) {
811 return NETDEV_TX_BUSY
;
812 } /* else fall through */
815 card
->stats
.tx_dropped
++;
816 card
->stats
.tx_errors
++;
817 dev_kfree_skb_any(skb
);
818 netif_wake_queue(dev
);
822 static int __qeth_l2_open(struct net_device
*dev
)
824 struct qeth_card
*card
= dev
->ml_priv
;
827 QETH_CARD_TEXT(card
, 4, "qethopen");
828 if (card
->state
== CARD_STATE_UP
)
830 if (card
->state
!= CARD_STATE_SOFTSETUP
)
833 if ((card
->info
.type
!= QETH_CARD_TYPE_OSN
) &&
834 (!(card
->info
.mac_bits
& QETH_LAYER2_MAC_REGISTERED
))) {
835 QETH_CARD_TEXT(card
, 4, "nomacadr");
838 card
->data
.state
= CH_STATE_UP
;
839 card
->state
= CARD_STATE_UP
;
840 netif_start_queue(dev
);
842 if (qdio_stop_irq(card
->data
.ccwdev
, 0) >= 0) {
843 napi_enable(&card
->napi
);
844 napi_schedule(&card
->napi
);
850 static int qeth_l2_open(struct net_device
*dev
)
852 struct qeth_card
*card
= dev
->ml_priv
;
854 QETH_CARD_TEXT(card
, 5, "qethope_");
855 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
856 QETH_CARD_TEXT(card
, 3, "openREC");
859 return __qeth_l2_open(dev
);
862 static int qeth_l2_stop(struct net_device
*dev
)
864 struct qeth_card
*card
= dev
->ml_priv
;
866 QETH_CARD_TEXT(card
, 4, "qethstop");
867 netif_tx_disable(dev
);
868 if (card
->state
== CARD_STATE_UP
) {
869 card
->state
= CARD_STATE_SOFTSETUP
;
870 napi_disable(&card
->napi
);
875 static const struct device_type qeth_l2_devtype
= {
876 .name
= "qeth_layer2",
877 .groups
= qeth_l2_attr_groups
,
880 static int qeth_l2_probe_device(struct ccwgroup_device
*gdev
)
882 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
885 if (gdev
->dev
.type
== &qeth_generic_devtype
) {
886 rc
= qeth_l2_create_device_attributes(&gdev
->dev
);
890 INIT_LIST_HEAD(&card
->vid_list
);
891 hash_init(card
->mac_htable
);
892 card
->options
.layer2
= 1;
893 card
->info
.hwtrap
= 0;
894 qeth_l2_vnicc_set_defaults(card
);
898 static void qeth_l2_remove_device(struct ccwgroup_device
*cgdev
)
900 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
902 if (cgdev
->dev
.type
== &qeth_generic_devtype
)
903 qeth_l2_remove_device_attributes(&cgdev
->dev
);
904 qeth_set_allowed_threads(card
, 0, 1);
905 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
907 if (cgdev
->state
== CCWGROUP_ONLINE
)
908 qeth_l2_set_offline(cgdev
);
911 unregister_netdev(card
->dev
);
912 free_netdev(card
->dev
);
918 static const struct ethtool_ops qeth_l2_ethtool_ops
= {
919 .get_link
= ethtool_op_get_link
,
920 .get_strings
= qeth_core_get_strings
,
921 .get_ethtool_stats
= qeth_core_get_ethtool_stats
,
922 .get_sset_count
= qeth_core_get_sset_count
,
923 .get_drvinfo
= qeth_core_get_drvinfo
,
924 .get_link_ksettings
= qeth_core_ethtool_get_link_ksettings
,
927 static const struct ethtool_ops qeth_l2_osn_ops
= {
928 .get_strings
= qeth_core_get_strings
,
929 .get_ethtool_stats
= qeth_core_get_ethtool_stats
,
930 .get_sset_count
= qeth_core_get_sset_count
,
931 .get_drvinfo
= qeth_core_get_drvinfo
,
934 static const struct net_device_ops qeth_l2_netdev_ops
= {
935 .ndo_open
= qeth_l2_open
,
936 .ndo_stop
= qeth_l2_stop
,
937 .ndo_get_stats
= qeth_get_stats
,
938 .ndo_start_xmit
= qeth_l2_hard_start_xmit
,
939 .ndo_features_check
= qeth_features_check
,
940 .ndo_validate_addr
= eth_validate_addr
,
941 .ndo_set_rx_mode
= qeth_l2_set_rx_mode
,
942 .ndo_do_ioctl
= qeth_do_ioctl
,
943 .ndo_set_mac_address
= qeth_l2_set_mac_address
,
944 .ndo_change_mtu
= qeth_change_mtu
,
945 .ndo_vlan_rx_add_vid
= qeth_l2_vlan_rx_add_vid
,
946 .ndo_vlan_rx_kill_vid
= qeth_l2_vlan_rx_kill_vid
,
947 .ndo_tx_timeout
= qeth_tx_timeout
,
948 .ndo_fix_features
= qeth_fix_features
,
949 .ndo_set_features
= qeth_set_features
952 static int qeth_l2_setup_netdev(struct qeth_card
*card
)
954 switch (card
->info
.type
) {
955 case QETH_CARD_TYPE_IQD
:
956 card
->dev
= alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN
,
959 case QETH_CARD_TYPE_OSN
:
960 card
->dev
= alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN
,
964 card
->dev
= alloc_etherdev(0);
970 card
->dev
->ml_priv
= card
;
971 card
->dev
->priv_flags
|= IFF_UNICAST_FLT
;
972 card
->dev
->watchdog_timeo
= QETH_TX_TIMEOUT
;
973 card
->dev
->mtu
= card
->info
.initial_mtu
;
974 card
->dev
->min_mtu
= 64;
975 card
->dev
->max_mtu
= ETH_MAX_MTU
;
976 card
->dev
->dev_port
= card
->info
.portno
;
977 card
->dev
->netdev_ops
= &qeth_l2_netdev_ops
;
978 if (card
->info
.type
== QETH_CARD_TYPE_OSN
) {
979 card
->dev
->ethtool_ops
= &qeth_l2_osn_ops
;
980 card
->dev
->flags
|= IFF_NOARP
;
982 card
->dev
->ethtool_ops
= &qeth_l2_ethtool_ops
;
985 if (card
->info
.type
== QETH_CARD_TYPE_OSM
)
986 card
->dev
->features
|= NETIF_F_VLAN_CHALLENGED
;
988 card
->dev
->features
|= NETIF_F_HW_VLAN_CTAG_FILTER
;
990 if (card
->info
.type
!= QETH_CARD_TYPE_OSN
&&
991 card
->info
.type
!= QETH_CARD_TYPE_IQD
) {
992 card
->dev
->priv_flags
&= ~IFF_TX_SKB_SHARING
;
993 card
->dev
->needed_headroom
= sizeof(struct qeth_hdr
);
994 card
->dev
->hw_features
|= NETIF_F_SG
;
995 card
->dev
->vlan_features
|= NETIF_F_SG
;
998 if (card
->info
.type
== QETH_CARD_TYPE_OSD
&& !card
->info
.guestlan
) {
999 card
->dev
->features
|= NETIF_F_SG
;
1000 /* OSA 3S and earlier has no RX/TX support */
1001 if (qeth_is_supported(card
, IPA_OUTBOUND_CHECKSUM
)) {
1002 card
->dev
->hw_features
|= NETIF_F_IP_CSUM
;
1003 card
->dev
->vlan_features
|= NETIF_F_IP_CSUM
;
1006 if (qeth_is_supported6(card
, IPA_OUTBOUND_CHECKSUM_V6
)) {
1007 card
->dev
->hw_features
|= NETIF_F_IPV6_CSUM
;
1008 card
->dev
->vlan_features
|= NETIF_F_IPV6_CSUM
;
1010 if (qeth_is_supported(card
, IPA_INBOUND_CHECKSUM
) ||
1011 qeth_is_supported6(card
, IPA_INBOUND_CHECKSUM_V6
)) {
1012 card
->dev
->hw_features
|= NETIF_F_RXCSUM
;
1013 card
->dev
->vlan_features
|= NETIF_F_RXCSUM
;
1016 card
->info
.broadcast_capable
= 1;
1017 qeth_l2_request_initial_mac(card
);
1018 SET_NETDEV_DEV(card
->dev
, &card
->gdev
->dev
);
1019 netif_napi_add(card
->dev
, &card
->napi
, qeth_poll
, QETH_NAPI_WEIGHT
);
1020 netif_carrier_off(card
->dev
);
1021 return register_netdev(card
->dev
);
1024 static int qeth_l2_start_ipassists(struct qeth_card
*card
)
1026 /* configure isolation level */
1027 if (qeth_set_access_ctrl_online(card
, 0))
1032 static void qeth_l2_trace_features(struct qeth_card
*card
)
1034 /* Set BridgePort features */
1035 QETH_CARD_TEXT(card
, 2, "featuSBP");
1036 QETH_CARD_HEX(card
, 2, &card
->options
.sbp
.supported_funcs
,
1037 sizeof(card
->options
.sbp
.supported_funcs
));
1038 /* VNIC Characteristics features */
1039 QETH_CARD_TEXT(card
, 2, "feaVNICC");
1040 QETH_CARD_HEX(card
, 2, &card
->options
.vnicc
.sup_chars
,
1041 sizeof(card
->options
.vnicc
.sup_chars
));
1044 static int __qeth_l2_set_online(struct ccwgroup_device
*gdev
, int recovery_mode
)
1046 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
1048 enum qeth_card_states recover_flag
;
1050 mutex_lock(&card
->discipline_mutex
);
1051 mutex_lock(&card
->conf_mutex
);
1052 QETH_DBF_TEXT(SETUP
, 2, "setonlin");
1053 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1055 recover_flag
= card
->state
;
1056 rc
= qeth_core_hardsetup_card(card
);
1058 QETH_DBF_TEXT_(SETUP
, 2, "2err%04x", rc
);
1062 qeth_bridgeport_query_support(card
);
1063 if (card
->options
.sbp
.supported_funcs
)
1064 dev_info(&card
->gdev
->dev
,
1065 "The device represents a Bridge Capable Port\n");
1067 if (!card
->dev
&& qeth_l2_setup_netdev(card
)) {
1072 if (card
->info
.type
!= QETH_CARD_TYPE_OSN
&&
1073 !qeth_l2_send_setmac(card
, card
->dev
->dev_addr
))
1074 card
->info
.mac_bits
|= QETH_LAYER2_MAC_REGISTERED
;
1076 if (qeth_is_diagass_supported(card
, QETH_DIAGS_CMD_TRAP
)) {
1077 if (card
->info
.hwtrap
&&
1078 qeth_hw_trap(card
, QETH_DIAGS_TRAP_ARM
))
1079 card
->info
.hwtrap
= 0;
1081 card
->info
.hwtrap
= 0;
1083 /* for the rx_bcast characteristic, init VNICC after setmac */
1084 qeth_l2_vnicc_init(card
);
1086 qeth_trace_features(card
);
1087 qeth_l2_trace_features(card
);
1089 qeth_l2_setup_bridgeport_attrs(card
);
1091 card
->state
= CARD_STATE_HARDSETUP
;
1092 qeth_print_status_message(card
);
1095 QETH_DBF_TEXT(SETUP
, 2, "softsetp");
1097 if ((card
->info
.type
== QETH_CARD_TYPE_OSD
) ||
1098 (card
->info
.type
== QETH_CARD_TYPE_OSX
)) {
1099 rc
= qeth_l2_start_ipassists(card
);
1104 if (card
->info
.type
!= QETH_CARD_TYPE_OSN
)
1105 qeth_l2_process_vlans(card
);
1107 netif_tx_disable(card
->dev
);
1109 rc
= qeth_init_qdio_queues(card
);
1111 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
1115 card
->state
= CARD_STATE_SOFTSETUP
;
1116 if (card
->lan_online
)
1117 netif_carrier_on(card
->dev
);
1119 netif_carrier_off(card
->dev
);
1121 qeth_set_allowed_threads(card
, 0xffffffff, 0);
1123 qeth_enable_hw_features(card
->dev
);
1124 if (recover_flag
== CARD_STATE_RECOVER
) {
1125 if (recovery_mode
&&
1126 card
->info
.type
!= QETH_CARD_TYPE_OSN
) {
1127 __qeth_l2_open(card
->dev
);
1130 dev_open(card
->dev
);
1133 /* this also sets saved unicast addresses */
1134 qeth_l2_set_rx_mode(card
->dev
);
1136 /* let user_space know that device is online */
1137 kobject_uevent(&gdev
->dev
.kobj
, KOBJ_CHANGE
);
1138 mutex_unlock(&card
->conf_mutex
);
1139 mutex_unlock(&card
->discipline_mutex
);
1143 qeth_l2_stop_card(card
, 0);
1144 ccw_device_set_offline(CARD_DDEV(card
));
1145 ccw_device_set_offline(CARD_WDEV(card
));
1146 ccw_device_set_offline(CARD_RDEV(card
));
1147 qdio_free(CARD_DDEV(card
));
1148 if (recover_flag
== CARD_STATE_RECOVER
)
1149 card
->state
= CARD_STATE_RECOVER
;
1151 card
->state
= CARD_STATE_DOWN
;
1152 mutex_unlock(&card
->conf_mutex
);
1153 mutex_unlock(&card
->discipline_mutex
);
1157 static int qeth_l2_set_online(struct ccwgroup_device
*gdev
)
1159 return __qeth_l2_set_online(gdev
, 0);
1162 static int __qeth_l2_set_offline(struct ccwgroup_device
*cgdev
,
1165 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
1166 int rc
= 0, rc2
= 0, rc3
= 0;
1167 enum qeth_card_states recover_flag
;
1169 mutex_lock(&card
->discipline_mutex
);
1170 mutex_lock(&card
->conf_mutex
);
1171 QETH_DBF_TEXT(SETUP
, 3, "setoffl");
1172 QETH_DBF_HEX(SETUP
, 3, &card
, sizeof(void *));
1174 if (card
->dev
&& netif_carrier_ok(card
->dev
))
1175 netif_carrier_off(card
->dev
);
1176 recover_flag
= card
->state
;
1177 if ((!recovery_mode
&& card
->info
.hwtrap
) || card
->info
.hwtrap
== 2) {
1178 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
1179 card
->info
.hwtrap
= 1;
1181 qeth_l2_stop_card(card
, recovery_mode
);
1182 rc
= ccw_device_set_offline(CARD_DDEV(card
));
1183 rc2
= ccw_device_set_offline(CARD_WDEV(card
));
1184 rc3
= ccw_device_set_offline(CARD_RDEV(card
));
1186 rc
= (rc2
) ? rc2
: rc3
;
1188 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
1189 qdio_free(CARD_DDEV(card
));
1190 if (recover_flag
== CARD_STATE_UP
)
1191 card
->state
= CARD_STATE_RECOVER
;
1192 /* let user_space know that device is offline */
1193 kobject_uevent(&cgdev
->dev
.kobj
, KOBJ_CHANGE
);
1194 mutex_unlock(&card
->conf_mutex
);
1195 mutex_unlock(&card
->discipline_mutex
);
1199 static int qeth_l2_set_offline(struct ccwgroup_device
*cgdev
)
1201 return __qeth_l2_set_offline(cgdev
, 0);
1204 static int qeth_l2_recover(void *ptr
)
1206 struct qeth_card
*card
;
1209 card
= (struct qeth_card
*) ptr
;
1210 QETH_CARD_TEXT(card
, 2, "recover1");
1211 if (!qeth_do_run_thread(card
, QETH_RECOVER_THREAD
))
1213 QETH_CARD_TEXT(card
, 2, "recover2");
1214 dev_warn(&card
->gdev
->dev
,
1215 "A recovery process has been started for the device\n");
1216 qeth_set_recovery_task(card
);
1217 __qeth_l2_set_offline(card
->gdev
, 1);
1218 rc
= __qeth_l2_set_online(card
->gdev
, 1);
1220 dev_info(&card
->gdev
->dev
,
1221 "Device successfully recovered!\n");
1223 qeth_close_dev(card
);
1224 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
1225 "failed to recover an error on the device\n");
1227 qeth_clear_recovery_task(card
);
1228 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
1229 qeth_clear_thread_running_bit(card
, QETH_RECOVER_THREAD
);
1233 static int __init
qeth_l2_init(void)
1235 pr_info("register layer 2 discipline\n");
1239 static void __exit
qeth_l2_exit(void)
1241 pr_info("unregister layer 2 discipline\n");
1244 static int qeth_l2_pm_suspend(struct ccwgroup_device
*gdev
)
1246 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
1249 netif_device_detach(card
->dev
);
1250 qeth_set_allowed_threads(card
, 0, 1);
1251 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
1252 if (gdev
->state
== CCWGROUP_OFFLINE
)
1254 if (card
->state
== CARD_STATE_UP
) {
1255 if (card
->info
.hwtrap
)
1256 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
1257 __qeth_l2_set_offline(card
->gdev
, 1);
1259 __qeth_l2_set_offline(card
->gdev
, 0);
1263 static int qeth_l2_pm_resume(struct ccwgroup_device
*gdev
)
1265 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
1268 if (gdev
->state
== CCWGROUP_OFFLINE
)
1271 if (card
->state
== CARD_STATE_RECOVER
) {
1272 rc
= __qeth_l2_set_online(card
->gdev
, 1);
1275 dev_close(card
->dev
);
1279 rc
= __qeth_l2_set_online(card
->gdev
, 0);
1281 qeth_set_allowed_threads(card
, 0xffffffff, 0);
1283 netif_device_attach(card
->dev
);
1285 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
1286 "failed to recover an error on the device\n");
1290 /* Returns zero if the command is successfully "consumed" */
1291 static int qeth_l2_control_event(struct qeth_card
*card
,
1292 struct qeth_ipa_cmd
*cmd
)
1294 switch (cmd
->hdr
.command
) {
1295 case IPA_CMD_SETBRIDGEPORT_OSA
:
1296 case IPA_CMD_SETBRIDGEPORT_IQD
:
1297 if (cmd
->data
.sbp
.hdr
.command_code
==
1298 IPA_SBP_BRIDGE_PORT_STATE_CHANGE
) {
1299 qeth_bridge_state_change(card
, cmd
);
1303 case IPA_CMD_ADDRESS_CHANGE_NOTIF
:
1304 qeth_bridge_host_event(card
, cmd
);
1311 struct qeth_discipline qeth_l2_discipline
= {
1312 .devtype
= &qeth_l2_devtype
,
1313 .process_rx_buffer
= qeth_l2_process_inbound_buffer
,
1314 .recover
= qeth_l2_recover
,
1315 .setup
= qeth_l2_probe_device
,
1316 .remove
= qeth_l2_remove_device
,
1317 .set_online
= qeth_l2_set_online
,
1318 .set_offline
= qeth_l2_set_offline
,
1319 .freeze
= qeth_l2_pm_suspend
,
1320 .thaw
= qeth_l2_pm_resume
,
1321 .restore
= qeth_l2_pm_resume
,
1323 .control_event_handler
= qeth_l2_control_event
,
1325 EXPORT_SYMBOL_GPL(qeth_l2_discipline
);
1327 static int qeth_osn_send_control_data(struct qeth_card
*card
, int len
,
1328 struct qeth_cmd_buffer
*iob
)
1330 unsigned long flags
;
1333 QETH_CARD_TEXT(card
, 5, "osndctrd");
1335 wait_event(card
->wait_q
,
1336 atomic_cmpxchg(&card
->write
.irq_pending
, 0, 1) == 0);
1337 qeth_prepare_control_data(card
, len
, iob
);
1338 QETH_CARD_TEXT(card
, 6, "osnoirqp");
1339 spin_lock_irqsave(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
1340 rc
= ccw_device_start_timeout(CARD_WDEV(card
), &card
->write
.ccw
,
1341 (addr_t
) iob
, 0, 0, QETH_IPA_TIMEOUT
);
1342 spin_unlock_irqrestore(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
1344 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
1345 "ccw_device_start rc = %i\n", rc
);
1346 QETH_CARD_TEXT_(card
, 2, " err%d", rc
);
1347 qeth_release_buffer(iob
->channel
, iob
);
1348 atomic_set(&card
->write
.irq_pending
, 0);
1349 wake_up(&card
->wait_q
);
1354 static int qeth_osn_send_ipa_cmd(struct qeth_card
*card
,
1355 struct qeth_cmd_buffer
*iob
, int data_len
)
1359 QETH_CARD_TEXT(card
, 4, "osndipa");
1361 qeth_prepare_ipa_cmd(card
, iob
, QETH_PROT_OSN2
);
1362 s1
= (u16
)(IPA_PDU_HEADER_SIZE
+ data_len
);
1364 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob
->data
), &s1
, 2);
1365 memcpy(QETH_IPA_PDU_LEN_PDU1(iob
->data
), &s2
, 2);
1366 memcpy(QETH_IPA_PDU_LEN_PDU2(iob
->data
), &s2
, 2);
1367 memcpy(QETH_IPA_PDU_LEN_PDU3(iob
->data
), &s2
, 2);
1368 return qeth_osn_send_control_data(card
, s1
, iob
);
1371 int qeth_osn_assist(struct net_device
*dev
, void *data
, int data_len
)
1373 struct qeth_cmd_buffer
*iob
;
1374 struct qeth_card
*card
;
1378 card
= dev
->ml_priv
;
1381 QETH_CARD_TEXT(card
, 2, "osnsdmc");
1382 if (!qeth_card_hw_is_reachable(card
))
1384 iob
= qeth_wait_for_buffer(&card
->write
);
1385 memcpy(__ipa_cmd(iob
), data
, data_len
);
1386 return qeth_osn_send_ipa_cmd(card
, iob
, data_len
);
1388 EXPORT_SYMBOL(qeth_osn_assist
);
1390 int qeth_osn_register(unsigned char *read_dev_no
, struct net_device
**dev
,
1391 int (*assist_cb
)(struct net_device
*, void *),
1392 int (*data_cb
)(struct sk_buff
*))
1394 struct qeth_card
*card
;
1396 *dev
= qeth_l2_netdev_by_devno(read_dev_no
);
1399 card
= (*dev
)->ml_priv
;
1402 QETH_CARD_TEXT(card
, 2, "osnreg");
1403 if ((assist_cb
== NULL
) || (data_cb
== NULL
))
1405 card
->osn_info
.assist_cb
= assist_cb
;
1406 card
->osn_info
.data_cb
= data_cb
;
1409 EXPORT_SYMBOL(qeth_osn_register
);
1411 void qeth_osn_deregister(struct net_device
*dev
)
1413 struct qeth_card
*card
;
1417 card
= dev
->ml_priv
;
1420 QETH_CARD_TEXT(card
, 2, "osndereg");
1421 card
->osn_info
.assist_cb
= NULL
;
1422 card
->osn_info
.data_cb
= NULL
;
1425 EXPORT_SYMBOL(qeth_osn_deregister
);
1427 /* SETBRIDGEPORT support, async notifications */
1429 enum qeth_an_event_type
{anev_reg_unreg
, anev_abort
, anev_reset
};
1432 * qeth_bridge_emit_host_event() - bridgeport address change notification
1433 * @card: qeth_card structure pointer, for udev events.
1434 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1435 * and reset token and addr_lnid are unused and may be NULL.
1436 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1437 * object, 0 - addition of an object.
1438 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1439 * @token: "network token" structure identifying physical address of the port.
1440 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1442 * This function is called when registrations and deregistrations are
1443 * reported by the hardware, and also when notifications are enabled -
1444 * for all currently registered addresses.
1446 static void qeth_bridge_emit_host_event(struct qeth_card
*card
,
1447 enum qeth_an_event_type evtype
,
1448 u8 code
, struct net_if_token
*token
, struct mac_addr_lnid
*addr_lnid
)
1455 case anev_reg_unreg
:
1456 snprintf(str
[i
], sizeof(str
[i
]), "BRIDGEDHOST=%s",
1457 (code
& IPA_ADDR_CHANGE_CODE_REMOVAL
)
1458 ? "deregister" : "register");
1459 env
[i
] = str
[i
]; i
++;
1460 if (code
& IPA_ADDR_CHANGE_CODE_VLANID
) {
1461 snprintf(str
[i
], sizeof(str
[i
]), "VLAN=%d",
1463 env
[i
] = str
[i
]; i
++;
1465 if (code
& IPA_ADDR_CHANGE_CODE_MACADDR
) {
1466 snprintf(str
[i
], sizeof(str
[i
]), "MAC=%pM",
1468 env
[i
] = str
[i
]; i
++;
1470 snprintf(str
[i
], sizeof(str
[i
]), "NTOK_BUSID=%x.%x.%04x",
1471 token
->cssid
, token
->ssid
, token
->devnum
);
1472 env
[i
] = str
[i
]; i
++;
1473 snprintf(str
[i
], sizeof(str
[i
]), "NTOK_IID=%02x", token
->iid
);
1474 env
[i
] = str
[i
]; i
++;
1475 snprintf(str
[i
], sizeof(str
[i
]), "NTOK_CHPID=%02x",
1477 env
[i
] = str
[i
]; i
++;
1478 snprintf(str
[i
], sizeof(str
[i
]), "NTOK_CHID=%04x", token
->chid
);
1479 env
[i
] = str
[i
]; i
++;
1482 snprintf(str
[i
], sizeof(str
[i
]), "BRIDGEDHOST=abort");
1483 env
[i
] = str
[i
]; i
++;
1486 snprintf(str
[i
], sizeof(str
[i
]), "BRIDGEDHOST=reset");
1487 env
[i
] = str
[i
]; i
++;
1491 kobject_uevent_env(&card
->gdev
->dev
.kobj
, KOBJ_CHANGE
, env
);
1494 struct qeth_bridge_state_data
{
1495 struct work_struct worker
;
1496 struct qeth_card
*card
;
1497 struct qeth_sbp_state_change qports
;
1500 static void qeth_bridge_state_change_worker(struct work_struct
*work
)
1502 struct qeth_bridge_state_data
*data
=
1503 container_of(work
, struct qeth_bridge_state_data
, worker
);
1504 /* We are only interested in the first entry - local port */
1505 struct qeth_sbp_port_entry
*entry
= &data
->qports
.entry
[0];
1506 char env_locrem
[32];
1516 /* Role should not change by itself, but if it did, */
1517 /* information from the hardware is authoritative. */
1518 mutex_lock(&data
->card
->conf_mutex
);
1519 data
->card
->options
.sbp
.role
= entry
->role
;
1520 mutex_unlock(&data
->card
->conf_mutex
);
1522 snprintf(env_locrem
, sizeof(env_locrem
), "BRIDGEPORT=statechange");
1523 snprintf(env_role
, sizeof(env_role
), "ROLE=%s",
1524 (entry
->role
== QETH_SBP_ROLE_NONE
) ? "none" :
1525 (entry
->role
== QETH_SBP_ROLE_PRIMARY
) ? "primary" :
1526 (entry
->role
== QETH_SBP_ROLE_SECONDARY
) ? "secondary" :
1528 snprintf(env_state
, sizeof(env_state
), "STATE=%s",
1529 (entry
->state
== QETH_SBP_STATE_INACTIVE
) ? "inactive" :
1530 (entry
->state
== QETH_SBP_STATE_STANDBY
) ? "standby" :
1531 (entry
->state
== QETH_SBP_STATE_ACTIVE
) ? "active" :
1533 kobject_uevent_env(&data
->card
->gdev
->dev
.kobj
,
1538 static void qeth_bridge_state_change(struct qeth_card
*card
,
1539 struct qeth_ipa_cmd
*cmd
)
1541 struct qeth_sbp_state_change
*qports
=
1542 &cmd
->data
.sbp
.data
.state_change
;
1543 struct qeth_bridge_state_data
*data
;
1546 QETH_CARD_TEXT(card
, 2, "brstchng");
1547 if (qports
->entry_length
!= sizeof(struct qeth_sbp_port_entry
)) {
1548 QETH_CARD_TEXT_(card
, 2, "BPsz%04x", qports
->entry_length
);
1551 extrasize
= sizeof(struct qeth_sbp_port_entry
) * qports
->num_entries
;
1552 data
= kzalloc(sizeof(struct qeth_bridge_state_data
) + extrasize
,
1555 QETH_CARD_TEXT(card
, 2, "BPSalloc");
1558 INIT_WORK(&data
->worker
, qeth_bridge_state_change_worker
);
1560 memcpy(&data
->qports
, qports
,
1561 sizeof(struct qeth_sbp_state_change
) + extrasize
);
1562 queue_work(qeth_wq
, &data
->worker
);
1565 struct qeth_bridge_host_data
{
1566 struct work_struct worker
;
1567 struct qeth_card
*card
;
1568 struct qeth_ipacmd_addr_change hostevs
;
1571 static void qeth_bridge_host_event_worker(struct work_struct
*work
)
1573 struct qeth_bridge_host_data
*data
=
1574 container_of(work
, struct qeth_bridge_host_data
, worker
);
1577 if (data
->hostevs
.lost_event_mask
) {
1578 dev_info(&data
->card
->gdev
->dev
,
1579 "Address notification from the Bridge Port stopped %s (%s)\n",
1580 data
->card
->dev
->name
,
1581 (data
->hostevs
.lost_event_mask
== 0x01)
1583 : (data
->hostevs
.lost_event_mask
== 0x02)
1584 ? "Bridge port state change"
1585 : "Unknown reason");
1586 mutex_lock(&data
->card
->conf_mutex
);
1587 data
->card
->options
.sbp
.hostnotification
= 0;
1588 mutex_unlock(&data
->card
->conf_mutex
);
1589 qeth_bridge_emit_host_event(data
->card
, anev_abort
,
1592 for (i
= 0; i
< data
->hostevs
.num_entries
; i
++) {
1593 struct qeth_ipacmd_addr_change_entry
*entry
=
1594 &data
->hostevs
.entry
[i
];
1595 qeth_bridge_emit_host_event(data
->card
,
1598 &entry
->token
, &entry
->addr_lnid
);
1603 static void qeth_bridge_host_event(struct qeth_card
*card
,
1604 struct qeth_ipa_cmd
*cmd
)
1606 struct qeth_ipacmd_addr_change
*hostevs
=
1607 &cmd
->data
.addrchange
;
1608 struct qeth_bridge_host_data
*data
;
1611 QETH_CARD_TEXT(card
, 2, "brhostev");
1612 if (cmd
->hdr
.return_code
!= 0x0000) {
1613 if (cmd
->hdr
.return_code
== 0x0010) {
1614 if (hostevs
->lost_event_mask
== 0x00)
1615 hostevs
->lost_event_mask
= 0xff;
1617 QETH_CARD_TEXT_(card
, 2, "BPHe%04x",
1618 cmd
->hdr
.return_code
);
1622 extrasize
= sizeof(struct qeth_ipacmd_addr_change_entry
) *
1623 hostevs
->num_entries
;
1624 data
= kzalloc(sizeof(struct qeth_bridge_host_data
) + extrasize
,
1627 QETH_CARD_TEXT(card
, 2, "BPHalloc");
1630 INIT_WORK(&data
->worker
, qeth_bridge_host_event_worker
);
1632 memcpy(&data
->hostevs
, hostevs
,
1633 sizeof(struct qeth_ipacmd_addr_change
) + extrasize
);
1634 queue_work(qeth_wq
, &data
->worker
);
1637 /* SETBRIDGEPORT support; sending commands */
1639 struct _qeth_sbp_cbctl
{
1645 enum qeth_sbp_roles
*role
;
1646 enum qeth_sbp_states
*state
;
1652 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes.
1653 * @card: qeth_card structure pointer, for debug messages.
1654 * @cbctl: state structure with hardware return codes.
1655 * @setcmd: IPA command code
1657 * Returns negative errno-compatible error indication or 0 on success.
1659 static int qeth_bridgeport_makerc(struct qeth_card
*card
,
1660 struct _qeth_sbp_cbctl
*cbctl
, enum qeth_ipa_sbp_cmd setcmd
)
1663 int is_iqd
= (card
->info
.type
== QETH_CARD_TYPE_IQD
);
1665 if ((is_iqd
&& (cbctl
->ipa_rc
== IPA_RC_SUCCESS
)) ||
1666 (!is_iqd
&& (cbctl
->ipa_rc
== cbctl
->cmd_rc
)))
1667 switch (cbctl
->cmd_rc
) {
1668 case IPA_RC_SUCCESS
:
1671 case IPA_RC_L2_UNSUPPORTED_CMD
:
1672 case IPA_RC_UNSUPPORTED_COMMAND
:
1675 case IPA_RC_SBP_OSA_NOT_CONFIGURED
:
1676 case IPA_RC_SBP_IQD_NOT_CONFIGURED
:
1677 rc
= -ENODEV
; /* maybe not the best code here? */
1678 dev_err(&card
->gdev
->dev
,
1679 "The device is not configured as a Bridge Port\n");
1681 case IPA_RC_SBP_OSA_OS_MISMATCH
:
1682 case IPA_RC_SBP_IQD_OS_MISMATCH
:
1684 dev_err(&card
->gdev
->dev
,
1685 "A Bridge Port is already configured by a different operating system\n");
1687 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY
:
1688 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY
:
1690 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT
:
1692 dev_err(&card
->gdev
->dev
,
1693 "The LAN already has a primary Bridge Port\n");
1695 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT
:
1697 dev_err(&card
->gdev
->dev
,
1698 "The device is already a primary Bridge Port\n");
1704 case IPA_RC_SBP_OSA_CURRENT_SECOND
:
1705 case IPA_RC_SBP_IQD_CURRENT_SECOND
:
1707 dev_err(&card
->gdev
->dev
,
1708 "The device is already a secondary Bridge Port\n");
1710 case IPA_RC_SBP_OSA_LIMIT_SECOND
:
1711 case IPA_RC_SBP_IQD_LIMIT_SECOND
:
1713 dev_err(&card
->gdev
->dev
,
1714 "The LAN cannot have more secondary Bridge Ports\n");
1716 case IPA_RC_SBP_OSA_CURRENT_PRIMARY
:
1717 case IPA_RC_SBP_IQD_CURRENT_PRIMARY
:
1719 dev_err(&card
->gdev
->dev
,
1720 "The device is already a primary Bridge Port\n");
1722 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN
:
1723 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN
:
1725 dev_err(&card
->gdev
->dev
,
1726 "The device is not authorized to be a Bridge Port\n");
1732 switch (cbctl
->ipa_rc
) {
1733 case IPA_RC_NOTSUPP
:
1736 case IPA_RC_UNSUPPORTED_COMMAND
:
1744 QETH_CARD_TEXT_(card
, 2, "SBPi%04x", cbctl
->ipa_rc
);
1745 QETH_CARD_TEXT_(card
, 2, "SBPc%04x", cbctl
->cmd_rc
);
1750 static struct qeth_cmd_buffer
*qeth_sbp_build_cmd(struct qeth_card
*card
,
1751 enum qeth_ipa_sbp_cmd sbp_cmd
,
1752 unsigned int cmd_length
)
1754 enum qeth_ipa_cmds ipa_cmd
= (card
->info
.type
== QETH_CARD_TYPE_IQD
) ?
1755 IPA_CMD_SETBRIDGEPORT_IQD
:
1756 IPA_CMD_SETBRIDGEPORT_OSA
;
1757 struct qeth_cmd_buffer
*iob
;
1758 struct qeth_ipa_cmd
*cmd
;
1760 iob
= qeth_get_ipacmd_buffer(card
, ipa_cmd
, 0);
1763 cmd
= __ipa_cmd(iob
);
1764 cmd
->data
.sbp
.hdr
.cmdlength
= sizeof(struct qeth_ipacmd_sbp_hdr
) +
1766 cmd
->data
.sbp
.hdr
.command_code
= sbp_cmd
;
1767 cmd
->data
.sbp
.hdr
.used_total
= 1;
1768 cmd
->data
.sbp
.hdr
.seq_no
= 1;
1772 static int qeth_bridgeport_query_support_cb(struct qeth_card
*card
,
1773 struct qeth_reply
*reply
, unsigned long data
)
1775 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
1776 struct _qeth_sbp_cbctl
*cbctl
= (struct _qeth_sbp_cbctl
*)reply
->param
;
1777 QETH_CARD_TEXT(card
, 2, "brqsupcb");
1778 cbctl
->ipa_rc
= cmd
->hdr
.return_code
;
1779 cbctl
->cmd_rc
= cmd
->data
.sbp
.hdr
.return_code
;
1780 if ((cbctl
->ipa_rc
== 0) && (cbctl
->cmd_rc
== 0)) {
1781 cbctl
->data
.supported
=
1782 cmd
->data
.sbp
.data
.query_cmds_supp
.supported_cmds
;
1784 cbctl
->data
.supported
= 0;
1790 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1791 * @card: qeth_card structure pointer.
1793 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1794 * strucutre: card->options.sbp.supported_funcs.
1796 static void qeth_bridgeport_query_support(struct qeth_card
*card
)
1798 struct qeth_cmd_buffer
*iob
;
1799 struct _qeth_sbp_cbctl cbctl
;
1801 QETH_CARD_TEXT(card
, 2, "brqsuppo");
1802 iob
= qeth_sbp_build_cmd(card
, IPA_SBP_QUERY_COMMANDS_SUPPORTED
,
1803 sizeof(struct qeth_sbp_query_cmds_supp
));
1806 if (qeth_send_ipa_cmd(card
, iob
, qeth_bridgeport_query_support_cb
,
1808 qeth_bridgeport_makerc(card
, &cbctl
,
1809 IPA_SBP_QUERY_COMMANDS_SUPPORTED
)) {
1810 /* non-zero makerc signifies failure, and produce messages */
1811 card
->options
.sbp
.role
= QETH_SBP_ROLE_NONE
;
1814 card
->options
.sbp
.supported_funcs
= cbctl
.data
.supported
;
1817 static int qeth_bridgeport_query_ports_cb(struct qeth_card
*card
,
1818 struct qeth_reply
*reply
, unsigned long data
)
1820 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
1821 struct qeth_sbp_query_ports
*qports
= &cmd
->data
.sbp
.data
.query_ports
;
1822 struct _qeth_sbp_cbctl
*cbctl
= (struct _qeth_sbp_cbctl
*)reply
->param
;
1824 QETH_CARD_TEXT(card
, 2, "brqprtcb");
1825 cbctl
->ipa_rc
= cmd
->hdr
.return_code
;
1826 cbctl
->cmd_rc
= cmd
->data
.sbp
.hdr
.return_code
;
1827 if ((cbctl
->ipa_rc
!= 0) || (cbctl
->cmd_rc
!= 0))
1829 if (qports
->entry_length
!= sizeof(struct qeth_sbp_port_entry
)) {
1830 cbctl
->cmd_rc
= 0xffff;
1831 QETH_CARD_TEXT_(card
, 2, "SBPs%04x", qports
->entry_length
);
1834 /* first entry contains the state of the local port */
1835 if (qports
->num_entries
> 0) {
1836 if (cbctl
->data
.qports
.role
)
1837 *cbctl
->data
.qports
.role
= qports
->entry
[0].role
;
1838 if (cbctl
->data
.qports
.state
)
1839 *cbctl
->data
.qports
.state
= qports
->entry
[0].state
;
1845 * qeth_bridgeport_query_ports() - query local bridgeport status.
1846 * @card: qeth_card structure pointer.
1847 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1848 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1850 * Returns negative errno-compatible error indication or 0 on success.
1852 * 'role' and 'state' are not updated in case of hardware operation failure.
1854 int qeth_bridgeport_query_ports(struct qeth_card
*card
,
1855 enum qeth_sbp_roles
*role
, enum qeth_sbp_states
*state
)
1858 struct qeth_cmd_buffer
*iob
;
1859 struct _qeth_sbp_cbctl cbctl
= {
1868 QETH_CARD_TEXT(card
, 2, "brqports");
1869 if (!(card
->options
.sbp
.supported_funcs
& IPA_SBP_QUERY_BRIDGE_PORTS
))
1871 iob
= qeth_sbp_build_cmd(card
, IPA_SBP_QUERY_BRIDGE_PORTS
, 0);
1874 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_bridgeport_query_ports_cb
,
1878 return qeth_bridgeport_makerc(card
, &cbctl
, IPA_SBP_QUERY_BRIDGE_PORTS
);
1880 EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports
);
1882 static int qeth_bridgeport_set_cb(struct qeth_card
*card
,
1883 struct qeth_reply
*reply
, unsigned long data
)
1885 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*)data
;
1886 struct _qeth_sbp_cbctl
*cbctl
= (struct _qeth_sbp_cbctl
*)reply
->param
;
1887 QETH_CARD_TEXT(card
, 2, "brsetrcb");
1888 cbctl
->ipa_rc
= cmd
->hdr
.return_code
;
1889 cbctl
->cmd_rc
= cmd
->data
.sbp
.hdr
.return_code
;
1894 * qeth_bridgeport_setrole() - Assign primary role to the port.
1895 * @card: qeth_card structure pointer.
1896 * @role: Role to assign.
1898 * Returns negative errno-compatible error indication or 0 on success.
1900 int qeth_bridgeport_setrole(struct qeth_card
*card
, enum qeth_sbp_roles role
)
1904 struct qeth_cmd_buffer
*iob
;
1905 struct _qeth_sbp_cbctl cbctl
;
1906 enum qeth_ipa_sbp_cmd setcmd
;
1908 QETH_CARD_TEXT(card
, 2, "brsetrol");
1910 case QETH_SBP_ROLE_NONE
:
1911 setcmd
= IPA_SBP_RESET_BRIDGE_PORT_ROLE
;
1912 cmdlength
= sizeof(struct qeth_sbp_reset_role
);
1914 case QETH_SBP_ROLE_PRIMARY
:
1915 setcmd
= IPA_SBP_SET_PRIMARY_BRIDGE_PORT
;
1916 cmdlength
= sizeof(struct qeth_sbp_set_primary
);
1918 case QETH_SBP_ROLE_SECONDARY
:
1919 setcmd
= IPA_SBP_SET_SECONDARY_BRIDGE_PORT
;
1920 cmdlength
= sizeof(struct qeth_sbp_set_secondary
);
1925 if (!(card
->options
.sbp
.supported_funcs
& setcmd
))
1927 iob
= qeth_sbp_build_cmd(card
, setcmd
, cmdlength
);
1930 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_bridgeport_set_cb
,
1934 return qeth_bridgeport_makerc(card
, &cbctl
, setcmd
);
1938 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1939 * @card: qeth_card structure pointer, for debug messages.
1941 * Returns negative errno-compatible error indication or 0 on success.
1943 static int qeth_anset_makerc(struct qeth_card
*card
, int pnso_rc
, u16 response
)
1956 dev_err(&card
->gdev
->dev
,
1957 "Setting address notification failed\n");
1969 QETH_CARD_TEXT_(card
, 2, "SBPp%04x", pnso_rc
);
1970 QETH_CARD_TEXT_(card
, 2, "SBPr%04x", response
);
1975 static void qeth_bridgeport_an_set_cb(void *priv
,
1976 enum qdio_brinfo_entry_type type
, void *entry
)
1978 struct qeth_card
*card
= (struct qeth_card
*)priv
;
1979 struct qdio_brinfo_entry_l2
*l2entry
;
1982 if (type
!= l2_addr_lnid
) {
1987 l2entry
= (struct qdio_brinfo_entry_l2
*)entry
;
1988 code
= IPA_ADDR_CHANGE_CODE_MACADDR
;
1989 if (l2entry
->addr_lnid
.lnid
)
1990 code
|= IPA_ADDR_CHANGE_CODE_VLANID
;
1991 qeth_bridge_emit_host_event(card
, anev_reg_unreg
, code
,
1992 (struct net_if_token
*)&l2entry
->nit
,
1993 (struct mac_addr_lnid
*)&l2entry
->addr_lnid
);
1997 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1998 * @card: qeth_card structure pointer.
1999 * @enable: 0 - disable, non-zero - enable notifications
2001 * Returns negative errno-compatible error indication or 0 on success.
2003 * On enable, emits a series of address notifications udev events for all
2004 * currently registered hosts.
2006 int qeth_bridgeport_an_set(struct qeth_card
*card
, int enable
)
2010 struct ccw_device
*ddev
;
2011 struct subchannel_id schid
;
2015 if (!card
->options
.sbp
.supported_funcs
)
2017 ddev
= CARD_DDEV(card
);
2018 ccw_device_get_schid(ddev
, &schid
);
2021 qeth_bridge_emit_host_event(card
, anev_reset
, 0, NULL
, NULL
);
2022 rc
= qdio_pnso_brinfo(schid
, 1, &response
,
2023 qeth_bridgeport_an_set_cb
, card
);
2025 rc
= qdio_pnso_brinfo(schid
, 0, &response
, NULL
, NULL
);
2026 return qeth_anset_makerc(card
, rc
, response
);
2028 EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set
);
2030 static bool qeth_bridgeport_is_in_use(struct qeth_card
*card
)
2032 return (card
->options
.sbp
.role
|| card
->options
.sbp
.reflect_promisc
||
2033 card
->options
.sbp
.hostnotification
);
2036 /* VNIC Characteristics support */
2038 /* handle VNICC IPA command return codes; convert to error codes */
2039 static int qeth_l2_vnicc_makerc(struct qeth_card
*card
, int ipa_rc
)
2044 case IPA_RC_SUCCESS
:
2046 case IPA_RC_L2_UNSUPPORTED_CMD
:
2047 case IPA_RC_NOTSUPP
:
2050 case IPA_RC_VNICC_OOSEQ
:
2053 case IPA_RC_VNICC_VNICBP
:
2056 case IPA_RC_L2_ADDR_TABLE_FULL
:
2059 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP
:
2066 QETH_CARD_TEXT_(card
, 2, "err%04x", ipa_rc
);
2070 /* generic VNICC request call back control */
2071 struct _qeth_l2_vnicc_request_cbctl
{
2085 /* generic VNICC request call back */
2086 static int qeth_l2_vnicc_request_cb(struct qeth_card
*card
,
2087 struct qeth_reply
*reply
,
2090 struct _qeth_l2_vnicc_request_cbctl
*cbctl
=
2091 (struct _qeth_l2_vnicc_request_cbctl
*) reply
->param
;
2092 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
2093 struct qeth_ipacmd_vnicc
*rep
= &cmd
->data
.vnicc
;
2095 QETH_CARD_TEXT(card
, 2, "vniccrcb");
2096 if (cmd
->hdr
.return_code
)
2098 /* return results to caller */
2099 card
->options
.vnicc
.sup_chars
= rep
->hdr
.sup
;
2100 card
->options
.vnicc
.cur_chars
= rep
->hdr
.cur
;
2102 if (cbctl
->sub_cmd
== IPA_VNICC_QUERY_CMDS
)
2103 *cbctl
->result
.sup_cmds
= rep
->query_cmds
.sup_cmds
;
2105 if (cbctl
->sub_cmd
== IPA_VNICC_GET_TIMEOUT
)
2106 *cbctl
->result
.timeout
= rep
->getset_timeout
.timeout
;
2111 /* generic VNICC request */
2112 static int qeth_l2_vnicc_request(struct qeth_card
*card
,
2113 struct _qeth_l2_vnicc_request_cbctl
*cbctl
)
2115 struct qeth_ipacmd_vnicc
*req
;
2116 struct qeth_cmd_buffer
*iob
;
2117 struct qeth_ipa_cmd
*cmd
;
2120 QETH_CARD_TEXT(card
, 2, "vniccreq");
2122 /* get new buffer for request */
2123 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_VNICC
, 0);
2127 /* create header for request */
2128 cmd
= __ipa_cmd(iob
);
2129 req
= &cmd
->data
.vnicc
;
2131 /* create sub command header for request */
2132 req
->sub_hdr
.data_length
= sizeof(req
->sub_hdr
);
2133 req
->sub_hdr
.sub_command
= cbctl
->sub_cmd
;
2135 /* create sub command specific request fields */
2136 switch (cbctl
->sub_cmd
) {
2137 case IPA_VNICC_QUERY_CHARS
:
2139 case IPA_VNICC_QUERY_CMDS
:
2140 req
->sub_hdr
.data_length
+= sizeof(req
->query_cmds
);
2141 req
->query_cmds
.vnic_char
= cbctl
->param
.vnic_char
;
2143 case IPA_VNICC_ENABLE
:
2144 case IPA_VNICC_DISABLE
:
2145 req
->sub_hdr
.data_length
+= sizeof(req
->set_char
);
2146 req
->set_char
.vnic_char
= cbctl
->param
.vnic_char
;
2148 case IPA_VNICC_SET_TIMEOUT
:
2149 req
->getset_timeout
.timeout
= cbctl
->param
.timeout
;
2151 case IPA_VNICC_GET_TIMEOUT
:
2152 req
->sub_hdr
.data_length
+= sizeof(req
->getset_timeout
);
2153 req
->getset_timeout
.vnic_char
= cbctl
->param
.vnic_char
;
2156 qeth_release_buffer(iob
->channel
, iob
);
2161 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l2_vnicc_request_cb
,
2164 return qeth_l2_vnicc_makerc(card
, rc
);
2167 /* VNICC query VNIC characteristics request */
2168 static int qeth_l2_vnicc_query_chars(struct qeth_card
*card
)
2170 struct _qeth_l2_vnicc_request_cbctl cbctl
;
2172 /* prepare callback control */
2173 cbctl
.sub_cmd
= IPA_VNICC_QUERY_CHARS
;
2175 QETH_CARD_TEXT(card
, 2, "vniccqch");
2176 return qeth_l2_vnicc_request(card
, &cbctl
);
2179 /* VNICC query sub commands request */
2180 static int qeth_l2_vnicc_query_cmds(struct qeth_card
*card
, u32 vnic_char
,
2183 struct _qeth_l2_vnicc_request_cbctl cbctl
;
2185 /* prepare callback control */
2186 cbctl
.sub_cmd
= IPA_VNICC_QUERY_CMDS
;
2187 cbctl
.param
.vnic_char
= vnic_char
;
2188 cbctl
.result
.sup_cmds
= sup_cmds
;
2190 QETH_CARD_TEXT(card
, 2, "vniccqcm");
2191 return qeth_l2_vnicc_request(card
, &cbctl
);
2194 /* VNICC enable/disable characteristic request */
2195 static int qeth_l2_vnicc_set_char(struct qeth_card
*card
, u32 vnic_char
,
2198 struct _qeth_l2_vnicc_request_cbctl cbctl
;
2200 /* prepare callback control */
2201 cbctl
.sub_cmd
= cmd
;
2202 cbctl
.param
.vnic_char
= vnic_char
;
2204 QETH_CARD_TEXT(card
, 2, "vniccedc");
2205 return qeth_l2_vnicc_request(card
, &cbctl
);
2208 /* VNICC get/set timeout for characteristic request */
2209 static int qeth_l2_vnicc_getset_timeout(struct qeth_card
*card
, u32 vnicc
,
2210 u32 cmd
, u32
*timeout
)
2212 struct _qeth_l2_vnicc_request_cbctl cbctl
;
2214 /* prepare callback control */
2215 cbctl
.sub_cmd
= cmd
;
2216 cbctl
.param
.vnic_char
= vnicc
;
2217 if (cmd
== IPA_VNICC_SET_TIMEOUT
)
2218 cbctl
.param
.timeout
= *timeout
;
2219 if (cmd
== IPA_VNICC_GET_TIMEOUT
)
2220 cbctl
.result
.timeout
= timeout
;
2222 QETH_CARD_TEXT(card
, 2, "vniccgst");
2223 return qeth_l2_vnicc_request(card
, &cbctl
);
2226 /* set current VNICC flag state; called from sysfs store function */
2227 int qeth_l2_vnicc_set_state(struct qeth_card
*card
, u32 vnicc
, bool state
)
2232 QETH_CARD_TEXT(card
, 2, "vniccsch");
2234 /* do not change anything if BridgePort is enabled */
2235 if (qeth_bridgeport_is_in_use(card
))
2238 /* check if characteristic and enable/disable are supported */
2239 if (!(card
->options
.vnicc
.sup_chars
& vnicc
) ||
2240 !(card
->options
.vnicc
.set_char_sup
& vnicc
))
2243 /* set enable/disable command and store wanted characteristic */
2245 cmd
= IPA_VNICC_ENABLE
;
2246 card
->options
.vnicc
.wanted_chars
|= vnicc
;
2248 cmd
= IPA_VNICC_DISABLE
;
2249 card
->options
.vnicc
.wanted_chars
&= ~vnicc
;
2252 /* do we need to do anything? */
2253 if (card
->options
.vnicc
.cur_chars
== card
->options
.vnicc
.wanted_chars
)
2256 /* if card is not ready, simply stop here */
2257 if (!qeth_card_hw_is_reachable(card
)) {
2259 card
->options
.vnicc
.cur_chars
|= vnicc
;
2261 card
->options
.vnicc
.cur_chars
&= ~vnicc
;
2265 rc
= qeth_l2_vnicc_set_char(card
, vnicc
, cmd
);
2267 card
->options
.vnicc
.wanted_chars
=
2268 card
->options
.vnicc
.cur_chars
;
2270 /* successful online VNICC change; handle special cases */
2271 if (state
&& vnicc
== QETH_VNICC_RX_BCAST
)
2272 card
->options
.vnicc
.rx_bcast_enabled
= true;
2273 if (!state
&& vnicc
== QETH_VNICC_LEARNING
)
2274 qeth_l2_vnicc_recover_timeout(card
, vnicc
,
2275 &card
->options
.vnicc
.learning_timeout
);
2281 /* get current VNICC flag state; called from sysfs show function */
2282 int qeth_l2_vnicc_get_state(struct qeth_card
*card
, u32 vnicc
, bool *state
)
2286 QETH_CARD_TEXT(card
, 2, "vniccgch");
2288 /* do not get anything if BridgePort is enabled */
2289 if (qeth_bridgeport_is_in_use(card
))
2292 /* check if characteristic is supported */
2293 if (!(card
->options
.vnicc
.sup_chars
& vnicc
))
2296 /* if card is ready, query current VNICC state */
2297 if (qeth_card_hw_is_reachable(card
))
2298 rc
= qeth_l2_vnicc_query_chars(card
);
2300 *state
= (card
->options
.vnicc
.cur_chars
& vnicc
) ? true : false;
2304 /* set VNICC timeout; called from sysfs store function. Currently, only learning
2307 int qeth_l2_vnicc_set_timeout(struct qeth_card
*card
, u32 timeout
)
2311 QETH_CARD_TEXT(card
, 2, "vniccsto");
2313 /* do not change anything if BridgePort is enabled */
2314 if (qeth_bridgeport_is_in_use(card
))
2317 /* check if characteristic and set_timeout are supported */
2318 if (!(card
->options
.vnicc
.sup_chars
& QETH_VNICC_LEARNING
) ||
2319 !(card
->options
.vnicc
.getset_timeout_sup
& QETH_VNICC_LEARNING
))
2322 /* do we need to do anything? */
2323 if (card
->options
.vnicc
.learning_timeout
== timeout
)
2326 /* if card is not ready, simply store the value internally and return */
2327 if (!qeth_card_hw_is_reachable(card
)) {
2328 card
->options
.vnicc
.learning_timeout
= timeout
;
2332 /* send timeout value to card; if successful, store value internally */
2333 rc
= qeth_l2_vnicc_getset_timeout(card
, QETH_VNICC_LEARNING
,
2334 IPA_VNICC_SET_TIMEOUT
, &timeout
);
2336 card
->options
.vnicc
.learning_timeout
= timeout
;
2341 /* get current VNICC timeout; called from sysfs show function. Currently, only
2342 * learning supports timeout
2344 int qeth_l2_vnicc_get_timeout(struct qeth_card
*card
, u32
*timeout
)
2348 QETH_CARD_TEXT(card
, 2, "vniccgto");
2350 /* do not get anything if BridgePort is enabled */
2351 if (qeth_bridgeport_is_in_use(card
))
2354 /* check if characteristic and get_timeout are supported */
2355 if (!(card
->options
.vnicc
.sup_chars
& QETH_VNICC_LEARNING
) ||
2356 !(card
->options
.vnicc
.getset_timeout_sup
& QETH_VNICC_LEARNING
))
2358 /* if card is ready, get timeout. Otherwise, just return stored value */
2359 *timeout
= card
->options
.vnicc
.learning_timeout
;
2360 if (qeth_card_hw_is_reachable(card
))
2361 rc
= qeth_l2_vnicc_getset_timeout(card
, QETH_VNICC_LEARNING
,
2362 IPA_VNICC_GET_TIMEOUT
,
2368 /* check if VNICC is currently enabled */
2369 bool qeth_l2_vnicc_is_in_use(struct qeth_card
*card
)
2371 /* if everything is turned off, VNICC is not active */
2372 if (!card
->options
.vnicc
.cur_chars
)
2374 /* default values are only OK if rx_bcast was not enabled by user
2375 * or the card is offline.
2377 if (card
->options
.vnicc
.cur_chars
== QETH_VNICC_DEFAULT
) {
2378 if (!card
->options
.vnicc
.rx_bcast_enabled
||
2379 !qeth_card_hw_is_reachable(card
))
2385 /* recover user timeout setting */
2386 static bool qeth_l2_vnicc_recover_timeout(struct qeth_card
*card
, u32 vnicc
,
2389 if (card
->options
.vnicc
.sup_chars
& vnicc
&&
2390 card
->options
.vnicc
.getset_timeout_sup
& vnicc
&&
2391 !qeth_l2_vnicc_getset_timeout(card
, vnicc
, IPA_VNICC_SET_TIMEOUT
,
2394 *timeout
= QETH_VNICC_DEFAULT_TIMEOUT
;
2398 /* recover user characteristic setting */
2399 static bool qeth_l2_vnicc_recover_char(struct qeth_card
*card
, u32 vnicc
,
2402 u32 cmd
= enable
? IPA_VNICC_ENABLE
: IPA_VNICC_DISABLE
;
2404 if (card
->options
.vnicc
.sup_chars
& vnicc
&&
2405 card
->options
.vnicc
.set_char_sup
& vnicc
&&
2406 !qeth_l2_vnicc_set_char(card
, vnicc
, cmd
))
2408 card
->options
.vnicc
.wanted_chars
&= ~vnicc
;
2409 card
->options
.vnicc
.wanted_chars
|= QETH_VNICC_DEFAULT
& vnicc
;
2413 /* (re-)initialize VNICC */
2414 static void qeth_l2_vnicc_init(struct qeth_card
*card
)
2416 u32
*timeout
= &card
->options
.vnicc
.learning_timeout
;
2417 unsigned int chars_len
, i
;
2418 unsigned long chars_tmp
;
2419 u32 sup_cmds
, vnicc
;
2422 QETH_CARD_TEXT(card
, 2, "vniccini");
2423 /* reset rx_bcast */
2424 card
->options
.vnicc
.rx_bcast_enabled
= 0;
2425 /* initial query and storage of VNIC characteristics */
2426 if (qeth_l2_vnicc_query_chars(card
)) {
2427 if (card
->options
.vnicc
.wanted_chars
!= QETH_VNICC_DEFAULT
||
2428 *timeout
!= QETH_VNICC_DEFAULT_TIMEOUT
)
2429 dev_err(&card
->gdev
->dev
, "Configuring the VNIC characteristics failed\n");
2430 /* fail quietly if user didn't change the default config */
2431 card
->options
.vnicc
.sup_chars
= 0;
2432 card
->options
.vnicc
.cur_chars
= 0;
2433 card
->options
.vnicc
.wanted_chars
= QETH_VNICC_DEFAULT
;
2436 /* get supported commands for each supported characteristic */
2437 chars_tmp
= card
->options
.vnicc
.sup_chars
;
2438 chars_len
= sizeof(card
->options
.vnicc
.sup_chars
) * BITS_PER_BYTE
;
2439 for_each_set_bit(i
, &chars_tmp
, chars_len
) {
2441 qeth_l2_vnicc_query_cmds(card
, vnicc
, &sup_cmds
);
2442 if (!(sup_cmds
& IPA_VNICC_SET_TIMEOUT
) ||
2443 !(sup_cmds
& IPA_VNICC_GET_TIMEOUT
))
2444 card
->options
.vnicc
.getset_timeout_sup
&= ~vnicc
;
2445 if (!(sup_cmds
& IPA_VNICC_ENABLE
) ||
2446 !(sup_cmds
& IPA_VNICC_DISABLE
))
2447 card
->options
.vnicc
.set_char_sup
&= ~vnicc
;
2449 /* enforce assumed default values and recover settings, if changed */
2450 error
= qeth_l2_vnicc_recover_timeout(card
, QETH_VNICC_LEARNING
,
2452 chars_tmp
= card
->options
.vnicc
.wanted_chars
^ QETH_VNICC_DEFAULT
;
2453 chars_tmp
|= QETH_VNICC_BRIDGE_INVISIBLE
;
2454 chars_len
= sizeof(card
->options
.vnicc
.wanted_chars
) * BITS_PER_BYTE
;
2455 for_each_set_bit(i
, &chars_tmp
, chars_len
) {
2457 enable
= card
->options
.vnicc
.wanted_chars
& vnicc
;
2458 error
|= qeth_l2_vnicc_recover_char(card
, vnicc
, enable
);
2461 dev_err(&card
->gdev
->dev
, "Configuring the VNIC characteristics failed\n");
2464 /* configure default values of VNIC characteristics */
2465 static void qeth_l2_vnicc_set_defaults(struct qeth_card
*card
)
2467 /* characteristics values */
2468 card
->options
.vnicc
.sup_chars
= QETH_VNICC_ALL
;
2469 card
->options
.vnicc
.cur_chars
= QETH_VNICC_DEFAULT
;
2470 card
->options
.vnicc
.learning_timeout
= QETH_VNICC_DEFAULT_TIMEOUT
;
2471 /* supported commands */
2472 card
->options
.vnicc
.set_char_sup
= QETH_VNICC_ALL
;
2473 card
->options
.vnicc
.getset_timeout_sup
= QETH_VNICC_LEARNING
;
2474 /* settings wanted by users */
2475 card
->options
.vnicc
.wanted_chars
= QETH_VNICC_DEFAULT
;
2478 module_init(qeth_l2_init
);
2479 module_exit(qeth_l2_exit
);
2480 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2481 MODULE_DESCRIPTION("qeth layer 2 discipline");
2482 MODULE_LICENSE("GPL");