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>
21 #include <linux/list.h>
22 #include <linux/hash.h>
23 #include <linux/hashtable.h>
24 #include <linux/string.h>
25 #include <asm/setup.h>
26 #include "qeth_core.h"
29 static int qeth_l2_set_offline(struct ccwgroup_device
*);
30 static int qeth_l2_stop(struct net_device
*);
31 static void qeth_l2_set_rx_mode(struct net_device
*);
32 static void qeth_bridgeport_query_support(struct qeth_card
*card
);
33 static void qeth_bridge_state_change(struct qeth_card
*card
,
34 struct qeth_ipa_cmd
*cmd
);
35 static void qeth_bridge_host_event(struct qeth_card
*card
,
36 struct qeth_ipa_cmd
*cmd
);
37 static void qeth_l2_vnicc_set_defaults(struct qeth_card
*card
);
38 static void qeth_l2_vnicc_init(struct qeth_card
*card
);
39 static bool qeth_l2_vnicc_recover_timeout(struct qeth_card
*card
, u32 vnicc
,
42 static struct net_device
*qeth_l2_netdev_by_devno(unsigned char *read_dev_no
)
44 struct qeth_card
*card
;
45 struct net_device
*ndev
;
48 struct ccw_dev_id read_devid
;
51 memcpy(&temp_dev_no
, read_dev_no
, 2);
52 read_lock_irqsave(&qeth_core_card_list
.rwlock
, flags
);
53 list_for_each_entry(card
, &qeth_core_card_list
.list
, list
) {
54 ccw_device_get_id(CARD_RDEV(card
), &read_devid
);
55 if (read_devid
.devno
== temp_dev_no
) {
60 read_unlock_irqrestore(&qeth_core_card_list
.rwlock
, flags
);
64 static int qeth_setdelmac_makerc(struct qeth_card
*card
, int retcode
)
69 QETH_CARD_TEXT_(card
, 2, "err%04x", retcode
);
74 case IPA_RC_L2_UNSUPPORTED_CMD
:
77 case IPA_RC_L2_ADDR_TABLE_FULL
:
80 case IPA_RC_L2_DUP_MAC
:
81 case IPA_RC_L2_DUP_LAYER3_MAC
:
84 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP
:
85 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP
:
88 case IPA_RC_L2_MAC_NOT_FOUND
:
101 static int qeth_l2_send_setdelmac(struct qeth_card
*card
, __u8
*mac
,
102 enum qeth_ipa_cmds ipacmd
)
104 struct qeth_ipa_cmd
*cmd
;
105 struct qeth_cmd_buffer
*iob
;
107 QETH_CARD_TEXT(card
, 2, "L2sdmac");
108 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, QETH_PROT_IPV4
);
111 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
112 cmd
->data
.setdelmac
.mac_length
= ETH_ALEN
;
113 ether_addr_copy(cmd
->data
.setdelmac
.mac
, mac
);
114 return qeth_setdelmac_makerc(card
, qeth_send_ipa_cmd(card
, iob
,
118 static int qeth_l2_send_setmac(struct qeth_card
*card
, __u8
*mac
)
122 QETH_CARD_TEXT(card
, 2, "L2Setmac");
123 rc
= qeth_l2_send_setdelmac(card
, mac
, IPA_CMD_SETVMAC
);
125 card
->info
.mac_bits
|= QETH_LAYER2_MAC_REGISTERED
;
126 ether_addr_copy(card
->dev
->dev_addr
, mac
);
127 dev_info(&card
->gdev
->dev
,
128 "MAC address %pM successfully registered on device %s\n",
129 card
->dev
->dev_addr
, card
->dev
->name
);
131 card
->info
.mac_bits
&= ~QETH_LAYER2_MAC_REGISTERED
;
134 dev_warn(&card
->gdev
->dev
,
135 "MAC address %pM already exists\n", mac
);
138 dev_warn(&card
->gdev
->dev
,
139 "MAC address %pM is not authorized\n", mac
);
146 static int qeth_l2_send_delmac(struct qeth_card
*card
, __u8
*mac
)
150 QETH_CARD_TEXT(card
, 2, "L2Delmac");
151 if (!(card
->info
.mac_bits
& QETH_LAYER2_MAC_REGISTERED
))
153 rc
= qeth_l2_send_setdelmac(card
, mac
, IPA_CMD_DELVMAC
);
155 card
->info
.mac_bits
&= ~QETH_LAYER2_MAC_REGISTERED
;
159 static int qeth_l2_write_mac(struct qeth_card
*card
, u8
*mac
)
161 enum qeth_ipa_cmds cmd
= is_multicast_ether_addr_64bits(mac
) ?
162 IPA_CMD_SETGMAC
: IPA_CMD_SETVMAC
;
165 QETH_CARD_TEXT(card
, 2, "L2Wmac");
166 rc
= qeth_l2_send_setdelmac(card
, mac
, cmd
);
168 QETH_DBF_MESSAGE(2, "MAC %pM already registered on %s\n",
169 mac
, QETH_CARD_IFNAME(card
));
171 QETH_DBF_MESSAGE(2, "Failed to register MAC %pM on %s: %d\n",
172 mac
, QETH_CARD_IFNAME(card
), rc
);
176 static int qeth_l2_remove_mac(struct qeth_card
*card
, u8
*mac
)
178 enum qeth_ipa_cmds cmd
= is_multicast_ether_addr_64bits(mac
) ?
179 IPA_CMD_DELGMAC
: IPA_CMD_DELVMAC
;
182 QETH_CARD_TEXT(card
, 2, "L2Rmac");
183 rc
= qeth_l2_send_setdelmac(card
, mac
, cmd
);
185 QETH_DBF_MESSAGE(2, "Failed to delete MAC %pM on %s: %d\n",
186 mac
, QETH_CARD_IFNAME(card
), rc
);
190 static void qeth_l2_del_all_macs(struct qeth_card
*card
)
192 struct qeth_mac
*mac
;
193 struct hlist_node
*tmp
;
196 spin_lock_bh(&card
->mclock
);
197 hash_for_each_safe(card
->mac_htable
, i
, tmp
, mac
, hnode
) {
198 hash_del(&mac
->hnode
);
201 spin_unlock_bh(&card
->mclock
);
204 static int qeth_l2_get_cast_type(struct qeth_card
*card
, struct sk_buff
*skb
)
206 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
208 if (is_broadcast_ether_addr(skb
->data
))
209 return RTN_BROADCAST
;
210 if (is_multicast_ether_addr(skb
->data
))
211 return RTN_MULTICAST
;
215 static void qeth_l2_hdr_csum(struct qeth_card
*card
, struct qeth_hdr
*hdr
,
218 struct iphdr
*iph
= ip_hdr(skb
);
220 /* tcph->check contains already the pseudo hdr checksum
221 * so just set the header flags
223 if (iph
->protocol
== IPPROTO_UDP
)
224 hdr
->hdr
.l2
.flags
[1] |= QETH_HDR_EXT_UDP
;
225 hdr
->hdr
.l2
.flags
[1] |= QETH_HDR_EXT_CSUM_TRANSP_REQ
|
226 QETH_HDR_EXT_CSUM_HDR_REQ
;
228 if (card
->options
.performance_stats
)
229 card
->perf_stats
.tx_csum
++;
232 static void qeth_l2_fill_header(struct qeth_hdr
*hdr
, struct sk_buff
*skb
,
233 int cast_type
, unsigned int data_len
)
235 struct vlan_ethhdr
*veth
= (struct vlan_ethhdr
*)skb_mac_header(skb
);
237 memset(hdr
, 0, sizeof(struct qeth_hdr
));
238 hdr
->hdr
.l2
.id
= QETH_HEADER_TYPE_LAYER2
;
239 hdr
->hdr
.l2
.pkt_length
= data_len
;
241 /* set byte byte 3 to casting flags */
242 if (cast_type
== RTN_MULTICAST
)
243 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_MULTICAST
;
244 else if (cast_type
== RTN_BROADCAST
)
245 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_BROADCAST
;
247 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_UNICAST
;
249 /* VSWITCH relies on the VLAN
250 * information to be present in
252 if (veth
->h_vlan_proto
== __constant_htons(ETH_P_8021Q
)) {
253 hdr
->hdr
.l2
.flags
[2] |= QETH_LAYER2_FLAG_VLAN
;
254 hdr
->hdr
.l2
.vlan_id
= ntohs(veth
->h_vlan_TCI
);
258 static int qeth_setdelvlan_makerc(struct qeth_card
*card
, int retcode
)
261 QETH_CARD_TEXT_(card
, 2, "err%04x", retcode
);
266 case IPA_RC_L2_INVALID_VLAN_ID
:
268 case IPA_RC_L2_DUP_VLAN_ID
:
270 case IPA_RC_L2_VLAN_ID_NOT_FOUND
:
272 case IPA_RC_L2_VLAN_ID_NOT_ALLOWED
:
281 static int qeth_l2_send_setdelvlan_cb(struct qeth_card
*card
,
282 struct qeth_reply
*reply
,
285 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
287 QETH_CARD_TEXT(card
, 2, "L2sdvcb");
288 if (cmd
->hdr
.return_code
) {
289 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x.\n",
290 cmd
->data
.setdelvlan
.vlan_id
,
291 QETH_CARD_IFNAME(card
), cmd
->hdr
.return_code
);
292 QETH_CARD_TEXT_(card
, 2, "L2VL%4x", cmd
->hdr
.command
);
293 QETH_CARD_TEXT_(card
, 2, "err%d", cmd
->hdr
.return_code
);
298 static int qeth_l2_send_setdelvlan(struct qeth_card
*card
, __u16 i
,
299 enum qeth_ipa_cmds ipacmd
)
301 struct qeth_ipa_cmd
*cmd
;
302 struct qeth_cmd_buffer
*iob
;
304 QETH_CARD_TEXT_(card
, 4, "L2sdv%x", ipacmd
);
305 iob
= qeth_get_ipacmd_buffer(card
, ipacmd
, QETH_PROT_IPV4
);
308 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
309 cmd
->data
.setdelvlan
.vlan_id
= i
;
310 return qeth_setdelvlan_makerc(card
, qeth_send_ipa_cmd(card
, iob
,
311 qeth_l2_send_setdelvlan_cb
, NULL
));
314 static void qeth_l2_process_vlans(struct qeth_card
*card
)
316 struct qeth_vlan_vid
*id
;
317 QETH_CARD_TEXT(card
, 3, "L2prcvln");
318 spin_lock_bh(&card
->vlanlock
);
319 list_for_each_entry(id
, &card
->vid_list
, list
) {
320 qeth_l2_send_setdelvlan(card
, id
->vid
, IPA_CMD_SETVLAN
);
322 spin_unlock_bh(&card
->vlanlock
);
325 static int qeth_l2_vlan_rx_add_vid(struct net_device
*dev
,
326 __be16 proto
, u16 vid
)
328 struct qeth_card
*card
= dev
->ml_priv
;
329 struct qeth_vlan_vid
*id
;
332 QETH_CARD_TEXT_(card
, 4, "aid:%d", vid
);
335 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
336 QETH_CARD_TEXT(card
, 3, "aidREC");
339 id
= kmalloc(sizeof(struct qeth_vlan_vid
), GFP_ATOMIC
);
342 rc
= qeth_l2_send_setdelvlan(card
, vid
, IPA_CMD_SETVLAN
);
347 spin_lock_bh(&card
->vlanlock
);
348 list_add_tail(&id
->list
, &card
->vid_list
);
349 spin_unlock_bh(&card
->vlanlock
);
356 static int qeth_l2_vlan_rx_kill_vid(struct net_device
*dev
,
357 __be16 proto
, u16 vid
)
359 struct qeth_vlan_vid
*id
, *tmpid
= NULL
;
360 struct qeth_card
*card
= dev
->ml_priv
;
363 QETH_CARD_TEXT_(card
, 4, "kid:%d", vid
);
364 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
365 QETH_CARD_TEXT(card
, 3, "kidREC");
368 spin_lock_bh(&card
->vlanlock
);
369 list_for_each_entry(id
, &card
->vid_list
, list
) {
370 if (id
->vid
== vid
) {
376 spin_unlock_bh(&card
->vlanlock
);
378 rc
= qeth_l2_send_setdelvlan(card
, vid
, IPA_CMD_DELVLAN
);
381 qeth_l2_set_rx_mode(card
->dev
);
385 static void qeth_l2_stop_card(struct qeth_card
*card
, int recovery_mode
)
387 QETH_DBF_TEXT(SETUP
, 2, "stopcard");
388 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
390 qeth_set_allowed_threads(card
, 0, 1);
391 if (card
->read
.state
== CH_STATE_UP
&&
392 card
->write
.state
== CH_STATE_UP
&&
393 (card
->state
== CARD_STATE_UP
)) {
395 card
->info
.type
!= QETH_CARD_TYPE_OSN
) {
396 qeth_l2_stop(card
->dev
);
399 dev_close(card
->dev
);
402 card
->info
.mac_bits
&= ~QETH_LAYER2_MAC_REGISTERED
;
403 card
->state
= CARD_STATE_SOFTSETUP
;
405 if (card
->state
== CARD_STATE_SOFTSETUP
) {
406 qeth_l2_del_all_macs(card
);
407 qeth_clear_ipacmd_list(card
);
408 card
->state
= CARD_STATE_HARDSETUP
;
410 if (card
->state
== CARD_STATE_HARDSETUP
) {
411 qeth_qdio_clear_card(card
, 0);
412 qeth_clear_qdio_buffers(card
);
413 qeth_clear_working_pool_list(card
);
414 card
->state
= CARD_STATE_DOWN
;
416 if (card
->state
== CARD_STATE_DOWN
) {
417 qeth_clear_cmd_buffers(&card
->read
);
418 qeth_clear_cmd_buffers(&card
->write
);
422 static int qeth_l2_process_inbound_buffer(struct qeth_card
*card
,
423 int budget
, int *done
)
427 struct qeth_hdr
*hdr
;
431 WARN_ON_ONCE(!budget
);
433 skb
= qeth_core_get_next_skb(card
,
434 &card
->qdio
.in_q
->bufs
[card
->rx
.b_index
],
435 &card
->rx
.b_element
, &card
->rx
.e_offset
, &hdr
);
440 skb
->dev
= card
->dev
;
441 switch (hdr
->hdr
.l2
.id
) {
442 case QETH_HEADER_TYPE_LAYER2
:
443 skb
->pkt_type
= PACKET_HOST
;
444 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
445 if ((card
->dev
->features
& NETIF_F_RXCSUM
)
446 && ((hdr
->hdr
.l2
.flags
[1] &
447 (QETH_HDR_EXT_CSUM_HDR_REQ
|
448 QETH_HDR_EXT_CSUM_TRANSP_REQ
)) ==
449 (QETH_HDR_EXT_CSUM_HDR_REQ
|
450 QETH_HDR_EXT_CSUM_TRANSP_REQ
)))
451 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
453 skb
->ip_summed
= CHECKSUM_NONE
;
454 if (skb
->protocol
== htons(ETH_P_802_2
))
455 *((__u32
*)skb
->cb
) = ++card
->seqno
.pkt_seqno
;
457 napi_gro_receive(&card
->napi
, skb
);
459 case QETH_HEADER_TYPE_OSN
:
460 if (card
->info
.type
== QETH_CARD_TYPE_OSN
) {
461 skb_push(skb
, sizeof(struct qeth_hdr
));
462 skb_copy_to_linear_data(skb
, hdr
,
463 sizeof(struct qeth_hdr
));
465 card
->osn_info
.data_cb(skb
);
470 dev_kfree_skb_any(skb
);
471 QETH_CARD_TEXT(card
, 3, "inbunkno");
472 QETH_DBF_HEX(CTRL
, 3, hdr
, QETH_DBF_CTRL_LEN
);
477 card
->stats
.rx_packets
++;
478 card
->stats
.rx_bytes
+= len
;
483 static int qeth_l2_request_initial_mac(struct qeth_card
*card
)
486 char vendor_pre
[] = {0x02, 0x00, 0x00};
488 QETH_DBF_TEXT(SETUP
, 2, "l2reqmac");
489 QETH_DBF_TEXT_(SETUP
, 2, "doL2%s", CARD_BUS_ID(card
));
492 rc
= qeth_vm_request_mac(card
);
495 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %s: x%x\n",
496 CARD_BUS_ID(card
), rc
);
497 QETH_DBF_TEXT_(SETUP
, 2, "err%04x", rc
);
498 /* fall back to alternative mechanism: */
501 if (card
->info
.type
== QETH_CARD_TYPE_IQD
||
502 card
->info
.type
== QETH_CARD_TYPE_OSM
||
503 card
->info
.type
== QETH_CARD_TYPE_OSX
||
504 card
->info
.guestlan
) {
505 rc
= qeth_setadpparms_change_macaddr(card
);
507 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
508 "device %s: x%x\n", CARD_BUS_ID(card
), rc
);
509 QETH_DBF_TEXT_(SETUP
, 2, "1err%04x", rc
);
513 eth_random_addr(card
->dev
->dev_addr
);
514 memcpy(card
->dev
->dev_addr
, vendor_pre
, 3);
517 QETH_DBF_HEX(SETUP
, 2, card
->dev
->dev_addr
, card
->dev
->addr_len
);
521 static int qeth_l2_set_mac_address(struct net_device
*dev
, void *p
)
523 struct sockaddr
*addr
= p
;
524 struct qeth_card
*card
= dev
->ml_priv
;
527 QETH_CARD_TEXT(card
, 3, "setmac");
529 if (card
->info
.type
== QETH_CARD_TYPE_OSN
||
530 card
->info
.type
== QETH_CARD_TYPE_OSM
||
531 card
->info
.type
== QETH_CARD_TYPE_OSX
) {
532 QETH_CARD_TEXT(card
, 3, "setmcTYP");
535 QETH_CARD_HEX(card
, 3, addr
->sa_data
, ETH_ALEN
);
536 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
537 QETH_CARD_TEXT(card
, 3, "setmcREC");
540 rc
= qeth_l2_send_delmac(card
, &card
->dev
->dev_addr
[0]);
541 if (!rc
|| (rc
== -ENOENT
))
542 rc
= qeth_l2_send_setmac(card
, addr
->sa_data
);
543 return rc
? -EINVAL
: 0;
546 static void qeth_promisc_to_bridge(struct qeth_card
*card
)
548 struct net_device
*dev
= card
->dev
;
549 enum qeth_ipa_promisc_modes promisc_mode
;
553 QETH_CARD_TEXT(card
, 3, "pmisc2br");
555 if (!card
->options
.sbp
.reflect_promisc
)
557 promisc_mode
= (dev
->flags
& IFF_PROMISC
) ? SET_PROMISC_MODE_ON
558 : SET_PROMISC_MODE_OFF
;
559 if (promisc_mode
== card
->info
.promisc_mode
)
562 if (promisc_mode
== SET_PROMISC_MODE_ON
) {
563 if (card
->options
.sbp
.reflect_promisc_primary
)
564 role
= QETH_SBP_ROLE_PRIMARY
;
566 role
= QETH_SBP_ROLE_SECONDARY
;
568 role
= QETH_SBP_ROLE_NONE
;
570 rc
= qeth_bridgeport_setrole(card
, role
);
571 QETH_DBF_TEXT_(SETUP
, 2, "bpm%c%04x",
572 (promisc_mode
== SET_PROMISC_MODE_ON
) ? '+' : '-', rc
);
574 card
->options
.sbp
.role
= role
;
575 card
->info
.promisc_mode
= promisc_mode
;
579 /* New MAC address is added to the hash table and marked to be written on card
580 * only if there is not in the hash table storage already
583 static void qeth_l2_add_mac(struct qeth_card
*card
, struct netdev_hw_addr
*ha
)
585 u32 mac_hash
= get_unaligned((u32
*)(&ha
->addr
[2]));
586 struct qeth_mac
*mac
;
588 hash_for_each_possible(card
->mac_htable
, mac
, hnode
, mac_hash
) {
589 if (ether_addr_equal_64bits(ha
->addr
, mac
->mac_addr
)) {
590 mac
->disp_flag
= QETH_DISP_ADDR_DO_NOTHING
;
595 mac
= kzalloc(sizeof(struct qeth_mac
), GFP_ATOMIC
);
599 ether_addr_copy(mac
->mac_addr
, ha
->addr
);
600 mac
->disp_flag
= QETH_DISP_ADDR_ADD
;
602 hash_add(card
->mac_htable
, &mac
->hnode
, mac_hash
);
605 static void qeth_l2_set_rx_mode(struct net_device
*dev
)
607 struct qeth_card
*card
= dev
->ml_priv
;
608 struct netdev_hw_addr
*ha
;
609 struct qeth_mac
*mac
;
610 struct hlist_node
*tmp
;
614 if (card
->info
.type
== QETH_CARD_TYPE_OSN
)
617 QETH_CARD_TEXT(card
, 3, "setmulti");
618 if (qeth_threads_running(card
, QETH_RECOVER_THREAD
) &&
619 (card
->state
!= CARD_STATE_UP
))
622 spin_lock_bh(&card
->mclock
);
624 netdev_for_each_mc_addr(ha
, dev
)
625 qeth_l2_add_mac(card
, ha
);
626 netdev_for_each_uc_addr(ha
, dev
)
627 qeth_l2_add_mac(card
, ha
);
629 hash_for_each_safe(card
->mac_htable
, i
, tmp
, mac
, hnode
) {
630 switch (mac
->disp_flag
) {
631 case QETH_DISP_ADDR_DELETE
:
632 qeth_l2_remove_mac(card
, mac
->mac_addr
);
633 hash_del(&mac
->hnode
);
636 case QETH_DISP_ADDR_ADD
:
637 rc
= qeth_l2_write_mac(card
, mac
->mac_addr
);
639 hash_del(&mac
->hnode
);
645 /* for next call to set_rx_mode(): */
646 mac
->disp_flag
= QETH_DISP_ADDR_DELETE
;
650 spin_unlock_bh(&card
->mclock
);
652 if (qeth_adp_supported(card
, IPA_SETADP_SET_PROMISC_MODE
))
653 qeth_setadp_promisc_mode(card
);
655 qeth_promisc_to_bridge(card
);
658 static int qeth_l2_xmit_iqd(struct qeth_card
*card
, struct sk_buff
*skb
,
659 struct qeth_qdio_out_q
*queue
, int cast_type
)
661 unsigned int data_offset
= ETH_HLEN
;
662 struct qeth_hdr
*hdr
;
665 hdr
= kmem_cache_alloc(qeth_core_header_cache
, GFP_ATOMIC
);
668 qeth_l2_fill_header(hdr
, skb
, cast_type
, skb
->len
);
669 skb_copy_from_linear_data(skb
, ((char *)hdr
) + sizeof(*hdr
),
672 if (!qeth_get_elements_no(card
, skb
, 1, data_offset
)) {
676 rc
= qeth_do_send_packet_fast(queue
, skb
, hdr
, data_offset
,
677 sizeof(*hdr
) + data_offset
);
680 kmem_cache_free(qeth_core_header_cache
, hdr
);
684 static int qeth_l2_xmit_osa(struct qeth_card
*card
, struct sk_buff
*skb
,
685 struct qeth_qdio_out_q
*queue
, int cast_type
)
687 int push_len
= sizeof(struct qeth_hdr
);
688 unsigned int elements
, nr_frags
;
689 unsigned int hdr_elements
= 0;
690 struct qeth_hdr
*hdr
= NULL
;
691 unsigned int hd_len
= 0;
694 /* fix hardware limitation: as long as we do not have sbal
695 * chaining we can not send long frag lists
697 if (!qeth_get_elements_no(card
, skb
, 0, 0)) {
698 rc
= skb_linearize(skb
);
700 if (card
->options
.performance_stats
) {
702 card
->perf_stats
.tx_linfail
++;
704 card
->perf_stats
.tx_lin
++;
709 nr_frags
= skb_shinfo(skb
)->nr_frags
;
711 rc
= skb_cow_head(skb
, push_len
);
714 push_len
= qeth_push_hdr(skb
, &hdr
, push_len
);
718 /* hdr was allocated from cache */
719 hd_len
= sizeof(*hdr
);
722 qeth_l2_fill_header(hdr
, skb
, cast_type
, skb
->len
- push_len
);
723 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
724 qeth_l2_hdr_csum(card
, hdr
, skb
);
726 elements
= qeth_get_elements_no(card
, skb
, hdr_elements
, 0);
731 elements
+= hdr_elements
;
733 /* TODO: remove the skb_orphan() once TX completion is fast enough */
735 rc
= qeth_do_send_packet(card
, queue
, skb
, hdr
, 0, hd_len
, elements
);
738 if (card
->options
.performance_stats
&& nr_frags
) {
739 card
->perf_stats
.sg_skbs_sent
++;
740 /* nr_frags + skb->data */
741 card
->perf_stats
.sg_frags_sent
+= nr_frags
+ 1;
745 kmem_cache_free(qeth_core_header_cache
, hdr
);
747 /* roll back to ETH header */
748 skb_pull(skb
, push_len
);
753 static int qeth_l2_xmit_osn(struct qeth_card
*card
, struct sk_buff
*skb
,
754 struct qeth_qdio_out_q
*queue
)
756 unsigned int elements
;
757 struct qeth_hdr
*hdr
;
759 if (skb
->protocol
== htons(ETH_P_IPV6
))
760 return -EPROTONOSUPPORT
;
762 hdr
= (struct qeth_hdr
*)skb
->data
;
763 elements
= qeth_get_elements_no(card
, skb
, 0, 0);
766 if (qeth_hdr_chk_and_bounce(skb
, &hdr
, sizeof(*hdr
)))
768 return qeth_do_send_packet(card
, queue
, skb
, hdr
, 0, 0, elements
);
771 static netdev_tx_t
qeth_l2_hard_start_xmit(struct sk_buff
*skb
,
772 struct net_device
*dev
)
774 struct qeth_card
*card
= dev
->ml_priv
;
775 int cast_type
= qeth_l2_get_cast_type(card
, skb
);
776 struct qeth_qdio_out_q
*queue
;
777 int tx_bytes
= skb
->len
;
780 if (card
->qdio
.do_prio_queueing
|| (cast_type
&&
781 card
->info
.is_multicast_different
))
782 queue
= card
->qdio
.out_qs
[qeth_get_priority_queue(card
, skb
,
783 qeth_get_ip_version(skb
), cast_type
)];
785 queue
= card
->qdio
.out_qs
[card
->qdio
.default_out_queue
];
787 if ((card
->state
!= CARD_STATE_UP
) || !card
->lan_online
) {
788 card
->stats
.tx_carrier_errors
++;
792 if (card
->options
.performance_stats
) {
793 card
->perf_stats
.outbound_cnt
++;
794 card
->perf_stats
.outbound_start_time
= qeth_get_micros();
796 netif_stop_queue(dev
);
798 switch (card
->info
.type
) {
799 case QETH_CARD_TYPE_OSN
:
800 rc
= qeth_l2_xmit_osn(card
, skb
, queue
);
802 case QETH_CARD_TYPE_IQD
:
803 rc
= qeth_l2_xmit_iqd(card
, skb
, queue
, cast_type
);
806 rc
= qeth_l2_xmit_osa(card
, skb
, queue
, cast_type
);
810 card
->stats
.tx_packets
++;
811 card
->stats
.tx_bytes
+= tx_bytes
;
812 if (card
->options
.performance_stats
)
813 card
->perf_stats
.outbound_time
+= qeth_get_micros() -
814 card
->perf_stats
.outbound_start_time
;
815 netif_wake_queue(dev
);
817 } else if (rc
== -EBUSY
) {
818 return NETDEV_TX_BUSY
;
819 } /* else fall through */
822 card
->stats
.tx_dropped
++;
823 card
->stats
.tx_errors
++;
824 dev_kfree_skb_any(skb
);
825 netif_wake_queue(dev
);
829 static int __qeth_l2_open(struct net_device
*dev
)
831 struct qeth_card
*card
= dev
->ml_priv
;
834 QETH_CARD_TEXT(card
, 4, "qethopen");
835 if (card
->state
== CARD_STATE_UP
)
837 if (card
->state
!= CARD_STATE_SOFTSETUP
)
840 if ((card
->info
.type
!= QETH_CARD_TYPE_OSN
) &&
841 (!(card
->info
.mac_bits
& QETH_LAYER2_MAC_REGISTERED
))) {
842 QETH_CARD_TEXT(card
, 4, "nomacadr");
845 card
->data
.state
= CH_STATE_UP
;
846 card
->state
= CARD_STATE_UP
;
847 netif_start_queue(dev
);
849 if (qdio_stop_irq(card
->data
.ccwdev
, 0) >= 0) {
850 napi_enable(&card
->napi
);
851 napi_schedule(&card
->napi
);
857 static int qeth_l2_open(struct net_device
*dev
)
859 struct qeth_card
*card
= dev
->ml_priv
;
861 QETH_CARD_TEXT(card
, 5, "qethope_");
862 if (qeth_wait_for_threads(card
, QETH_RECOVER_THREAD
)) {
863 QETH_CARD_TEXT(card
, 3, "openREC");
866 return __qeth_l2_open(dev
);
869 static int qeth_l2_stop(struct net_device
*dev
)
871 struct qeth_card
*card
= dev
->ml_priv
;
873 QETH_CARD_TEXT(card
, 4, "qethstop");
874 netif_tx_disable(dev
);
875 if (card
->state
== CARD_STATE_UP
) {
876 card
->state
= CARD_STATE_SOFTSETUP
;
877 napi_disable(&card
->napi
);
882 static const struct device_type qeth_l2_devtype
= {
883 .name
= "qeth_layer2",
884 .groups
= qeth_l2_attr_groups
,
887 static int qeth_l2_probe_device(struct ccwgroup_device
*gdev
)
889 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
892 if (gdev
->dev
.type
== &qeth_generic_devtype
) {
893 rc
= qeth_l2_create_device_attributes(&gdev
->dev
);
897 INIT_LIST_HEAD(&card
->vid_list
);
898 hash_init(card
->mac_htable
);
899 card
->options
.layer2
= 1;
900 card
->info
.hwtrap
= 0;
901 qeth_l2_vnicc_set_defaults(card
);
905 static void qeth_l2_remove_device(struct ccwgroup_device
*cgdev
)
907 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
909 if (cgdev
->dev
.type
== &qeth_generic_devtype
)
910 qeth_l2_remove_device_attributes(&cgdev
->dev
);
911 qeth_set_allowed_threads(card
, 0, 1);
912 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
914 if (cgdev
->state
== CCWGROUP_ONLINE
)
915 qeth_l2_set_offline(cgdev
);
918 netif_napi_del(&card
->napi
);
919 unregister_netdev(card
->dev
);
925 static const struct ethtool_ops qeth_l2_ethtool_ops
= {
926 .get_link
= ethtool_op_get_link
,
927 .get_strings
= qeth_core_get_strings
,
928 .get_ethtool_stats
= qeth_core_get_ethtool_stats
,
929 .get_sset_count
= qeth_core_get_sset_count
,
930 .get_drvinfo
= qeth_core_get_drvinfo
,
931 .get_link_ksettings
= qeth_core_ethtool_get_link_ksettings
,
934 static const struct ethtool_ops qeth_l2_osn_ops
= {
935 .get_strings
= qeth_core_get_strings
,
936 .get_ethtool_stats
= qeth_core_get_ethtool_stats
,
937 .get_sset_count
= qeth_core_get_sset_count
,
938 .get_drvinfo
= qeth_core_get_drvinfo
,
941 static const struct net_device_ops qeth_l2_netdev_ops
= {
942 .ndo_open
= qeth_l2_open
,
943 .ndo_stop
= qeth_l2_stop
,
944 .ndo_get_stats
= qeth_get_stats
,
945 .ndo_start_xmit
= qeth_l2_hard_start_xmit
,
946 .ndo_features_check
= qeth_features_check
,
947 .ndo_validate_addr
= eth_validate_addr
,
948 .ndo_set_rx_mode
= qeth_l2_set_rx_mode
,
949 .ndo_do_ioctl
= qeth_do_ioctl
,
950 .ndo_set_mac_address
= qeth_l2_set_mac_address
,
951 .ndo_change_mtu
= qeth_change_mtu
,
952 .ndo_vlan_rx_add_vid
= qeth_l2_vlan_rx_add_vid
,
953 .ndo_vlan_rx_kill_vid
= qeth_l2_vlan_rx_kill_vid
,
954 .ndo_tx_timeout
= qeth_tx_timeout
,
955 .ndo_fix_features
= qeth_fix_features
,
956 .ndo_set_features
= qeth_set_features
959 static int qeth_l2_setup_netdev(struct qeth_card
*card
)
961 switch (card
->info
.type
) {
962 case QETH_CARD_TYPE_IQD
:
963 card
->dev
= alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN
,
966 case QETH_CARD_TYPE_OSN
:
967 card
->dev
= alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN
,
971 card
->dev
= alloc_etherdev(0);
977 card
->dev
->ml_priv
= card
;
978 card
->dev
->watchdog_timeo
= QETH_TX_TIMEOUT
;
979 card
->dev
->mtu
= card
->info
.initial_mtu
;
980 card
->dev
->min_mtu
= 64;
981 card
->dev
->max_mtu
= ETH_MAX_MTU
;
982 card
->dev
->netdev_ops
= &qeth_l2_netdev_ops
;
983 if (card
->info
.type
== QETH_CARD_TYPE_OSN
) {
984 card
->dev
->ethtool_ops
= &qeth_l2_osn_ops
;
985 card
->dev
->flags
|= IFF_NOARP
;
987 card
->dev
->ethtool_ops
= &qeth_l2_ethtool_ops
;
990 if (card
->info
.type
== QETH_CARD_TYPE_OSM
)
991 card
->dev
->features
|= NETIF_F_VLAN_CHALLENGED
;
993 card
->dev
->features
|= NETIF_F_HW_VLAN_CTAG_FILTER
;
994 if (card
->info
.type
== QETH_CARD_TYPE_OSD
&& !card
->info
.guestlan
) {
995 card
->dev
->hw_features
= NETIF_F_SG
;
996 card
->dev
->vlan_features
= NETIF_F_SG
;
997 card
->dev
->features
|= NETIF_F_SG
;
998 /* OSA 3S and earlier has no RX/TX support */
999 if (qeth_is_supported(card
, IPA_OUTBOUND_CHECKSUM
)) {
1000 card
->dev
->hw_features
|= NETIF_F_IP_CSUM
;
1001 card
->dev
->vlan_features
|= NETIF_F_IP_CSUM
;
1003 if (qeth_is_supported(card
, IPA_INBOUND_CHECKSUM
)) {
1004 card
->dev
->hw_features
|= NETIF_F_RXCSUM
;
1005 card
->dev
->vlan_features
|= NETIF_F_RXCSUM
;
1008 if (card
->info
.type
!= QETH_CARD_TYPE_OSN
&&
1009 card
->info
.type
!= QETH_CARD_TYPE_IQD
) {
1010 card
->dev
->priv_flags
&= ~IFF_TX_SKB_SHARING
;
1011 card
->dev
->needed_headroom
= sizeof(struct qeth_hdr
);
1014 card
->info
.broadcast_capable
= 1;
1015 qeth_l2_request_initial_mac(card
);
1016 SET_NETDEV_DEV(card
->dev
, &card
->gdev
->dev
);
1017 netif_napi_add(card
->dev
, &card
->napi
, qeth_poll
, QETH_NAPI_WEIGHT
);
1018 netif_carrier_off(card
->dev
);
1019 return register_netdev(card
->dev
);
1022 static int qeth_l2_start_ipassists(struct qeth_card
*card
)
1024 /* configure isolation level */
1025 if (qeth_set_access_ctrl_online(card
, 0))
1030 static void qeth_l2_trace_features(struct qeth_card
*card
)
1032 /* Set BridgePort features */
1033 QETH_CARD_TEXT(card
, 2, "featuSBP");
1034 QETH_CARD_HEX(card
, 2, &card
->options
.sbp
.supported_funcs
,
1035 sizeof(card
->options
.sbp
.supported_funcs
));
1036 /* VNIC Characteristics features */
1037 QETH_CARD_TEXT(card
, 2, "feaVNICC");
1038 QETH_CARD_HEX(card
, 2, &card
->options
.vnicc
.sup_chars
,
1039 sizeof(card
->options
.vnicc
.sup_chars
));
1042 static int __qeth_l2_set_online(struct ccwgroup_device
*gdev
, int recovery_mode
)
1044 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
1046 enum qeth_card_states recover_flag
;
1048 mutex_lock(&card
->discipline_mutex
);
1049 mutex_lock(&card
->conf_mutex
);
1050 QETH_DBF_TEXT(SETUP
, 2, "setonlin");
1051 QETH_DBF_HEX(SETUP
, 2, &card
, sizeof(void *));
1053 recover_flag
= card
->state
;
1054 rc
= qeth_core_hardsetup_card(card
);
1056 QETH_DBF_TEXT_(SETUP
, 2, "2err%04x", rc
);
1060 qeth_bridgeport_query_support(card
);
1061 if (card
->options
.sbp
.supported_funcs
)
1062 dev_info(&card
->gdev
->dev
,
1063 "The device represents a Bridge Capable Port\n");
1065 if (!card
->dev
&& qeth_l2_setup_netdev(card
)) {
1070 if (card
->info
.type
!= QETH_CARD_TYPE_OSN
)
1071 qeth_l2_send_setmac(card
, &card
->dev
->dev_addr
[0]);
1073 if (qeth_is_diagass_supported(card
, QETH_DIAGS_CMD_TRAP
)) {
1074 if (card
->info
.hwtrap
&&
1075 qeth_hw_trap(card
, QETH_DIAGS_TRAP_ARM
))
1076 card
->info
.hwtrap
= 0;
1078 card
->info
.hwtrap
= 0;
1080 /* for the rx_bcast characteristic, init VNICC after setmac */
1081 qeth_l2_vnicc_init(card
);
1083 qeth_trace_features(card
);
1084 qeth_l2_trace_features(card
);
1086 qeth_l2_setup_bridgeport_attrs(card
);
1088 card
->state
= CARD_STATE_HARDSETUP
;
1089 memset(&card
->rx
, 0, sizeof(struct qeth_rx
));
1090 qeth_print_status_message(card
);
1093 QETH_DBF_TEXT(SETUP
, 2, "softsetp");
1095 if ((card
->info
.type
== QETH_CARD_TYPE_OSD
) ||
1096 (card
->info
.type
== QETH_CARD_TYPE_OSX
)) {
1097 rc
= qeth_l2_start_ipassists(card
);
1102 if (card
->info
.type
!= QETH_CARD_TYPE_OSN
)
1103 qeth_l2_process_vlans(card
);
1105 netif_tx_disable(card
->dev
);
1107 rc
= qeth_init_qdio_queues(card
);
1109 QETH_DBF_TEXT_(SETUP
, 2, "6err%d", rc
);
1113 card
->state
= CARD_STATE_SOFTSETUP
;
1114 if (card
->lan_online
)
1115 netif_carrier_on(card
->dev
);
1117 netif_carrier_off(card
->dev
);
1119 qeth_set_allowed_threads(card
, 0xffffffff, 0);
1120 if (recover_flag
== CARD_STATE_RECOVER
) {
1121 if (recovery_mode
&&
1122 card
->info
.type
!= QETH_CARD_TYPE_OSN
) {
1123 __qeth_l2_open(card
->dev
);
1126 dev_open(card
->dev
);
1129 /* this also sets saved unicast addresses */
1130 qeth_l2_set_rx_mode(card
->dev
);
1132 qeth_recover_features(card
->dev
);
1135 /* let user_space know that device is online */
1136 kobject_uevent(&gdev
->dev
.kobj
, KOBJ_CHANGE
);
1137 mutex_unlock(&card
->conf_mutex
);
1138 mutex_unlock(&card
->discipline_mutex
);
1142 qeth_l2_stop_card(card
, 0);
1143 ccw_device_set_offline(CARD_DDEV(card
));
1144 ccw_device_set_offline(CARD_WDEV(card
));
1145 ccw_device_set_offline(CARD_RDEV(card
));
1146 qdio_free(CARD_DDEV(card
));
1147 if (recover_flag
== CARD_STATE_RECOVER
)
1148 card
->state
= CARD_STATE_RECOVER
;
1150 card
->state
= CARD_STATE_DOWN
;
1151 mutex_unlock(&card
->conf_mutex
);
1152 mutex_unlock(&card
->discipline_mutex
);
1156 static int qeth_l2_set_online(struct ccwgroup_device
*gdev
)
1158 return __qeth_l2_set_online(gdev
, 0);
1161 static int __qeth_l2_set_offline(struct ccwgroup_device
*cgdev
,
1164 struct qeth_card
*card
= dev_get_drvdata(&cgdev
->dev
);
1165 int rc
= 0, rc2
= 0, rc3
= 0;
1166 enum qeth_card_states recover_flag
;
1168 mutex_lock(&card
->discipline_mutex
);
1169 mutex_lock(&card
->conf_mutex
);
1170 QETH_DBF_TEXT(SETUP
, 3, "setoffl");
1171 QETH_DBF_HEX(SETUP
, 3, &card
, sizeof(void *));
1173 if (card
->dev
&& netif_carrier_ok(card
->dev
))
1174 netif_carrier_off(card
->dev
);
1175 recover_flag
= card
->state
;
1176 if ((!recovery_mode
&& card
->info
.hwtrap
) || card
->info
.hwtrap
== 2) {
1177 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
1178 card
->info
.hwtrap
= 1;
1180 qeth_l2_stop_card(card
, recovery_mode
);
1181 rc
= ccw_device_set_offline(CARD_DDEV(card
));
1182 rc2
= ccw_device_set_offline(CARD_WDEV(card
));
1183 rc3
= ccw_device_set_offline(CARD_RDEV(card
));
1185 rc
= (rc2
) ? rc2
: rc3
;
1187 QETH_DBF_TEXT_(SETUP
, 2, "1err%d", rc
);
1188 qdio_free(CARD_DDEV(card
));
1189 if (recover_flag
== CARD_STATE_UP
)
1190 card
->state
= CARD_STATE_RECOVER
;
1191 /* let user_space know that device is offline */
1192 kobject_uevent(&cgdev
->dev
.kobj
, KOBJ_CHANGE
);
1193 mutex_unlock(&card
->conf_mutex
);
1194 mutex_unlock(&card
->discipline_mutex
);
1198 static int qeth_l2_set_offline(struct ccwgroup_device
*cgdev
)
1200 return __qeth_l2_set_offline(cgdev
, 0);
1203 static int qeth_l2_recover(void *ptr
)
1205 struct qeth_card
*card
;
1208 card
= (struct qeth_card
*) ptr
;
1209 QETH_CARD_TEXT(card
, 2, "recover1");
1210 if (!qeth_do_run_thread(card
, QETH_RECOVER_THREAD
))
1212 QETH_CARD_TEXT(card
, 2, "recover2");
1213 dev_warn(&card
->gdev
->dev
,
1214 "A recovery process has been started for the device\n");
1215 qeth_set_recovery_task(card
);
1216 __qeth_l2_set_offline(card
->gdev
, 1);
1217 rc
= __qeth_l2_set_online(card
->gdev
, 1);
1219 dev_info(&card
->gdev
->dev
,
1220 "Device successfully recovered!\n");
1222 qeth_close_dev(card
);
1223 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
1224 "failed to recover an error on the device\n");
1226 qeth_clear_recovery_task(card
);
1227 qeth_clear_thread_start_bit(card
, QETH_RECOVER_THREAD
);
1228 qeth_clear_thread_running_bit(card
, QETH_RECOVER_THREAD
);
1232 static int __init
qeth_l2_init(void)
1234 pr_info("register layer 2 discipline\n");
1238 static void __exit
qeth_l2_exit(void)
1240 pr_info("unregister layer 2 discipline\n");
1243 static int qeth_l2_pm_suspend(struct ccwgroup_device
*gdev
)
1245 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
1248 netif_device_detach(card
->dev
);
1249 qeth_set_allowed_threads(card
, 0, 1);
1250 wait_event(card
->wait_q
, qeth_threads_running(card
, 0xffffffff) == 0);
1251 if (gdev
->state
== CCWGROUP_OFFLINE
)
1253 if (card
->state
== CARD_STATE_UP
) {
1254 if (card
->info
.hwtrap
)
1255 qeth_hw_trap(card
, QETH_DIAGS_TRAP_DISARM
);
1256 __qeth_l2_set_offline(card
->gdev
, 1);
1258 __qeth_l2_set_offline(card
->gdev
, 0);
1262 static int qeth_l2_pm_resume(struct ccwgroup_device
*gdev
)
1264 struct qeth_card
*card
= dev_get_drvdata(&gdev
->dev
);
1267 if (gdev
->state
== CCWGROUP_OFFLINE
)
1270 if (card
->state
== CARD_STATE_RECOVER
) {
1271 rc
= __qeth_l2_set_online(card
->gdev
, 1);
1274 dev_close(card
->dev
);
1278 rc
= __qeth_l2_set_online(card
->gdev
, 0);
1280 qeth_set_allowed_threads(card
, 0xffffffff, 0);
1282 netif_device_attach(card
->dev
);
1284 dev_warn(&card
->gdev
->dev
, "The qeth device driver "
1285 "failed to recover an error on the device\n");
1289 /* Returns zero if the command is successfully "consumed" */
1290 static int qeth_l2_control_event(struct qeth_card
*card
,
1291 struct qeth_ipa_cmd
*cmd
)
1293 switch (cmd
->hdr
.command
) {
1294 case IPA_CMD_SETBRIDGEPORT_OSA
:
1295 case IPA_CMD_SETBRIDGEPORT_IQD
:
1296 if (cmd
->data
.sbp
.hdr
.command_code
==
1297 IPA_SBP_BRIDGE_PORT_STATE_CHANGE
) {
1298 qeth_bridge_state_change(card
, cmd
);
1302 case IPA_CMD_ADDRESS_CHANGE_NOTIF
:
1303 qeth_bridge_host_event(card
, cmd
);
1310 struct qeth_discipline qeth_l2_discipline
= {
1311 .devtype
= &qeth_l2_devtype
,
1312 .start_poll
= qeth_qdio_start_poll
,
1313 .input_handler
= (qdio_handler_t
*) qeth_qdio_input_handler
,
1314 .output_handler
= (qdio_handler_t
*) qeth_qdio_output_handler
,
1315 .process_rx_buffer
= qeth_l2_process_inbound_buffer
,
1316 .recover
= qeth_l2_recover
,
1317 .setup
= qeth_l2_probe_device
,
1318 .remove
= qeth_l2_remove_device
,
1319 .set_online
= qeth_l2_set_online
,
1320 .set_offline
= qeth_l2_set_offline
,
1321 .freeze
= qeth_l2_pm_suspend
,
1322 .thaw
= qeth_l2_pm_resume
,
1323 .restore
= qeth_l2_pm_resume
,
1325 .control_event_handler
= qeth_l2_control_event
,
1327 EXPORT_SYMBOL_GPL(qeth_l2_discipline
);
1329 static int qeth_osn_send_control_data(struct qeth_card
*card
, int len
,
1330 struct qeth_cmd_buffer
*iob
)
1332 unsigned long flags
;
1335 QETH_CARD_TEXT(card
, 5, "osndctrd");
1337 wait_event(card
->wait_q
,
1338 atomic_cmpxchg(&card
->write
.irq_pending
, 0, 1) == 0);
1339 qeth_prepare_control_data(card
, len
, iob
);
1340 QETH_CARD_TEXT(card
, 6, "osnoirqp");
1341 spin_lock_irqsave(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
1342 rc
= ccw_device_start(card
->write
.ccwdev
, &card
->write
.ccw
,
1343 (addr_t
) iob
, 0, 0);
1344 spin_unlock_irqrestore(get_ccwdev_lock(card
->write
.ccwdev
), flags
);
1346 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
1347 "ccw_device_start rc = %i\n", rc
);
1348 QETH_CARD_TEXT_(card
, 2, " err%d", rc
);
1349 qeth_release_buffer(iob
->channel
, iob
);
1350 atomic_set(&card
->write
.irq_pending
, 0);
1351 wake_up(&card
->wait_q
);
1356 static int qeth_osn_send_ipa_cmd(struct qeth_card
*card
,
1357 struct qeth_cmd_buffer
*iob
, int data_len
)
1361 QETH_CARD_TEXT(card
, 4, "osndipa");
1363 qeth_prepare_ipa_cmd(card
, iob
, QETH_PROT_OSN2
);
1364 s1
= (u16
)(IPA_PDU_HEADER_SIZE
+ data_len
);
1366 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob
->data
), &s1
, 2);
1367 memcpy(QETH_IPA_PDU_LEN_PDU1(iob
->data
), &s2
, 2);
1368 memcpy(QETH_IPA_PDU_LEN_PDU2(iob
->data
), &s2
, 2);
1369 memcpy(QETH_IPA_PDU_LEN_PDU3(iob
->data
), &s2
, 2);
1370 return qeth_osn_send_control_data(card
, s1
, iob
);
1373 int qeth_osn_assist(struct net_device
*dev
, void *data
, int data_len
)
1375 struct qeth_cmd_buffer
*iob
;
1376 struct qeth_card
*card
;
1381 card
= dev
->ml_priv
;
1384 QETH_CARD_TEXT(card
, 2, "osnsdmc");
1385 if (!qeth_card_hw_is_reachable(card
))
1387 iob
= qeth_wait_for_buffer(&card
->write
);
1388 memcpy(iob
->data
+IPA_PDU_HEADER_SIZE
, data
, data_len
);
1389 rc
= qeth_osn_send_ipa_cmd(card
, iob
, data_len
);
1392 EXPORT_SYMBOL(qeth_osn_assist
);
1394 int qeth_osn_register(unsigned char *read_dev_no
, struct net_device
**dev
,
1395 int (*assist_cb
)(struct net_device
*, void *),
1396 int (*data_cb
)(struct sk_buff
*))
1398 struct qeth_card
*card
;
1400 *dev
= qeth_l2_netdev_by_devno(read_dev_no
);
1403 card
= (*dev
)->ml_priv
;
1406 QETH_CARD_TEXT(card
, 2, "osnreg");
1407 if ((assist_cb
== NULL
) || (data_cb
== NULL
))
1409 card
->osn_info
.assist_cb
= assist_cb
;
1410 card
->osn_info
.data_cb
= data_cb
;
1413 EXPORT_SYMBOL(qeth_osn_register
);
1415 void qeth_osn_deregister(struct net_device
*dev
)
1417 struct qeth_card
*card
;
1421 card
= dev
->ml_priv
;
1424 QETH_CARD_TEXT(card
, 2, "osndereg");
1425 card
->osn_info
.assist_cb
= NULL
;
1426 card
->osn_info
.data_cb
= NULL
;
1429 EXPORT_SYMBOL(qeth_osn_deregister
);
1431 /* SETBRIDGEPORT support, async notifications */
1433 enum qeth_an_event_type
{anev_reg_unreg
, anev_abort
, anev_reset
};
1436 * qeth_bridge_emit_host_event() - bridgeport address change notification
1437 * @card: qeth_card structure pointer, for udev events.
1438 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1439 * and reset token and addr_lnid are unused and may be NULL.
1440 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1441 * object, 0 - addition of an object.
1442 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1443 * @token: "network token" structure identifying physical address of the port.
1444 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1446 * This function is called when registrations and deregistrations are
1447 * reported by the hardware, and also when notifications are enabled -
1448 * for all currently registered addresses.
1450 static void qeth_bridge_emit_host_event(struct qeth_card
*card
,
1451 enum qeth_an_event_type evtype
,
1452 u8 code
, struct net_if_token
*token
, struct mac_addr_lnid
*addr_lnid
)
1459 case anev_reg_unreg
:
1460 snprintf(str
[i
], sizeof(str
[i
]), "BRIDGEDHOST=%s",
1461 (code
& IPA_ADDR_CHANGE_CODE_REMOVAL
)
1462 ? "deregister" : "register");
1463 env
[i
] = str
[i
]; i
++;
1464 if (code
& IPA_ADDR_CHANGE_CODE_VLANID
) {
1465 snprintf(str
[i
], sizeof(str
[i
]), "VLAN=%d",
1467 env
[i
] = str
[i
]; i
++;
1469 if (code
& IPA_ADDR_CHANGE_CODE_MACADDR
) {
1470 snprintf(str
[i
], sizeof(str
[i
]), "MAC=%pM",
1472 env
[i
] = str
[i
]; i
++;
1474 snprintf(str
[i
], sizeof(str
[i
]), "NTOK_BUSID=%x.%x.%04x",
1475 token
->cssid
, token
->ssid
, token
->devnum
);
1476 env
[i
] = str
[i
]; i
++;
1477 snprintf(str
[i
], sizeof(str
[i
]), "NTOK_IID=%02x", token
->iid
);
1478 env
[i
] = str
[i
]; i
++;
1479 snprintf(str
[i
], sizeof(str
[i
]), "NTOK_CHPID=%02x",
1481 env
[i
] = str
[i
]; i
++;
1482 snprintf(str
[i
], sizeof(str
[i
]), "NTOK_CHID=%04x", token
->chid
);
1483 env
[i
] = str
[i
]; i
++;
1486 snprintf(str
[i
], sizeof(str
[i
]), "BRIDGEDHOST=abort");
1487 env
[i
] = str
[i
]; i
++;
1490 snprintf(str
[i
], sizeof(str
[i
]), "BRIDGEDHOST=reset");
1491 env
[i
] = str
[i
]; i
++;
1495 kobject_uevent_env(&card
->gdev
->dev
.kobj
, KOBJ_CHANGE
, env
);
1498 struct qeth_bridge_state_data
{
1499 struct work_struct worker
;
1500 struct qeth_card
*card
;
1501 struct qeth_sbp_state_change qports
;
1504 static void qeth_bridge_state_change_worker(struct work_struct
*work
)
1506 struct qeth_bridge_state_data
*data
=
1507 container_of(work
, struct qeth_bridge_state_data
, worker
);
1508 /* We are only interested in the first entry - local port */
1509 struct qeth_sbp_port_entry
*entry
= &data
->qports
.entry
[0];
1510 char env_locrem
[32];
1520 /* Role should not change by itself, but if it did, */
1521 /* information from the hardware is authoritative. */
1522 mutex_lock(&data
->card
->conf_mutex
);
1523 data
->card
->options
.sbp
.role
= entry
->role
;
1524 mutex_unlock(&data
->card
->conf_mutex
);
1526 snprintf(env_locrem
, sizeof(env_locrem
), "BRIDGEPORT=statechange");
1527 snprintf(env_role
, sizeof(env_role
), "ROLE=%s",
1528 (entry
->role
== QETH_SBP_ROLE_NONE
) ? "none" :
1529 (entry
->role
== QETH_SBP_ROLE_PRIMARY
) ? "primary" :
1530 (entry
->role
== QETH_SBP_ROLE_SECONDARY
) ? "secondary" :
1532 snprintf(env_state
, sizeof(env_state
), "STATE=%s",
1533 (entry
->state
== QETH_SBP_STATE_INACTIVE
) ? "inactive" :
1534 (entry
->state
== QETH_SBP_STATE_STANDBY
) ? "standby" :
1535 (entry
->state
== QETH_SBP_STATE_ACTIVE
) ? "active" :
1537 kobject_uevent_env(&data
->card
->gdev
->dev
.kobj
,
1542 static void qeth_bridge_state_change(struct qeth_card
*card
,
1543 struct qeth_ipa_cmd
*cmd
)
1545 struct qeth_sbp_state_change
*qports
=
1546 &cmd
->data
.sbp
.data
.state_change
;
1547 struct qeth_bridge_state_data
*data
;
1550 QETH_CARD_TEXT(card
, 2, "brstchng");
1551 if (qports
->entry_length
!= sizeof(struct qeth_sbp_port_entry
)) {
1552 QETH_CARD_TEXT_(card
, 2, "BPsz%04x", qports
->entry_length
);
1555 extrasize
= sizeof(struct qeth_sbp_port_entry
) * qports
->num_entries
;
1556 data
= kzalloc(sizeof(struct qeth_bridge_state_data
) + extrasize
,
1559 QETH_CARD_TEXT(card
, 2, "BPSalloc");
1562 INIT_WORK(&data
->worker
, qeth_bridge_state_change_worker
);
1564 memcpy(&data
->qports
, qports
,
1565 sizeof(struct qeth_sbp_state_change
) + extrasize
);
1566 queue_work(qeth_wq
, &data
->worker
);
1569 struct qeth_bridge_host_data
{
1570 struct work_struct worker
;
1571 struct qeth_card
*card
;
1572 struct qeth_ipacmd_addr_change hostevs
;
1575 static void qeth_bridge_host_event_worker(struct work_struct
*work
)
1577 struct qeth_bridge_host_data
*data
=
1578 container_of(work
, struct qeth_bridge_host_data
, worker
);
1581 if (data
->hostevs
.lost_event_mask
) {
1582 dev_info(&data
->card
->gdev
->dev
,
1583 "Address notification from the Bridge Port stopped %s (%s)\n",
1584 data
->card
->dev
->name
,
1585 (data
->hostevs
.lost_event_mask
== 0x01)
1587 : (data
->hostevs
.lost_event_mask
== 0x02)
1588 ? "Bridge port state change"
1589 : "Unknown reason");
1590 mutex_lock(&data
->card
->conf_mutex
);
1591 data
->card
->options
.sbp
.hostnotification
= 0;
1592 mutex_unlock(&data
->card
->conf_mutex
);
1593 qeth_bridge_emit_host_event(data
->card
, anev_abort
,
1596 for (i
= 0; i
< data
->hostevs
.num_entries
; i
++) {
1597 struct qeth_ipacmd_addr_change_entry
*entry
=
1598 &data
->hostevs
.entry
[i
];
1599 qeth_bridge_emit_host_event(data
->card
,
1602 &entry
->token
, &entry
->addr_lnid
);
1607 static void qeth_bridge_host_event(struct qeth_card
*card
,
1608 struct qeth_ipa_cmd
*cmd
)
1610 struct qeth_ipacmd_addr_change
*hostevs
=
1611 &cmd
->data
.addrchange
;
1612 struct qeth_bridge_host_data
*data
;
1615 QETH_CARD_TEXT(card
, 2, "brhostev");
1616 if (cmd
->hdr
.return_code
!= 0x0000) {
1617 if (cmd
->hdr
.return_code
== 0x0010) {
1618 if (hostevs
->lost_event_mask
== 0x00)
1619 hostevs
->lost_event_mask
= 0xff;
1621 QETH_CARD_TEXT_(card
, 2, "BPHe%04x",
1622 cmd
->hdr
.return_code
);
1626 extrasize
= sizeof(struct qeth_ipacmd_addr_change_entry
) *
1627 hostevs
->num_entries
;
1628 data
= kzalloc(sizeof(struct qeth_bridge_host_data
) + extrasize
,
1631 QETH_CARD_TEXT(card
, 2, "BPHalloc");
1634 INIT_WORK(&data
->worker
, qeth_bridge_host_event_worker
);
1636 memcpy(&data
->hostevs
, hostevs
,
1637 sizeof(struct qeth_ipacmd_addr_change
) + extrasize
);
1638 queue_work(qeth_wq
, &data
->worker
);
1641 /* SETBRIDGEPORT support; sending commands */
1643 struct _qeth_sbp_cbctl
{
1649 enum qeth_sbp_roles
*role
;
1650 enum qeth_sbp_states
*state
;
1656 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes.
1657 * @card: qeth_card structure pointer, for debug messages.
1658 * @cbctl: state structure with hardware return codes.
1659 * @setcmd: IPA command code
1661 * Returns negative errno-compatible error indication or 0 on success.
1663 static int qeth_bridgeport_makerc(struct qeth_card
*card
,
1664 struct _qeth_sbp_cbctl
*cbctl
, enum qeth_ipa_sbp_cmd setcmd
)
1667 int is_iqd
= (card
->info
.type
== QETH_CARD_TYPE_IQD
);
1669 if ((is_iqd
&& (cbctl
->ipa_rc
== IPA_RC_SUCCESS
)) ||
1670 (!is_iqd
&& (cbctl
->ipa_rc
== cbctl
->cmd_rc
)))
1671 switch (cbctl
->cmd_rc
) {
1672 case IPA_RC_SUCCESS
:
1675 case IPA_RC_L2_UNSUPPORTED_CMD
:
1676 case IPA_RC_UNSUPPORTED_COMMAND
:
1679 case IPA_RC_SBP_OSA_NOT_CONFIGURED
:
1680 case IPA_RC_SBP_IQD_NOT_CONFIGURED
:
1681 rc
= -ENODEV
; /* maybe not the best code here? */
1682 dev_err(&card
->gdev
->dev
,
1683 "The device is not configured as a Bridge Port\n");
1685 case IPA_RC_SBP_OSA_OS_MISMATCH
:
1686 case IPA_RC_SBP_IQD_OS_MISMATCH
:
1688 dev_err(&card
->gdev
->dev
,
1689 "A Bridge Port is already configured by a different operating system\n");
1691 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY
:
1692 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY
:
1694 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT
:
1696 dev_err(&card
->gdev
->dev
,
1697 "The LAN already has a primary Bridge Port\n");
1699 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT
:
1701 dev_err(&card
->gdev
->dev
,
1702 "The device is already a primary Bridge Port\n");
1708 case IPA_RC_SBP_OSA_CURRENT_SECOND
:
1709 case IPA_RC_SBP_IQD_CURRENT_SECOND
:
1711 dev_err(&card
->gdev
->dev
,
1712 "The device is already a secondary Bridge Port\n");
1714 case IPA_RC_SBP_OSA_LIMIT_SECOND
:
1715 case IPA_RC_SBP_IQD_LIMIT_SECOND
:
1717 dev_err(&card
->gdev
->dev
,
1718 "The LAN cannot have more secondary Bridge Ports\n");
1720 case IPA_RC_SBP_OSA_CURRENT_PRIMARY
:
1721 case IPA_RC_SBP_IQD_CURRENT_PRIMARY
:
1723 dev_err(&card
->gdev
->dev
,
1724 "The device is already a primary Bridge Port\n");
1726 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN
:
1727 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN
:
1729 dev_err(&card
->gdev
->dev
,
1730 "The device is not authorized to be a Bridge Port\n");
1736 switch (cbctl
->ipa_rc
) {
1737 case IPA_RC_NOTSUPP
:
1740 case IPA_RC_UNSUPPORTED_COMMAND
:
1748 QETH_CARD_TEXT_(card
, 2, "SBPi%04x", cbctl
->ipa_rc
);
1749 QETH_CARD_TEXT_(card
, 2, "SBPc%04x", cbctl
->cmd_rc
);
1754 static struct qeth_cmd_buffer
*qeth_sbp_build_cmd(struct qeth_card
*card
,
1755 enum qeth_ipa_sbp_cmd sbp_cmd
,
1756 unsigned int cmd_length
)
1758 enum qeth_ipa_cmds ipa_cmd
= (card
->info
.type
== QETH_CARD_TYPE_IQD
) ?
1759 IPA_CMD_SETBRIDGEPORT_IQD
:
1760 IPA_CMD_SETBRIDGEPORT_OSA
;
1761 struct qeth_cmd_buffer
*iob
;
1762 struct qeth_ipa_cmd
*cmd
;
1764 iob
= qeth_get_ipacmd_buffer(card
, ipa_cmd
, 0);
1767 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+IPA_PDU_HEADER_SIZE
);
1768 cmd
->data
.sbp
.hdr
.cmdlength
= sizeof(struct qeth_ipacmd_sbp_hdr
) +
1770 cmd
->data
.sbp
.hdr
.command_code
= sbp_cmd
;
1771 cmd
->data
.sbp
.hdr
.used_total
= 1;
1772 cmd
->data
.sbp
.hdr
.seq_no
= 1;
1776 static int qeth_bridgeport_query_support_cb(struct qeth_card
*card
,
1777 struct qeth_reply
*reply
, unsigned long data
)
1779 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
1780 struct _qeth_sbp_cbctl
*cbctl
= (struct _qeth_sbp_cbctl
*)reply
->param
;
1781 QETH_CARD_TEXT(card
, 2, "brqsupcb");
1782 cbctl
->ipa_rc
= cmd
->hdr
.return_code
;
1783 cbctl
->cmd_rc
= cmd
->data
.sbp
.hdr
.return_code
;
1784 if ((cbctl
->ipa_rc
== 0) && (cbctl
->cmd_rc
== 0)) {
1785 cbctl
->data
.supported
=
1786 cmd
->data
.sbp
.data
.query_cmds_supp
.supported_cmds
;
1788 cbctl
->data
.supported
= 0;
1794 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1795 * @card: qeth_card structure pointer.
1797 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1798 * strucutre: card->options.sbp.supported_funcs.
1800 static void qeth_bridgeport_query_support(struct qeth_card
*card
)
1802 struct qeth_cmd_buffer
*iob
;
1803 struct _qeth_sbp_cbctl cbctl
;
1805 QETH_CARD_TEXT(card
, 2, "brqsuppo");
1806 iob
= qeth_sbp_build_cmd(card
, IPA_SBP_QUERY_COMMANDS_SUPPORTED
,
1807 sizeof(struct qeth_sbp_query_cmds_supp
));
1810 if (qeth_send_ipa_cmd(card
, iob
, qeth_bridgeport_query_support_cb
,
1812 qeth_bridgeport_makerc(card
, &cbctl
,
1813 IPA_SBP_QUERY_COMMANDS_SUPPORTED
)) {
1814 /* non-zero makerc signifies failure, and produce messages */
1815 card
->options
.sbp
.role
= QETH_SBP_ROLE_NONE
;
1818 card
->options
.sbp
.supported_funcs
= cbctl
.data
.supported
;
1821 static int qeth_bridgeport_query_ports_cb(struct qeth_card
*card
,
1822 struct qeth_reply
*reply
, unsigned long data
)
1824 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
1825 struct qeth_sbp_query_ports
*qports
= &cmd
->data
.sbp
.data
.query_ports
;
1826 struct _qeth_sbp_cbctl
*cbctl
= (struct _qeth_sbp_cbctl
*)reply
->param
;
1828 QETH_CARD_TEXT(card
, 2, "brqprtcb");
1829 cbctl
->ipa_rc
= cmd
->hdr
.return_code
;
1830 cbctl
->cmd_rc
= cmd
->data
.sbp
.hdr
.return_code
;
1831 if ((cbctl
->ipa_rc
!= 0) || (cbctl
->cmd_rc
!= 0))
1833 if (qports
->entry_length
!= sizeof(struct qeth_sbp_port_entry
)) {
1834 cbctl
->cmd_rc
= 0xffff;
1835 QETH_CARD_TEXT_(card
, 2, "SBPs%04x", qports
->entry_length
);
1838 /* first entry contains the state of the local port */
1839 if (qports
->num_entries
> 0) {
1840 if (cbctl
->data
.qports
.role
)
1841 *cbctl
->data
.qports
.role
= qports
->entry
[0].role
;
1842 if (cbctl
->data
.qports
.state
)
1843 *cbctl
->data
.qports
.state
= qports
->entry
[0].state
;
1849 * qeth_bridgeport_query_ports() - query local bridgeport status.
1850 * @card: qeth_card structure pointer.
1851 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1852 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1854 * Returns negative errno-compatible error indication or 0 on success.
1856 * 'role' and 'state' are not updated in case of hardware operation failure.
1858 int qeth_bridgeport_query_ports(struct qeth_card
*card
,
1859 enum qeth_sbp_roles
*role
, enum qeth_sbp_states
*state
)
1862 struct qeth_cmd_buffer
*iob
;
1863 struct _qeth_sbp_cbctl cbctl
= {
1872 QETH_CARD_TEXT(card
, 2, "brqports");
1873 if (!(card
->options
.sbp
.supported_funcs
& IPA_SBP_QUERY_BRIDGE_PORTS
))
1875 iob
= qeth_sbp_build_cmd(card
, IPA_SBP_QUERY_BRIDGE_PORTS
, 0);
1878 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_bridgeport_query_ports_cb
,
1882 return qeth_bridgeport_makerc(card
, &cbctl
, IPA_SBP_QUERY_BRIDGE_PORTS
);
1884 EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports
);
1886 static int qeth_bridgeport_set_cb(struct qeth_card
*card
,
1887 struct qeth_reply
*reply
, unsigned long data
)
1889 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*)data
;
1890 struct _qeth_sbp_cbctl
*cbctl
= (struct _qeth_sbp_cbctl
*)reply
->param
;
1891 QETH_CARD_TEXT(card
, 2, "brsetrcb");
1892 cbctl
->ipa_rc
= cmd
->hdr
.return_code
;
1893 cbctl
->cmd_rc
= cmd
->data
.sbp
.hdr
.return_code
;
1898 * qeth_bridgeport_setrole() - Assign primary role to the port.
1899 * @card: qeth_card structure pointer.
1900 * @role: Role to assign.
1902 * Returns negative errno-compatible error indication or 0 on success.
1904 int qeth_bridgeport_setrole(struct qeth_card
*card
, enum qeth_sbp_roles role
)
1908 struct qeth_cmd_buffer
*iob
;
1909 struct _qeth_sbp_cbctl cbctl
;
1910 enum qeth_ipa_sbp_cmd setcmd
;
1912 QETH_CARD_TEXT(card
, 2, "brsetrol");
1914 case QETH_SBP_ROLE_NONE
:
1915 setcmd
= IPA_SBP_RESET_BRIDGE_PORT_ROLE
;
1916 cmdlength
= sizeof(struct qeth_sbp_reset_role
);
1918 case QETH_SBP_ROLE_PRIMARY
:
1919 setcmd
= IPA_SBP_SET_PRIMARY_BRIDGE_PORT
;
1920 cmdlength
= sizeof(struct qeth_sbp_set_primary
);
1922 case QETH_SBP_ROLE_SECONDARY
:
1923 setcmd
= IPA_SBP_SET_SECONDARY_BRIDGE_PORT
;
1924 cmdlength
= sizeof(struct qeth_sbp_set_secondary
);
1929 if (!(card
->options
.sbp
.supported_funcs
& setcmd
))
1931 iob
= qeth_sbp_build_cmd(card
, setcmd
, cmdlength
);
1934 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_bridgeport_set_cb
,
1938 return qeth_bridgeport_makerc(card
, &cbctl
, setcmd
);
1942 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1943 * @card: qeth_card structure pointer, for debug messages.
1945 * Returns negative errno-compatible error indication or 0 on success.
1947 static int qeth_anset_makerc(struct qeth_card
*card
, int pnso_rc
, u16 response
)
1960 dev_err(&card
->gdev
->dev
,
1961 "Setting address notification failed\n");
1973 QETH_CARD_TEXT_(card
, 2, "SBPp%04x", pnso_rc
);
1974 QETH_CARD_TEXT_(card
, 2, "SBPr%04x", response
);
1979 static void qeth_bridgeport_an_set_cb(void *priv
,
1980 enum qdio_brinfo_entry_type type
, void *entry
)
1982 struct qeth_card
*card
= (struct qeth_card
*)priv
;
1983 struct qdio_brinfo_entry_l2
*l2entry
;
1986 if (type
!= l2_addr_lnid
) {
1991 l2entry
= (struct qdio_brinfo_entry_l2
*)entry
;
1992 code
= IPA_ADDR_CHANGE_CODE_MACADDR
;
1993 if (l2entry
->addr_lnid
.lnid
)
1994 code
|= IPA_ADDR_CHANGE_CODE_VLANID
;
1995 qeth_bridge_emit_host_event(card
, anev_reg_unreg
, code
,
1996 (struct net_if_token
*)&l2entry
->nit
,
1997 (struct mac_addr_lnid
*)&l2entry
->addr_lnid
);
2001 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
2002 * @card: qeth_card structure pointer.
2003 * @enable: 0 - disable, non-zero - enable notifications
2005 * Returns negative errno-compatible error indication or 0 on success.
2007 * On enable, emits a series of address notifications udev events for all
2008 * currently registered hosts.
2010 int qeth_bridgeport_an_set(struct qeth_card
*card
, int enable
)
2014 struct ccw_device
*ddev
;
2015 struct subchannel_id schid
;
2019 if (!card
->options
.sbp
.supported_funcs
)
2021 ddev
= CARD_DDEV(card
);
2022 ccw_device_get_schid(ddev
, &schid
);
2025 qeth_bridge_emit_host_event(card
, anev_reset
, 0, NULL
, NULL
);
2026 rc
= qdio_pnso_brinfo(schid
, 1, &response
,
2027 qeth_bridgeport_an_set_cb
, card
);
2029 rc
= qdio_pnso_brinfo(schid
, 0, &response
, NULL
, NULL
);
2030 return qeth_anset_makerc(card
, rc
, response
);
2032 EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set
);
2034 static bool qeth_bridgeport_is_in_use(struct qeth_card
*card
)
2036 return (card
->options
.sbp
.role
|| card
->options
.sbp
.reflect_promisc
||
2037 card
->options
.sbp
.hostnotification
);
2040 /* VNIC Characteristics support */
2042 /* handle VNICC IPA command return codes; convert to error codes */
2043 static int qeth_l2_vnicc_makerc(struct qeth_card
*card
, int ipa_rc
)
2048 case IPA_RC_SUCCESS
:
2050 case IPA_RC_L2_UNSUPPORTED_CMD
:
2051 case IPA_RC_NOTSUPP
:
2054 case IPA_RC_VNICC_OOSEQ
:
2057 case IPA_RC_VNICC_VNICBP
:
2060 case IPA_RC_L2_ADDR_TABLE_FULL
:
2063 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP
:
2070 QETH_CARD_TEXT_(card
, 2, "err%04x", ipa_rc
);
2074 /* generic VNICC request call back control */
2075 struct _qeth_l2_vnicc_request_cbctl
{
2089 /* generic VNICC request call back */
2090 static int qeth_l2_vnicc_request_cb(struct qeth_card
*card
,
2091 struct qeth_reply
*reply
,
2094 struct _qeth_l2_vnicc_request_cbctl
*cbctl
=
2095 (struct _qeth_l2_vnicc_request_cbctl
*) reply
->param
;
2096 struct qeth_ipa_cmd
*cmd
= (struct qeth_ipa_cmd
*) data
;
2097 struct qeth_ipacmd_vnicc
*rep
= &cmd
->data
.vnicc
;
2099 QETH_CARD_TEXT(card
, 2, "vniccrcb");
2100 if (cmd
->hdr
.return_code
)
2102 /* return results to caller */
2103 card
->options
.vnicc
.sup_chars
= rep
->hdr
.sup
;
2104 card
->options
.vnicc
.cur_chars
= rep
->hdr
.cur
;
2106 if (cbctl
->sub_cmd
== IPA_VNICC_QUERY_CMDS
)
2107 *cbctl
->result
.sup_cmds
= rep
->query_cmds
.sup_cmds
;
2109 if (cbctl
->sub_cmd
== IPA_VNICC_GET_TIMEOUT
)
2110 *cbctl
->result
.timeout
= rep
->getset_timeout
.timeout
;
2115 /* generic VNICC request */
2116 static int qeth_l2_vnicc_request(struct qeth_card
*card
,
2117 struct _qeth_l2_vnicc_request_cbctl
*cbctl
)
2119 struct qeth_ipacmd_vnicc
*req
;
2120 struct qeth_cmd_buffer
*iob
;
2121 struct qeth_ipa_cmd
*cmd
;
2124 QETH_CARD_TEXT(card
, 2, "vniccreq");
2126 /* get new buffer for request */
2127 iob
= qeth_get_ipacmd_buffer(card
, IPA_CMD_VNICC
, 0);
2131 /* create header for request */
2132 cmd
= (struct qeth_ipa_cmd
*)(iob
->data
+ IPA_PDU_HEADER_SIZE
);
2133 req
= &cmd
->data
.vnicc
;
2135 /* create sub command header for request */
2136 req
->sub_hdr
.data_length
= sizeof(req
->sub_hdr
);
2137 req
->sub_hdr
.sub_command
= cbctl
->sub_cmd
;
2139 /* create sub command specific request fields */
2140 switch (cbctl
->sub_cmd
) {
2141 case IPA_VNICC_QUERY_CHARS
:
2143 case IPA_VNICC_QUERY_CMDS
:
2144 req
->sub_hdr
.data_length
+= sizeof(req
->query_cmds
);
2145 req
->query_cmds
.vnic_char
= cbctl
->param
.vnic_char
;
2147 case IPA_VNICC_ENABLE
:
2148 case IPA_VNICC_DISABLE
:
2149 req
->sub_hdr
.data_length
+= sizeof(req
->set_char
);
2150 req
->set_char
.vnic_char
= cbctl
->param
.vnic_char
;
2152 case IPA_VNICC_SET_TIMEOUT
:
2153 req
->getset_timeout
.timeout
= cbctl
->param
.timeout
;
2155 case IPA_VNICC_GET_TIMEOUT
:
2156 req
->sub_hdr
.data_length
+= sizeof(req
->getset_timeout
);
2157 req
->getset_timeout
.vnic_char
= cbctl
->param
.vnic_char
;
2160 qeth_release_buffer(iob
->channel
, iob
);
2165 rc
= qeth_send_ipa_cmd(card
, iob
, qeth_l2_vnicc_request_cb
,
2168 return qeth_l2_vnicc_makerc(card
, rc
);
2171 /* VNICC query VNIC characteristics request */
2172 static int qeth_l2_vnicc_query_chars(struct qeth_card
*card
)
2174 struct _qeth_l2_vnicc_request_cbctl cbctl
;
2176 /* prepare callback control */
2177 cbctl
.sub_cmd
= IPA_VNICC_QUERY_CHARS
;
2179 QETH_CARD_TEXT(card
, 2, "vniccqch");
2180 return qeth_l2_vnicc_request(card
, &cbctl
);
2183 /* VNICC query sub commands request */
2184 static int qeth_l2_vnicc_query_cmds(struct qeth_card
*card
, u32 vnic_char
,
2187 struct _qeth_l2_vnicc_request_cbctl cbctl
;
2189 /* prepare callback control */
2190 cbctl
.sub_cmd
= IPA_VNICC_QUERY_CMDS
;
2191 cbctl
.param
.vnic_char
= vnic_char
;
2192 cbctl
.result
.sup_cmds
= sup_cmds
;
2194 QETH_CARD_TEXT(card
, 2, "vniccqcm");
2195 return qeth_l2_vnicc_request(card
, &cbctl
);
2198 /* VNICC enable/disable characteristic request */
2199 static int qeth_l2_vnicc_set_char(struct qeth_card
*card
, u32 vnic_char
,
2202 struct _qeth_l2_vnicc_request_cbctl cbctl
;
2204 /* prepare callback control */
2205 cbctl
.sub_cmd
= cmd
;
2206 cbctl
.param
.vnic_char
= vnic_char
;
2208 QETH_CARD_TEXT(card
, 2, "vniccedc");
2209 return qeth_l2_vnicc_request(card
, &cbctl
);
2212 /* VNICC get/set timeout for characteristic request */
2213 static int qeth_l2_vnicc_getset_timeout(struct qeth_card
*card
, u32 vnicc
,
2214 u32 cmd
, u32
*timeout
)
2216 struct _qeth_l2_vnicc_request_cbctl cbctl
;
2218 /* prepare callback control */
2219 cbctl
.sub_cmd
= cmd
;
2220 cbctl
.param
.vnic_char
= vnicc
;
2221 if (cmd
== IPA_VNICC_SET_TIMEOUT
)
2222 cbctl
.param
.timeout
= *timeout
;
2223 if (cmd
== IPA_VNICC_GET_TIMEOUT
)
2224 cbctl
.result
.timeout
= timeout
;
2226 QETH_CARD_TEXT(card
, 2, "vniccgst");
2227 return qeth_l2_vnicc_request(card
, &cbctl
);
2230 /* set current VNICC flag state; called from sysfs store function */
2231 int qeth_l2_vnicc_set_state(struct qeth_card
*card
, u32 vnicc
, bool state
)
2236 QETH_CARD_TEXT(card
, 2, "vniccsch");
2238 /* do not change anything if BridgePort is enabled */
2239 if (qeth_bridgeport_is_in_use(card
))
2242 /* check if characteristic and enable/disable are supported */
2243 if (!(card
->options
.vnicc
.sup_chars
& vnicc
) ||
2244 !(card
->options
.vnicc
.set_char_sup
& vnicc
))
2247 /* set enable/disable command and store wanted characteristic */
2249 cmd
= IPA_VNICC_ENABLE
;
2250 card
->options
.vnicc
.wanted_chars
|= vnicc
;
2252 cmd
= IPA_VNICC_DISABLE
;
2253 card
->options
.vnicc
.wanted_chars
&= ~vnicc
;
2256 /* do we need to do anything? */
2257 if (card
->options
.vnicc
.cur_chars
== card
->options
.vnicc
.wanted_chars
)
2260 /* if card is not ready, simply stop here */
2261 if (!qeth_card_hw_is_reachable(card
)) {
2263 card
->options
.vnicc
.cur_chars
|= vnicc
;
2265 card
->options
.vnicc
.cur_chars
&= ~vnicc
;
2269 rc
= qeth_l2_vnicc_set_char(card
, vnicc
, cmd
);
2271 card
->options
.vnicc
.wanted_chars
=
2272 card
->options
.vnicc
.cur_chars
;
2274 /* successful online VNICC change; handle special cases */
2275 if (state
&& vnicc
== QETH_VNICC_RX_BCAST
)
2276 card
->options
.vnicc
.rx_bcast_enabled
= true;
2277 if (!state
&& vnicc
== QETH_VNICC_LEARNING
)
2278 qeth_l2_vnicc_recover_timeout(card
, vnicc
,
2279 &card
->options
.vnicc
.learning_timeout
);
2285 /* get current VNICC flag state; called from sysfs show function */
2286 int qeth_l2_vnicc_get_state(struct qeth_card
*card
, u32 vnicc
, bool *state
)
2290 QETH_CARD_TEXT(card
, 2, "vniccgch");
2292 /* do not get anything if BridgePort is enabled */
2293 if (qeth_bridgeport_is_in_use(card
))
2296 /* check if characteristic is supported */
2297 if (!(card
->options
.vnicc
.sup_chars
& vnicc
))
2300 /* if card is ready, query current VNICC state */
2301 if (qeth_card_hw_is_reachable(card
))
2302 rc
= qeth_l2_vnicc_query_chars(card
);
2304 *state
= (card
->options
.vnicc
.cur_chars
& vnicc
) ? true : false;
2308 /* set VNICC timeout; called from sysfs store function. Currently, only learning
2311 int qeth_l2_vnicc_set_timeout(struct qeth_card
*card
, u32 timeout
)
2315 QETH_CARD_TEXT(card
, 2, "vniccsto");
2317 /* do not change anything if BridgePort is enabled */
2318 if (qeth_bridgeport_is_in_use(card
))
2321 /* check if characteristic and set_timeout are supported */
2322 if (!(card
->options
.vnicc
.sup_chars
& QETH_VNICC_LEARNING
) ||
2323 !(card
->options
.vnicc
.getset_timeout_sup
& QETH_VNICC_LEARNING
))
2326 /* do we need to do anything? */
2327 if (card
->options
.vnicc
.learning_timeout
== timeout
)
2330 /* if card is not ready, simply store the value internally and return */
2331 if (!qeth_card_hw_is_reachable(card
)) {
2332 card
->options
.vnicc
.learning_timeout
= timeout
;
2336 /* send timeout value to card; if successful, store value internally */
2337 rc
= qeth_l2_vnicc_getset_timeout(card
, QETH_VNICC_LEARNING
,
2338 IPA_VNICC_SET_TIMEOUT
, &timeout
);
2340 card
->options
.vnicc
.learning_timeout
= timeout
;
2345 /* get current VNICC timeout; called from sysfs show function. Currently, only
2346 * learning supports timeout
2348 int qeth_l2_vnicc_get_timeout(struct qeth_card
*card
, u32
*timeout
)
2352 QETH_CARD_TEXT(card
, 2, "vniccgto");
2354 /* do not get anything if BridgePort is enabled */
2355 if (qeth_bridgeport_is_in_use(card
))
2358 /* check if characteristic and get_timeout are supported */
2359 if (!(card
->options
.vnicc
.sup_chars
& QETH_VNICC_LEARNING
) ||
2360 !(card
->options
.vnicc
.getset_timeout_sup
& QETH_VNICC_LEARNING
))
2362 /* if card is ready, get timeout. Otherwise, just return stored value */
2363 *timeout
= card
->options
.vnicc
.learning_timeout
;
2364 if (qeth_card_hw_is_reachable(card
))
2365 rc
= qeth_l2_vnicc_getset_timeout(card
, QETH_VNICC_LEARNING
,
2366 IPA_VNICC_GET_TIMEOUT
,
2372 /* check if VNICC is currently enabled */
2373 bool qeth_l2_vnicc_is_in_use(struct qeth_card
*card
)
2375 /* if everything is turned off, VNICC is not active */
2376 if (!card
->options
.vnicc
.cur_chars
)
2378 /* default values are only OK if rx_bcast was not enabled by user
2379 * or the card is offline.
2381 if (card
->options
.vnicc
.cur_chars
== QETH_VNICC_DEFAULT
) {
2382 if (!card
->options
.vnicc
.rx_bcast_enabled
||
2383 !qeth_card_hw_is_reachable(card
))
2389 /* recover user timeout setting */
2390 static bool qeth_l2_vnicc_recover_timeout(struct qeth_card
*card
, u32 vnicc
,
2393 if (card
->options
.vnicc
.sup_chars
& vnicc
&&
2394 card
->options
.vnicc
.getset_timeout_sup
& vnicc
&&
2395 !qeth_l2_vnicc_getset_timeout(card
, vnicc
, IPA_VNICC_SET_TIMEOUT
,
2398 *timeout
= QETH_VNICC_DEFAULT_TIMEOUT
;
2402 /* recover user characteristic setting */
2403 static bool qeth_l2_vnicc_recover_char(struct qeth_card
*card
, u32 vnicc
,
2406 u32 cmd
= enable
? IPA_VNICC_ENABLE
: IPA_VNICC_DISABLE
;
2408 if (card
->options
.vnicc
.sup_chars
& vnicc
&&
2409 card
->options
.vnicc
.set_char_sup
& vnicc
&&
2410 !qeth_l2_vnicc_set_char(card
, vnicc
, cmd
))
2412 card
->options
.vnicc
.wanted_chars
&= ~vnicc
;
2413 card
->options
.vnicc
.wanted_chars
|= QETH_VNICC_DEFAULT
& vnicc
;
2417 /* (re-)initialize VNICC */
2418 static void qeth_l2_vnicc_init(struct qeth_card
*card
)
2420 u32
*timeout
= &card
->options
.vnicc
.learning_timeout
;
2421 unsigned int chars_len
, i
;
2422 unsigned long chars_tmp
;
2423 u32 sup_cmds
, vnicc
;
2426 QETH_CARD_TEXT(card
, 2, "vniccini");
2427 /* reset rx_bcast */
2428 card
->options
.vnicc
.rx_bcast_enabled
= 0;
2429 /* initial query and storage of VNIC characteristics */
2430 if (qeth_l2_vnicc_query_chars(card
)) {
2431 if (card
->options
.vnicc
.wanted_chars
!= QETH_VNICC_DEFAULT
||
2432 *timeout
!= QETH_VNICC_DEFAULT_TIMEOUT
)
2433 dev_err(&card
->gdev
->dev
, "Configuring the VNIC characteristics failed\n");
2434 /* fail quietly if user didn't change the default config */
2435 card
->options
.vnicc
.sup_chars
= 0;
2436 card
->options
.vnicc
.cur_chars
= 0;
2437 card
->options
.vnicc
.wanted_chars
= QETH_VNICC_DEFAULT
;
2440 /* get supported commands for each supported characteristic */
2441 chars_tmp
= card
->options
.vnicc
.sup_chars
;
2442 chars_len
= sizeof(card
->options
.vnicc
.sup_chars
) * BITS_PER_BYTE
;
2443 for_each_set_bit(i
, &chars_tmp
, chars_len
) {
2445 qeth_l2_vnicc_query_cmds(card
, vnicc
, &sup_cmds
);
2446 if (!(sup_cmds
& IPA_VNICC_SET_TIMEOUT
) ||
2447 !(sup_cmds
& IPA_VNICC_GET_TIMEOUT
))
2448 card
->options
.vnicc
.getset_timeout_sup
&= ~vnicc
;
2449 if (!(sup_cmds
& IPA_VNICC_ENABLE
) ||
2450 !(sup_cmds
& IPA_VNICC_DISABLE
))
2451 card
->options
.vnicc
.set_char_sup
&= ~vnicc
;
2453 /* enforce assumed default values and recover settings, if changed */
2454 error
= qeth_l2_vnicc_recover_timeout(card
, QETH_VNICC_LEARNING
,
2456 chars_tmp
= card
->options
.vnicc
.wanted_chars
^ QETH_VNICC_DEFAULT
;
2457 chars_tmp
|= QETH_VNICC_BRIDGE_INVISIBLE
;
2458 chars_len
= sizeof(card
->options
.vnicc
.wanted_chars
) * BITS_PER_BYTE
;
2459 for_each_set_bit(i
, &chars_tmp
, chars_len
) {
2461 enable
= card
->options
.vnicc
.wanted_chars
& vnicc
;
2462 error
|= qeth_l2_vnicc_recover_char(card
, vnicc
, enable
);
2465 dev_err(&card
->gdev
->dev
, "Configuring the VNIC characteristics failed\n");
2468 /* configure default values of VNIC characteristics */
2469 static void qeth_l2_vnicc_set_defaults(struct qeth_card
*card
)
2471 /* characteristics values */
2472 card
->options
.vnicc
.sup_chars
= QETH_VNICC_ALL
;
2473 card
->options
.vnicc
.cur_chars
= QETH_VNICC_DEFAULT
;
2474 card
->options
.vnicc
.learning_timeout
= QETH_VNICC_DEFAULT_TIMEOUT
;
2475 /* supported commands */
2476 card
->options
.vnicc
.set_char_sup
= QETH_VNICC_ALL
;
2477 card
->options
.vnicc
.getset_timeout_sup
= QETH_VNICC_LEARNING
;
2478 /* settings wanted by users */
2479 card
->options
.vnicc
.wanted_chars
= QETH_VNICC_DEFAULT
;
2482 module_init(qeth_l2_init
);
2483 module_exit(qeth_l2_exit
);
2484 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2485 MODULE_DESCRIPTION("qeth layer 2 discipline");
2486 MODULE_LICENSE("GPL");