2 * Copyright IBM Corp. 2007, 2009
3 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4 * Frank Pavlic <fpavlic@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
6 * Frank Blaschka <frank.blaschka@de.ibm.com>
9 #define KMSG_COMPONENT "qeth"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/string.h>
15 #include <linux/errno.h>
16 #include <linux/kernel.h>
17 #include <linux/slab.h>
18 #include <linux/etherdevice.h>
20 #include <linux/list.h>
21 #include <linux/hash.h>
22 #include <linux/hashtable.h>
23 #include <linux/string.h>
24 #include <asm/setup.h>
25 #include "qeth_core.h"
28 static int qeth_l2_set_offline(struct ccwgroup_device *);
29 static int qeth_l2_stop(struct net_device *);
30 static void qeth_l2_set_rx_mode(struct net_device *);
31 static void qeth_bridgeport_query_support(struct qeth_card *card);
32 static void qeth_bridge_state_change(struct qeth_card *card,
33 struct qeth_ipa_cmd *cmd);
34 static void qeth_bridge_host_event(struct qeth_card *card,
35 struct qeth_ipa_cmd *cmd);
37 static int qeth_l2_verify_dev(struct net_device *dev)
39 struct qeth_card *card;
43 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
44 list_for_each_entry(card, &qeth_core_card_list.list, list) {
45 if (card->dev == dev) {
50 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
55 static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
57 struct qeth_card *card;
58 struct net_device *ndev;
61 struct ccw_dev_id read_devid;
64 memcpy(&temp_dev_no, read_dev_no, 2);
65 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
66 list_for_each_entry(card, &qeth_core_card_list.list, list) {
67 ccw_device_get_id(CARD_RDEV(card), &read_devid);
68 if (read_devid.devno == temp_dev_no) {
73 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
77 static int qeth_setdel_makerc(struct qeth_card *card, int retcode)
82 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
87 case IPA_RC_L2_UNSUPPORTED_CMD:
90 case IPA_RC_L2_ADDR_TABLE_FULL:
93 case IPA_RC_L2_DUP_MAC:
94 case IPA_RC_L2_DUP_LAYER3_MAC:
97 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
98 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
101 case IPA_RC_L2_MAC_NOT_FOUND:
114 static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
115 enum qeth_ipa_cmds ipacmd)
117 struct qeth_ipa_cmd *cmd;
118 struct qeth_cmd_buffer *iob;
120 QETH_CARD_TEXT(card, 2, "L2sdmac");
121 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
124 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
125 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
126 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
127 return qeth_setdel_makerc(card, qeth_send_ipa_cmd(card, iob,
131 static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
135 QETH_CARD_TEXT(card, 2, "L2Setmac");
136 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC);
138 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
139 memcpy(card->dev->dev_addr, mac, OSA_ADDR_LEN);
140 dev_info(&card->gdev->dev,
141 "MAC address %pM successfully registered on device %s\n",
142 card->dev->dev_addr, card->dev->name);
144 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
147 dev_warn(&card->gdev->dev,
148 "MAC address %pM already exists\n", mac);
151 dev_warn(&card->gdev->dev,
152 "MAC address %pM is not authorized\n", mac);
159 static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
163 QETH_CARD_TEXT(card, 2, "L2Delmac");
164 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
166 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC);
168 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
172 static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
176 QETH_CARD_TEXT(card, 2, "L2Sgmac");
177 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC);
179 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s\n",
180 mac, QETH_CARD_IFNAME(card));
182 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %d\n",
183 mac, QETH_CARD_IFNAME(card), rc);
187 static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
191 QETH_CARD_TEXT(card, 2, "L2Dgmac");
192 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC);
195 "Could not delete group MAC %pM on %s: %d\n",
196 mac, QETH_CARD_IFNAME(card), rc);
200 static int qeth_l2_write_mac(struct qeth_card *card, struct qeth_mac *mac)
203 return qeth_l2_send_setdelmac(card, mac->mac_addr,
206 return qeth_l2_send_setgroupmac(card, mac->mac_addr);
210 static int qeth_l2_remove_mac(struct qeth_card *card, struct qeth_mac *mac)
213 return qeth_l2_send_setdelmac(card, mac->mac_addr,
216 return qeth_l2_send_delgroupmac(card, mac->mac_addr);
220 static void qeth_l2_del_all_macs(struct qeth_card *card)
222 struct qeth_mac *mac;
223 struct hlist_node *tmp;
226 spin_lock_bh(&card->mclock);
227 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
228 hash_del(&mac->hnode);
231 spin_unlock_bh(&card->mclock);
234 static int qeth_l2_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
236 if (card->info.type == QETH_CARD_TYPE_OSN)
238 if (is_broadcast_ether_addr(skb->data))
239 return RTN_BROADCAST;
240 if (is_multicast_ether_addr(skb->data))
241 return RTN_MULTICAST;
245 static void qeth_l2_hdr_csum(struct qeth_card *card, struct qeth_hdr *hdr,
248 struct iphdr *iph = ip_hdr(skb);
250 /* tcph->check contains already the pseudo hdr checksum
251 * so just set the header flags
253 if (iph->protocol == IPPROTO_UDP)
254 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_UDP;
255 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
256 QETH_HDR_EXT_CSUM_HDR_REQ;
258 if (card->options.performance_stats)
259 card->perf_stats.tx_csum++;
262 static void qeth_l2_fill_header(struct qeth_hdr *hdr, struct sk_buff *skb,
263 int cast_type, unsigned int data_len)
265 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
267 memset(hdr, 0, sizeof(struct qeth_hdr));
268 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
269 hdr->hdr.l2.pkt_length = data_len;
271 /* set byte byte 3 to casting flags */
272 if (cast_type == RTN_MULTICAST)
273 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
274 else if (cast_type == RTN_BROADCAST)
275 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
277 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
279 /* VSWITCH relies on the VLAN
280 * information to be present in
282 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
283 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
284 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
288 static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
289 struct qeth_reply *reply, unsigned long data)
291 struct qeth_ipa_cmd *cmd;
293 QETH_CARD_TEXT(card, 2, "L2sdvcb");
294 cmd = (struct qeth_ipa_cmd *) data;
295 if (cmd->hdr.return_code) {
296 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
297 "Continuing\n", cmd->data.setdelvlan.vlan_id,
298 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
299 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
300 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
305 static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
306 enum qeth_ipa_cmds ipacmd)
308 struct qeth_ipa_cmd *cmd;
309 struct qeth_cmd_buffer *iob;
311 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
312 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
315 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
316 cmd->data.setdelvlan.vlan_id = i;
317 return qeth_send_ipa_cmd(card, iob,
318 qeth_l2_send_setdelvlan_cb, NULL);
321 static void qeth_l2_process_vlans(struct qeth_card *card)
323 struct qeth_vlan_vid *id;
324 QETH_CARD_TEXT(card, 3, "L2prcvln");
325 spin_lock_bh(&card->vlanlock);
326 list_for_each_entry(id, &card->vid_list, list) {
327 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
329 spin_unlock_bh(&card->vlanlock);
332 static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
333 __be16 proto, u16 vid)
335 struct qeth_card *card = dev->ml_priv;
336 struct qeth_vlan_vid *id;
339 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
342 if (card->info.type == QETH_CARD_TYPE_OSM) {
343 QETH_CARD_TEXT(card, 3, "aidOSM");
346 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
347 QETH_CARD_TEXT(card, 3, "aidREC");
350 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
353 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
358 spin_lock_bh(&card->vlanlock);
359 list_add_tail(&id->list, &card->vid_list);
360 spin_unlock_bh(&card->vlanlock);
367 static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
368 __be16 proto, u16 vid)
370 struct qeth_vlan_vid *id, *tmpid = NULL;
371 struct qeth_card *card = dev->ml_priv;
374 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
375 if (card->info.type == QETH_CARD_TYPE_OSM) {
376 QETH_CARD_TEXT(card, 3, "kidOSM");
379 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
380 QETH_CARD_TEXT(card, 3, "kidREC");
383 spin_lock_bh(&card->vlanlock);
384 list_for_each_entry(id, &card->vid_list, list) {
385 if (id->vid == vid) {
391 spin_unlock_bh(&card->vlanlock);
393 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
396 qeth_l2_set_rx_mode(card->dev);
400 static void qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
402 QETH_DBF_TEXT(SETUP , 2, "stopcard");
403 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
405 qeth_set_allowed_threads(card, 0, 1);
406 if (card->read.state == CH_STATE_UP &&
407 card->write.state == CH_STATE_UP &&
408 (card->state == CARD_STATE_UP)) {
410 card->info.type != QETH_CARD_TYPE_OSN) {
411 qeth_l2_stop(card->dev);
414 dev_close(card->dev);
417 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
418 card->state = CARD_STATE_SOFTSETUP;
420 if (card->state == CARD_STATE_SOFTSETUP) {
421 qeth_l2_del_all_macs(card);
422 qeth_clear_ipacmd_list(card);
423 card->state = CARD_STATE_HARDSETUP;
425 if (card->state == CARD_STATE_HARDSETUP) {
426 qeth_qdio_clear_card(card, 0);
427 qeth_clear_qdio_buffers(card);
428 qeth_clear_working_pool_list(card);
429 card->state = CARD_STATE_DOWN;
431 if (card->state == CARD_STATE_DOWN) {
432 qeth_clear_cmd_buffers(&card->read);
433 qeth_clear_cmd_buffers(&card->write);
437 static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
438 int budget, int *done)
442 struct qeth_hdr *hdr;
446 WARN_ON_ONCE(!budget);
448 skb = qeth_core_get_next_skb(card,
449 &card->qdio.in_q->bufs[card->rx.b_index],
450 &card->rx.b_element, &card->rx.e_offset, &hdr);
455 skb->dev = card->dev;
456 switch (hdr->hdr.l2.id) {
457 case QETH_HEADER_TYPE_LAYER2:
458 skb->pkt_type = PACKET_HOST;
459 skb->protocol = eth_type_trans(skb, skb->dev);
460 if ((card->dev->features & NETIF_F_RXCSUM)
461 && ((hdr->hdr.l2.flags[1] &
462 (QETH_HDR_EXT_CSUM_HDR_REQ |
463 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
464 (QETH_HDR_EXT_CSUM_HDR_REQ |
465 QETH_HDR_EXT_CSUM_TRANSP_REQ)))
466 skb->ip_summed = CHECKSUM_UNNECESSARY;
468 skb->ip_summed = CHECKSUM_NONE;
469 if (skb->protocol == htons(ETH_P_802_2))
470 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
472 napi_gro_receive(&card->napi, skb);
474 case QETH_HEADER_TYPE_OSN:
475 if (card->info.type == QETH_CARD_TYPE_OSN) {
476 skb_push(skb, sizeof(struct qeth_hdr));
477 skb_copy_to_linear_data(skb, hdr,
478 sizeof(struct qeth_hdr));
480 card->osn_info.data_cb(skb);
485 dev_kfree_skb_any(skb);
486 QETH_CARD_TEXT(card, 3, "inbunkno");
487 QETH_DBF_HEX(CTRL, 3, hdr, sizeof(*hdr));
492 card->stats.rx_packets++;
493 card->stats.rx_bytes += len;
498 static int qeth_l2_request_initial_mac(struct qeth_card *card)
501 char vendor_pre[] = {0x02, 0x00, 0x00};
503 QETH_DBF_TEXT(SETUP, 2, "l2reqmac");
504 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
507 rc = qeth_vm_request_mac(card);
510 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %s: x%x\n",
511 CARD_BUS_ID(card), rc);
512 QETH_DBF_TEXT_(SETUP, 2, "err%04x", rc);
513 /* fall back to alternative mechanism: */
516 if (card->info.type == QETH_CARD_TYPE_IQD ||
517 card->info.type == QETH_CARD_TYPE_OSM ||
518 card->info.type == QETH_CARD_TYPE_OSX ||
519 card->info.guestlan) {
520 rc = qeth_setadpparms_change_macaddr(card);
522 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
523 "device %s: x%x\n", CARD_BUS_ID(card), rc);
524 QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
528 eth_random_addr(card->dev->dev_addr);
529 memcpy(card->dev->dev_addr, vendor_pre, 3);
532 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, card->dev->addr_len);
536 static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
538 struct sockaddr *addr = p;
539 struct qeth_card *card = dev->ml_priv;
542 QETH_CARD_TEXT(card, 3, "setmac");
544 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
545 QETH_CARD_TEXT(card, 3, "setmcINV");
549 if (card->info.type == QETH_CARD_TYPE_OSN ||
550 card->info.type == QETH_CARD_TYPE_OSM ||
551 card->info.type == QETH_CARD_TYPE_OSX) {
552 QETH_CARD_TEXT(card, 3, "setmcTYP");
555 QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN);
556 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
557 QETH_CARD_TEXT(card, 3, "setmcREC");
560 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
561 if (!rc || (rc == -ENOENT))
562 rc = qeth_l2_send_setmac(card, addr->sa_data);
563 return rc ? -EINVAL : 0;
566 static void qeth_promisc_to_bridge(struct qeth_card *card)
568 struct net_device *dev = card->dev;
569 enum qeth_ipa_promisc_modes promisc_mode;
573 QETH_CARD_TEXT(card, 3, "pmisc2br");
575 if (!card->options.sbp.reflect_promisc)
577 promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON
578 : SET_PROMISC_MODE_OFF;
579 if (promisc_mode == card->info.promisc_mode)
582 if (promisc_mode == SET_PROMISC_MODE_ON) {
583 if (card->options.sbp.reflect_promisc_primary)
584 role = QETH_SBP_ROLE_PRIMARY;
586 role = QETH_SBP_ROLE_SECONDARY;
588 role = QETH_SBP_ROLE_NONE;
590 rc = qeth_bridgeport_setrole(card, role);
591 QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x",
592 (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc);
594 card->options.sbp.role = role;
595 card->info.promisc_mode = promisc_mode;
599 /* New MAC address is added to the hash table and marked to be written on card
600 * only if there is not in the hash table storage already
603 static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha,
606 u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2]));
607 struct qeth_mac *mac;
609 hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) {
610 if (is_uc == mac->is_uc &&
611 !memcmp(ha->addr, mac->mac_addr, OSA_ADDR_LEN)) {
612 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
617 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
622 memcpy(mac->mac_addr, ha->addr, OSA_ADDR_LEN);
624 mac->disp_flag = QETH_DISP_ADDR_ADD;
626 hash_add(card->mac_htable, &mac->hnode, mac_hash);
629 static void qeth_l2_set_rx_mode(struct net_device *dev)
631 struct qeth_card *card = dev->ml_priv;
632 struct netdev_hw_addr *ha;
633 struct qeth_mac *mac;
634 struct hlist_node *tmp;
638 if (card->info.type == QETH_CARD_TYPE_OSN)
641 QETH_CARD_TEXT(card, 3, "setmulti");
642 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
643 (card->state != CARD_STATE_UP))
646 spin_lock_bh(&card->mclock);
648 netdev_for_each_mc_addr(ha, dev)
649 qeth_l2_add_mac(card, ha, 0);
651 netdev_for_each_uc_addr(ha, dev)
652 qeth_l2_add_mac(card, ha, 1);
654 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
655 if (mac->disp_flag == QETH_DISP_ADDR_DELETE) {
656 qeth_l2_remove_mac(card, mac);
657 hash_del(&mac->hnode);
660 } else if (mac->disp_flag == QETH_DISP_ADDR_ADD) {
661 rc = qeth_l2_write_mac(card, mac);
663 hash_del(&mac->hnode);
666 mac->disp_flag = QETH_DISP_ADDR_DELETE;
668 mac->disp_flag = QETH_DISP_ADDR_DELETE;
671 spin_unlock_bh(&card->mclock);
673 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
674 qeth_setadp_promisc_mode(card);
676 qeth_promisc_to_bridge(card);
679 static int qeth_l2_xmit_iqd(struct qeth_card *card, struct sk_buff *skb,
680 struct qeth_qdio_out_q *queue, int cast_type)
682 unsigned int data_offset = ETH_HLEN;
683 struct qeth_hdr *hdr;
686 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
689 qeth_l2_fill_header(hdr, skb, cast_type, skb->len);
690 skb_copy_from_linear_data(skb, ((char *)hdr) + sizeof(*hdr),
693 if (!qeth_get_elements_no(card, skb, 1, data_offset)) {
697 rc = qeth_do_send_packet_fast(card, queue, skb, hdr, data_offset,
698 sizeof(*hdr) + data_offset);
701 kmem_cache_free(qeth_core_header_cache, hdr);
705 static int qeth_l2_xmit_osa(struct qeth_card *card, struct sk_buff *skb,
706 struct qeth_qdio_out_q *queue, int cast_type)
708 int push_len = sizeof(struct qeth_hdr);
709 unsigned int elements, nr_frags;
710 unsigned int hdr_elements = 0;
711 struct qeth_hdr *hdr = NULL;
712 unsigned int hd_len = 0;
715 /* fix hardware limitation: as long as we do not have sbal
716 * chaining we can not send long frag lists
718 if (!qeth_get_elements_no(card, skb, 0, 0)) {
719 rc = skb_linearize(skb);
721 if (card->options.performance_stats) {
723 card->perf_stats.tx_linfail++;
725 card->perf_stats.tx_lin++;
730 nr_frags = skb_shinfo(skb)->nr_frags;
732 rc = skb_cow_head(skb, push_len);
735 push_len = qeth_push_hdr(skb, &hdr, push_len);
739 /* hdr was allocated from cache */
740 hd_len = sizeof(*hdr);
743 qeth_l2_fill_header(hdr, skb, cast_type, skb->len - push_len);
744 if (skb->ip_summed == CHECKSUM_PARTIAL)
745 qeth_l2_hdr_csum(card, hdr, skb);
747 elements = qeth_get_elements_no(card, skb, hdr_elements, 0);
752 elements += hdr_elements;
754 /* TODO: remove the skb_orphan() once TX completion is fast enough */
756 rc = qeth_do_send_packet(card, queue, skb, hdr, 0, hd_len, elements);
759 if (card->options.performance_stats && nr_frags) {
760 card->perf_stats.sg_skbs_sent++;
761 /* nr_frags + skb->data */
762 card->perf_stats.sg_frags_sent += nr_frags + 1;
766 kmem_cache_free(qeth_core_header_cache, hdr);
768 /* roll back to ETH header */
769 skb_pull(skb, push_len);
774 static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb,
775 struct qeth_qdio_out_q *queue)
777 unsigned int elements;
778 struct qeth_hdr *hdr;
780 if (skb->protocol == htons(ETH_P_IPV6))
781 return -EPROTONOSUPPORT;
783 hdr = (struct qeth_hdr *)skb->data;
784 elements = qeth_get_elements_no(card, skb, 0, 0);
787 if (qeth_hdr_chk_and_bounce(skb, &hdr, sizeof(*hdr)))
789 return qeth_do_send_packet(card, queue, skb, hdr, 0, 0, elements);
792 static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb,
793 struct net_device *dev)
795 struct qeth_card *card = dev->ml_priv;
796 int cast_type = qeth_l2_get_cast_type(card, skb);
797 struct qeth_qdio_out_q *queue;
798 int tx_bytes = skb->len;
801 if (card->qdio.do_prio_queueing || (cast_type &&
802 card->info.is_multicast_different))
803 queue = card->qdio.out_qs[qeth_get_priority_queue(card, skb,
804 qeth_get_ip_version(skb), cast_type)];
806 queue = card->qdio.out_qs[card->qdio.default_out_queue];
808 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
809 card->stats.tx_carrier_errors++;
813 if (card->options.performance_stats) {
814 card->perf_stats.outbound_cnt++;
815 card->perf_stats.outbound_start_time = qeth_get_micros();
817 netif_stop_queue(dev);
819 switch (card->info.type) {
820 case QETH_CARD_TYPE_OSN:
821 rc = qeth_l2_xmit_osn(card, skb, queue);
823 case QETH_CARD_TYPE_IQD:
824 rc = qeth_l2_xmit_iqd(card, skb, queue, cast_type);
827 rc = qeth_l2_xmit_osa(card, skb, queue, cast_type);
831 card->stats.tx_packets++;
832 card->stats.tx_bytes += tx_bytes;
833 if (card->options.performance_stats)
834 card->perf_stats.outbound_time += qeth_get_micros() -
835 card->perf_stats.outbound_start_time;
836 netif_wake_queue(dev);
838 } else if (rc == -EBUSY) {
839 return NETDEV_TX_BUSY;
840 } /* else fall through */
843 card->stats.tx_dropped++;
844 card->stats.tx_errors++;
845 dev_kfree_skb_any(skb);
846 netif_wake_queue(dev);
850 static int __qeth_l2_open(struct net_device *dev)
852 struct qeth_card *card = dev->ml_priv;
855 QETH_CARD_TEXT(card, 4, "qethopen");
856 if (card->state == CARD_STATE_UP)
858 if (card->state != CARD_STATE_SOFTSETUP)
861 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
862 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
863 QETH_CARD_TEXT(card, 4, "nomacadr");
866 card->data.state = CH_STATE_UP;
867 card->state = CARD_STATE_UP;
868 netif_start_queue(dev);
870 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
871 napi_enable(&card->napi);
873 napi_schedule(&card->napi);
874 /* kick-start the NAPI softirq: */
881 static int qeth_l2_open(struct net_device *dev)
883 struct qeth_card *card = dev->ml_priv;
885 QETH_CARD_TEXT(card, 5, "qethope_");
886 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
887 QETH_CARD_TEXT(card, 3, "openREC");
890 return __qeth_l2_open(dev);
893 static int qeth_l2_stop(struct net_device *dev)
895 struct qeth_card *card = dev->ml_priv;
897 QETH_CARD_TEXT(card, 4, "qethstop");
898 netif_tx_disable(dev);
899 if (card->state == CARD_STATE_UP) {
900 card->state = CARD_STATE_SOFTSETUP;
901 napi_disable(&card->napi);
906 static const struct device_type qeth_l2_devtype = {
907 .name = "qeth_layer2",
908 .groups = qeth_l2_attr_groups,
911 static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
913 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
916 if (gdev->dev.type == &qeth_generic_devtype) {
917 rc = qeth_l2_create_device_attributes(&gdev->dev);
921 INIT_LIST_HEAD(&card->vid_list);
922 hash_init(card->mac_htable);
923 card->options.layer2 = 1;
924 card->info.hwtrap = 0;
928 static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
930 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
932 if (cgdev->dev.type == &qeth_generic_devtype)
933 qeth_l2_remove_device_attributes(&cgdev->dev);
934 qeth_set_allowed_threads(card, 0, 1);
935 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
937 if (cgdev->state == CCWGROUP_ONLINE)
938 qeth_l2_set_offline(cgdev);
941 unregister_netdev(card->dev);
942 free_netdev(card->dev);
948 static const struct ethtool_ops qeth_l2_ethtool_ops = {
949 .get_link = ethtool_op_get_link,
950 .get_strings = qeth_core_get_strings,
951 .get_ethtool_stats = qeth_core_get_ethtool_stats,
952 .get_sset_count = qeth_core_get_sset_count,
953 .get_drvinfo = qeth_core_get_drvinfo,
954 .get_link_ksettings = qeth_core_ethtool_get_link_ksettings,
957 static const struct ethtool_ops qeth_l2_osn_ops = {
958 .get_strings = qeth_core_get_strings,
959 .get_ethtool_stats = qeth_core_get_ethtool_stats,
960 .get_sset_count = qeth_core_get_sset_count,
961 .get_drvinfo = qeth_core_get_drvinfo,
964 static const struct net_device_ops qeth_l2_netdev_ops = {
965 .ndo_open = qeth_l2_open,
966 .ndo_stop = qeth_l2_stop,
967 .ndo_get_stats = qeth_get_stats,
968 .ndo_start_xmit = qeth_l2_hard_start_xmit,
969 .ndo_features_check = qeth_features_check,
970 .ndo_validate_addr = eth_validate_addr,
971 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
972 .ndo_do_ioctl = qeth_do_ioctl,
973 .ndo_set_mac_address = qeth_l2_set_mac_address,
974 .ndo_change_mtu = qeth_change_mtu,
975 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
976 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
977 .ndo_tx_timeout = qeth_tx_timeout,
978 .ndo_fix_features = qeth_fix_features,
979 .ndo_set_features = qeth_set_features
982 static int qeth_l2_setup_netdev(struct qeth_card *card)
984 switch (card->info.type) {
985 case QETH_CARD_TYPE_IQD:
986 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
989 case QETH_CARD_TYPE_OSN:
990 card->dev = alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN,
994 card->dev = alloc_etherdev(0);
1000 card->dev->ml_priv = card;
1001 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
1002 card->dev->mtu = card->info.initial_mtu;
1003 card->dev->min_mtu = 64;
1004 card->dev->max_mtu = ETH_MAX_MTU;
1005 card->dev->netdev_ops = &qeth_l2_netdev_ops;
1006 if (card->info.type == QETH_CARD_TYPE_OSN) {
1007 card->dev->ethtool_ops = &qeth_l2_osn_ops;
1008 card->dev->flags |= IFF_NOARP;
1010 card->dev->ethtool_ops = &qeth_l2_ethtool_ops;
1012 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
1013 if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) {
1014 card->dev->hw_features = NETIF_F_SG;
1015 card->dev->vlan_features = NETIF_F_SG;
1016 card->dev->features |= NETIF_F_SG;
1017 /* OSA 3S and earlier has no RX/TX support */
1018 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
1019 card->dev->hw_features |= NETIF_F_IP_CSUM;
1020 card->dev->vlan_features |= NETIF_F_IP_CSUM;
1022 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
1023 card->dev->hw_features |= NETIF_F_RXCSUM;
1024 card->dev->vlan_features |= NETIF_F_RXCSUM;
1027 if (card->info.type != QETH_CARD_TYPE_OSN &&
1028 card->info.type != QETH_CARD_TYPE_IQD) {
1029 card->dev->priv_flags &= ~IFF_TX_SKB_SHARING;
1030 card->dev->needed_headroom = sizeof(struct qeth_hdr);
1033 card->info.broadcast_capable = 1;
1034 qeth_l2_request_initial_mac(card);
1035 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
1036 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
1037 netif_carrier_off(card->dev);
1038 return register_netdev(card->dev);
1041 static int qeth_l2_start_ipassists(struct qeth_card *card)
1043 /* configure isolation level */
1044 if (qeth_set_access_ctrl_online(card, 0))
1049 static void qeth_l2_trace_features(struct qeth_card *card)
1051 QETH_CARD_TEXT(card, 2, "l2featur");
1052 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs,
1053 sizeof(card->options.sbp.supported_funcs));
1056 static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
1058 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1060 enum qeth_card_states recover_flag;
1062 mutex_lock(&card->discipline_mutex);
1063 mutex_lock(&card->conf_mutex);
1064 QETH_DBF_TEXT(SETUP, 2, "setonlin");
1065 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
1067 recover_flag = card->state;
1068 rc = qeth_core_hardsetup_card(card);
1070 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
1074 qeth_bridgeport_query_support(card);
1075 if (card->options.sbp.supported_funcs)
1076 dev_info(&card->gdev->dev,
1077 "The device represents a Bridge Capable Port\n");
1078 qeth_trace_features(card);
1079 qeth_l2_trace_features(card);
1081 if (!card->dev && qeth_l2_setup_netdev(card)) {
1086 if (card->info.type != QETH_CARD_TYPE_OSN)
1087 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
1089 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
1090 if (card->info.hwtrap &&
1091 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
1092 card->info.hwtrap = 0;
1094 card->info.hwtrap = 0;
1096 qeth_l2_setup_bridgeport_attrs(card);
1098 card->state = CARD_STATE_HARDSETUP;
1099 memset(&card->rx, 0, sizeof(struct qeth_rx));
1100 qeth_print_status_message(card);
1103 QETH_DBF_TEXT(SETUP, 2, "softsetp");
1105 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
1106 (card->info.type == QETH_CARD_TYPE_OSX)) {
1107 rc = qeth_l2_start_ipassists(card);
1112 if (card->info.type != QETH_CARD_TYPE_OSN &&
1113 card->info.type != QETH_CARD_TYPE_OSM)
1114 qeth_l2_process_vlans(card);
1116 netif_tx_disable(card->dev);
1118 rc = qeth_init_qdio_queues(card);
1120 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
1124 card->state = CARD_STATE_SOFTSETUP;
1125 if (card->lan_online)
1126 netif_carrier_on(card->dev);
1128 netif_carrier_off(card->dev);
1130 qeth_set_allowed_threads(card, 0xffffffff, 0);
1131 if (recover_flag == CARD_STATE_RECOVER) {
1132 if (recovery_mode &&
1133 card->info.type != QETH_CARD_TYPE_OSN) {
1134 __qeth_l2_open(card->dev);
1137 dev_open(card->dev);
1140 /* this also sets saved unicast addresses */
1141 qeth_l2_set_rx_mode(card->dev);
1143 qeth_recover_features(card->dev);
1146 /* let user_space know that device is online */
1147 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
1148 mutex_unlock(&card->conf_mutex);
1149 mutex_unlock(&card->discipline_mutex);
1153 qeth_l2_stop_card(card, 0);
1154 ccw_device_set_offline(CARD_DDEV(card));
1155 ccw_device_set_offline(CARD_WDEV(card));
1156 ccw_device_set_offline(CARD_RDEV(card));
1157 qdio_free(CARD_DDEV(card));
1158 if (recover_flag == CARD_STATE_RECOVER)
1159 card->state = CARD_STATE_RECOVER;
1161 card->state = CARD_STATE_DOWN;
1162 mutex_unlock(&card->conf_mutex);
1163 mutex_unlock(&card->discipline_mutex);
1167 static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1169 return __qeth_l2_set_online(gdev, 0);
1172 static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1175 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1176 int rc = 0, rc2 = 0, rc3 = 0;
1177 enum qeth_card_states recover_flag;
1179 mutex_lock(&card->discipline_mutex);
1180 mutex_lock(&card->conf_mutex);
1181 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1182 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
1184 if (card->dev && netif_carrier_ok(card->dev))
1185 netif_carrier_off(card->dev);
1186 recover_flag = card->state;
1187 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
1188 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1189 card->info.hwtrap = 1;
1191 qeth_l2_stop_card(card, recovery_mode);
1192 rc = ccw_device_set_offline(CARD_DDEV(card));
1193 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1194 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1196 rc = (rc2) ? rc2 : rc3;
1198 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1199 qdio_free(CARD_DDEV(card));
1200 if (recover_flag == CARD_STATE_UP)
1201 card->state = CARD_STATE_RECOVER;
1202 /* let user_space know that device is offline */
1203 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
1204 mutex_unlock(&card->conf_mutex);
1205 mutex_unlock(&card->discipline_mutex);
1209 static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1211 return __qeth_l2_set_offline(cgdev, 0);
1214 static int qeth_l2_recover(void *ptr)
1216 struct qeth_card *card;
1219 card = (struct qeth_card *) ptr;
1220 QETH_CARD_TEXT(card, 2, "recover1");
1221 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1223 QETH_CARD_TEXT(card, 2, "recover2");
1224 dev_warn(&card->gdev->dev,
1225 "A recovery process has been started for the device\n");
1226 qeth_set_recovery_task(card);
1227 __qeth_l2_set_offline(card->gdev, 1);
1228 rc = __qeth_l2_set_online(card->gdev, 1);
1230 dev_info(&card->gdev->dev,
1231 "Device successfully recovered!\n");
1233 qeth_close_dev(card);
1234 dev_warn(&card->gdev->dev, "The qeth device driver "
1235 "failed to recover an error on the device\n");
1237 qeth_clear_recovery_task(card);
1238 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1239 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
1243 static int __init qeth_l2_init(void)
1245 pr_info("register layer 2 discipline\n");
1249 static void __exit qeth_l2_exit(void)
1251 pr_info("unregister layer 2 discipline\n");
1254 static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1256 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1259 netif_device_detach(card->dev);
1260 qeth_set_allowed_threads(card, 0, 1);
1261 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1262 if (gdev->state == CCWGROUP_OFFLINE)
1264 if (card->state == CARD_STATE_UP) {
1265 if (card->info.hwtrap)
1266 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1267 __qeth_l2_set_offline(card->gdev, 1);
1269 __qeth_l2_set_offline(card->gdev, 0);
1273 static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1275 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1278 if (gdev->state == CCWGROUP_OFFLINE)
1281 if (card->state == CARD_STATE_RECOVER) {
1282 rc = __qeth_l2_set_online(card->gdev, 1);
1285 dev_close(card->dev);
1289 rc = __qeth_l2_set_online(card->gdev, 0);
1291 qeth_set_allowed_threads(card, 0xffffffff, 0);
1293 netif_device_attach(card->dev);
1295 dev_warn(&card->gdev->dev, "The qeth device driver "
1296 "failed to recover an error on the device\n");
1300 /* Returns zero if the command is successfully "consumed" */
1301 static int qeth_l2_control_event(struct qeth_card *card,
1302 struct qeth_ipa_cmd *cmd)
1304 switch (cmd->hdr.command) {
1305 case IPA_CMD_SETBRIDGEPORT_OSA:
1306 case IPA_CMD_SETBRIDGEPORT_IQD:
1307 if (cmd->data.sbp.hdr.command_code ==
1308 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
1309 qeth_bridge_state_change(card, cmd);
1313 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
1314 qeth_bridge_host_event(card, cmd);
1321 struct qeth_discipline qeth_l2_discipline = {
1322 .devtype = &qeth_l2_devtype,
1323 .start_poll = qeth_qdio_start_poll,
1324 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
1325 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
1326 .process_rx_buffer = qeth_l2_process_inbound_buffer,
1327 .recover = qeth_l2_recover,
1328 .setup = qeth_l2_probe_device,
1329 .remove = qeth_l2_remove_device,
1330 .set_online = qeth_l2_set_online,
1331 .set_offline = qeth_l2_set_offline,
1332 .freeze = qeth_l2_pm_suspend,
1333 .thaw = qeth_l2_pm_resume,
1334 .restore = qeth_l2_pm_resume,
1336 .control_event_handler = qeth_l2_control_event,
1338 EXPORT_SYMBOL_GPL(qeth_l2_discipline);
1340 static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1341 struct qeth_cmd_buffer *iob)
1343 unsigned long flags;
1346 QETH_CARD_TEXT(card, 5, "osndctrd");
1348 wait_event(card->wait_q,
1349 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1350 qeth_prepare_control_data(card, len, iob);
1351 QETH_CARD_TEXT(card, 6, "osnoirqp");
1352 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1353 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1354 (addr_t) iob, 0, 0);
1355 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1357 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
1358 "ccw_device_start rc = %i\n", rc);
1359 QETH_CARD_TEXT_(card, 2, " err%d", rc);
1360 qeth_release_buffer(iob->channel, iob);
1361 atomic_set(&card->write.irq_pending, 0);
1362 wake_up(&card->wait_q);
1367 static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1368 struct qeth_cmd_buffer *iob, int data_len)
1372 QETH_CARD_TEXT(card, 4, "osndipa");
1374 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1375 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1377 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1378 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1379 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1380 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1381 return qeth_osn_send_control_data(card, s1, iob);
1384 int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1386 struct qeth_cmd_buffer *iob;
1387 struct qeth_card *card;
1392 card = dev->ml_priv;
1395 QETH_CARD_TEXT(card, 2, "osnsdmc");
1396 if (!qeth_card_hw_is_reachable(card))
1398 iob = qeth_wait_for_buffer(&card->write);
1399 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1400 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1403 EXPORT_SYMBOL(qeth_osn_assist);
1405 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1406 int (*assist_cb)(struct net_device *, void *),
1407 int (*data_cb)(struct sk_buff *))
1409 struct qeth_card *card;
1411 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1414 card = (*dev)->ml_priv;
1417 QETH_CARD_TEXT(card, 2, "osnreg");
1418 if ((assist_cb == NULL) || (data_cb == NULL))
1420 card->osn_info.assist_cb = assist_cb;
1421 card->osn_info.data_cb = data_cb;
1424 EXPORT_SYMBOL(qeth_osn_register);
1426 void qeth_osn_deregister(struct net_device *dev)
1428 struct qeth_card *card;
1432 card = dev->ml_priv;
1435 QETH_CARD_TEXT(card, 2, "osndereg");
1436 card->osn_info.assist_cb = NULL;
1437 card->osn_info.data_cb = NULL;
1440 EXPORT_SYMBOL(qeth_osn_deregister);
1442 /* SETBRIDGEPORT support, async notifications */
1444 enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1447 * qeth_bridge_emit_host_event() - bridgeport address change notification
1448 * @card: qeth_card structure pointer, for udev events.
1449 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1450 * and reset token and addr_lnid are unused and may be NULL.
1451 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1452 * object, 0 - addition of an object.
1453 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1454 * @token: "network token" structure identifying physical address of the port.
1455 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1457 * This function is called when registrations and deregistrations are
1458 * reported by the hardware, and also when notifications are enabled -
1459 * for all currently registered addresses.
1461 static void qeth_bridge_emit_host_event(struct qeth_card *card,
1462 enum qeth_an_event_type evtype,
1463 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1470 case anev_reg_unreg:
1471 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1472 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1473 ? "deregister" : "register");
1474 env[i] = str[i]; i++;
1475 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1476 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1478 env[i] = str[i]; i++;
1480 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
1481 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
1483 env[i] = str[i]; i++;
1485 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1486 token->cssid, token->ssid, token->devnum);
1487 env[i] = str[i]; i++;
1488 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1489 env[i] = str[i]; i++;
1490 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1492 env[i] = str[i]; i++;
1493 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1494 env[i] = str[i]; i++;
1497 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1498 env[i] = str[i]; i++;
1501 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1502 env[i] = str[i]; i++;
1506 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1509 struct qeth_bridge_state_data {
1510 struct work_struct worker;
1511 struct qeth_card *card;
1512 struct qeth_sbp_state_change qports;
1515 static void qeth_bridge_state_change_worker(struct work_struct *work)
1517 struct qeth_bridge_state_data *data =
1518 container_of(work, struct qeth_bridge_state_data, worker);
1519 /* We are only interested in the first entry - local port */
1520 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1521 char env_locrem[32];
1531 /* Role should not change by itself, but if it did, */
1532 /* information from the hardware is authoritative. */
1533 mutex_lock(&data->card->conf_mutex);
1534 data->card->options.sbp.role = entry->role;
1535 mutex_unlock(&data->card->conf_mutex);
1537 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1538 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1539 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1540 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1541 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1543 snprintf(env_state, sizeof(env_state), "STATE=%s",
1544 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1545 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1546 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1548 kobject_uevent_env(&data->card->gdev->dev.kobj,
1553 static void qeth_bridge_state_change(struct qeth_card *card,
1554 struct qeth_ipa_cmd *cmd)
1556 struct qeth_sbp_state_change *qports =
1557 &cmd->data.sbp.data.state_change;
1558 struct qeth_bridge_state_data *data;
1561 QETH_CARD_TEXT(card, 2, "brstchng");
1562 if (qports->num_entries == 0) {
1563 QETH_CARD_TEXT(card, 2, "BPempty");
1566 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1567 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
1570 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1571 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1574 QETH_CARD_TEXT(card, 2, "BPSalloc");
1577 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1579 memcpy(&data->qports, qports,
1580 sizeof(struct qeth_sbp_state_change) + extrasize);
1581 queue_work(qeth_wq, &data->worker);
1584 struct qeth_bridge_host_data {
1585 struct work_struct worker;
1586 struct qeth_card *card;
1587 struct qeth_ipacmd_addr_change hostevs;
1590 static void qeth_bridge_host_event_worker(struct work_struct *work)
1592 struct qeth_bridge_host_data *data =
1593 container_of(work, struct qeth_bridge_host_data, worker);
1596 if (data->hostevs.lost_event_mask) {
1597 dev_info(&data->card->gdev->dev,
1598 "Address notification from the Bridge Port stopped %s (%s)\n",
1599 data->card->dev->name,
1600 (data->hostevs.lost_event_mask == 0x01)
1602 : (data->hostevs.lost_event_mask == 0x02)
1603 ? "Bridge port state change"
1604 : "Unknown reason");
1605 mutex_lock(&data->card->conf_mutex);
1606 data->card->options.sbp.hostnotification = 0;
1607 mutex_unlock(&data->card->conf_mutex);
1608 qeth_bridge_emit_host_event(data->card, anev_abort,
1611 for (i = 0; i < data->hostevs.num_entries; i++) {
1612 struct qeth_ipacmd_addr_change_entry *entry =
1613 &data->hostevs.entry[i];
1614 qeth_bridge_emit_host_event(data->card,
1617 &entry->token, &entry->addr_lnid);
1622 static void qeth_bridge_host_event(struct qeth_card *card,
1623 struct qeth_ipa_cmd *cmd)
1625 struct qeth_ipacmd_addr_change *hostevs =
1626 &cmd->data.addrchange;
1627 struct qeth_bridge_host_data *data;
1630 QETH_CARD_TEXT(card, 2, "brhostev");
1631 if (cmd->hdr.return_code != 0x0000) {
1632 if (cmd->hdr.return_code == 0x0010) {
1633 if (hostevs->lost_event_mask == 0x00)
1634 hostevs->lost_event_mask = 0xff;
1636 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1637 cmd->hdr.return_code);
1641 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1642 hostevs->num_entries;
1643 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1646 QETH_CARD_TEXT(card, 2, "BPHalloc");
1649 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1651 memcpy(&data->hostevs, hostevs,
1652 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1653 queue_work(qeth_wq, &data->worker);
1656 /* SETBRIDGEPORT support; sending commands */
1658 struct _qeth_sbp_cbctl {
1664 enum qeth_sbp_roles *role;
1665 enum qeth_sbp_states *state;
1671 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes.
1672 * @card: qeth_card structure pointer, for debug messages.
1673 * @cbctl: state structure with hardware return codes.
1674 * @setcmd: IPA command code
1676 * Returns negative errno-compatible error indication or 0 on success.
1678 static int qeth_bridgeport_makerc(struct qeth_card *card,
1679 struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd)
1682 int is_iqd = (card->info.type == QETH_CARD_TYPE_IQD);
1684 if ((is_iqd && (cbctl->ipa_rc == IPA_RC_SUCCESS)) ||
1685 (!is_iqd && (cbctl->ipa_rc == cbctl->cmd_rc)))
1686 switch (cbctl->cmd_rc) {
1687 case IPA_RC_SUCCESS:
1690 case IPA_RC_L2_UNSUPPORTED_CMD:
1691 case IPA_RC_UNSUPPORTED_COMMAND:
1694 case IPA_RC_SBP_OSA_NOT_CONFIGURED:
1695 case IPA_RC_SBP_IQD_NOT_CONFIGURED:
1696 rc = -ENODEV; /* maybe not the best code here? */
1697 dev_err(&card->gdev->dev,
1698 "The device is not configured as a Bridge Port\n");
1700 case IPA_RC_SBP_OSA_OS_MISMATCH:
1701 case IPA_RC_SBP_IQD_OS_MISMATCH:
1703 dev_err(&card->gdev->dev,
1704 "A Bridge Port is already configured by a different operating system\n");
1706 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY:
1707 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY:
1709 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1711 dev_err(&card->gdev->dev,
1712 "The LAN already has a primary Bridge Port\n");
1714 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1716 dev_err(&card->gdev->dev,
1717 "The device is already a primary Bridge Port\n");
1723 case IPA_RC_SBP_OSA_CURRENT_SECOND:
1724 case IPA_RC_SBP_IQD_CURRENT_SECOND:
1726 dev_err(&card->gdev->dev,
1727 "The device is already a secondary Bridge Port\n");
1729 case IPA_RC_SBP_OSA_LIMIT_SECOND:
1730 case IPA_RC_SBP_IQD_LIMIT_SECOND:
1732 dev_err(&card->gdev->dev,
1733 "The LAN cannot have more secondary Bridge Ports\n");
1735 case IPA_RC_SBP_OSA_CURRENT_PRIMARY:
1736 case IPA_RC_SBP_IQD_CURRENT_PRIMARY:
1738 dev_err(&card->gdev->dev,
1739 "The device is already a primary Bridge Port\n");
1741 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN:
1742 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN:
1744 dev_err(&card->gdev->dev,
1745 "The device is not authorized to be a Bridge Port\n");
1751 switch (cbctl->ipa_rc) {
1752 case IPA_RC_NOTSUPP:
1755 case IPA_RC_UNSUPPORTED_COMMAND:
1763 QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc);
1764 QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc);
1769 static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card,
1770 enum qeth_ipa_sbp_cmd sbp_cmd,
1771 unsigned int cmd_length)
1773 enum qeth_ipa_cmds ipa_cmd = (card->info.type == QETH_CARD_TYPE_IQD) ?
1774 IPA_CMD_SETBRIDGEPORT_IQD :
1775 IPA_CMD_SETBRIDGEPORT_OSA;
1776 struct qeth_cmd_buffer *iob;
1777 struct qeth_ipa_cmd *cmd;
1779 iob = qeth_get_ipacmd_buffer(card, ipa_cmd, 0);
1782 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1783 cmd->data.sbp.hdr.cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1785 cmd->data.sbp.hdr.command_code = sbp_cmd;
1786 cmd->data.sbp.hdr.used_total = 1;
1787 cmd->data.sbp.hdr.seq_no = 1;
1791 static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1792 struct qeth_reply *reply, unsigned long data)
1794 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1795 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1796 QETH_CARD_TEXT(card, 2, "brqsupcb");
1797 cbctl->ipa_rc = cmd->hdr.return_code;
1798 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1799 if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) {
1800 cbctl->data.supported =
1801 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1803 cbctl->data.supported = 0;
1809 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1810 * @card: qeth_card structure pointer.
1812 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1813 * strucutre: card->options.sbp.supported_funcs.
1815 static void qeth_bridgeport_query_support(struct qeth_card *card)
1817 struct qeth_cmd_buffer *iob;
1818 struct _qeth_sbp_cbctl cbctl;
1820 QETH_CARD_TEXT(card, 2, "brqsuppo");
1821 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED,
1822 sizeof(struct qeth_sbp_query_cmds_supp));
1825 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1827 qeth_bridgeport_makerc(card, &cbctl,
1828 IPA_SBP_QUERY_COMMANDS_SUPPORTED)) {
1829 /* non-zero makerc signifies failure, and produce messages */
1830 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1833 card->options.sbp.supported_funcs = cbctl.data.supported;
1836 static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1837 struct qeth_reply *reply, unsigned long data)
1839 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1840 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1841 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1843 QETH_CARD_TEXT(card, 2, "brqprtcb");
1844 cbctl->ipa_rc = cmd->hdr.return_code;
1845 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1846 if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0))
1848 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1849 cbctl->cmd_rc = 0xffff;
1850 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1853 /* first entry contains the state of the local port */
1854 if (qports->num_entries > 0) {
1855 if (cbctl->data.qports.role)
1856 *cbctl->data.qports.role = qports->entry[0].role;
1857 if (cbctl->data.qports.state)
1858 *cbctl->data.qports.state = qports->entry[0].state;
1864 * qeth_bridgeport_query_ports() - query local bridgeport status.
1865 * @card: qeth_card structure pointer.
1866 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1867 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1869 * Returns negative errno-compatible error indication or 0 on success.
1871 * 'role' and 'state' are not updated in case of hardware operation failure.
1873 int qeth_bridgeport_query_ports(struct qeth_card *card,
1874 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1877 struct qeth_cmd_buffer *iob;
1878 struct _qeth_sbp_cbctl cbctl = {
1887 QETH_CARD_TEXT(card, 2, "brqports");
1888 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1890 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0);
1893 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1897 return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS);
1899 EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports);
1901 static int qeth_bridgeport_set_cb(struct qeth_card *card,
1902 struct qeth_reply *reply, unsigned long data)
1904 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
1905 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1906 QETH_CARD_TEXT(card, 2, "brsetrcb");
1907 cbctl->ipa_rc = cmd->hdr.return_code;
1908 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1913 * qeth_bridgeport_setrole() - Assign primary role to the port.
1914 * @card: qeth_card structure pointer.
1915 * @role: Role to assign.
1917 * Returns negative errno-compatible error indication or 0 on success.
1919 int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1923 struct qeth_cmd_buffer *iob;
1924 struct _qeth_sbp_cbctl cbctl;
1925 enum qeth_ipa_sbp_cmd setcmd;
1927 QETH_CARD_TEXT(card, 2, "brsetrol");
1929 case QETH_SBP_ROLE_NONE:
1930 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
1931 cmdlength = sizeof(struct qeth_sbp_reset_role);
1933 case QETH_SBP_ROLE_PRIMARY:
1934 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
1935 cmdlength = sizeof(struct qeth_sbp_set_primary);
1937 case QETH_SBP_ROLE_SECONDARY:
1938 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
1939 cmdlength = sizeof(struct qeth_sbp_set_secondary);
1944 if (!(card->options.sbp.supported_funcs & setcmd))
1946 iob = qeth_sbp_build_cmd(card, setcmd, cmdlength);
1949 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb,
1953 return qeth_bridgeport_makerc(card, &cbctl, setcmd);
1957 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1958 * @card: qeth_card structure pointer, for debug messages.
1960 * Returns negative errno-compatible error indication or 0 on success.
1962 static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
1975 dev_err(&card->gdev->dev,
1976 "Setting address notification failed\n");
1988 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
1989 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
1994 static void qeth_bridgeport_an_set_cb(void *priv,
1995 enum qdio_brinfo_entry_type type, void *entry)
1997 struct qeth_card *card = (struct qeth_card *)priv;
1998 struct qdio_brinfo_entry_l2 *l2entry;
2001 if (type != l2_addr_lnid) {
2006 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
2007 code = IPA_ADDR_CHANGE_CODE_MACADDR;
2008 if (l2entry->addr_lnid.lnid < VLAN_N_VID)
2009 code |= IPA_ADDR_CHANGE_CODE_VLANID;
2010 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
2011 (struct net_if_token *)&l2entry->nit,
2012 (struct mac_addr_lnid *)&l2entry->addr_lnid);
2016 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
2017 * @card: qeth_card structure pointer.
2018 * @enable: 0 - disable, non-zero - enable notifications
2020 * Returns negative errno-compatible error indication or 0 on success.
2022 * On enable, emits a series of address notifications udev events for all
2023 * currently registered hosts.
2025 int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
2029 struct ccw_device *ddev;
2030 struct subchannel_id schid;
2034 if (!card->options.sbp.supported_funcs)
2036 ddev = CARD_DDEV(card);
2037 ccw_device_get_schid(ddev, &schid);
2040 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
2041 rc = qdio_pnso_brinfo(schid, 1, &response,
2042 qeth_bridgeport_an_set_cb, card);
2044 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
2045 return qeth_anset_makerc(card, rc, response);
2047 EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set);
2049 module_init(qeth_l2_init);
2050 module_exit(qeth_l2_exit);
2051 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2052 MODULE_DESCRIPTION("qeth layer 2 discipline");
2053 MODULE_LICENSE("GPL");