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 #define KMSG_COMPONENT "qeth"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/string.h>
17 #include <linux/errno.h>
18 #include <linux/kernel.h>
19 #include <linux/etherdevice.h>
20 #include <linux/mii.h>
23 #include <asm/s390_rdev.h>
25 #include "qeth_core.h"
26 #include "qeth_core_offl.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 *,
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 = dev->ml_priv;
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;
109 struct ccw_dev_id read_devid;
112 memcpy(&temp_dev_no, read_dev_no, 2);
113 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
114 list_for_each_entry(card, &qeth_core_card_list.list, list) {
115 ccw_device_get_id(CARD_RDEV(card), &read_devid);
116 if (read_devid.devno == temp_dev_no) {
121 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
125 static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card,
126 struct qeth_reply *reply,
129 struct qeth_ipa_cmd *cmd;
132 QETH_DBF_TEXT(TRACE, 2, "L2Sgmacb");
133 cmd = (struct qeth_ipa_cmd *) data;
134 mac = &cmd->data.setdelmac.mac[0];
135 /* MAC already registered, needed in couple/uncouple case */
136 if (cmd->hdr.return_code == 0x2005) {
137 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s \n",
138 mac, QETH_CARD_IFNAME(card));
139 cmd->hdr.return_code = 0;
141 if (cmd->hdr.return_code)
142 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %x\n",
143 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
147 static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
149 QETH_DBF_TEXT(TRACE, 2, "L2Sgmac");
150 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
151 qeth_l2_send_setgroupmac_cb);
154 static int qeth_l2_send_delgroupmac_cb(struct qeth_card *card,
155 struct qeth_reply *reply,
158 struct qeth_ipa_cmd *cmd;
161 QETH_DBF_TEXT(TRACE, 2, "L2Dgmacb");
162 cmd = (struct qeth_ipa_cmd *) data;
163 mac = &cmd->data.setdelmac.mac[0];
164 if (cmd->hdr.return_code)
165 QETH_DBF_MESSAGE(2, "Could not delete group MAC %pM on %s: %x\n",
166 mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
170 static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
172 QETH_DBF_TEXT(TRACE, 2, "L2Dgmac");
173 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
174 qeth_l2_send_delgroupmac_cb);
177 static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac, int vmac)
179 struct qeth_mc_mac *mc;
182 mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC);
187 memcpy(mc->mc_addr, mac, OSA_ADDR_LEN);
188 mc->mc_addrlen = OSA_ADDR_LEN;
192 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
195 rc = qeth_l2_send_setgroupmac(card, mac);
199 list_add_tail(&mc->list, &card->mc_list);
204 static void qeth_l2_del_all_mc(struct qeth_card *card)
206 struct qeth_mc_mac *mc, *tmp;
208 spin_lock_bh(&card->mclock);
209 list_for_each_entry_safe(mc, tmp, &card->mc_list, list) {
211 qeth_l2_send_setdelmac(card, mc->mc_addr,
212 IPA_CMD_DELVMAC, NULL);
214 qeth_l2_send_delgroupmac(card, mc->mc_addr);
218 spin_unlock_bh(&card->mclock);
221 static void qeth_l2_get_packet_type(struct qeth_card *card,
222 struct qeth_hdr *hdr, struct sk_buff *skb)
226 if (!memcmp(skb->data + QETH_HEADER_SIZE,
227 skb->dev->broadcast, 6)) {
229 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
232 hdr_mac = *((__u16 *)skb->data);
234 switch (card->info.link_type) {
235 case QETH_LINK_TYPE_HSTR:
236 case QETH_LINK_TYPE_LANE_TR:
237 if ((hdr_mac == QETH_TR_MAC_NC) ||
238 (hdr_mac == QETH_TR_MAC_C))
239 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
241 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
243 /* eth or so multicast? */
245 if ((hdr_mac == QETH_ETH_MAC_V4) ||
246 (hdr_mac == QETH_ETH_MAC_V6))
247 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
249 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
253 static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
254 struct sk_buff *skb, int ipv, int cast_type)
256 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
258 memset(hdr, 0, sizeof(struct qeth_hdr));
259 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
261 /* set byte byte 3 to casting flags */
262 if (cast_type == RTN_MULTICAST)
263 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
264 else if (cast_type == RTN_BROADCAST)
265 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
267 qeth_l2_get_packet_type(card, hdr, skb);
269 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
270 /* VSWITCH relies on the VLAN
271 * information to be present in
273 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
274 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
275 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
279 static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
280 struct qeth_reply *reply, unsigned long data)
282 struct qeth_ipa_cmd *cmd;
284 QETH_DBF_TEXT(TRACE, 2, "L2sdvcb");
285 cmd = (struct qeth_ipa_cmd *) data;
286 if (cmd->hdr.return_code) {
287 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
288 "Continuing\n", cmd->data.setdelvlan.vlan_id,
289 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
290 QETH_DBF_TEXT_(TRACE, 2, "L2VL%4x", cmd->hdr.command);
291 QETH_DBF_TEXT_(TRACE, 2, "L2%s", CARD_BUS_ID(card));
292 QETH_DBF_TEXT_(TRACE, 2, "err%d", cmd->hdr.return_code);
297 static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
298 enum qeth_ipa_cmds ipacmd)
300 struct qeth_ipa_cmd *cmd;
301 struct qeth_cmd_buffer *iob;
303 QETH_DBF_TEXT_(TRACE, 4, "L2sdv%x", ipacmd);
304 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
305 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
306 cmd->data.setdelvlan.vlan_id = i;
307 return qeth_send_ipa_cmd(card, iob,
308 qeth_l2_send_setdelvlan_cb, NULL);
311 static void qeth_l2_process_vlans(struct qeth_card *card, int clear)
313 struct qeth_vlan_vid *id;
314 QETH_DBF_TEXT(TRACE, 3, "L2prcvln");
315 spin_lock_bh(&card->vlanlock);
316 list_for_each_entry(id, &card->vid_list, list) {
318 qeth_l2_send_setdelvlan(card, id->vid,
321 qeth_l2_send_setdelvlan(card, id->vid,
324 spin_unlock_bh(&card->vlanlock);
327 static void qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
329 struct qeth_card *card = dev->ml_priv;
330 struct qeth_vlan_vid *id;
332 QETH_DBF_TEXT_(TRACE, 4, "aid:%d", vid);
333 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
336 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
337 spin_lock_bh(&card->vlanlock);
338 list_add_tail(&id->list, &card->vid_list);
339 spin_unlock_bh(&card->vlanlock);
343 static void qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
345 struct qeth_vlan_vid *id, *tmpid = NULL;
346 struct qeth_card *card = dev->ml_priv;
348 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
349 spin_lock_bh(&card->vlanlock);
350 list_for_each_entry(id, &card->vid_list, list) {
351 if (id->vid == vid) {
357 spin_unlock_bh(&card->vlanlock);
359 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
362 qeth_l2_set_multicast_list(card->dev);
365 static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
369 QETH_DBF_TEXT(SETUP , 2, "stopcard");
370 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
372 qeth_set_allowed_threads(card, 0, 1);
373 if (card->read.state == CH_STATE_UP &&
374 card->write.state == CH_STATE_UP &&
375 (card->state == CARD_STATE_UP)) {
377 card->info.type != QETH_CARD_TYPE_OSN) {
378 qeth_l2_stop(card->dev);
381 dev_close(card->dev);
384 if (!card->use_hard_stop) {
385 __u8 *mac = &card->dev->dev_addr[0];
386 rc = qeth_l2_send_delmac(card, mac);
387 QETH_DBF_TEXT_(SETUP, 2, "Lerr%d", rc);
389 card->state = CARD_STATE_SOFTSETUP;
391 if (card->state == CARD_STATE_SOFTSETUP) {
392 qeth_l2_process_vlans(card, 1);
393 if (!card->use_hard_stop)
394 qeth_l2_del_all_mc(card);
395 qeth_clear_ipacmd_list(card);
396 card->state = CARD_STATE_HARDSETUP;
398 if (card->state == CARD_STATE_HARDSETUP) {
399 qeth_qdio_clear_card(card, 0);
400 qeth_clear_qdio_buffers(card);
401 qeth_clear_working_pool_list(card);
402 card->state = CARD_STATE_DOWN;
404 if (card->state == CARD_STATE_DOWN) {
405 qeth_clear_cmd_buffers(&card->read);
406 qeth_clear_cmd_buffers(&card->write);
408 card->use_hard_stop = 0;
412 static void qeth_l2_process_inbound_buffer(struct qeth_card *card,
413 struct qeth_qdio_buffer *buf, int index)
415 struct qdio_buffer_element *element;
417 struct qeth_hdr *hdr;
421 /* get first element of current buffer */
422 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
424 if (card->options.performance_stats)
425 card->perf_stats.bufs_rec++;
426 while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element,
428 skb->dev = card->dev;
430 if (!(card->dev->flags & IFF_UP)) {
431 dev_kfree_skb_any(skb);
435 switch (hdr->hdr.l2.id) {
436 case QETH_HEADER_TYPE_LAYER2:
437 skb->pkt_type = PACKET_HOST;
438 skb->protocol = eth_type_trans(skb, skb->dev);
439 if (card->options.checksum_type == NO_CHECKSUMMING)
440 skb->ip_summed = CHECKSUM_UNNECESSARY;
442 skb->ip_summed = CHECKSUM_NONE;
443 if (skb->protocol == htons(ETH_P_802_2))
444 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
448 case QETH_HEADER_TYPE_OSN:
449 if (card->info.type == QETH_CARD_TYPE_OSN) {
450 skb_push(skb, sizeof(struct qeth_hdr));
451 skb_copy_to_linear_data(skb, hdr,
452 sizeof(struct qeth_hdr));
454 card->osn_info.data_cb(skb);
459 dev_kfree_skb_any(skb);
460 QETH_DBF_TEXT(TRACE, 3, "inbunkno");
461 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
464 card->dev->last_rx = jiffies;
465 card->stats.rx_packets++;
466 card->stats.rx_bytes += len;
470 static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
471 enum qeth_ipa_cmds ipacmd,
472 int (*reply_cb) (struct qeth_card *,
476 struct qeth_ipa_cmd *cmd;
477 struct qeth_cmd_buffer *iob;
479 QETH_DBF_TEXT(TRACE, 2, "L2sdmac");
480 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
481 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
482 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
483 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
484 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
487 static int qeth_l2_send_setmac_cb(struct qeth_card *card,
488 struct qeth_reply *reply,
491 struct qeth_ipa_cmd *cmd;
493 QETH_DBF_TEXT(TRACE, 2, "L2Smaccb");
494 cmd = (struct qeth_ipa_cmd *) data;
495 if (cmd->hdr.return_code) {
496 QETH_DBF_TEXT_(TRACE, 2, "L2er%x", cmd->hdr.return_code);
497 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
498 cmd->hdr.return_code = -EIO;
500 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
501 memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac,
503 dev_info(&card->gdev->dev,
504 "MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
505 "successfully registered on device %s\n",
506 card->dev->dev_addr[0], card->dev->dev_addr[1],
507 card->dev->dev_addr[2], card->dev->dev_addr[3],
508 card->dev->dev_addr[4], card->dev->dev_addr[5],
514 static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
516 QETH_DBF_TEXT(TRACE, 2, "L2Setmac");
517 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
518 qeth_l2_send_setmac_cb);
521 static int qeth_l2_send_delmac_cb(struct qeth_card *card,
522 struct qeth_reply *reply,
525 struct qeth_ipa_cmd *cmd;
527 QETH_DBF_TEXT(TRACE, 2, "L2Dmaccb");
528 cmd = (struct qeth_ipa_cmd *) data;
529 if (cmd->hdr.return_code) {
530 QETH_DBF_TEXT_(TRACE, 2, "err%d", cmd->hdr.return_code);
531 cmd->hdr.return_code = -EIO;
534 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
539 static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
541 QETH_DBF_TEXT(TRACE, 2, "L2Delmac");
542 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
544 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
545 qeth_l2_send_delmac_cb);
548 static int qeth_l2_request_initial_mac(struct qeth_card *card)
551 char vendor_pre[] = {0x02, 0x00, 0x00};
553 QETH_DBF_TEXT(SETUP, 2, "doL2init");
554 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
556 rc = qeth_query_setadapterparms(card);
558 QETH_DBF_MESSAGE(2, "could not query adapter parameters on "
559 "device %s: x%x\n", CARD_BUS_ID(card), rc);
562 if ((card->info.type == QETH_CARD_TYPE_IQD) ||
563 (card->info.guestlan)) {
564 rc = qeth_setadpparms_change_macaddr(card);
566 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
567 "device %s: x%x\n", CARD_BUS_ID(card), rc);
568 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
571 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
573 random_ether_addr(card->dev->dev_addr);
574 memcpy(card->dev->dev_addr, vendor_pre, 3);
579 static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
581 struct sockaddr *addr = p;
582 struct qeth_card *card = dev->ml_priv;
585 QETH_DBF_TEXT(TRACE, 3, "setmac");
587 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
588 QETH_DBF_TEXT(TRACE, 3, "setmcINV");
592 if (card->info.type == QETH_CARD_TYPE_OSN) {
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 = dev->ml_priv;
607 struct dev_addr_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->da_addr, 0);
618 for (dm = dev->uc_list; dm; dm = dm->next)
619 qeth_l2_add_mc(card, dm->da_addr, 1);
621 spin_unlock_bh(&card->mclock);
622 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
624 qeth_setadp_promisc_mode(card);
627 static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
630 struct qeth_hdr *hdr = NULL;
632 struct qeth_card *card = dev->ml_priv;
633 struct sk_buff *new_skb = skb;
634 int ipv = qeth_get_ip_version(skb);
635 int cast_type = qeth_get_cast_type(card, skb);
636 struct qeth_qdio_out_q *queue = card->qdio.out_qs
637 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
638 int tx_bytes = skb->len;
639 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
640 struct qeth_eddp_context *ctx = NULL;
641 int data_offset = -1;
642 int elements_needed = 0;
645 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
646 card->stats.tx_carrier_errors++;
650 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
651 (skb->protocol == htons(ETH_P_IPV6)))
654 if (card->options.performance_stats) {
655 card->perf_stats.outbound_cnt++;
656 card->perf_stats.outbound_start_time = qeth_get_micros();
658 netif_stop_queue(dev);
661 large_send = QETH_LARGE_SEND_EDDP;
663 if (card->info.type == QETH_CARD_TYPE_OSN)
664 hdr = (struct qeth_hdr *)skb->data;
666 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
667 (skb_shinfo(skb)->nr_frags == 0)) {
669 data_offset = ETH_HLEN;
671 hdr = kmem_cache_alloc(qeth_core_header_cache,
676 skb_reset_mac_header(new_skb);
677 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
678 hdr->hdr.l2.pkt_length = new_skb->len;
679 memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
680 skb_mac_header(new_skb), ETH_HLEN);
682 /* create a clone with writeable headroom */
683 new_skb = skb_realloc_headroom(skb,
684 sizeof(struct qeth_hdr));
687 hdr = (struct qeth_hdr *)skb_push(new_skb,
688 sizeof(struct qeth_hdr));
689 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
690 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
694 if (large_send == QETH_LARGE_SEND_EDDP) {
695 ctx = qeth_eddp_create_context(card, new_skb, hdr,
696 skb->sk->sk_protocol);
698 QETH_DBF_MESSAGE(2, "could not create eddp context\n");
702 elements = qeth_get_elements_no(card, (void *)hdr, new_skb,
705 if (data_offset >= 0)
706 kmem_cache_free(qeth_core_header_cache, hdr);
711 if ((large_send == QETH_LARGE_SEND_NO) &&
712 (skb->ip_summed == CHECKSUM_PARTIAL))
713 qeth_tx_csum(new_skb);
715 if (card->info.type != QETH_CARD_TYPE_IQD)
716 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
719 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
720 elements, ctx, data_offset, hd_len);
722 card->stats.tx_packets++;
723 card->stats.tx_bytes += tx_bytes;
725 dev_kfree_skb_any(skb);
726 if (card->options.performance_stats) {
727 if (large_send != QETH_LARGE_SEND_NO) {
728 card->perf_stats.large_send_bytes += tx_bytes;
729 card->perf_stats.large_send_cnt++;
731 if (skb_shinfo(new_skb)->nr_frags > 0) {
732 card->perf_stats.sg_skbs_sent++;
733 /* nr_frags + skb->data */
734 card->perf_stats.sg_frags_sent +=
735 skb_shinfo(new_skb)->nr_frags + 1;
740 qeth_eddp_put_context(ctx);
741 dev_kfree_skb_any(new_skb);
745 qeth_eddp_put_context(ctx);
747 if (data_offset >= 0)
748 kmem_cache_free(qeth_core_header_cache, hdr);
752 dev_kfree_skb_any(new_skb);
753 return NETDEV_TX_BUSY;
758 netif_wake_queue(dev);
759 if (card->options.performance_stats)
760 card->perf_stats.outbound_time += qeth_get_micros() -
761 card->perf_stats.outbound_start_time;
765 card->stats.tx_dropped++;
766 card->stats.tx_errors++;
767 if ((new_skb != skb) && new_skb)
768 dev_kfree_skb_any(new_skb);
769 dev_kfree_skb_any(skb);
770 netif_wake_queue(dev);
774 static void qeth_l2_qdio_input_handler(struct ccw_device *ccwdev,
775 unsigned int qdio_err, unsigned int queue,
776 int first_element, int count, unsigned long card_ptr)
778 struct net_device *net_dev;
779 struct qeth_card *card;
780 struct qeth_qdio_buffer *buffer;
784 card = (struct qeth_card *) card_ptr;
786 if (card->options.performance_stats) {
787 card->perf_stats.inbound_cnt++;
788 card->perf_stats.inbound_start_time = qeth_get_micros();
790 if (qdio_err & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
791 QETH_DBF_TEXT(TRACE, 1, "qdinchk");
792 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
793 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", first_element,
795 QETH_DBF_TEXT_(TRACE, 1, "%04X", queue);
796 qeth_schedule_recovery(card);
799 for (i = first_element; i < (first_element + count); ++i) {
800 index = i % QDIO_MAX_BUFFERS_PER_Q;
801 buffer = &card->qdio.in_q->bufs[index];
803 qeth_check_qdio_errors(buffer->buffer, qdio_err, "qinerr")))
804 qeth_l2_process_inbound_buffer(card, buffer, index);
805 /* clear buffer and give back to hardware */
806 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
807 qeth_queue_input_buffer(card, index);
809 if (card->options.performance_stats)
810 card->perf_stats.inbound_time += qeth_get_micros() -
811 card->perf_stats.inbound_start_time;
814 static int qeth_l2_open(struct net_device *dev)
816 struct qeth_card *card = dev->ml_priv;
818 QETH_DBF_TEXT(TRACE, 4, "qethopen");
819 if (card->state != CARD_STATE_SOFTSETUP)
822 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
823 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
824 QETH_DBF_TEXT(TRACE, 4, "nomacadr");
827 card->data.state = CH_STATE_UP;
828 card->state = CARD_STATE_UP;
829 netif_start_queue(dev);
831 if (!card->lan_online && netif_carrier_ok(dev))
832 netif_carrier_off(dev);
837 static int qeth_l2_stop(struct net_device *dev)
839 struct qeth_card *card = dev->ml_priv;
841 QETH_DBF_TEXT(TRACE, 4, "qethstop");
842 netif_tx_disable(dev);
843 if (card->state == CARD_STATE_UP)
844 card->state = CARD_STATE_SOFTSETUP;
848 static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
850 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
852 INIT_LIST_HEAD(&card->vid_list);
853 INIT_LIST_HEAD(&card->mc_list);
854 card->options.layer2 = 1;
855 card->discipline.input_handler = (qdio_handler_t *)
856 qeth_l2_qdio_input_handler;
857 card->discipline.output_handler = (qdio_handler_t *)
858 qeth_qdio_output_handler;
859 card->discipline.recover = qeth_l2_recover;
863 static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
865 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
867 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
869 if (cgdev->state == CCWGROUP_ONLINE) {
870 card->use_hard_stop = 1;
871 qeth_l2_set_offline(cgdev);
875 unregister_netdev(card->dev);
879 qeth_l2_del_all_mc(card);
883 static int qeth_l2_ethtool_set_tso(struct net_device *dev, u32 data)
885 struct qeth_card *card = dev->ml_priv;
888 if (card->options.large_send == QETH_LARGE_SEND_NO) {
889 card->options.large_send = QETH_LARGE_SEND_EDDP;
890 dev->features |= NETIF_F_TSO;
893 dev->features &= ~NETIF_F_TSO;
894 card->options.large_send = QETH_LARGE_SEND_NO;
899 static struct ethtool_ops qeth_l2_ethtool_ops = {
900 .get_link = ethtool_op_get_link,
901 .get_tx_csum = ethtool_op_get_tx_csum,
902 .set_tx_csum = ethtool_op_set_tx_hw_csum,
903 .get_sg = ethtool_op_get_sg,
904 .set_sg = ethtool_op_set_sg,
905 .get_tso = ethtool_op_get_tso,
906 .set_tso = qeth_l2_ethtool_set_tso,
907 .get_strings = qeth_core_get_strings,
908 .get_ethtool_stats = qeth_core_get_ethtool_stats,
909 .get_stats_count = qeth_core_get_stats_count,
910 .get_drvinfo = qeth_core_get_drvinfo,
911 .get_settings = qeth_core_ethtool_get_settings,
914 static struct ethtool_ops qeth_l2_osn_ops = {
915 .get_strings = qeth_core_get_strings,
916 .get_ethtool_stats = qeth_core_get_ethtool_stats,
917 .get_stats_count = qeth_core_get_stats_count,
918 .get_drvinfo = qeth_core_get_drvinfo,
921 static int qeth_l2_setup_netdev(struct qeth_card *card)
923 switch (card->info.type) {
924 case QETH_CARD_TYPE_OSAE:
925 card->dev = alloc_etherdev(0);
927 case QETH_CARD_TYPE_IQD:
928 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
930 case QETH_CARD_TYPE_OSN:
931 card->dev = alloc_netdev(0, "osn%d", ether_setup);
932 card->dev->flags |= IFF_NOARP;
935 card->dev = alloc_etherdev(0);
941 card->dev->ml_priv = card;
942 card->dev->tx_timeout = &qeth_tx_timeout;
943 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
944 card->dev->open = qeth_l2_open;
945 card->dev->stop = qeth_l2_stop;
946 card->dev->hard_start_xmit = qeth_l2_hard_start_xmit;
947 card->dev->do_ioctl = qeth_l2_do_ioctl;
948 card->dev->get_stats = qeth_get_stats;
949 card->dev->change_mtu = qeth_change_mtu;
950 card->dev->set_multicast_list = qeth_l2_set_multicast_list;
951 card->dev->vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid;
952 card->dev->vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid;
953 card->dev->set_mac_address = qeth_l2_set_mac_address;
954 card->dev->mtu = card->info.initial_mtu;
955 if (card->info.type != QETH_CARD_TYPE_OSN)
956 SET_ETHTOOL_OPS(card->dev, &qeth_l2_ethtool_ops);
958 SET_ETHTOOL_OPS(card->dev, &qeth_l2_osn_ops);
959 card->dev->features |= NETIF_F_HW_VLAN_FILTER;
960 card->info.broadcast_capable = 1;
961 qeth_l2_request_initial_mac(card);
962 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
963 return register_netdev(card->dev);
966 static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
968 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
970 enum qeth_card_states recover_flag;
973 QETH_DBF_TEXT(SETUP, 2, "setonlin");
974 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
976 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
977 recover_flag = card->state;
978 rc = ccw_device_set_online(CARD_RDEV(card));
980 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
983 rc = ccw_device_set_online(CARD_WDEV(card));
985 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
988 rc = ccw_device_set_online(CARD_DDEV(card));
990 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
994 rc = qeth_core_hardsetup_card(card);
996 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
1000 if (!card->dev && qeth_l2_setup_netdev(card))
1003 if (card->info.type != QETH_CARD_TYPE_OSN)
1004 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
1006 card->state = CARD_STATE_HARDSETUP;
1007 qeth_print_status_message(card);
1010 QETH_DBF_TEXT(SETUP, 2, "softsetp");
1012 rc = qeth_send_startlan(card);
1014 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1016 dev_warn(&card->gdev->dev,
1017 "The LAN is offline\n");
1018 card->lan_online = 0;
1022 card->lan_online = 1;
1024 if (card->info.type != QETH_CARD_TYPE_OSN) {
1025 qeth_set_large_send(card, card->options.large_send);
1026 qeth_l2_process_vlans(card, 0);
1029 netif_tx_disable(card->dev);
1031 rc = qeth_init_qdio_queues(card);
1033 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
1036 card->state = CARD_STATE_SOFTSETUP;
1037 netif_carrier_on(card->dev);
1039 qeth_set_allowed_threads(card, 0xffffffff, 0);
1040 if (recover_flag == CARD_STATE_RECOVER) {
1041 if (recovery_mode &&
1042 card->info.type != QETH_CARD_TYPE_OSN) {
1043 qeth_l2_open(card->dev);
1046 dev_open(card->dev);
1049 /* this also sets saved unicast addresses */
1050 qeth_l2_set_multicast_list(card->dev);
1052 /* let user_space know that device is online */
1053 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
1056 card->use_hard_stop = 1;
1057 qeth_l2_stop_card(card, 0);
1058 ccw_device_set_offline(CARD_DDEV(card));
1059 ccw_device_set_offline(CARD_WDEV(card));
1060 ccw_device_set_offline(CARD_RDEV(card));
1061 if (recover_flag == CARD_STATE_RECOVER)
1062 card->state = CARD_STATE_RECOVER;
1064 card->state = CARD_STATE_DOWN;
1068 static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1070 return __qeth_l2_set_online(gdev, 0);
1073 static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1076 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1077 int rc = 0, rc2 = 0, rc3 = 0;
1078 enum qeth_card_states recover_flag;
1080 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1081 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
1083 if (card->dev && netif_carrier_ok(card->dev))
1084 netif_carrier_off(card->dev);
1085 recover_flag = card->state;
1086 qeth_l2_stop_card(card, recovery_mode);
1087 rc = ccw_device_set_offline(CARD_DDEV(card));
1088 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1089 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1091 rc = (rc2) ? rc2 : rc3;
1093 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1094 if (recover_flag == CARD_STATE_UP)
1095 card->state = CARD_STATE_RECOVER;
1096 /* let user_space know that device is offline */
1097 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
1101 static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1103 return __qeth_l2_set_offline(cgdev, 0);
1106 static int qeth_l2_recover(void *ptr)
1108 struct qeth_card *card;
1111 card = (struct qeth_card *) ptr;
1112 QETH_DBF_TEXT(TRACE, 2, "recover1");
1113 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
1114 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1116 QETH_DBF_TEXT(TRACE, 2, "recover2");
1117 dev_warn(&card->gdev->dev,
1118 "A recovery process has been started for the device\n");
1119 card->use_hard_stop = 1;
1120 __qeth_l2_set_offline(card->gdev, 1);
1121 rc = __qeth_l2_set_online(card->gdev, 1);
1122 /* don't run another scheduled recovery */
1123 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1124 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
1126 dev_info(&card->gdev->dev,
1127 "Device successfully recovered!\n");
1131 dev_close(card->dev);
1134 dev_warn(&card->gdev->dev, "The qeth device driver "
1135 "failed to recover an error on the device\n");
1140 static int __init qeth_l2_init(void)
1142 pr_info("register layer 2 discipline\n");
1146 static void __exit qeth_l2_exit(void)
1148 pr_info("unregister layer 2 discipline\n");
1151 static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1153 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1154 qeth_qdio_clear_card(card, 0);
1155 qeth_clear_qdio_buffers(card);
1158 struct ccwgroup_driver qeth_l2_ccwgroup_driver = {
1159 .probe = qeth_l2_probe_device,
1160 .remove = qeth_l2_remove_device,
1161 .set_online = qeth_l2_set_online,
1162 .set_offline = qeth_l2_set_offline,
1163 .shutdown = qeth_l2_shutdown,
1165 EXPORT_SYMBOL_GPL(qeth_l2_ccwgroup_driver);
1167 static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1168 struct qeth_cmd_buffer *iob)
1170 unsigned long flags;
1173 QETH_DBF_TEXT(TRACE, 5, "osndctrd");
1175 wait_event(card->wait_q,
1176 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1177 qeth_prepare_control_data(card, len, iob);
1178 QETH_DBF_TEXT(TRACE, 6, "osnoirqp");
1179 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1180 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1181 (addr_t) iob, 0, 0);
1182 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1184 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
1185 "ccw_device_start rc = %i\n", rc);
1186 QETH_DBF_TEXT_(TRACE, 2, " err%d", rc);
1187 qeth_release_buffer(iob->channel, iob);
1188 atomic_set(&card->write.irq_pending, 0);
1189 wake_up(&card->wait_q);
1194 static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1195 struct qeth_cmd_buffer *iob, int data_len)
1199 QETH_DBF_TEXT(TRACE, 4, "osndipa");
1201 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1202 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1204 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1205 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1206 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1207 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1208 return qeth_osn_send_control_data(card, s1, iob);
1211 int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1213 struct qeth_cmd_buffer *iob;
1214 struct qeth_card *card;
1217 QETH_DBF_TEXT(TRACE, 2, "osnsdmc");
1220 card = dev->ml_priv;
1223 if ((card->state != CARD_STATE_UP) &&
1224 (card->state != CARD_STATE_SOFTSETUP))
1226 iob = qeth_wait_for_buffer(&card->write);
1227 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1228 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1231 EXPORT_SYMBOL(qeth_osn_assist);
1233 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1234 int (*assist_cb)(struct net_device *, void *),
1235 int (*data_cb)(struct sk_buff *))
1237 struct qeth_card *card;
1239 QETH_DBF_TEXT(TRACE, 2, "osnreg");
1240 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1243 card = (*dev)->ml_priv;
1246 if ((assist_cb == NULL) || (data_cb == NULL))
1248 card->osn_info.assist_cb = assist_cb;
1249 card->osn_info.data_cb = data_cb;
1252 EXPORT_SYMBOL(qeth_osn_register);
1254 void qeth_osn_deregister(struct net_device *dev)
1256 struct qeth_card *card;
1258 QETH_DBF_TEXT(TRACE, 2, "osndereg");
1261 card = dev->ml_priv;
1264 card->osn_info.assist_cb = NULL;
1265 card->osn_info.data_cb = NULL;
1268 EXPORT_SYMBOL(qeth_osn_deregister);
1270 module_init(qeth_l2_init);
1271 module_exit(qeth_l2_exit);
1272 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1273 MODULE_DESCRIPTION("qeth layer 2 discipline");
1274 MODULE_LICENSE("GPL");