sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / s390 / net / qeth_l2_main.c
blob9c921c2833f16ea29113bd6cc017d9d2ae01b72d
1 /*
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>
7 */
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>
19 #include <linux/mii.h>
20 #include <linux/ip.h>
21 #include <linux/list.h>
22 #include <linux/hash.h>
23 #include <linux/hashtable.h>
24 #include <linux/string.h>
25 #include "qeth_core.h"
26 #include "qeth_l2.h"
28 static int qeth_l2_set_offline(struct ccwgroup_device *);
29 static int qeth_l2_stop(struct net_device *);
30 static int qeth_l2_send_delmac(struct qeth_card *, __u8 *);
31 static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *,
32 enum qeth_ipa_cmds);
33 static void qeth_l2_set_rx_mode(struct net_device *);
34 static int qeth_l2_recover(void *);
35 static void qeth_bridgeport_query_support(struct qeth_card *card);
36 static void qeth_bridge_state_change(struct qeth_card *card,
37 struct qeth_ipa_cmd *cmd);
38 static void qeth_bridge_host_event(struct qeth_card *card,
39 struct qeth_ipa_cmd *cmd);
41 static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
43 struct qeth_card *card = dev->ml_priv;
44 struct mii_ioctl_data *mii_data;
45 int rc = 0;
47 if (!card)
48 return -ENODEV;
50 if (!qeth_card_hw_is_reachable(card))
51 return -ENODEV;
53 if (card->info.type == QETH_CARD_TYPE_OSN)
54 return -EPERM;
56 switch (cmd) {
57 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
58 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
59 break;
60 case SIOC_QETH_GET_CARD_TYPE:
61 if ((card->info.type == QETH_CARD_TYPE_OSD ||
62 card->info.type == QETH_CARD_TYPE_OSM ||
63 card->info.type == QETH_CARD_TYPE_OSX) &&
64 !card->info.guestlan)
65 return 1;
66 return 0;
67 break;
68 case SIOCGMIIPHY:
69 mii_data = if_mii(rq);
70 mii_data->phy_id = 0;
71 break;
72 case SIOCGMIIREG:
73 mii_data = if_mii(rq);
74 if (mii_data->phy_id != 0)
75 rc = -EINVAL;
76 else
77 mii_data->val_out = qeth_mdio_read(dev,
78 mii_data->phy_id, mii_data->reg_num);
79 break;
80 case SIOC_QETH_QUERY_OAT:
81 rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
82 break;
83 default:
84 rc = -EOPNOTSUPP;
86 if (rc)
87 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
88 return rc;
91 static int qeth_l2_verify_dev(struct net_device *dev)
93 struct qeth_card *card;
94 unsigned long flags;
95 int rc = 0;
97 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
98 list_for_each_entry(card, &qeth_core_card_list.list, list) {
99 if (card->dev == dev) {
100 rc = QETH_REAL_CARD;
101 break;
104 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
106 return rc;
109 static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
111 struct qeth_card *card;
112 struct net_device *ndev;
113 __u16 temp_dev_no;
114 unsigned long flags;
115 struct ccw_dev_id read_devid;
117 ndev = NULL;
118 memcpy(&temp_dev_no, read_dev_no, 2);
119 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
120 list_for_each_entry(card, &qeth_core_card_list.list, list) {
121 ccw_device_get_id(CARD_RDEV(card), &read_devid);
122 if (read_devid.devno == temp_dev_no) {
123 ndev = card->dev;
124 break;
127 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
128 return ndev;
131 static int qeth_setdel_makerc(struct qeth_card *card, int retcode)
133 int rc;
135 if (retcode)
136 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
137 switch (retcode) {
138 case IPA_RC_SUCCESS:
139 rc = 0;
140 break;
141 case IPA_RC_L2_UNSUPPORTED_CMD:
142 rc = -EOPNOTSUPP;
143 break;
144 case IPA_RC_L2_ADDR_TABLE_FULL:
145 rc = -ENOSPC;
146 break;
147 case IPA_RC_L2_DUP_MAC:
148 case IPA_RC_L2_DUP_LAYER3_MAC:
149 rc = -EEXIST;
150 break;
151 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
152 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
153 rc = -EPERM;
154 break;
155 case IPA_RC_L2_MAC_NOT_FOUND:
156 rc = -ENOENT;
157 break;
158 case -ENOMEM:
159 rc = -ENOMEM;
160 break;
161 default:
162 rc = -EIO;
163 break;
165 return rc;
168 static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
170 int rc;
172 QETH_CARD_TEXT(card, 2, "L2Sgmac");
173 rc = qeth_setdel_makerc(card, qeth_l2_send_setdelmac(card, mac,
174 IPA_CMD_SETGMAC));
175 if (rc == -EEXIST)
176 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s\n",
177 mac, QETH_CARD_IFNAME(card));
178 else if (rc)
179 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %d\n",
180 mac, QETH_CARD_IFNAME(card), rc);
181 return rc;
184 static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
186 int rc;
188 QETH_CARD_TEXT(card, 2, "L2Dgmac");
189 rc = qeth_setdel_makerc(card, qeth_l2_send_setdelmac(card, mac,
190 IPA_CMD_DELGMAC));
191 if (rc)
192 QETH_DBF_MESSAGE(2,
193 "Could not delete group MAC %pM on %s: %d\n",
194 mac, QETH_CARD_IFNAME(card), rc);
195 return rc;
198 static inline u32 qeth_l2_mac_hash(const u8 *addr)
200 return get_unaligned((u32 *)(&addr[2]));
203 static int qeth_l2_write_mac(struct qeth_card *card, struct qeth_mac *mac)
206 int rc;
208 if (mac->is_uc) {
209 rc = qeth_setdel_makerc(card,
210 qeth_l2_send_setdelmac(card, mac->mac_addr,
211 IPA_CMD_SETVMAC));
212 } else {
213 rc = qeth_setdel_makerc(card,
214 qeth_l2_send_setgroupmac(card, mac->mac_addr));
216 return rc;
219 static void qeth_l2_del_all_macs(struct qeth_card *card, int del)
221 struct qeth_mac *mac;
222 struct hlist_node *tmp;
223 int i;
225 spin_lock_bh(&card->mclock);
226 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
227 if (del) {
228 if (mac->is_uc)
229 qeth_l2_send_setdelmac(card, mac->mac_addr,
230 IPA_CMD_DELVMAC);
231 else
232 qeth_l2_send_delgroupmac(card, mac->mac_addr);
234 hash_del(&mac->hnode);
235 kfree(mac);
237 spin_unlock_bh(&card->mclock);
240 static inline int qeth_l2_get_cast_type(struct qeth_card *card,
241 struct sk_buff *skb)
243 if (card->info.type == QETH_CARD_TYPE_OSN)
244 return RTN_UNSPEC;
245 if (is_broadcast_ether_addr(skb->data))
246 return RTN_BROADCAST;
247 if (is_multicast_ether_addr(skb->data))
248 return RTN_MULTICAST;
249 return RTN_UNSPEC;
252 static inline void qeth_l2_hdr_csum(struct qeth_card *card,
253 struct qeth_hdr *hdr, struct sk_buff *skb)
255 struct iphdr *iph = ip_hdr(skb);
257 /* tcph->check contains already the pseudo hdr checksum
258 * so just set the header flags
260 if (iph->protocol == IPPROTO_UDP)
261 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_UDP;
262 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
263 QETH_HDR_EXT_CSUM_HDR_REQ;
264 iph->check = 0;
265 if (card->options.performance_stats)
266 card->perf_stats.tx_csum++;
269 static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
270 struct sk_buff *skb, int cast_type)
272 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
274 memset(hdr, 0, sizeof(struct qeth_hdr));
275 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
277 /* set byte byte 3 to casting flags */
278 if (cast_type == RTN_MULTICAST)
279 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
280 else if (cast_type == RTN_BROADCAST)
281 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
282 else
283 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
285 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
286 /* VSWITCH relies on the VLAN
287 * information to be present in
288 * the QDIO header */
289 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
290 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
291 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
295 static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
296 struct qeth_reply *reply, unsigned long data)
298 struct qeth_ipa_cmd *cmd;
300 QETH_CARD_TEXT(card, 2, "L2sdvcb");
301 cmd = (struct qeth_ipa_cmd *) data;
302 if (cmd->hdr.return_code) {
303 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
304 "Continuing\n", cmd->data.setdelvlan.vlan_id,
305 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
306 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
307 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
309 return 0;
312 static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
313 enum qeth_ipa_cmds ipacmd)
315 struct qeth_ipa_cmd *cmd;
316 struct qeth_cmd_buffer *iob;
318 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
319 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
320 if (!iob)
321 return -ENOMEM;
322 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
323 cmd->data.setdelvlan.vlan_id = i;
324 return qeth_send_ipa_cmd(card, iob,
325 qeth_l2_send_setdelvlan_cb, NULL);
328 static void qeth_l2_process_vlans(struct qeth_card *card)
330 struct qeth_vlan_vid *id;
331 QETH_CARD_TEXT(card, 3, "L2prcvln");
332 spin_lock_bh(&card->vlanlock);
333 list_for_each_entry(id, &card->vid_list, list) {
334 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
336 spin_unlock_bh(&card->vlanlock);
339 static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
340 __be16 proto, u16 vid)
342 struct qeth_card *card = dev->ml_priv;
343 struct qeth_vlan_vid *id;
344 int rc;
346 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
347 if (!vid)
348 return 0;
349 if (card->info.type == QETH_CARD_TYPE_OSM) {
350 QETH_CARD_TEXT(card, 3, "aidOSM");
351 return 0;
353 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
354 QETH_CARD_TEXT(card, 3, "aidREC");
355 return 0;
357 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
358 if (id) {
359 id->vid = vid;
360 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
361 if (rc) {
362 kfree(id);
363 return rc;
365 spin_lock_bh(&card->vlanlock);
366 list_add_tail(&id->list, &card->vid_list);
367 spin_unlock_bh(&card->vlanlock);
368 } else {
369 return -ENOMEM;
371 return 0;
374 static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
375 __be16 proto, u16 vid)
377 struct qeth_vlan_vid *id, *tmpid = NULL;
378 struct qeth_card *card = dev->ml_priv;
379 int rc = 0;
381 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
382 if (card->info.type == QETH_CARD_TYPE_OSM) {
383 QETH_CARD_TEXT(card, 3, "kidOSM");
384 return 0;
386 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
387 QETH_CARD_TEXT(card, 3, "kidREC");
388 return 0;
390 spin_lock_bh(&card->vlanlock);
391 list_for_each_entry(id, &card->vid_list, list) {
392 if (id->vid == vid) {
393 list_del(&id->list);
394 tmpid = id;
395 break;
398 spin_unlock_bh(&card->vlanlock);
399 if (tmpid) {
400 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
401 kfree(tmpid);
403 qeth_l2_set_rx_mode(card->dev);
404 return rc;
407 static void qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
409 QETH_DBF_TEXT(SETUP , 2, "stopcard");
410 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
412 qeth_set_allowed_threads(card, 0, 1);
413 if (card->read.state == CH_STATE_UP &&
414 card->write.state == CH_STATE_UP &&
415 (card->state == CARD_STATE_UP)) {
416 if (recovery_mode &&
417 card->info.type != QETH_CARD_TYPE_OSN) {
418 qeth_l2_stop(card->dev);
419 } else {
420 rtnl_lock();
421 dev_close(card->dev);
422 rtnl_unlock();
424 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
425 card->state = CARD_STATE_SOFTSETUP;
427 if (card->state == CARD_STATE_SOFTSETUP) {
428 qeth_l2_del_all_macs(card, 0);
429 qeth_clear_ipacmd_list(card);
430 card->state = CARD_STATE_HARDSETUP;
432 if (card->state == CARD_STATE_HARDSETUP) {
433 qeth_qdio_clear_card(card, 0);
434 qeth_clear_qdio_buffers(card);
435 qeth_clear_working_pool_list(card);
436 card->state = CARD_STATE_DOWN;
438 if (card->state == CARD_STATE_DOWN) {
439 qeth_clear_cmd_buffers(&card->read);
440 qeth_clear_cmd_buffers(&card->write);
444 static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
445 int budget, int *done)
447 int work_done = 0;
448 struct sk_buff *skb;
449 struct qeth_hdr *hdr;
450 unsigned int len;
452 *done = 0;
453 WARN_ON_ONCE(!budget);
454 while (budget) {
455 skb = qeth_core_get_next_skb(card,
456 &card->qdio.in_q->bufs[card->rx.b_index],
457 &card->rx.b_element, &card->rx.e_offset, &hdr);
458 if (!skb) {
459 *done = 1;
460 break;
462 skb->dev = card->dev;
463 switch (hdr->hdr.l2.id) {
464 case QETH_HEADER_TYPE_LAYER2:
465 skb->pkt_type = PACKET_HOST;
466 skb->protocol = eth_type_trans(skb, skb->dev);
467 if ((card->dev->features & NETIF_F_RXCSUM)
468 && ((hdr->hdr.l2.flags[1] &
469 (QETH_HDR_EXT_CSUM_HDR_REQ |
470 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
471 (QETH_HDR_EXT_CSUM_HDR_REQ |
472 QETH_HDR_EXT_CSUM_TRANSP_REQ)))
473 skb->ip_summed = CHECKSUM_UNNECESSARY;
474 else
475 skb->ip_summed = CHECKSUM_NONE;
476 if (skb->protocol == htons(ETH_P_802_2))
477 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
478 len = skb->len;
479 napi_gro_receive(&card->napi, skb);
480 break;
481 case QETH_HEADER_TYPE_OSN:
482 if (card->info.type == QETH_CARD_TYPE_OSN) {
483 skb_push(skb, sizeof(struct qeth_hdr));
484 skb_copy_to_linear_data(skb, hdr,
485 sizeof(struct qeth_hdr));
486 len = skb->len;
487 card->osn_info.data_cb(skb);
488 break;
490 /* else unknown */
491 default:
492 dev_kfree_skb_any(skb);
493 QETH_CARD_TEXT(card, 3, "inbunkno");
494 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
495 continue;
497 work_done++;
498 budget--;
499 card->stats.rx_packets++;
500 card->stats.rx_bytes += len;
502 return work_done;
505 static int qeth_l2_poll(struct napi_struct *napi, int budget)
507 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
508 int work_done = 0;
509 struct qeth_qdio_buffer *buffer;
510 int done;
511 int new_budget = budget;
513 if (card->options.performance_stats) {
514 card->perf_stats.inbound_cnt++;
515 card->perf_stats.inbound_start_time = qeth_get_micros();
518 while (1) {
519 if (!card->rx.b_count) {
520 card->rx.qdio_err = 0;
521 card->rx.b_count = qdio_get_next_buffers(
522 card->data.ccwdev, 0, &card->rx.b_index,
523 &card->rx.qdio_err);
524 if (card->rx.b_count <= 0) {
525 card->rx.b_count = 0;
526 break;
528 card->rx.b_element =
529 &card->qdio.in_q->bufs[card->rx.b_index]
530 .buffer->element[0];
531 card->rx.e_offset = 0;
534 while (card->rx.b_count) {
535 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
536 if (!(card->rx.qdio_err &&
537 qeth_check_qdio_errors(card, buffer->buffer,
538 card->rx.qdio_err, "qinerr")))
539 work_done += qeth_l2_process_inbound_buffer(
540 card, new_budget, &done);
541 else
542 done = 1;
544 if (done) {
545 if (card->options.performance_stats)
546 card->perf_stats.bufs_rec++;
547 qeth_put_buffer_pool_entry(card,
548 buffer->pool_entry);
549 qeth_queue_input_buffer(card, card->rx.b_index);
550 card->rx.b_count--;
551 if (card->rx.b_count) {
552 card->rx.b_index =
553 (card->rx.b_index + 1) %
554 QDIO_MAX_BUFFERS_PER_Q;
555 card->rx.b_element =
556 &card->qdio.in_q
557 ->bufs[card->rx.b_index]
558 .buffer->element[0];
559 card->rx.e_offset = 0;
563 if (work_done >= budget)
564 goto out;
565 else
566 new_budget = budget - work_done;
570 napi_complete(napi);
571 if (qdio_start_irq(card->data.ccwdev, 0))
572 napi_schedule(&card->napi);
573 out:
574 if (card->options.performance_stats)
575 card->perf_stats.inbound_time += qeth_get_micros() -
576 card->perf_stats.inbound_start_time;
577 return work_done;
580 static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
581 enum qeth_ipa_cmds ipacmd)
583 struct qeth_ipa_cmd *cmd;
584 struct qeth_cmd_buffer *iob;
586 QETH_CARD_TEXT(card, 2, "L2sdmac");
587 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
588 if (!iob)
589 return -ENOMEM;
590 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
591 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
592 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
593 return qeth_send_ipa_cmd(card, iob, NULL, NULL);
596 static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
598 int rc;
600 QETH_CARD_TEXT(card, 2, "L2Setmac");
601 rc = qeth_setdel_makerc(card, qeth_l2_send_setdelmac(card, mac,
602 IPA_CMD_SETVMAC));
603 if (rc == 0) {
604 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
605 memcpy(card->dev->dev_addr, mac, OSA_ADDR_LEN);
606 dev_info(&card->gdev->dev,
607 "MAC address %pM successfully registered on device %s\n",
608 card->dev->dev_addr, card->dev->name);
609 } else {
610 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
611 switch (rc) {
612 case -EEXIST:
613 dev_warn(&card->gdev->dev,
614 "MAC address %pM already exists\n", mac);
615 break;
616 case -EPERM:
617 dev_warn(&card->gdev->dev,
618 "MAC address %pM is not authorized\n", mac);
619 break;
622 return rc;
625 static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
627 int rc;
629 QETH_CARD_TEXT(card, 2, "L2Delmac");
630 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
631 return 0;
632 rc = qeth_setdel_makerc(card, qeth_l2_send_setdelmac(card, mac,
633 IPA_CMD_DELVMAC));
634 if (rc == 0)
635 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
636 return rc;
639 static int qeth_l2_request_initial_mac(struct qeth_card *card)
641 int rc = 0;
642 char vendor_pre[] = {0x02, 0x00, 0x00};
644 QETH_DBF_TEXT(SETUP, 2, "doL2init");
645 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
647 if (qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
648 rc = qeth_query_setadapterparms(card);
649 if (rc) {
650 QETH_DBF_MESSAGE(2, "could not query adapter "
651 "parameters on device %s: x%x\n",
652 CARD_BUS_ID(card), rc);
656 if (card->info.type == QETH_CARD_TYPE_IQD ||
657 card->info.type == QETH_CARD_TYPE_OSM ||
658 card->info.type == QETH_CARD_TYPE_OSX ||
659 card->info.guestlan) {
660 rc = qeth_setadpparms_change_macaddr(card);
661 if (rc) {
662 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
663 "device %s: x%x\n", CARD_BUS_ID(card), rc);
664 QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
665 return rc;
667 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
668 } else {
669 eth_random_addr(card->dev->dev_addr);
670 memcpy(card->dev->dev_addr, vendor_pre, 3);
672 return 0;
675 static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
677 struct sockaddr *addr = p;
678 struct qeth_card *card = dev->ml_priv;
679 int rc = 0;
681 QETH_CARD_TEXT(card, 3, "setmac");
683 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
684 QETH_CARD_TEXT(card, 3, "setmcINV");
685 return -EOPNOTSUPP;
688 if (card->info.type == QETH_CARD_TYPE_OSN ||
689 card->info.type == QETH_CARD_TYPE_OSM ||
690 card->info.type == QETH_CARD_TYPE_OSX) {
691 QETH_CARD_TEXT(card, 3, "setmcTYP");
692 return -EOPNOTSUPP;
694 QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN);
695 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
696 QETH_CARD_TEXT(card, 3, "setmcREC");
697 return -ERESTARTSYS;
699 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
700 if (!rc || (rc == -ENOENT))
701 rc = qeth_l2_send_setmac(card, addr->sa_data);
702 return rc ? -EINVAL : 0;
705 static void qeth_promisc_to_bridge(struct qeth_card *card)
707 struct net_device *dev = card->dev;
708 enum qeth_ipa_promisc_modes promisc_mode;
709 int role;
710 int rc;
712 QETH_CARD_TEXT(card, 3, "pmisc2br");
714 if (!card->options.sbp.reflect_promisc)
715 return;
716 promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON
717 : SET_PROMISC_MODE_OFF;
718 if (promisc_mode == card->info.promisc_mode)
719 return;
721 if (promisc_mode == SET_PROMISC_MODE_ON) {
722 if (card->options.sbp.reflect_promisc_primary)
723 role = QETH_SBP_ROLE_PRIMARY;
724 else
725 role = QETH_SBP_ROLE_SECONDARY;
726 } else
727 role = QETH_SBP_ROLE_NONE;
729 rc = qeth_bridgeport_setrole(card, role);
730 QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x",
731 (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc);
732 if (!rc) {
733 card->options.sbp.role = role;
734 card->info.promisc_mode = promisc_mode;
738 /* New MAC address is added to the hash table and marked to be written on card
739 * only if there is not in the hash table storage already
742 static void
743 qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha, u8 is_uc)
745 struct qeth_mac *mac;
747 hash_for_each_possible(card->mac_htable, mac, hnode,
748 qeth_l2_mac_hash(ha->addr)) {
749 if (is_uc == mac->is_uc &&
750 !memcmp(ha->addr, mac->mac_addr, OSA_ADDR_LEN)) {
751 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
752 return;
756 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
758 if (!mac)
759 return;
761 memcpy(mac->mac_addr, ha->addr, OSA_ADDR_LEN);
762 mac->is_uc = is_uc;
763 mac->disp_flag = QETH_DISP_ADDR_ADD;
765 hash_add(card->mac_htable, &mac->hnode,
766 qeth_l2_mac_hash(mac->mac_addr));
770 static void qeth_l2_set_rx_mode(struct net_device *dev)
772 struct qeth_card *card = dev->ml_priv;
773 struct netdev_hw_addr *ha;
774 struct qeth_mac *mac;
775 struct hlist_node *tmp;
776 int i;
777 int rc;
779 if (card->info.type == QETH_CARD_TYPE_OSN)
780 return;
782 QETH_CARD_TEXT(card, 3, "setmulti");
783 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
784 (card->state != CARD_STATE_UP))
785 return;
787 spin_lock_bh(&card->mclock);
789 netdev_for_each_mc_addr(ha, dev)
790 qeth_l2_add_mac(card, ha, 0);
792 netdev_for_each_uc_addr(ha, dev)
793 qeth_l2_add_mac(card, ha, 1);
795 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
796 if (mac->disp_flag == QETH_DISP_ADDR_DELETE) {
797 if (!mac->is_uc)
798 rc = qeth_l2_send_delgroupmac(card,
799 mac->mac_addr);
800 else {
801 rc = qeth_l2_send_setdelmac(card, mac->mac_addr,
802 IPA_CMD_DELVMAC);
805 hash_del(&mac->hnode);
806 kfree(mac);
808 } else if (mac->disp_flag == QETH_DISP_ADDR_ADD) {
809 rc = qeth_l2_write_mac(card, mac);
810 if (rc) {
811 hash_del(&mac->hnode);
812 kfree(mac);
813 } else
814 mac->disp_flag = QETH_DISP_ADDR_DELETE;
815 } else
816 mac->disp_flag = QETH_DISP_ADDR_DELETE;
819 spin_unlock_bh(&card->mclock);
821 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
822 qeth_setadp_promisc_mode(card);
823 else
824 qeth_promisc_to_bridge(card);
827 static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
829 int rc;
830 struct qeth_hdr *hdr = NULL;
831 int elements = 0;
832 struct qeth_card *card = dev->ml_priv;
833 struct sk_buff *new_skb = skb;
834 int cast_type = qeth_l2_get_cast_type(card, skb);
835 struct qeth_qdio_out_q *queue;
836 int tx_bytes = skb->len;
837 int data_offset = -1;
838 int elements_needed = 0;
839 int hd_len = 0;
840 int nr_frags;
842 if (card->qdio.do_prio_queueing || (cast_type &&
843 card->info.is_multicast_different))
844 queue = card->qdio.out_qs[qeth_get_priority_queue(card, skb,
845 qeth_get_ip_version(skb), cast_type)];
846 else
847 queue = card->qdio.out_qs[card->qdio.default_out_queue];
849 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
850 card->stats.tx_carrier_errors++;
851 goto tx_drop;
854 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
855 (skb->protocol == htons(ETH_P_IPV6)))
856 goto tx_drop;
858 if (card->options.performance_stats) {
859 card->perf_stats.outbound_cnt++;
860 card->perf_stats.outbound_start_time = qeth_get_micros();
862 netif_stop_queue(dev);
864 /* fix hardware limitation: as long as we do not have sbal
865 * chaining we can not send long frag lists
867 if ((card->info.type != QETH_CARD_TYPE_IQD) &&
868 !qeth_get_elements_no(card, new_skb, 0)) {
869 int lin_rc = skb_linearize(new_skb);
871 if (card->options.performance_stats) {
872 if (lin_rc)
873 card->perf_stats.tx_linfail++;
874 else
875 card->perf_stats.tx_lin++;
877 if (lin_rc)
878 goto tx_drop;
881 if (card->info.type == QETH_CARD_TYPE_OSN)
882 hdr = (struct qeth_hdr *)skb->data;
883 else {
884 if (card->info.type == QETH_CARD_TYPE_IQD) {
885 new_skb = skb;
886 data_offset = ETH_HLEN;
887 hd_len = ETH_HLEN;
888 hdr = kmem_cache_alloc(qeth_core_header_cache,
889 GFP_ATOMIC);
890 if (!hdr)
891 goto tx_drop;
892 elements_needed++;
893 skb_reset_mac_header(new_skb);
894 qeth_l2_fill_header(card, hdr, new_skb, cast_type);
895 hdr->hdr.l2.pkt_length = new_skb->len;
896 memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
897 skb_mac_header(new_skb), ETH_HLEN);
898 } else {
899 /* create a clone with writeable headroom */
900 new_skb = skb_realloc_headroom(skb,
901 sizeof(struct qeth_hdr));
902 if (!new_skb)
903 goto tx_drop;
904 hdr = (struct qeth_hdr *)skb_push(new_skb,
905 sizeof(struct qeth_hdr));
906 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
907 qeth_l2_fill_header(card, hdr, new_skb, cast_type);
908 if (new_skb->ip_summed == CHECKSUM_PARTIAL)
909 qeth_l2_hdr_csum(card, hdr, new_skb);
913 elements = qeth_get_elements_no(card, new_skb, elements_needed);
914 if (!elements) {
915 if (data_offset >= 0)
916 kmem_cache_free(qeth_core_header_cache, hdr);
917 goto tx_drop;
920 if (card->info.type != QETH_CARD_TYPE_IQD) {
921 if (qeth_hdr_chk_and_bounce(new_skb, &hdr,
922 sizeof(struct qeth_hdr_layer2)))
923 goto tx_drop;
924 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
925 elements);
926 } else
927 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
928 elements, data_offset, hd_len);
929 if (!rc) {
930 card->stats.tx_packets++;
931 card->stats.tx_bytes += tx_bytes;
932 if (card->options.performance_stats) {
933 nr_frags = skb_shinfo(new_skb)->nr_frags;
934 if (nr_frags) {
935 card->perf_stats.sg_skbs_sent++;
936 /* nr_frags + skb->data */
937 card->perf_stats.sg_frags_sent += nr_frags + 1;
940 if (new_skb != skb)
941 dev_kfree_skb_any(skb);
942 rc = NETDEV_TX_OK;
943 } else {
944 if (data_offset >= 0)
945 kmem_cache_free(qeth_core_header_cache, hdr);
947 if (rc == -EBUSY) {
948 if (new_skb != skb)
949 dev_kfree_skb_any(new_skb);
950 return NETDEV_TX_BUSY;
951 } else
952 goto tx_drop;
955 netif_wake_queue(dev);
956 if (card->options.performance_stats)
957 card->perf_stats.outbound_time += qeth_get_micros() -
958 card->perf_stats.outbound_start_time;
959 return rc;
961 tx_drop:
962 card->stats.tx_dropped++;
963 card->stats.tx_errors++;
964 if ((new_skb != skb) && new_skb)
965 dev_kfree_skb_any(new_skb);
966 dev_kfree_skb_any(skb);
967 netif_wake_queue(dev);
968 return NETDEV_TX_OK;
971 static int __qeth_l2_open(struct net_device *dev)
973 struct qeth_card *card = dev->ml_priv;
974 int rc = 0;
976 QETH_CARD_TEXT(card, 4, "qethopen");
977 if (card->state == CARD_STATE_UP)
978 return rc;
979 if (card->state != CARD_STATE_SOFTSETUP)
980 return -ENODEV;
982 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
983 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
984 QETH_CARD_TEXT(card, 4, "nomacadr");
985 return -EPERM;
987 card->data.state = CH_STATE_UP;
988 card->state = CARD_STATE_UP;
989 netif_start_queue(dev);
991 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
992 napi_enable(&card->napi);
993 napi_schedule(&card->napi);
994 } else
995 rc = -EIO;
996 return rc;
999 static int qeth_l2_open(struct net_device *dev)
1001 struct qeth_card *card = dev->ml_priv;
1003 QETH_CARD_TEXT(card, 5, "qethope_");
1004 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
1005 QETH_CARD_TEXT(card, 3, "openREC");
1006 return -ERESTARTSYS;
1008 return __qeth_l2_open(dev);
1011 static int qeth_l2_stop(struct net_device *dev)
1013 struct qeth_card *card = dev->ml_priv;
1015 QETH_CARD_TEXT(card, 4, "qethstop");
1016 netif_tx_disable(dev);
1017 if (card->state == CARD_STATE_UP) {
1018 card->state = CARD_STATE_SOFTSETUP;
1019 napi_disable(&card->napi);
1021 return 0;
1024 static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
1026 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1028 qeth_l2_create_device_attributes(&gdev->dev);
1029 INIT_LIST_HEAD(&card->vid_list);
1030 hash_init(card->mac_htable);
1031 card->options.layer2 = 1;
1032 card->info.hwtrap = 0;
1033 return 0;
1036 static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
1038 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1040 qeth_l2_remove_device_attributes(&cgdev->dev);
1041 qeth_set_allowed_threads(card, 0, 1);
1042 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1044 if (cgdev->state == CCWGROUP_ONLINE)
1045 qeth_l2_set_offline(cgdev);
1047 if (card->dev) {
1048 netif_napi_del(&card->napi);
1049 unregister_netdev(card->dev);
1050 card->dev = NULL;
1052 return;
1055 static const struct ethtool_ops qeth_l2_ethtool_ops = {
1056 .get_link = ethtool_op_get_link,
1057 .get_strings = qeth_core_get_strings,
1058 .get_ethtool_stats = qeth_core_get_ethtool_stats,
1059 .get_sset_count = qeth_core_get_sset_count,
1060 .get_drvinfo = qeth_core_get_drvinfo,
1061 .get_settings = qeth_core_ethtool_get_settings,
1064 static const struct ethtool_ops qeth_l2_osn_ops = {
1065 .get_strings = qeth_core_get_strings,
1066 .get_ethtool_stats = qeth_core_get_ethtool_stats,
1067 .get_sset_count = qeth_core_get_sset_count,
1068 .get_drvinfo = qeth_core_get_drvinfo,
1071 static const struct net_device_ops qeth_l2_netdev_ops = {
1072 .ndo_open = qeth_l2_open,
1073 .ndo_stop = qeth_l2_stop,
1074 .ndo_get_stats = qeth_get_stats,
1075 .ndo_start_xmit = qeth_l2_hard_start_xmit,
1076 .ndo_validate_addr = eth_validate_addr,
1077 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
1078 .ndo_do_ioctl = qeth_l2_do_ioctl,
1079 .ndo_set_mac_address = qeth_l2_set_mac_address,
1080 .ndo_change_mtu = qeth_change_mtu,
1081 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
1082 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
1083 .ndo_tx_timeout = qeth_tx_timeout,
1084 .ndo_fix_features = qeth_fix_features,
1085 .ndo_set_features = qeth_set_features
1088 static int qeth_l2_setup_netdev(struct qeth_card *card)
1090 switch (card->info.type) {
1091 case QETH_CARD_TYPE_IQD:
1092 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
1093 ether_setup);
1094 break;
1095 case QETH_CARD_TYPE_OSN:
1096 card->dev = alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN,
1097 ether_setup);
1098 card->dev->flags |= IFF_NOARP;
1099 break;
1100 default:
1101 card->dev = alloc_etherdev(0);
1104 if (!card->dev)
1105 return -ENODEV;
1107 card->dev->ml_priv = card;
1108 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
1109 card->dev->mtu = card->info.initial_mtu;
1110 card->dev->min_mtu = 64;
1111 card->dev->max_mtu = ETH_MAX_MTU;
1112 card->dev->netdev_ops = &qeth_l2_netdev_ops;
1113 card->dev->ethtool_ops =
1114 (card->info.type != QETH_CARD_TYPE_OSN) ?
1115 &qeth_l2_ethtool_ops : &qeth_l2_osn_ops;
1116 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
1117 if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) {
1118 card->dev->hw_features = NETIF_F_SG;
1119 card->dev->vlan_features = NETIF_F_SG;
1120 /* OSA 3S and earlier has no RX/TX support */
1121 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
1122 card->dev->hw_features |= NETIF_F_IP_CSUM;
1123 card->dev->vlan_features |= NETIF_F_IP_CSUM;
1125 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
1126 card->dev->hw_features |= NETIF_F_RXCSUM;
1127 card->dev->vlan_features |= NETIF_F_RXCSUM;
1130 card->info.broadcast_capable = 1;
1131 qeth_l2_request_initial_mac(card);
1132 card->dev->gso_max_size = (QETH_MAX_BUFFER_ELEMENTS(card) - 1) *
1133 PAGE_SIZE;
1134 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
1135 netif_napi_add(card->dev, &card->napi, qeth_l2_poll, QETH_NAPI_WEIGHT);
1136 netif_carrier_off(card->dev);
1137 return register_netdev(card->dev);
1140 static int qeth_l2_start_ipassists(struct qeth_card *card)
1142 /* configure isolation level */
1143 if (qeth_set_access_ctrl_online(card, 0))
1144 return -ENODEV;
1145 return 0;
1148 static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
1150 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1151 int rc = 0;
1152 enum qeth_card_states recover_flag;
1154 mutex_lock(&card->discipline_mutex);
1155 mutex_lock(&card->conf_mutex);
1156 QETH_DBF_TEXT(SETUP, 2, "setonlin");
1157 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
1159 recover_flag = card->state;
1160 rc = qeth_core_hardsetup_card(card);
1161 if (rc) {
1162 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
1163 rc = -ENODEV;
1164 goto out_remove;
1166 qeth_bridgeport_query_support(card);
1167 if (card->options.sbp.supported_funcs)
1168 dev_info(&card->gdev->dev,
1169 "The device represents a Bridge Capable Port\n");
1170 qeth_trace_features(card);
1172 if (!card->dev && qeth_l2_setup_netdev(card)) {
1173 rc = -ENODEV;
1174 goto out_remove;
1177 if (card->info.type != QETH_CARD_TYPE_OSN)
1178 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
1180 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
1181 if (card->info.hwtrap &&
1182 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
1183 card->info.hwtrap = 0;
1184 } else
1185 card->info.hwtrap = 0;
1187 qeth_l2_setup_bridgeport_attrs(card);
1189 card->state = CARD_STATE_HARDSETUP;
1190 memset(&card->rx, 0, sizeof(struct qeth_rx));
1191 qeth_print_status_message(card);
1193 /* softsetup */
1194 QETH_DBF_TEXT(SETUP, 2, "softsetp");
1196 rc = qeth_send_startlan(card);
1197 if (rc) {
1198 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1199 if (rc == 0xe080) {
1200 dev_warn(&card->gdev->dev,
1201 "The LAN is offline\n");
1202 card->lan_online = 0;
1203 goto contin;
1205 rc = -ENODEV;
1206 goto out_remove;
1207 } else
1208 card->lan_online = 1;
1210 contin:
1211 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
1212 (card->info.type == QETH_CARD_TYPE_OSX)) {
1213 rc = qeth_l2_start_ipassists(card);
1214 if (rc)
1215 goto out_remove;
1218 if (card->info.type != QETH_CARD_TYPE_OSN &&
1219 card->info.type != QETH_CARD_TYPE_OSM)
1220 qeth_l2_process_vlans(card);
1222 netif_tx_disable(card->dev);
1224 rc = qeth_init_qdio_queues(card);
1225 if (rc) {
1226 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
1227 rc = -ENODEV;
1228 goto out_remove;
1230 card->state = CARD_STATE_SOFTSETUP;
1231 if (card->lan_online)
1232 netif_carrier_on(card->dev);
1233 else
1234 netif_carrier_off(card->dev);
1236 qeth_set_allowed_threads(card, 0xffffffff, 0);
1237 if (recover_flag == CARD_STATE_RECOVER) {
1238 if (recovery_mode &&
1239 card->info.type != QETH_CARD_TYPE_OSN) {
1240 __qeth_l2_open(card->dev);
1241 } else {
1242 rtnl_lock();
1243 dev_open(card->dev);
1244 rtnl_unlock();
1246 /* this also sets saved unicast addresses */
1247 qeth_l2_set_rx_mode(card->dev);
1248 rtnl_lock();
1249 qeth_recover_features(card->dev);
1250 rtnl_unlock();
1252 /* let user_space know that device is online */
1253 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
1254 mutex_unlock(&card->conf_mutex);
1255 mutex_unlock(&card->discipline_mutex);
1256 return 0;
1258 out_remove:
1259 qeth_l2_stop_card(card, 0);
1260 ccw_device_set_offline(CARD_DDEV(card));
1261 ccw_device_set_offline(CARD_WDEV(card));
1262 ccw_device_set_offline(CARD_RDEV(card));
1263 qdio_free(CARD_DDEV(card));
1264 if (recover_flag == CARD_STATE_RECOVER)
1265 card->state = CARD_STATE_RECOVER;
1266 else
1267 card->state = CARD_STATE_DOWN;
1268 mutex_unlock(&card->conf_mutex);
1269 mutex_unlock(&card->discipline_mutex);
1270 return rc;
1273 static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1275 return __qeth_l2_set_online(gdev, 0);
1278 static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1279 int recovery_mode)
1281 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1282 int rc = 0, rc2 = 0, rc3 = 0;
1283 enum qeth_card_states recover_flag;
1285 mutex_lock(&card->discipline_mutex);
1286 mutex_lock(&card->conf_mutex);
1287 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1288 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
1290 if (card->dev && netif_carrier_ok(card->dev))
1291 netif_carrier_off(card->dev);
1292 recover_flag = card->state;
1293 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
1294 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1295 card->info.hwtrap = 1;
1297 qeth_l2_stop_card(card, recovery_mode);
1298 rc = ccw_device_set_offline(CARD_DDEV(card));
1299 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1300 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1301 if (!rc)
1302 rc = (rc2) ? rc2 : rc3;
1303 if (rc)
1304 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1305 qdio_free(CARD_DDEV(card));
1306 if (recover_flag == CARD_STATE_UP)
1307 card->state = CARD_STATE_RECOVER;
1308 /* let user_space know that device is offline */
1309 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
1310 mutex_unlock(&card->conf_mutex);
1311 mutex_unlock(&card->discipline_mutex);
1312 return 0;
1315 static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1317 return __qeth_l2_set_offline(cgdev, 0);
1320 static int qeth_l2_recover(void *ptr)
1322 struct qeth_card *card;
1323 int rc = 0;
1325 card = (struct qeth_card *) ptr;
1326 QETH_CARD_TEXT(card, 2, "recover1");
1327 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1328 return 0;
1329 QETH_CARD_TEXT(card, 2, "recover2");
1330 dev_warn(&card->gdev->dev,
1331 "A recovery process has been started for the device\n");
1332 qeth_set_recovery_task(card);
1333 __qeth_l2_set_offline(card->gdev, 1);
1334 rc = __qeth_l2_set_online(card->gdev, 1);
1335 if (!rc)
1336 dev_info(&card->gdev->dev,
1337 "Device successfully recovered!\n");
1338 else {
1339 qeth_close_dev(card);
1340 dev_warn(&card->gdev->dev, "The qeth device driver "
1341 "failed to recover an error on the device\n");
1343 qeth_clear_recovery_task(card);
1344 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1345 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
1346 return 0;
1349 static int __init qeth_l2_init(void)
1351 pr_info("register layer 2 discipline\n");
1352 return 0;
1355 static void __exit qeth_l2_exit(void)
1357 pr_info("unregister layer 2 discipline\n");
1360 static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1362 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1363 qeth_set_allowed_threads(card, 0, 1);
1364 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
1365 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1366 qeth_qdio_clear_card(card, 0);
1367 qeth_clear_qdio_buffers(card);
1368 qdio_free(CARD_DDEV(card));
1371 static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1373 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1375 if (card->dev)
1376 netif_device_detach(card->dev);
1377 qeth_set_allowed_threads(card, 0, 1);
1378 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1379 if (gdev->state == CCWGROUP_OFFLINE)
1380 return 0;
1381 if (card->state == CARD_STATE_UP) {
1382 if (card->info.hwtrap)
1383 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1384 __qeth_l2_set_offline(card->gdev, 1);
1385 } else
1386 __qeth_l2_set_offline(card->gdev, 0);
1387 return 0;
1390 static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1392 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1393 int rc = 0;
1395 if (gdev->state == CCWGROUP_OFFLINE)
1396 goto out;
1398 if (card->state == CARD_STATE_RECOVER) {
1399 rc = __qeth_l2_set_online(card->gdev, 1);
1400 if (rc) {
1401 rtnl_lock();
1402 dev_close(card->dev);
1403 rtnl_unlock();
1405 } else
1406 rc = __qeth_l2_set_online(card->gdev, 0);
1407 out:
1408 qeth_set_allowed_threads(card, 0xffffffff, 0);
1409 if (card->dev)
1410 netif_device_attach(card->dev);
1411 if (rc)
1412 dev_warn(&card->gdev->dev, "The qeth device driver "
1413 "failed to recover an error on the device\n");
1414 return rc;
1417 /* Returns zero if the command is successfully "consumed" */
1418 static int qeth_l2_control_event(struct qeth_card *card,
1419 struct qeth_ipa_cmd *cmd)
1421 switch (cmd->hdr.command) {
1422 case IPA_CMD_SETBRIDGEPORT_OSA:
1423 case IPA_CMD_SETBRIDGEPORT_IQD:
1424 if (cmd->data.sbp.hdr.command_code ==
1425 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
1426 qeth_bridge_state_change(card, cmd);
1427 return 0;
1428 } else
1429 return 1;
1430 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
1431 qeth_bridge_host_event(card, cmd);
1432 return 0;
1433 default:
1434 return 1;
1438 struct qeth_discipline qeth_l2_discipline = {
1439 .start_poll = qeth_qdio_start_poll,
1440 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
1441 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
1442 .recover = qeth_l2_recover,
1443 .setup = qeth_l2_probe_device,
1444 .remove = qeth_l2_remove_device,
1445 .set_online = qeth_l2_set_online,
1446 .set_offline = qeth_l2_set_offline,
1447 .shutdown = qeth_l2_shutdown,
1448 .freeze = qeth_l2_pm_suspend,
1449 .thaw = qeth_l2_pm_resume,
1450 .restore = qeth_l2_pm_resume,
1451 .control_event_handler = qeth_l2_control_event,
1453 EXPORT_SYMBOL_GPL(qeth_l2_discipline);
1455 static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1456 struct qeth_cmd_buffer *iob)
1458 unsigned long flags;
1459 int rc = 0;
1461 QETH_CARD_TEXT(card, 5, "osndctrd");
1463 wait_event(card->wait_q,
1464 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1465 qeth_prepare_control_data(card, len, iob);
1466 QETH_CARD_TEXT(card, 6, "osnoirqp");
1467 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1468 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1469 (addr_t) iob, 0, 0);
1470 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1471 if (rc) {
1472 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
1473 "ccw_device_start rc = %i\n", rc);
1474 QETH_CARD_TEXT_(card, 2, " err%d", rc);
1475 qeth_release_buffer(iob->channel, iob);
1476 atomic_set(&card->write.irq_pending, 0);
1477 wake_up(&card->wait_q);
1479 return rc;
1482 static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1483 struct qeth_cmd_buffer *iob, int data_len)
1485 u16 s1, s2;
1487 QETH_CARD_TEXT(card, 4, "osndipa");
1489 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1490 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1491 s2 = (u16)data_len;
1492 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1493 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1494 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1495 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1496 return qeth_osn_send_control_data(card, s1, iob);
1499 int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1501 struct qeth_cmd_buffer *iob;
1502 struct qeth_card *card;
1503 int rc;
1505 if (!dev)
1506 return -ENODEV;
1507 card = dev->ml_priv;
1508 if (!card)
1509 return -ENODEV;
1510 QETH_CARD_TEXT(card, 2, "osnsdmc");
1511 if (!qeth_card_hw_is_reachable(card))
1512 return -ENODEV;
1513 iob = qeth_wait_for_buffer(&card->write);
1514 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1515 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1516 return rc;
1518 EXPORT_SYMBOL(qeth_osn_assist);
1520 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1521 int (*assist_cb)(struct net_device *, void *),
1522 int (*data_cb)(struct sk_buff *))
1524 struct qeth_card *card;
1526 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1527 if (*dev == NULL)
1528 return -ENODEV;
1529 card = (*dev)->ml_priv;
1530 if (!card)
1531 return -ENODEV;
1532 QETH_CARD_TEXT(card, 2, "osnreg");
1533 if ((assist_cb == NULL) || (data_cb == NULL))
1534 return -EINVAL;
1535 card->osn_info.assist_cb = assist_cb;
1536 card->osn_info.data_cb = data_cb;
1537 return 0;
1539 EXPORT_SYMBOL(qeth_osn_register);
1541 void qeth_osn_deregister(struct net_device *dev)
1543 struct qeth_card *card;
1545 if (!dev)
1546 return;
1547 card = dev->ml_priv;
1548 if (!card)
1549 return;
1550 QETH_CARD_TEXT(card, 2, "osndereg");
1551 card->osn_info.assist_cb = NULL;
1552 card->osn_info.data_cb = NULL;
1553 return;
1555 EXPORT_SYMBOL(qeth_osn_deregister);
1557 /* SETBRIDGEPORT support, async notifications */
1559 enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1562 * qeth_bridge_emit_host_event() - bridgeport address change notification
1563 * @card: qeth_card structure pointer, for udev events.
1564 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1565 * and reset token and addr_lnid are unused and may be NULL.
1566 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1567 * object, 0 - addition of an object.
1568 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1569 * @token: "network token" structure identifying physical address of the port.
1570 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1572 * This function is called when registrations and deregistrations are
1573 * reported by the hardware, and also when notifications are enabled -
1574 * for all currently registered addresses.
1576 static void qeth_bridge_emit_host_event(struct qeth_card *card,
1577 enum qeth_an_event_type evtype,
1578 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1580 char str[7][32];
1581 char *env[8];
1582 int i = 0;
1584 switch (evtype) {
1585 case anev_reg_unreg:
1586 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1587 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1588 ? "deregister" : "register");
1589 env[i] = str[i]; i++;
1590 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1591 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1592 addr_lnid->lnid);
1593 env[i] = str[i]; i++;
1595 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
1596 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
1597 addr_lnid->mac);
1598 env[i] = str[i]; i++;
1600 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1601 token->cssid, token->ssid, token->devnum);
1602 env[i] = str[i]; i++;
1603 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1604 env[i] = str[i]; i++;
1605 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1606 token->chpid);
1607 env[i] = str[i]; i++;
1608 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1609 env[i] = str[i]; i++;
1610 break;
1611 case anev_abort:
1612 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1613 env[i] = str[i]; i++;
1614 break;
1615 case anev_reset:
1616 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1617 env[i] = str[i]; i++;
1618 break;
1620 env[i] = NULL;
1621 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1624 struct qeth_bridge_state_data {
1625 struct work_struct worker;
1626 struct qeth_card *card;
1627 struct qeth_sbp_state_change qports;
1630 static void qeth_bridge_state_change_worker(struct work_struct *work)
1632 struct qeth_bridge_state_data *data =
1633 container_of(work, struct qeth_bridge_state_data, worker);
1634 /* We are only interested in the first entry - local port */
1635 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1636 char env_locrem[32];
1637 char env_role[32];
1638 char env_state[32];
1639 char *env[] = {
1640 env_locrem,
1641 env_role,
1642 env_state,
1643 NULL
1646 /* Role should not change by itself, but if it did, */
1647 /* information from the hardware is authoritative. */
1648 mutex_lock(&data->card->conf_mutex);
1649 data->card->options.sbp.role = entry->role;
1650 mutex_unlock(&data->card->conf_mutex);
1652 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1653 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1654 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1655 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1656 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1657 "<INVALID>");
1658 snprintf(env_state, sizeof(env_state), "STATE=%s",
1659 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1660 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1661 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1662 "<INVALID>");
1663 kobject_uevent_env(&data->card->gdev->dev.kobj,
1664 KOBJ_CHANGE, env);
1665 kfree(data);
1668 static void qeth_bridge_state_change(struct qeth_card *card,
1669 struct qeth_ipa_cmd *cmd)
1671 struct qeth_sbp_state_change *qports =
1672 &cmd->data.sbp.data.state_change;
1673 struct qeth_bridge_state_data *data;
1674 int extrasize;
1676 QETH_CARD_TEXT(card, 2, "brstchng");
1677 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1678 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
1679 return;
1681 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1682 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1683 GFP_ATOMIC);
1684 if (!data) {
1685 QETH_CARD_TEXT(card, 2, "BPSalloc");
1686 return;
1688 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1689 data->card = card;
1690 memcpy(&data->qports, qports,
1691 sizeof(struct qeth_sbp_state_change) + extrasize);
1692 queue_work(qeth_wq, &data->worker);
1695 struct qeth_bridge_host_data {
1696 struct work_struct worker;
1697 struct qeth_card *card;
1698 struct qeth_ipacmd_addr_change hostevs;
1701 static void qeth_bridge_host_event_worker(struct work_struct *work)
1703 struct qeth_bridge_host_data *data =
1704 container_of(work, struct qeth_bridge_host_data, worker);
1705 int i;
1707 if (data->hostevs.lost_event_mask) {
1708 dev_info(&data->card->gdev->dev,
1709 "Address notification from the Bridge Port stopped %s (%s)\n",
1710 data->card->dev->name,
1711 (data->hostevs.lost_event_mask == 0x01)
1712 ? "Overflow"
1713 : (data->hostevs.lost_event_mask == 0x02)
1714 ? "Bridge port state change"
1715 : "Unknown reason");
1716 mutex_lock(&data->card->conf_mutex);
1717 data->card->options.sbp.hostnotification = 0;
1718 mutex_unlock(&data->card->conf_mutex);
1719 qeth_bridge_emit_host_event(data->card, anev_abort,
1720 0, NULL, NULL);
1721 } else
1722 for (i = 0; i < data->hostevs.num_entries; i++) {
1723 struct qeth_ipacmd_addr_change_entry *entry =
1724 &data->hostevs.entry[i];
1725 qeth_bridge_emit_host_event(data->card,
1726 anev_reg_unreg,
1727 entry->change_code,
1728 &entry->token, &entry->addr_lnid);
1730 kfree(data);
1733 static void qeth_bridge_host_event(struct qeth_card *card,
1734 struct qeth_ipa_cmd *cmd)
1736 struct qeth_ipacmd_addr_change *hostevs =
1737 &cmd->data.addrchange;
1738 struct qeth_bridge_host_data *data;
1739 int extrasize;
1741 QETH_CARD_TEXT(card, 2, "brhostev");
1742 if (cmd->hdr.return_code != 0x0000) {
1743 if (cmd->hdr.return_code == 0x0010) {
1744 if (hostevs->lost_event_mask == 0x00)
1745 hostevs->lost_event_mask = 0xff;
1746 } else {
1747 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1748 cmd->hdr.return_code);
1749 return;
1752 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1753 hostevs->num_entries;
1754 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1755 GFP_ATOMIC);
1756 if (!data) {
1757 QETH_CARD_TEXT(card, 2, "BPHalloc");
1758 return;
1760 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1761 data->card = card;
1762 memcpy(&data->hostevs, hostevs,
1763 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1764 queue_work(qeth_wq, &data->worker);
1767 /* SETBRIDGEPORT support; sending commands */
1769 struct _qeth_sbp_cbctl {
1770 u16 ipa_rc;
1771 u16 cmd_rc;
1772 union {
1773 u32 supported;
1774 struct {
1775 enum qeth_sbp_roles *role;
1776 enum qeth_sbp_states *state;
1777 } qports;
1778 } data;
1782 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes.
1783 * @card: qeth_card structure pointer, for debug messages.
1784 * @cbctl: state structure with hardware return codes.
1785 * @setcmd: IPA command code
1787 * Returns negative errno-compatible error indication or 0 on success.
1789 static int qeth_bridgeport_makerc(struct qeth_card *card,
1790 struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd)
1792 int rc;
1793 int is_iqd = (card->info.type == QETH_CARD_TYPE_IQD);
1795 if ((is_iqd && (cbctl->ipa_rc == IPA_RC_SUCCESS)) ||
1796 (!is_iqd && (cbctl->ipa_rc == cbctl->cmd_rc)))
1797 switch (cbctl->cmd_rc) {
1798 case 0x0000:
1799 rc = 0;
1800 break;
1801 case 0x2B04:
1802 case 0x0004:
1803 rc = -EOPNOTSUPP;
1804 break;
1805 case 0x2B0C:
1806 case 0x000C: /* Not configured as bridge Port */
1807 rc = -ENODEV; /* maybe not the best code here? */
1808 dev_err(&card->gdev->dev,
1809 "The device is not configured as a Bridge Port\n");
1810 break;
1811 case 0x2B10:
1812 case 0x0010: /* OS mismatch */
1813 rc = -EPERM;
1814 dev_err(&card->gdev->dev,
1815 "A Bridge Port is already configured by a different operating system\n");
1816 break;
1817 case 0x2B14:
1818 case 0x0014: /* Another device is Primary */
1819 switch (setcmd) {
1820 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1821 rc = -EEXIST;
1822 dev_err(&card->gdev->dev,
1823 "The LAN already has a primary Bridge Port\n");
1824 break;
1825 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1826 rc = -EBUSY;
1827 dev_err(&card->gdev->dev,
1828 "The device is already a primary Bridge Port\n");
1829 break;
1830 default:
1831 rc = -EIO;
1833 break;
1834 case 0x2B18:
1835 case 0x0018: /* This device is currently Secondary */
1836 rc = -EBUSY;
1837 dev_err(&card->gdev->dev,
1838 "The device is already a secondary Bridge Port\n");
1839 break;
1840 case 0x2B1C:
1841 case 0x001C: /* Limit for Secondary devices reached */
1842 rc = -EEXIST;
1843 dev_err(&card->gdev->dev,
1844 "The LAN cannot have more secondary Bridge Ports\n");
1845 break;
1846 case 0x2B24:
1847 case 0x0024: /* This device is currently Primary */
1848 rc = -EBUSY;
1849 dev_err(&card->gdev->dev,
1850 "The device is already a primary Bridge Port\n");
1851 break;
1852 case 0x2B20:
1853 case 0x0020: /* Not authorized by zManager */
1854 rc = -EACCES;
1855 dev_err(&card->gdev->dev,
1856 "The device is not authorized to be a Bridge Port\n");
1857 break;
1858 default:
1859 rc = -EIO;
1861 else
1862 switch (cbctl->ipa_rc) {
1863 case IPA_RC_NOTSUPP:
1864 rc = -EOPNOTSUPP;
1865 break;
1866 case IPA_RC_UNSUPPORTED_COMMAND:
1867 rc = -EOPNOTSUPP;
1868 break;
1869 default:
1870 rc = -EIO;
1873 if (rc) {
1874 QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc);
1875 QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc);
1877 return rc;
1880 static inline int ipa_cmd_sbp(struct qeth_card *card)
1882 return (card->info.type == QETH_CARD_TYPE_IQD) ?
1883 IPA_CMD_SETBRIDGEPORT_IQD :
1884 IPA_CMD_SETBRIDGEPORT_OSA;
1887 static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1888 struct qeth_reply *reply, unsigned long data)
1890 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1891 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1892 QETH_CARD_TEXT(card, 2, "brqsupcb");
1893 cbctl->ipa_rc = cmd->hdr.return_code;
1894 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1895 if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) {
1896 cbctl->data.supported =
1897 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1898 } else {
1899 cbctl->data.supported = 0;
1901 return 0;
1905 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1906 * @card: qeth_card structure pointer.
1908 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1909 * strucutre: card->options.sbp.supported_funcs.
1911 static void qeth_bridgeport_query_support(struct qeth_card *card)
1913 struct qeth_cmd_buffer *iob;
1914 struct qeth_ipa_cmd *cmd;
1915 struct _qeth_sbp_cbctl cbctl;
1917 QETH_CARD_TEXT(card, 2, "brqsuppo");
1918 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0);
1919 if (!iob)
1920 return;
1921 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1922 cmd->data.sbp.hdr.cmdlength =
1923 sizeof(struct qeth_ipacmd_sbp_hdr) +
1924 sizeof(struct qeth_sbp_query_cmds_supp);
1925 cmd->data.sbp.hdr.command_code =
1926 IPA_SBP_QUERY_COMMANDS_SUPPORTED;
1927 cmd->data.sbp.hdr.used_total = 1;
1928 cmd->data.sbp.hdr.seq_no = 1;
1929 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1930 (void *)&cbctl) ||
1931 qeth_bridgeport_makerc(card, &cbctl,
1932 IPA_SBP_QUERY_COMMANDS_SUPPORTED)) {
1933 /* non-zero makerc signifies failure, and produce messages */
1934 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1935 return;
1937 card->options.sbp.supported_funcs = cbctl.data.supported;
1940 static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1941 struct qeth_reply *reply, unsigned long data)
1943 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1944 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1945 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1947 QETH_CARD_TEXT(card, 2, "brqprtcb");
1948 cbctl->ipa_rc = cmd->hdr.return_code;
1949 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1950 if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0))
1951 return 0;
1952 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1953 cbctl->cmd_rc = 0xffff;
1954 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1955 return 0;
1957 /* first entry contains the state of the local port */
1958 if (qports->num_entries > 0) {
1959 if (cbctl->data.qports.role)
1960 *cbctl->data.qports.role = qports->entry[0].role;
1961 if (cbctl->data.qports.state)
1962 *cbctl->data.qports.state = qports->entry[0].state;
1964 return 0;
1968 * qeth_bridgeport_query_ports() - query local bridgeport status.
1969 * @card: qeth_card structure pointer.
1970 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1971 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1973 * Returns negative errno-compatible error indication or 0 on success.
1975 * 'role' and 'state' are not updated in case of hardware operation failure.
1977 int qeth_bridgeport_query_ports(struct qeth_card *card,
1978 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1980 int rc = 0;
1981 struct qeth_cmd_buffer *iob;
1982 struct qeth_ipa_cmd *cmd;
1983 struct _qeth_sbp_cbctl cbctl = {
1984 .data = {
1985 .qports = {
1986 .role = role,
1987 .state = state,
1992 QETH_CARD_TEXT(card, 2, "brqports");
1993 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1994 return -EOPNOTSUPP;
1995 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0);
1996 if (!iob)
1997 return -ENOMEM;
1998 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1999 cmd->data.sbp.hdr.cmdlength =
2000 sizeof(struct qeth_ipacmd_sbp_hdr);
2001 cmd->data.sbp.hdr.command_code =
2002 IPA_SBP_QUERY_BRIDGE_PORTS;
2003 cmd->data.sbp.hdr.used_total = 1;
2004 cmd->data.sbp.hdr.seq_no = 1;
2005 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
2006 (void *)&cbctl);
2007 if (rc < 0)
2008 return rc;
2009 return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS);
2011 EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports);
2013 static int qeth_bridgeport_set_cb(struct qeth_card *card,
2014 struct qeth_reply *reply, unsigned long data)
2016 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
2017 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
2018 QETH_CARD_TEXT(card, 2, "brsetrcb");
2019 cbctl->ipa_rc = cmd->hdr.return_code;
2020 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
2021 return 0;
2025 * qeth_bridgeport_setrole() - Assign primary role to the port.
2026 * @card: qeth_card structure pointer.
2027 * @role: Role to assign.
2029 * Returns negative errno-compatible error indication or 0 on success.
2031 int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
2033 int rc = 0;
2034 int cmdlength;
2035 struct qeth_cmd_buffer *iob;
2036 struct qeth_ipa_cmd *cmd;
2037 struct _qeth_sbp_cbctl cbctl;
2038 enum qeth_ipa_sbp_cmd setcmd;
2040 QETH_CARD_TEXT(card, 2, "brsetrol");
2041 switch (role) {
2042 case QETH_SBP_ROLE_NONE:
2043 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
2044 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
2045 sizeof(struct qeth_sbp_reset_role);
2046 break;
2047 case QETH_SBP_ROLE_PRIMARY:
2048 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
2049 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
2050 sizeof(struct qeth_sbp_set_primary);
2051 break;
2052 case QETH_SBP_ROLE_SECONDARY:
2053 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
2054 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
2055 sizeof(struct qeth_sbp_set_secondary);
2056 break;
2057 default:
2058 return -EINVAL;
2060 if (!(card->options.sbp.supported_funcs & setcmd))
2061 return -EOPNOTSUPP;
2062 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0);
2063 if (!iob)
2064 return -ENOMEM;
2065 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2066 cmd->data.sbp.hdr.cmdlength = cmdlength;
2067 cmd->data.sbp.hdr.command_code = setcmd;
2068 cmd->data.sbp.hdr.used_total = 1;
2069 cmd->data.sbp.hdr.seq_no = 1;
2070 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb,
2071 (void *)&cbctl);
2072 if (rc < 0)
2073 return rc;
2074 return qeth_bridgeport_makerc(card, &cbctl, setcmd);
2078 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
2079 * @card: qeth_card structure pointer, for debug messages.
2081 * Returns negative errno-compatible error indication or 0 on success.
2083 static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
2085 int rc;
2087 if (pnso_rc == 0)
2088 switch (response) {
2089 case 0x0001:
2090 rc = 0;
2091 break;
2092 case 0x0004:
2093 case 0x0100:
2094 case 0x0106:
2095 rc = -EOPNOTSUPP;
2096 dev_err(&card->gdev->dev,
2097 "Setting address notification failed\n");
2098 break;
2099 case 0x0107:
2100 rc = -EAGAIN;
2101 break;
2102 default:
2103 rc = -EIO;
2105 else
2106 rc = -EIO;
2108 if (rc) {
2109 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
2110 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
2112 return rc;
2115 static void qeth_bridgeport_an_set_cb(void *priv,
2116 enum qdio_brinfo_entry_type type, void *entry)
2118 struct qeth_card *card = (struct qeth_card *)priv;
2119 struct qdio_brinfo_entry_l2 *l2entry;
2120 u8 code;
2122 if (type != l2_addr_lnid) {
2123 WARN_ON_ONCE(1);
2124 return;
2127 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
2128 code = IPA_ADDR_CHANGE_CODE_MACADDR;
2129 if (l2entry->addr_lnid.lnid)
2130 code |= IPA_ADDR_CHANGE_CODE_VLANID;
2131 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
2132 (struct net_if_token *)&l2entry->nit,
2133 (struct mac_addr_lnid *)&l2entry->addr_lnid);
2137 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
2138 * @card: qeth_card structure pointer.
2139 * @enable: 0 - disable, non-zero - enable notifications
2141 * Returns negative errno-compatible error indication or 0 on success.
2143 * On enable, emits a series of address notifications udev events for all
2144 * currently registered hosts.
2146 int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
2148 int rc;
2149 u16 response;
2150 struct ccw_device *ddev;
2151 struct subchannel_id schid;
2153 if (!card)
2154 return -EINVAL;
2155 if (!card->options.sbp.supported_funcs)
2156 return -EOPNOTSUPP;
2157 ddev = CARD_DDEV(card);
2158 ccw_device_get_schid(ddev, &schid);
2160 if (enable) {
2161 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
2162 rc = qdio_pnso_brinfo(schid, 1, &response,
2163 qeth_bridgeport_an_set_cb, card);
2164 } else
2165 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
2166 return qeth_anset_makerc(card, rc, response);
2168 EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set);
2170 module_init(qeth_l2_init);
2171 module_exit(qeth_l2_exit);
2172 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2173 MODULE_DESCRIPTION("qeth layer 2 discipline");
2174 MODULE_LICENSE("GPL");