2 * drivers/s390/net/qeth_l2_main.c
4 * Copyright IBM Corp. 2007
5 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
6 * Frank Pavlic <fpavlic@de.ibm.com>,
7 * Thomas Spatzier <tspat@de.ibm.com>,
8 * Frank Blaschka <frank.blaschka@de.ibm.com>
11 #include <linux/module.h>
12 #include <linux/moduleparam.h>
13 #include <linux/string.h>
14 #include <linux/errno.h>
15 #include <linux/kernel.h>
16 #include <linux/etherdevice.h>
17 #include <linux/mii.h>
20 #include <asm/s390_rdev.h>
22 #include "qeth_core.h"
23 #include "qeth_core_offl.h"
25 #define QETH_DBF_TXT_BUF qeth_l2_dbf_txt_buf
26 static DEFINE_PER_CPU(char[256], qeth_l2_dbf_txt_buf);
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 *,
33 int (*reply_cb) (struct qeth_card *,
36 static void qeth_l2_set_multicast_list(struct net_device *);
37 static int qeth_l2_recover(void *);
39 static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
41 struct qeth_card *card = netdev_priv(dev);
42 struct mii_ioctl_data *mii_data;
48 if ((card->state != CARD_STATE_UP) &&
49 (card->state != CARD_STATE_SOFTSETUP))
52 if (card->info.type == QETH_CARD_TYPE_OSN)
56 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
57 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
59 case SIOC_QETH_GET_CARD_TYPE:
60 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
66 mii_data = if_mii(rq);
70 mii_data = if_mii(rq);
71 if (mii_data->phy_id != 0)
74 mii_data->val_out = qeth_mdio_read(dev,
75 mii_data->phy_id, mii_data->reg_num);
81 QETH_DBF_TEXT_(TRACE, 2, "ioce%d", rc);
85 static int qeth_l2_verify_dev(struct net_device *dev)
87 struct qeth_card *card;
91 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
92 list_for_each_entry(card, &qeth_core_card_list.list, list) {
93 if (card->dev == dev) {
98 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
103 static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
105 struct qeth_card *card;
106 struct net_device *ndev;
107 unsigned char *readno;
108 __u16 temp_dev_no, card_dev_no;
113 memcpy(&temp_dev_no, read_dev_no, 2);
114 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
115 list_for_each_entry(card, &qeth_core_card_list.list, list) {
116 readno = CARD_RDEV_ID(card);
117 readno += (strlen(readno) - 4);
118 card_dev_no = simple_strtoul(readno, &endp, 16);
119 if (card_dev_no == temp_dev_no) {
124 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
128 static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card,
129 struct qeth_reply *reply,
132 struct qeth_ipa_cmd *cmd;
135 QETH_DBF_TEXT(TRACE, 2, "L2Sgmacb");
136 cmd = (struct qeth_ipa_cmd *) data;
137 mac = &cmd->data.setdelmac.mac[0];
138 /* MAC already registered, needed in couple/uncouple case */
139 if (cmd->hdr.return_code == 0x2005) {
140 PRINT_WARN("Group MAC %02x:%02x:%02x:%02x:%02x:%02x " \
141 "already existing on %s \n",
142 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
143 QETH_CARD_IFNAME(card));
144 cmd->hdr.return_code = 0;
146 if (cmd->hdr.return_code)
147 PRINT_ERR("Could not set group MAC " \
148 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
149 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
150 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
154 static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
156 QETH_DBF_TEXT(TRACE, 2, "L2Sgmac");
157 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
158 qeth_l2_send_setgroupmac_cb);
161 static int qeth_l2_send_delgroupmac_cb(struct qeth_card *card,
162 struct qeth_reply *reply,
165 struct qeth_ipa_cmd *cmd;
168 QETH_DBF_TEXT(TRACE, 2, "L2Dgmacb");
169 cmd = (struct qeth_ipa_cmd *) data;
170 mac = &cmd->data.setdelmac.mac[0];
171 if (cmd->hdr.return_code)
172 PRINT_ERR("Could not delete group MAC " \
173 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
174 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
175 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
179 static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
181 QETH_DBF_TEXT(TRACE, 2, "L2Dgmac");
182 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
183 qeth_l2_send_delgroupmac_cb);
186 static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac)
188 struct qeth_mc_mac *mc;
190 mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC);
193 PRINT_ERR("no mem vor mc mac address\n");
197 memcpy(mc->mc_addr, mac, OSA_ADDR_LEN);
198 mc->mc_addrlen = OSA_ADDR_LEN;
200 if (!qeth_l2_send_setgroupmac(card, mac))
201 list_add_tail(&mc->list, &card->mc_list);
206 static void qeth_l2_del_all_mc(struct qeth_card *card)
208 struct qeth_mc_mac *mc, *tmp;
210 spin_lock_bh(&card->mclock);
211 list_for_each_entry_safe(mc, tmp, &card->mc_list, list) {
212 qeth_l2_send_delgroupmac(card, mc->mc_addr);
216 spin_unlock_bh(&card->mclock);
219 static void qeth_l2_get_packet_type(struct qeth_card *card,
220 struct qeth_hdr *hdr, struct sk_buff *skb)
224 if (!memcmp(skb->data + QETH_HEADER_SIZE,
225 skb->dev->broadcast, 6)) {
227 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
230 hdr_mac = *((__u16 *)skb->data);
232 switch (card->info.link_type) {
233 case QETH_LINK_TYPE_HSTR:
234 case QETH_LINK_TYPE_LANE_TR:
235 if ((hdr_mac == QETH_TR_MAC_NC) ||
236 (hdr_mac == QETH_TR_MAC_C))
237 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
239 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
241 /* eth or so multicast? */
243 if ((hdr_mac == QETH_ETH_MAC_V4) ||
244 (hdr_mac == QETH_ETH_MAC_V6))
245 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
247 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
251 static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
252 struct sk_buff *skb, int ipv, int cast_type)
254 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)((skb->data) +
257 memset(hdr, 0, sizeof(struct qeth_hdr));
258 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
260 /* set byte byte 3 to casting flags */
261 if (cast_type == RTN_MULTICAST)
262 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
263 else if (cast_type == RTN_BROADCAST)
264 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
266 qeth_l2_get_packet_type(card, hdr, skb);
268 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
269 /* VSWITCH relies on the VLAN
270 * information to be present in
272 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
273 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
274 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
278 static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
279 struct qeth_reply *reply, unsigned long data)
281 struct qeth_ipa_cmd *cmd;
283 QETH_DBF_TEXT(TRACE, 2, "L2sdvcb");
284 cmd = (struct qeth_ipa_cmd *) data;
285 if (cmd->hdr.return_code) {
286 PRINT_ERR("Error in processing VLAN %i on %s: 0x%x. "
287 "Continuing\n", cmd->data.setdelvlan.vlan_id,
288 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
289 QETH_DBF_TEXT_(TRACE, 2, "L2VL%4x", cmd->hdr.command);
290 QETH_DBF_TEXT_(TRACE, 2, "L2%s", CARD_BUS_ID(card));
291 QETH_DBF_TEXT_(TRACE, 2, "err%d", cmd->hdr.return_code);
296 static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
297 enum qeth_ipa_cmds ipacmd)
299 struct qeth_ipa_cmd *cmd;
300 struct qeth_cmd_buffer *iob;
302 QETH_DBF_TEXT_(TRACE, 4, "L2sdv%x", ipacmd);
303 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
304 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
305 cmd->data.setdelvlan.vlan_id = i;
306 return qeth_send_ipa_cmd(card, iob,
307 qeth_l2_send_setdelvlan_cb, NULL);
310 static void qeth_l2_process_vlans(struct qeth_card *card, int clear)
312 struct qeth_vlan_vid *id;
313 QETH_DBF_TEXT(TRACE, 3, "L2prcvln");
314 spin_lock_bh(&card->vlanlock);
315 list_for_each_entry(id, &card->vid_list, list) {
317 qeth_l2_send_setdelvlan(card, id->vid,
320 qeth_l2_send_setdelvlan(card, id->vid,
323 spin_unlock_bh(&card->vlanlock);
326 static void qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
328 struct qeth_card *card = netdev_priv(dev);
329 struct qeth_vlan_vid *id;
331 QETH_DBF_TEXT_(TRACE, 4, "aid:%d", vid);
332 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
335 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
336 spin_lock_bh(&card->vlanlock);
337 list_add_tail(&id->list, &card->vid_list);
338 spin_unlock_bh(&card->vlanlock);
340 PRINT_ERR("no memory for vid\n");
344 static void qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
346 struct qeth_vlan_vid *id, *tmpid = NULL;
347 struct qeth_card *card = netdev_priv(dev);
349 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
350 spin_lock_bh(&card->vlanlock);
351 list_for_each_entry(id, &card->vid_list, list) {
352 if (id->vid == vid) {
358 spin_unlock_bh(&card->vlanlock);
360 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
363 qeth_l2_set_multicast_list(card->dev);
366 static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
370 QETH_DBF_TEXT(SETUP , 2, "stopcard");
371 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
373 qeth_set_allowed_threads(card, 0, 1);
374 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD))
376 if (card->read.state == CH_STATE_UP &&
377 card->write.state == CH_STATE_UP &&
378 (card->state == CARD_STATE_UP)) {
380 card->info.type != QETH_CARD_TYPE_OSN) {
381 qeth_l2_stop(card->dev);
384 dev_close(card->dev);
387 if (!card->use_hard_stop) {
388 __u8 *mac = &card->dev->dev_addr[0];
389 rc = qeth_l2_send_delmac(card, mac);
390 QETH_DBF_TEXT_(SETUP, 2, "Lerr%d", rc);
392 card->state = CARD_STATE_SOFTSETUP;
394 if (card->state == CARD_STATE_SOFTSETUP) {
395 qeth_l2_process_vlans(card, 1);
396 qeth_l2_del_all_mc(card);
397 qeth_clear_ipacmd_list(card);
398 card->state = CARD_STATE_HARDSETUP;
400 if (card->state == CARD_STATE_HARDSETUP) {
401 qeth_qdio_clear_card(card, 0);
402 qeth_clear_qdio_buffers(card);
403 qeth_clear_working_pool_list(card);
404 card->state = CARD_STATE_DOWN;
406 if (card->state == CARD_STATE_DOWN) {
407 qeth_clear_cmd_buffers(&card->read);
408 qeth_clear_cmd_buffers(&card->write);
410 card->use_hard_stop = 0;
414 static void qeth_l2_process_inbound_buffer(struct qeth_card *card,
415 struct qeth_qdio_buffer *buf, int index)
417 struct qdio_buffer_element *element;
419 struct qeth_hdr *hdr;
423 /* get first element of current buffer */
424 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
426 if (card->options.performance_stats)
427 card->perf_stats.bufs_rec++;
428 while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element,
430 skb->dev = card->dev;
432 if (!(card->dev->flags & IFF_UP)) {
433 dev_kfree_skb_any(skb);
437 switch (hdr->hdr.l2.id) {
438 case QETH_HEADER_TYPE_LAYER2:
439 skb->pkt_type = PACKET_HOST;
440 skb->protocol = eth_type_trans(skb, skb->dev);
441 if (card->options.checksum_type == NO_CHECKSUMMING)
442 skb->ip_summed = CHECKSUM_UNNECESSARY;
444 skb->ip_summed = CHECKSUM_NONE;
445 if (skb->protocol == htons(ETH_P_802_2))
446 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
450 case QETH_HEADER_TYPE_OSN:
451 skb_push(skb, sizeof(struct qeth_hdr));
452 skb_copy_to_linear_data(skb, hdr,
453 sizeof(struct qeth_hdr));
455 card->osn_info.data_cb(skb);
458 dev_kfree_skb_any(skb);
459 QETH_DBF_TEXT(TRACE, 3, "inbunkno");
460 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
463 card->dev->last_rx = jiffies;
464 card->stats.rx_packets++;
465 card->stats.rx_bytes += len;
469 static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
470 enum qeth_ipa_cmds ipacmd,
471 int (*reply_cb) (struct qeth_card *,
475 struct qeth_ipa_cmd *cmd;
476 struct qeth_cmd_buffer *iob;
478 QETH_DBF_TEXT(TRACE, 2, "L2sdmac");
479 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
480 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
481 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
482 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
483 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
486 static int qeth_l2_send_setmac_cb(struct qeth_card *card,
487 struct qeth_reply *reply,
490 struct qeth_ipa_cmd *cmd;
492 QETH_DBF_TEXT(TRACE, 2, "L2Smaccb");
493 cmd = (struct qeth_ipa_cmd *) data;
494 if (cmd->hdr.return_code) {
495 QETH_DBF_TEXT_(TRACE, 2, "L2er%x", cmd->hdr.return_code);
496 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
497 cmd->hdr.return_code = -EIO;
499 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
500 memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac,
502 PRINT_INFO("MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
503 "successfully registered on device %s\n",
504 card->dev->dev_addr[0], card->dev->dev_addr[1],
505 card->dev->dev_addr[2], card->dev->dev_addr[3],
506 card->dev->dev_addr[4], card->dev->dev_addr[5],
512 static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
514 QETH_DBF_TEXT(TRACE, 2, "L2Setmac");
515 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
516 qeth_l2_send_setmac_cb);
519 static int qeth_l2_send_delmac_cb(struct qeth_card *card,
520 struct qeth_reply *reply,
523 struct qeth_ipa_cmd *cmd;
525 QETH_DBF_TEXT(TRACE, 2, "L2Dmaccb");
526 cmd = (struct qeth_ipa_cmd *) data;
527 if (cmd->hdr.return_code) {
528 QETH_DBF_TEXT_(TRACE, 2, "err%d", cmd->hdr.return_code);
529 cmd->hdr.return_code = -EIO;
532 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
537 static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
539 QETH_DBF_TEXT(TRACE, 2, "L2Delmac");
540 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
542 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
543 qeth_l2_send_delmac_cb);
546 static int qeth_l2_request_initial_mac(struct qeth_card *card)
549 char vendor_pre[] = {0x02, 0x00, 0x00};
551 QETH_DBF_TEXT(SETUP, 2, "doL2init");
552 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
554 rc = qeth_query_setadapterparms(card);
556 PRINT_WARN("could not query adapter parameters on device %s: "
557 "x%x\n", CARD_BUS_ID(card), rc);
560 if (card->info.guestlan) {
561 rc = qeth_setadpparms_change_macaddr(card);
563 PRINT_WARN("couldn't get MAC address on "
565 CARD_BUS_ID(card), rc);
566 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
569 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
571 random_ether_addr(card->dev->dev_addr);
572 memcpy(card->dev->dev_addr, vendor_pre, 3);
577 static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
579 struct sockaddr *addr = p;
580 struct qeth_card *card = netdev_priv(dev);
583 QETH_DBF_TEXT(TRACE, 3, "setmac");
585 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
586 QETH_DBF_TEXT(TRACE, 3, "setmcINV");
590 if (card->info.type == QETH_CARD_TYPE_OSN) {
591 PRINT_WARN("Setting MAC address on %s is not supported.\n",
593 QETH_DBF_TEXT(TRACE, 3, "setmcOSN");
596 QETH_DBF_TEXT_(TRACE, 3, "%s", CARD_BUS_ID(card));
597 QETH_DBF_HEX(TRACE, 3, addr->sa_data, OSA_ADDR_LEN);
598 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
600 rc = qeth_l2_send_setmac(card, addr->sa_data);
604 static void qeth_l2_set_multicast_list(struct net_device *dev)
606 struct qeth_card *card = netdev_priv(dev);
607 struct dev_mc_list *dm;
609 if (card->info.type == QETH_CARD_TYPE_OSN)
612 QETH_DBF_TEXT(TRACE, 3, "setmulti");
613 qeth_l2_del_all_mc(card);
614 spin_lock_bh(&card->mclock);
615 for (dm = dev->mc_list; dm; dm = dm->next)
616 qeth_l2_add_mc(card, dm->dmi_addr);
617 spin_unlock_bh(&card->mclock);
618 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
620 qeth_setadp_promisc_mode(card);
623 static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
626 struct qeth_hdr *hdr = NULL;
628 struct qeth_card *card = netdev_priv(dev);
629 struct sk_buff *new_skb = skb;
630 int ipv = qeth_get_ip_version(skb);
631 int cast_type = qeth_get_cast_type(card, skb);
632 struct qeth_qdio_out_q *queue = card->qdio.out_qs
633 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
634 int tx_bytes = skb->len;
635 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
636 struct qeth_eddp_context *ctx = NULL;
638 QETH_DBF_TEXT(TRACE, 6, "l2xmit");
640 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
641 card->stats.tx_carrier_errors++;
645 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
646 (skb->protocol == htons(ETH_P_IPV6)))
649 if (card->options.performance_stats) {
650 card->perf_stats.outbound_cnt++;
651 card->perf_stats.outbound_start_time = qeth_get_micros();
653 netif_stop_queue(dev);
656 large_send = QETH_LARGE_SEND_EDDP;
658 if (card->info.type == QETH_CARD_TYPE_OSN)
659 hdr = (struct qeth_hdr *)skb->data;
661 new_skb = qeth_prepare_skb(card, skb, &hdr);
664 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
667 if (large_send == QETH_LARGE_SEND_EDDP) {
668 ctx = qeth_eddp_create_context(card, new_skb, hdr,
669 skb->sk->sk_protocol);
671 PRINT_WARN("could not create eddp context\n");
675 elements = qeth_get_elements_no(card, (void *)hdr, new_skb, 0);
680 if ((large_send == QETH_LARGE_SEND_NO) &&
681 (skb->ip_summed == CHECKSUM_PARTIAL))
682 qeth_tx_csum(new_skb);
684 if (card->info.type != QETH_CARD_TYPE_IQD)
685 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
688 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
691 card->stats.tx_packets++;
692 card->stats.tx_bytes += tx_bytes;
694 dev_kfree_skb_any(skb);
695 if (card->options.performance_stats) {
696 if (large_send != QETH_LARGE_SEND_NO) {
697 card->perf_stats.large_send_bytes += tx_bytes;
698 card->perf_stats.large_send_cnt++;
700 if (skb_shinfo(new_skb)->nr_frags > 0) {
701 card->perf_stats.sg_skbs_sent++;
702 /* nr_frags + skb->data */
703 card->perf_stats.sg_frags_sent +=
704 skb_shinfo(new_skb)->nr_frags + 1;
709 qeth_eddp_put_context(ctx);
710 dev_kfree_skb_any(new_skb);
714 qeth_eddp_put_context(ctx);
718 dev_kfree_skb_any(new_skb);
719 return NETDEV_TX_BUSY;
724 netif_wake_queue(dev);
725 if (card->options.performance_stats)
726 card->perf_stats.outbound_time += qeth_get_micros() -
727 card->perf_stats.outbound_start_time;
731 card->stats.tx_dropped++;
732 card->stats.tx_errors++;
733 if ((new_skb != skb) && new_skb)
734 dev_kfree_skb_any(new_skb);
735 dev_kfree_skb_any(skb);
739 static void qeth_l2_qdio_input_handler(struct ccw_device *ccwdev,
740 unsigned int status, unsigned int qdio_err,
741 unsigned int siga_err, unsigned int queue,
742 int first_element, int count, unsigned long card_ptr)
744 struct net_device *net_dev;
745 struct qeth_card *card;
746 struct qeth_qdio_buffer *buffer;
750 QETH_DBF_TEXT(TRACE, 6, "qdinput");
751 card = (struct qeth_card *) card_ptr;
753 if (card->options.performance_stats) {
754 card->perf_stats.inbound_cnt++;
755 card->perf_stats.inbound_start_time = qeth_get_micros();
757 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
758 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION) {
759 QETH_DBF_TEXT(TRACE, 1, "qdinchk");
760 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
761 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", first_element,
763 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", queue, status);
764 qeth_schedule_recovery(card);
768 for (i = first_element; i < (first_element + count); ++i) {
769 index = i % QDIO_MAX_BUFFERS_PER_Q;
770 buffer = &card->qdio.in_q->bufs[index];
771 if (!((status & QDIO_STATUS_LOOK_FOR_ERROR) &&
772 qeth_check_qdio_errors(buffer->buffer,
773 qdio_err, siga_err, "qinerr")))
774 qeth_l2_process_inbound_buffer(card, buffer, index);
775 /* clear buffer and give back to hardware */
776 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
777 qeth_queue_input_buffer(card, index);
779 if (card->options.performance_stats)
780 card->perf_stats.inbound_time += qeth_get_micros() -
781 card->perf_stats.inbound_start_time;
784 static int qeth_l2_open(struct net_device *dev)
786 struct qeth_card *card = netdev_priv(dev);
788 QETH_DBF_TEXT(TRACE, 4, "qethopen");
789 if (card->state != CARD_STATE_SOFTSETUP)
792 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
793 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
794 QETH_DBF_TEXT(TRACE, 4, "nomacadr");
797 card->data.state = CH_STATE_UP;
798 card->state = CARD_STATE_UP;
799 card->dev->flags |= IFF_UP;
800 netif_start_queue(dev);
802 if (!card->lan_online && netif_carrier_ok(dev))
803 netif_carrier_off(dev);
808 static int qeth_l2_stop(struct net_device *dev)
810 struct qeth_card *card = netdev_priv(dev);
812 QETH_DBF_TEXT(TRACE, 4, "qethstop");
813 netif_tx_disable(dev);
814 card->dev->flags &= ~IFF_UP;
815 if (card->state == CARD_STATE_UP)
816 card->state = CARD_STATE_SOFTSETUP;
820 static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
822 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
824 INIT_LIST_HEAD(&card->vid_list);
825 INIT_LIST_HEAD(&card->mc_list);
826 card->options.layer2 = 1;
827 card->discipline.input_handler = (qdio_handler_t *)
828 qeth_l2_qdio_input_handler;
829 card->discipline.output_handler = (qdio_handler_t *)
830 qeth_qdio_output_handler;
831 card->discipline.recover = qeth_l2_recover;
835 static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
837 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
839 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
841 if (cgdev->state == CCWGROUP_ONLINE) {
842 card->use_hard_stop = 1;
843 qeth_l2_set_offline(cgdev);
847 unregister_netdev(card->dev);
851 qeth_l2_del_all_mc(card);
855 static struct ethtool_ops qeth_l2_ethtool_ops = {
856 .get_link = ethtool_op_get_link,
857 .get_tx_csum = ethtool_op_get_tx_csum,
858 .set_tx_csum = ethtool_op_set_tx_hw_csum,
859 .get_sg = ethtool_op_get_sg,
860 .set_sg = ethtool_op_set_sg,
861 .get_tso = ethtool_op_get_tso,
862 .set_tso = ethtool_op_set_tso,
863 .get_strings = qeth_core_get_strings,
864 .get_ethtool_stats = qeth_core_get_ethtool_stats,
865 .get_stats_count = qeth_core_get_stats_count,
866 .get_drvinfo = qeth_core_get_drvinfo,
869 static struct ethtool_ops qeth_l2_osn_ops = {
870 .get_strings = qeth_core_get_strings,
871 .get_ethtool_stats = qeth_core_get_ethtool_stats,
872 .get_stats_count = qeth_core_get_stats_count,
873 .get_drvinfo = qeth_core_get_drvinfo,
876 static int qeth_l2_setup_netdev(struct qeth_card *card)
878 switch (card->info.type) {
879 case QETH_CARD_TYPE_OSAE:
880 card->dev = alloc_etherdev(0);
882 case QETH_CARD_TYPE_IQD:
883 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
885 case QETH_CARD_TYPE_OSN:
886 card->dev = alloc_netdev(0, "osn%d", ether_setup);
887 card->dev->flags |= IFF_NOARP;
890 card->dev = alloc_etherdev(0);
896 card->dev->priv = card;
897 card->dev->tx_timeout = &qeth_tx_timeout;
898 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
899 card->dev->open = qeth_l2_open;
900 card->dev->stop = qeth_l2_stop;
901 card->dev->hard_start_xmit = qeth_l2_hard_start_xmit;
902 card->dev->do_ioctl = qeth_l2_do_ioctl;
903 card->dev->get_stats = qeth_get_stats;
904 card->dev->change_mtu = qeth_change_mtu;
905 card->dev->set_multicast_list = qeth_l2_set_multicast_list;
906 card->dev->vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid;
907 card->dev->vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid;
908 card->dev->set_mac_address = qeth_l2_set_mac_address;
909 card->dev->mtu = card->info.initial_mtu;
910 if (card->info.type != QETH_CARD_TYPE_OSN)
911 SET_ETHTOOL_OPS(card->dev, &qeth_l2_ethtool_ops);
913 SET_ETHTOOL_OPS(card->dev, &qeth_l2_osn_ops);
914 card->dev->features |= NETIF_F_HW_VLAN_FILTER;
915 card->info.broadcast_capable = 1;
916 qeth_l2_request_initial_mac(card);
917 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
918 return register_netdev(card->dev);
921 static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
923 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
925 enum qeth_card_states recover_flag;
928 QETH_DBF_TEXT(SETUP, 2, "setonlin");
929 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
931 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
932 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)) {
933 PRINT_WARN("set_online of card %s interrupted by user!\n",
938 recover_flag = card->state;
939 rc = ccw_device_set_online(CARD_RDEV(card));
941 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
944 rc = ccw_device_set_online(CARD_WDEV(card));
946 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
949 rc = ccw_device_set_online(CARD_DDEV(card));
951 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
955 rc = qeth_core_hardsetup_card(card);
957 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
961 if (!card->dev && qeth_l2_setup_netdev(card))
964 if (card->info.type != QETH_CARD_TYPE_OSN)
965 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
967 card->state = CARD_STATE_HARDSETUP;
968 qeth_print_status_message(card);
971 QETH_DBF_TEXT(SETUP, 2, "softsetp");
973 rc = qeth_send_startlan(card);
975 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
977 PRINT_WARN("LAN on card %s if offline! "
978 "Waiting for STARTLAN from card.\n",
980 card->lan_online = 0;
984 card->lan_online = 1;
986 if (card->info.type != QETH_CARD_TYPE_OSN) {
987 qeth_set_large_send(card, card->options.large_send);
988 qeth_l2_process_vlans(card, 0);
991 netif_tx_disable(card->dev);
993 rc = qeth_init_qdio_queues(card);
995 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
998 card->state = CARD_STATE_SOFTSETUP;
999 netif_carrier_on(card->dev);
1001 qeth_set_allowed_threads(card, 0xffffffff, 0);
1002 if (recover_flag == CARD_STATE_RECOVER) {
1003 if (recovery_mode &&
1004 card->info.type != QETH_CARD_TYPE_OSN) {
1005 qeth_l2_open(card->dev);
1008 dev_open(card->dev);
1011 /* this also sets saved unicast addresses */
1012 qeth_l2_set_multicast_list(card->dev);
1014 /* let user_space know that device is online */
1015 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
1018 card->use_hard_stop = 1;
1019 qeth_l2_stop_card(card, 0);
1020 ccw_device_set_offline(CARD_DDEV(card));
1021 ccw_device_set_offline(CARD_WDEV(card));
1022 ccw_device_set_offline(CARD_RDEV(card));
1023 if (recover_flag == CARD_STATE_RECOVER)
1024 card->state = CARD_STATE_RECOVER;
1026 card->state = CARD_STATE_DOWN;
1030 static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1032 return __qeth_l2_set_online(gdev, 0);
1035 static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1038 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1039 int rc = 0, rc2 = 0, rc3 = 0;
1040 enum qeth_card_states recover_flag;
1042 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1043 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
1045 if (card->dev && netif_carrier_ok(card->dev))
1046 netif_carrier_off(card->dev);
1047 recover_flag = card->state;
1048 if (qeth_l2_stop_card(card, recovery_mode) == -ERESTARTSYS) {
1049 PRINT_WARN("Stopping card %s interrupted by user!\n",
1051 return -ERESTARTSYS;
1053 rc = ccw_device_set_offline(CARD_DDEV(card));
1054 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1055 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1057 rc = (rc2) ? rc2 : rc3;
1059 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1060 if (recover_flag == CARD_STATE_UP)
1061 card->state = CARD_STATE_RECOVER;
1062 /* let user_space know that device is offline */
1063 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
1067 static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1069 return __qeth_l2_set_offline(cgdev, 0);
1072 static int qeth_l2_recover(void *ptr)
1074 struct qeth_card *card;
1077 card = (struct qeth_card *) ptr;
1078 QETH_DBF_TEXT(TRACE, 2, "recover1");
1079 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
1080 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1082 QETH_DBF_TEXT(TRACE, 2, "recover2");
1083 PRINT_WARN("Recovery of device %s started ...\n",
1085 card->use_hard_stop = 1;
1086 __qeth_l2_set_offline(card->gdev, 1);
1087 rc = __qeth_l2_set_online(card->gdev, 1);
1088 /* don't run another scheduled recovery */
1089 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1090 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
1092 PRINT_INFO("Device %s successfully recovered!\n",
1095 PRINT_INFO("Device %s could not be recovered!\n",
1100 static int __init qeth_l2_init(void)
1102 PRINT_INFO("register layer 2 discipline\n");
1106 static void __exit qeth_l2_exit(void)
1108 PRINT_INFO("unregister layer 2 discipline\n");
1111 static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1113 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1114 qeth_qdio_clear_card(card, 0);
1115 qeth_clear_qdio_buffers(card);
1118 struct ccwgroup_driver qeth_l2_ccwgroup_driver = {
1119 .probe = qeth_l2_probe_device,
1120 .remove = qeth_l2_remove_device,
1121 .set_online = qeth_l2_set_online,
1122 .set_offline = qeth_l2_set_offline,
1123 .shutdown = qeth_l2_shutdown,
1125 EXPORT_SYMBOL_GPL(qeth_l2_ccwgroup_driver);
1127 static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1128 struct qeth_cmd_buffer *iob)
1130 unsigned long flags;
1133 QETH_DBF_TEXT(TRACE, 5, "osndctrd");
1135 wait_event(card->wait_q,
1136 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1137 qeth_prepare_control_data(card, len, iob);
1138 QETH_DBF_TEXT(TRACE, 6, "osnoirqp");
1139 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1140 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1141 (addr_t) iob, 0, 0);
1142 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1144 PRINT_WARN("qeth_osn_send_control_data: "
1145 "ccw_device_start rc = %i\n", rc);
1146 QETH_DBF_TEXT_(TRACE, 2, " err%d", rc);
1147 qeth_release_buffer(iob->channel, iob);
1148 atomic_set(&card->write.irq_pending, 0);
1149 wake_up(&card->wait_q);
1154 static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1155 struct qeth_cmd_buffer *iob, int data_len)
1159 QETH_DBF_TEXT(TRACE, 4, "osndipa");
1161 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1162 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1164 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1165 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1166 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1167 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1168 return qeth_osn_send_control_data(card, s1, iob);
1171 int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1173 struct qeth_cmd_buffer *iob;
1174 struct qeth_card *card;
1177 QETH_DBF_TEXT(TRACE, 2, "osnsdmc");
1180 card = netdev_priv(dev);
1183 if ((card->state != CARD_STATE_UP) &&
1184 (card->state != CARD_STATE_SOFTSETUP))
1186 iob = qeth_wait_for_buffer(&card->write);
1187 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1188 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1191 EXPORT_SYMBOL(qeth_osn_assist);
1193 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1194 int (*assist_cb)(struct net_device *, void *),
1195 int (*data_cb)(struct sk_buff *))
1197 struct qeth_card *card;
1199 QETH_DBF_TEXT(TRACE, 2, "osnreg");
1200 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1203 card = netdev_priv(*dev);
1206 if ((assist_cb == NULL) || (data_cb == NULL))
1208 card->osn_info.assist_cb = assist_cb;
1209 card->osn_info.data_cb = data_cb;
1212 EXPORT_SYMBOL(qeth_osn_register);
1214 void qeth_osn_deregister(struct net_device *dev)
1216 struct qeth_card *card;
1218 QETH_DBF_TEXT(TRACE, 2, "osndereg");
1221 card = netdev_priv(dev);
1224 card->osn_info.assist_cb = NULL;
1225 card->osn_info.data_cb = NULL;
1228 EXPORT_SYMBOL(qeth_osn_deregister);
1230 module_init(qeth_l2_init);
1231 module_exit(qeth_l2_exit);
1232 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1233 MODULE_DESCRIPTION("qeth layer 2 discipline");
1234 MODULE_LICENSE("GPL");