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 static int qeth_l2_set_offline(struct ccwgroup_device *);
26 static int qeth_l2_stop(struct net_device *);
27 static int qeth_l2_send_delmac(struct qeth_card *, __u8 *);
28 static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *,
30 int (*reply_cb) (struct qeth_card *,
33 static void qeth_l2_set_multicast_list(struct net_device *);
34 static int qeth_l2_recover(void *);
36 static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38 struct qeth_card *card = dev->ml_priv;
39 struct mii_ioctl_data *mii_data;
45 if ((card->state != CARD_STATE_UP) &&
46 (card->state != CARD_STATE_SOFTSETUP))
49 if (card->info.type == QETH_CARD_TYPE_OSN)
53 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
54 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
56 case SIOC_QETH_GET_CARD_TYPE:
57 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
63 mii_data = if_mii(rq);
67 mii_data = if_mii(rq);
68 if (mii_data->phy_id != 0)
71 mii_data->val_out = qeth_mdio_read(dev,
72 mii_data->phy_id, mii_data->reg_num);
78 QETH_DBF_TEXT_(TRACE, 2, "ioce%d", rc);
82 static int qeth_l2_verify_dev(struct net_device *dev)
84 struct qeth_card *card;
88 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
89 list_for_each_entry(card, &qeth_core_card_list.list, list) {
90 if (card->dev == dev) {
95 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
100 static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
102 struct qeth_card *card;
103 struct net_device *ndev;
106 struct ccw_dev_id read_devid;
109 memcpy(&temp_dev_no, read_dev_no, 2);
110 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
111 list_for_each_entry(card, &qeth_core_card_list.list, list) {
112 ccw_device_get_id(CARD_RDEV(card), &read_devid);
113 if (read_devid.devno == temp_dev_no) {
118 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
122 static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card,
123 struct qeth_reply *reply,
126 struct qeth_ipa_cmd *cmd;
129 QETH_DBF_TEXT(TRACE, 2, "L2Sgmacb");
130 cmd = (struct qeth_ipa_cmd *) data;
131 mac = &cmd->data.setdelmac.mac[0];
132 /* MAC already registered, needed in couple/uncouple case */
133 if (cmd->hdr.return_code == 0x2005) {
134 QETH_DBF_MESSAGE(2, "Group MAC %02x:%02x:%02x:%02x:%02x:%02x "
135 "already existing on %s \n",
136 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
137 QETH_CARD_IFNAME(card));
138 cmd->hdr.return_code = 0;
140 if (cmd->hdr.return_code)
141 QETH_DBF_MESSAGE(2, "Could not set group MAC "
142 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
143 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
144 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
148 static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
150 QETH_DBF_TEXT(TRACE, 2, "L2Sgmac");
151 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
152 qeth_l2_send_setgroupmac_cb);
155 static int qeth_l2_send_delgroupmac_cb(struct qeth_card *card,
156 struct qeth_reply *reply,
159 struct qeth_ipa_cmd *cmd;
162 QETH_DBF_TEXT(TRACE, 2, "L2Dgmacb");
163 cmd = (struct qeth_ipa_cmd *) data;
164 mac = &cmd->data.setdelmac.mac[0];
165 if (cmd->hdr.return_code)
166 QETH_DBF_MESSAGE(2, "Could not delete group MAC "
167 "%02x:%02x:%02x:%02x:%02x:%02x on %s: %x\n",
168 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
169 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
173 static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
175 QETH_DBF_TEXT(TRACE, 2, "L2Dgmac");
176 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
177 qeth_l2_send_delgroupmac_cb);
180 static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac, int vmac)
182 struct qeth_mc_mac *mc;
185 mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC);
190 memcpy(mc->mc_addr, mac, OSA_ADDR_LEN);
191 mc->mc_addrlen = OSA_ADDR_LEN;
195 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
198 rc = qeth_l2_send_setgroupmac(card, mac);
202 list_add_tail(&mc->list, &card->mc_list);
207 static void qeth_l2_del_all_mc(struct qeth_card *card)
209 struct qeth_mc_mac *mc, *tmp;
211 spin_lock_bh(&card->mclock);
212 list_for_each_entry_safe(mc, tmp, &card->mc_list, list) {
214 qeth_l2_send_setdelmac(card, mc->mc_addr,
215 IPA_CMD_DELVMAC, NULL);
217 qeth_l2_send_delgroupmac(card, mc->mc_addr);
221 spin_unlock_bh(&card->mclock);
224 static void qeth_l2_get_packet_type(struct qeth_card *card,
225 struct qeth_hdr *hdr, struct sk_buff *skb)
229 if (!memcmp(skb->data + QETH_HEADER_SIZE,
230 skb->dev->broadcast, 6)) {
232 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
235 hdr_mac = *((__u16 *)skb->data);
237 switch (card->info.link_type) {
238 case QETH_LINK_TYPE_HSTR:
239 case QETH_LINK_TYPE_LANE_TR:
240 if ((hdr_mac == QETH_TR_MAC_NC) ||
241 (hdr_mac == QETH_TR_MAC_C))
242 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
244 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
246 /* eth or so multicast? */
248 if ((hdr_mac == QETH_ETH_MAC_V4) ||
249 (hdr_mac == QETH_ETH_MAC_V6))
250 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
252 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
256 static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
257 struct sk_buff *skb, int ipv, int cast_type)
259 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
261 memset(hdr, 0, sizeof(struct qeth_hdr));
262 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
264 /* set byte byte 3 to casting flags */
265 if (cast_type == RTN_MULTICAST)
266 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
267 else if (cast_type == RTN_BROADCAST)
268 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
270 qeth_l2_get_packet_type(card, hdr, skb);
272 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
273 /* VSWITCH relies on the VLAN
274 * information to be present in
276 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
277 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
278 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
282 static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
283 struct qeth_reply *reply, unsigned long data)
285 struct qeth_ipa_cmd *cmd;
287 QETH_DBF_TEXT(TRACE, 2, "L2sdvcb");
288 cmd = (struct qeth_ipa_cmd *) data;
289 if (cmd->hdr.return_code) {
290 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
291 "Continuing\n", cmd->data.setdelvlan.vlan_id,
292 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
293 QETH_DBF_TEXT_(TRACE, 2, "L2VL%4x", cmd->hdr.command);
294 QETH_DBF_TEXT_(TRACE, 2, "L2%s", CARD_BUS_ID(card));
295 QETH_DBF_TEXT_(TRACE, 2, "err%d", cmd->hdr.return_code);
300 static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
301 enum qeth_ipa_cmds ipacmd)
303 struct qeth_ipa_cmd *cmd;
304 struct qeth_cmd_buffer *iob;
306 QETH_DBF_TEXT_(TRACE, 4, "L2sdv%x", ipacmd);
307 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
308 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
309 cmd->data.setdelvlan.vlan_id = i;
310 return qeth_send_ipa_cmd(card, iob,
311 qeth_l2_send_setdelvlan_cb, NULL);
314 static void qeth_l2_process_vlans(struct qeth_card *card, int clear)
316 struct qeth_vlan_vid *id;
317 QETH_DBF_TEXT(TRACE, 3, "L2prcvln");
318 spin_lock_bh(&card->vlanlock);
319 list_for_each_entry(id, &card->vid_list, list) {
321 qeth_l2_send_setdelvlan(card, id->vid,
324 qeth_l2_send_setdelvlan(card, id->vid,
327 spin_unlock_bh(&card->vlanlock);
330 static void qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
332 struct qeth_card *card = dev->ml_priv;
333 struct qeth_vlan_vid *id;
335 QETH_DBF_TEXT_(TRACE, 4, "aid:%d", vid);
336 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
339 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
340 spin_lock_bh(&card->vlanlock);
341 list_add_tail(&id->list, &card->vid_list);
342 spin_unlock_bh(&card->vlanlock);
346 static void qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
348 struct qeth_vlan_vid *id, *tmpid = NULL;
349 struct qeth_card *card = dev->ml_priv;
351 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
352 spin_lock_bh(&card->vlanlock);
353 list_for_each_entry(id, &card->vid_list, list) {
354 if (id->vid == vid) {
360 spin_unlock_bh(&card->vlanlock);
362 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
365 qeth_l2_set_multicast_list(card->dev);
368 static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
372 QETH_DBF_TEXT(SETUP , 2, "stopcard");
373 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
375 qeth_set_allowed_threads(card, 0, 1);
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 if (!card->use_hard_stop)
397 qeth_l2_del_all_mc(card);
398 qeth_clear_ipacmd_list(card);
399 card->state = CARD_STATE_HARDSETUP;
401 if (card->state == CARD_STATE_HARDSETUP) {
402 qeth_qdio_clear_card(card, 0);
403 qeth_clear_qdio_buffers(card);
404 qeth_clear_working_pool_list(card);
405 card->state = CARD_STATE_DOWN;
407 if (card->state == CARD_STATE_DOWN) {
408 qeth_clear_cmd_buffers(&card->read);
409 qeth_clear_cmd_buffers(&card->write);
411 card->use_hard_stop = 0;
415 static void qeth_l2_process_inbound_buffer(struct qeth_card *card,
416 struct qeth_qdio_buffer *buf, int index)
418 struct qdio_buffer_element *element;
420 struct qeth_hdr *hdr;
424 /* get first element of current buffer */
425 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
427 if (card->options.performance_stats)
428 card->perf_stats.bufs_rec++;
429 while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element,
431 skb->dev = card->dev;
433 if (!(card->dev->flags & IFF_UP)) {
434 dev_kfree_skb_any(skb);
438 switch (hdr->hdr.l2.id) {
439 case QETH_HEADER_TYPE_LAYER2:
440 skb->pkt_type = PACKET_HOST;
441 skb->protocol = eth_type_trans(skb, skb->dev);
442 if (card->options.checksum_type == NO_CHECKSUMMING)
443 skb->ip_summed = CHECKSUM_UNNECESSARY;
445 skb->ip_summed = CHECKSUM_NONE;
446 if (skb->protocol == htons(ETH_P_802_2))
447 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
451 case QETH_HEADER_TYPE_OSN:
452 if (card->info.type == QETH_CARD_TYPE_OSN) {
453 skb_push(skb, sizeof(struct qeth_hdr));
454 skb_copy_to_linear_data(skb, hdr,
455 sizeof(struct qeth_hdr));
457 card->osn_info.data_cb(skb);
462 dev_kfree_skb_any(skb);
463 QETH_DBF_TEXT(TRACE, 3, "inbunkno");
464 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
467 card->dev->last_rx = jiffies;
468 card->stats.rx_packets++;
469 card->stats.rx_bytes += len;
473 static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
474 enum qeth_ipa_cmds ipacmd,
475 int (*reply_cb) (struct qeth_card *,
479 struct qeth_ipa_cmd *cmd;
480 struct qeth_cmd_buffer *iob;
482 QETH_DBF_TEXT(TRACE, 2, "L2sdmac");
483 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
484 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
485 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
486 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
487 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
490 static int qeth_l2_send_setmac_cb(struct qeth_card *card,
491 struct qeth_reply *reply,
494 struct qeth_ipa_cmd *cmd;
496 QETH_DBF_TEXT(TRACE, 2, "L2Smaccb");
497 cmd = (struct qeth_ipa_cmd *) data;
498 if (cmd->hdr.return_code) {
499 QETH_DBF_TEXT_(TRACE, 2, "L2er%x", cmd->hdr.return_code);
500 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
501 cmd->hdr.return_code = -EIO;
503 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
504 memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac,
506 PRINT_INFO("MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x "
507 "successfully registered on device %s\n",
508 card->dev->dev_addr[0], card->dev->dev_addr[1],
509 card->dev->dev_addr[2], card->dev->dev_addr[3],
510 card->dev->dev_addr[4], card->dev->dev_addr[5],
516 static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
518 QETH_DBF_TEXT(TRACE, 2, "L2Setmac");
519 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
520 qeth_l2_send_setmac_cb);
523 static int qeth_l2_send_delmac_cb(struct qeth_card *card,
524 struct qeth_reply *reply,
527 struct qeth_ipa_cmd *cmd;
529 QETH_DBF_TEXT(TRACE, 2, "L2Dmaccb");
530 cmd = (struct qeth_ipa_cmd *) data;
531 if (cmd->hdr.return_code) {
532 QETH_DBF_TEXT_(TRACE, 2, "err%d", cmd->hdr.return_code);
533 cmd->hdr.return_code = -EIO;
536 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
541 static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
543 QETH_DBF_TEXT(TRACE, 2, "L2Delmac");
544 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
546 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
547 qeth_l2_send_delmac_cb);
550 static int qeth_l2_request_initial_mac(struct qeth_card *card)
553 char vendor_pre[] = {0x02, 0x00, 0x00};
555 QETH_DBF_TEXT(SETUP, 2, "doL2init");
556 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
558 rc = qeth_query_setadapterparms(card);
560 QETH_DBF_MESSAGE(2, "could not query adapter parameters on "
561 "device %s: x%x\n", CARD_BUS_ID(card), rc);
564 if ((card->info.type == QETH_CARD_TYPE_IQD) ||
565 (card->info.guestlan)) {
566 rc = qeth_setadpparms_change_macaddr(card);
568 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
569 "device %s: x%x\n", CARD_BUS_ID(card), rc);
570 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
573 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
575 random_ether_addr(card->dev->dev_addr);
576 memcpy(card->dev->dev_addr, vendor_pre, 3);
581 static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
583 struct sockaddr *addr = p;
584 struct qeth_card *card = dev->ml_priv;
587 QETH_DBF_TEXT(TRACE, 3, "setmac");
589 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
590 QETH_DBF_TEXT(TRACE, 3, "setmcINV");
594 if (card->info.type == QETH_CARD_TYPE_OSN) {
595 QETH_DBF_TEXT(TRACE, 3, "setmcOSN");
598 QETH_DBF_TEXT_(TRACE, 3, "%s", CARD_BUS_ID(card));
599 QETH_DBF_HEX(TRACE, 3, addr->sa_data, OSA_ADDR_LEN);
600 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
602 rc = qeth_l2_send_setmac(card, addr->sa_data);
606 static void qeth_l2_set_multicast_list(struct net_device *dev)
608 struct qeth_card *card = dev->ml_priv;
609 struct dev_addr_list *dm;
611 if (card->info.type == QETH_CARD_TYPE_OSN)
614 QETH_DBF_TEXT(TRACE, 3, "setmulti");
615 qeth_l2_del_all_mc(card);
616 spin_lock_bh(&card->mclock);
617 for (dm = dev->mc_list; dm; dm = dm->next)
618 qeth_l2_add_mc(card, dm->da_addr, 0);
620 for (dm = dev->uc_list; dm; dm = dm->next)
621 qeth_l2_add_mc(card, dm->da_addr, 1);
623 spin_unlock_bh(&card->mclock);
624 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
626 qeth_setadp_promisc_mode(card);
629 static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
632 struct qeth_hdr *hdr = NULL;
634 struct qeth_card *card = dev->ml_priv;
635 struct sk_buff *new_skb = skb;
636 int ipv = qeth_get_ip_version(skb);
637 int cast_type = qeth_get_cast_type(card, skb);
638 struct qeth_qdio_out_q *queue = card->qdio.out_qs
639 [qeth_get_priority_queue(card, skb, ipv, cast_type)];
640 int tx_bytes = skb->len;
641 enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO;
642 struct qeth_eddp_context *ctx = NULL;
643 int data_offset = -1;
644 int elements_needed = 0;
647 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
648 card->stats.tx_carrier_errors++;
652 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
653 (skb->protocol == htons(ETH_P_IPV6)))
656 if (card->options.performance_stats) {
657 card->perf_stats.outbound_cnt++;
658 card->perf_stats.outbound_start_time = qeth_get_micros();
660 netif_stop_queue(dev);
663 large_send = QETH_LARGE_SEND_EDDP;
665 if (card->info.type == QETH_CARD_TYPE_OSN)
666 hdr = (struct qeth_hdr *)skb->data;
668 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
669 (skb_shinfo(skb)->nr_frags == 0)) {
671 data_offset = ETH_HLEN;
673 hdr = kmem_cache_alloc(qeth_core_header_cache,
678 skb_reset_mac_header(new_skb);
679 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
680 hdr->hdr.l2.pkt_length = new_skb->len;
681 memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
682 skb_mac_header(new_skb), ETH_HLEN);
684 /* create a clone with writeable headroom */
685 new_skb = skb_realloc_headroom(skb,
686 sizeof(struct qeth_hdr));
689 hdr = (struct qeth_hdr *)skb_push(new_skb,
690 sizeof(struct qeth_hdr));
691 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
692 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
696 if (large_send == QETH_LARGE_SEND_EDDP) {
697 ctx = qeth_eddp_create_context(card, new_skb, hdr,
698 skb->sk->sk_protocol);
700 QETH_DBF_MESSAGE(2, "could not create eddp context\n");
704 elements = qeth_get_elements_no(card, (void *)hdr, new_skb,
707 if (data_offset >= 0)
708 kmem_cache_free(qeth_core_header_cache, hdr);
713 if ((large_send == QETH_LARGE_SEND_NO) &&
714 (skb->ip_summed == CHECKSUM_PARTIAL))
715 qeth_tx_csum(new_skb);
717 if (card->info.type != QETH_CARD_TYPE_IQD)
718 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
721 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
722 elements, ctx, data_offset, hd_len);
724 card->stats.tx_packets++;
725 card->stats.tx_bytes += tx_bytes;
727 dev_kfree_skb_any(skb);
728 if (card->options.performance_stats) {
729 if (large_send != QETH_LARGE_SEND_NO) {
730 card->perf_stats.large_send_bytes += tx_bytes;
731 card->perf_stats.large_send_cnt++;
733 if (skb_shinfo(new_skb)->nr_frags > 0) {
734 card->perf_stats.sg_skbs_sent++;
735 /* nr_frags + skb->data */
736 card->perf_stats.sg_frags_sent +=
737 skb_shinfo(new_skb)->nr_frags + 1;
742 qeth_eddp_put_context(ctx);
743 dev_kfree_skb_any(new_skb);
747 qeth_eddp_put_context(ctx);
749 if (data_offset >= 0)
750 kmem_cache_free(qeth_core_header_cache, hdr);
754 dev_kfree_skb_any(new_skb);
755 return NETDEV_TX_BUSY;
760 netif_wake_queue(dev);
761 if (card->options.performance_stats)
762 card->perf_stats.outbound_time += qeth_get_micros() -
763 card->perf_stats.outbound_start_time;
767 card->stats.tx_dropped++;
768 card->stats.tx_errors++;
769 if ((new_skb != skb) && new_skb)
770 dev_kfree_skb_any(new_skb);
771 dev_kfree_skb_any(skb);
772 netif_wake_queue(dev);
776 static void qeth_l2_qdio_input_handler(struct ccw_device *ccwdev,
777 unsigned int qdio_err, unsigned int queue,
778 int first_element, int count, unsigned long card_ptr)
780 struct net_device *net_dev;
781 struct qeth_card *card;
782 struct qeth_qdio_buffer *buffer;
786 card = (struct qeth_card *) card_ptr;
788 if (card->options.performance_stats) {
789 card->perf_stats.inbound_cnt++;
790 card->perf_stats.inbound_start_time = qeth_get_micros();
792 if (qdio_err & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) {
793 QETH_DBF_TEXT(TRACE, 1, "qdinchk");
794 QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card));
795 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", first_element,
797 QETH_DBF_TEXT_(TRACE, 1, "%04X", queue);
798 qeth_schedule_recovery(card);
801 for (i = first_element; i < (first_element + count); ++i) {
802 index = i % QDIO_MAX_BUFFERS_PER_Q;
803 buffer = &card->qdio.in_q->bufs[index];
805 qeth_check_qdio_errors(buffer->buffer, qdio_err, "qinerr")))
806 qeth_l2_process_inbound_buffer(card, buffer, index);
807 /* clear buffer and give back to hardware */
808 qeth_put_buffer_pool_entry(card, buffer->pool_entry);
809 qeth_queue_input_buffer(card, index);
811 if (card->options.performance_stats)
812 card->perf_stats.inbound_time += qeth_get_micros() -
813 card->perf_stats.inbound_start_time;
816 static int qeth_l2_open(struct net_device *dev)
818 struct qeth_card *card = dev->ml_priv;
820 QETH_DBF_TEXT(TRACE, 4, "qethopen");
821 if (card->state != CARD_STATE_SOFTSETUP)
824 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
825 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
826 QETH_DBF_TEXT(TRACE, 4, "nomacadr");
829 card->data.state = CH_STATE_UP;
830 card->state = CARD_STATE_UP;
831 netif_start_queue(dev);
833 if (!card->lan_online && netif_carrier_ok(dev))
834 netif_carrier_off(dev);
839 static int qeth_l2_stop(struct net_device *dev)
841 struct qeth_card *card = dev->ml_priv;
843 QETH_DBF_TEXT(TRACE, 4, "qethstop");
844 netif_tx_disable(dev);
845 if (card->state == CARD_STATE_UP)
846 card->state = CARD_STATE_SOFTSETUP;
850 static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
852 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
854 INIT_LIST_HEAD(&card->vid_list);
855 INIT_LIST_HEAD(&card->mc_list);
856 card->options.layer2 = 1;
857 card->discipline.input_handler = (qdio_handler_t *)
858 qeth_l2_qdio_input_handler;
859 card->discipline.output_handler = (qdio_handler_t *)
860 qeth_qdio_output_handler;
861 card->discipline.recover = qeth_l2_recover;
865 static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
867 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
869 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
871 if (cgdev->state == CCWGROUP_ONLINE) {
872 card->use_hard_stop = 1;
873 qeth_l2_set_offline(cgdev);
877 unregister_netdev(card->dev);
881 qeth_l2_del_all_mc(card);
885 static int qeth_l2_ethtool_set_tso(struct net_device *dev, u32 data)
887 struct qeth_card *card = dev->ml_priv;
890 if (card->options.large_send == QETH_LARGE_SEND_NO) {
891 card->options.large_send = QETH_LARGE_SEND_EDDP;
892 dev->features |= NETIF_F_TSO;
895 dev->features &= ~NETIF_F_TSO;
896 card->options.large_send = QETH_LARGE_SEND_NO;
901 static struct ethtool_ops qeth_l2_ethtool_ops = {
902 .get_link = ethtool_op_get_link,
903 .get_tx_csum = ethtool_op_get_tx_csum,
904 .set_tx_csum = ethtool_op_set_tx_hw_csum,
905 .get_sg = ethtool_op_get_sg,
906 .set_sg = ethtool_op_set_sg,
907 .get_tso = ethtool_op_get_tso,
908 .set_tso = qeth_l2_ethtool_set_tso,
909 .get_strings = qeth_core_get_strings,
910 .get_ethtool_stats = qeth_core_get_ethtool_stats,
911 .get_stats_count = qeth_core_get_stats_count,
912 .get_drvinfo = qeth_core_get_drvinfo,
913 .get_settings = qeth_core_ethtool_get_settings,
916 static struct ethtool_ops qeth_l2_osn_ops = {
917 .get_strings = qeth_core_get_strings,
918 .get_ethtool_stats = qeth_core_get_ethtool_stats,
919 .get_stats_count = qeth_core_get_stats_count,
920 .get_drvinfo = qeth_core_get_drvinfo,
923 static int qeth_l2_setup_netdev(struct qeth_card *card)
925 switch (card->info.type) {
926 case QETH_CARD_TYPE_OSAE:
927 card->dev = alloc_etherdev(0);
929 case QETH_CARD_TYPE_IQD:
930 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
932 case QETH_CARD_TYPE_OSN:
933 card->dev = alloc_netdev(0, "osn%d", ether_setup);
934 card->dev->flags |= IFF_NOARP;
937 card->dev = alloc_etherdev(0);
943 card->dev->ml_priv = card;
944 card->dev->tx_timeout = &qeth_tx_timeout;
945 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
946 card->dev->open = qeth_l2_open;
947 card->dev->stop = qeth_l2_stop;
948 card->dev->hard_start_xmit = qeth_l2_hard_start_xmit;
949 card->dev->do_ioctl = qeth_l2_do_ioctl;
950 card->dev->get_stats = qeth_get_stats;
951 card->dev->change_mtu = qeth_change_mtu;
952 card->dev->set_multicast_list = qeth_l2_set_multicast_list;
953 card->dev->vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid;
954 card->dev->vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid;
955 card->dev->set_mac_address = qeth_l2_set_mac_address;
956 card->dev->mtu = card->info.initial_mtu;
957 if (card->info.type != QETH_CARD_TYPE_OSN)
958 SET_ETHTOOL_OPS(card->dev, &qeth_l2_ethtool_ops);
960 SET_ETHTOOL_OPS(card->dev, &qeth_l2_osn_ops);
961 card->dev->features |= NETIF_F_HW_VLAN_FILTER;
962 card->info.broadcast_capable = 1;
963 qeth_l2_request_initial_mac(card);
964 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
965 return register_netdev(card->dev);
968 static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
970 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
972 enum qeth_card_states recover_flag;
975 QETH_DBF_TEXT(SETUP, 2, "setonlin");
976 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
978 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
979 recover_flag = card->state;
980 rc = ccw_device_set_online(CARD_RDEV(card));
982 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
985 rc = ccw_device_set_online(CARD_WDEV(card));
987 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
990 rc = ccw_device_set_online(CARD_DDEV(card));
992 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
996 rc = qeth_core_hardsetup_card(card);
998 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
1002 if (!card->dev && qeth_l2_setup_netdev(card))
1005 if (card->info.type != QETH_CARD_TYPE_OSN)
1006 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
1008 card->state = CARD_STATE_HARDSETUP;
1009 qeth_print_status_message(card);
1012 QETH_DBF_TEXT(SETUP, 2, "softsetp");
1014 rc = qeth_send_startlan(card);
1016 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1018 PRINT_WARN("LAN on card %s if offline! "
1019 "Waiting for STARTLAN from card.\n",
1021 card->lan_online = 0;
1025 card->lan_online = 1;
1027 if (card->info.type != QETH_CARD_TYPE_OSN) {
1028 qeth_set_large_send(card, card->options.large_send);
1029 qeth_l2_process_vlans(card, 0);
1032 netif_tx_disable(card->dev);
1034 rc = qeth_init_qdio_queues(card);
1036 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
1039 card->state = CARD_STATE_SOFTSETUP;
1040 netif_carrier_on(card->dev);
1042 qeth_set_allowed_threads(card, 0xffffffff, 0);
1043 if (recover_flag == CARD_STATE_RECOVER) {
1044 if (recovery_mode &&
1045 card->info.type != QETH_CARD_TYPE_OSN) {
1046 qeth_l2_open(card->dev);
1049 dev_open(card->dev);
1052 /* this also sets saved unicast addresses */
1053 qeth_l2_set_multicast_list(card->dev);
1055 /* let user_space know that device is online */
1056 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
1059 card->use_hard_stop = 1;
1060 qeth_l2_stop_card(card, 0);
1061 ccw_device_set_offline(CARD_DDEV(card));
1062 ccw_device_set_offline(CARD_WDEV(card));
1063 ccw_device_set_offline(CARD_RDEV(card));
1064 if (recover_flag == CARD_STATE_RECOVER)
1065 card->state = CARD_STATE_RECOVER;
1067 card->state = CARD_STATE_DOWN;
1071 static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1073 return __qeth_l2_set_online(gdev, 0);
1076 static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1079 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1080 int rc = 0, rc2 = 0, rc3 = 0;
1081 enum qeth_card_states recover_flag;
1083 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1084 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
1086 if (card->dev && netif_carrier_ok(card->dev))
1087 netif_carrier_off(card->dev);
1088 recover_flag = card->state;
1089 qeth_l2_stop_card(card, recovery_mode);
1090 rc = ccw_device_set_offline(CARD_DDEV(card));
1091 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1092 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1094 rc = (rc2) ? rc2 : rc3;
1096 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1097 if (recover_flag == CARD_STATE_UP)
1098 card->state = CARD_STATE_RECOVER;
1099 /* let user_space know that device is offline */
1100 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
1104 static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1106 return __qeth_l2_set_offline(cgdev, 0);
1109 static int qeth_l2_recover(void *ptr)
1111 struct qeth_card *card;
1114 card = (struct qeth_card *) ptr;
1115 QETH_DBF_TEXT(TRACE, 2, "recover1");
1116 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
1117 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1119 QETH_DBF_TEXT(TRACE, 2, "recover2");
1120 PRINT_WARN("Recovery of device %s started ...\n",
1122 card->use_hard_stop = 1;
1123 __qeth_l2_set_offline(card->gdev, 1);
1124 rc = __qeth_l2_set_online(card->gdev, 1);
1125 /* don't run another scheduled recovery */
1126 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1127 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
1129 PRINT_INFO("Device %s successfully recovered!\n",
1133 dev_close(card->dev);
1135 PRINT_INFO("Device %s could not be recovered!\n",
1141 static int __init qeth_l2_init(void)
1143 PRINT_INFO("register layer 2 discipline\n");
1147 static void __exit qeth_l2_exit(void)
1149 PRINT_INFO("unregister layer 2 discipline\n");
1152 static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1154 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1155 qeth_qdio_clear_card(card, 0);
1156 qeth_clear_qdio_buffers(card);
1159 struct ccwgroup_driver qeth_l2_ccwgroup_driver = {
1160 .probe = qeth_l2_probe_device,
1161 .remove = qeth_l2_remove_device,
1162 .set_online = qeth_l2_set_online,
1163 .set_offline = qeth_l2_set_offline,
1164 .shutdown = qeth_l2_shutdown,
1166 EXPORT_SYMBOL_GPL(qeth_l2_ccwgroup_driver);
1168 static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1169 struct qeth_cmd_buffer *iob)
1171 unsigned long flags;
1174 QETH_DBF_TEXT(TRACE, 5, "osndctrd");
1176 wait_event(card->wait_q,
1177 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1178 qeth_prepare_control_data(card, len, iob);
1179 QETH_DBF_TEXT(TRACE, 6, "osnoirqp");
1180 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1181 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1182 (addr_t) iob, 0, 0);
1183 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1185 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
1186 "ccw_device_start rc = %i\n", rc);
1187 QETH_DBF_TEXT_(TRACE, 2, " err%d", rc);
1188 qeth_release_buffer(iob->channel, iob);
1189 atomic_set(&card->write.irq_pending, 0);
1190 wake_up(&card->wait_q);
1195 static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1196 struct qeth_cmd_buffer *iob, int data_len)
1200 QETH_DBF_TEXT(TRACE, 4, "osndipa");
1202 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1203 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1205 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1206 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1207 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1208 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1209 return qeth_osn_send_control_data(card, s1, iob);
1212 int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1214 struct qeth_cmd_buffer *iob;
1215 struct qeth_card *card;
1218 QETH_DBF_TEXT(TRACE, 2, "osnsdmc");
1221 card = dev->ml_priv;
1224 if ((card->state != CARD_STATE_UP) &&
1225 (card->state != CARD_STATE_SOFTSETUP))
1227 iob = qeth_wait_for_buffer(&card->write);
1228 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1229 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1232 EXPORT_SYMBOL(qeth_osn_assist);
1234 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1235 int (*assist_cb)(struct net_device *, void *),
1236 int (*data_cb)(struct sk_buff *))
1238 struct qeth_card *card;
1240 QETH_DBF_TEXT(TRACE, 2, "osnreg");
1241 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1244 card = (*dev)->ml_priv;
1247 if ((assist_cb == NULL) || (data_cb == NULL))
1249 card->osn_info.assist_cb = assist_cb;
1250 card->osn_info.data_cb = data_cb;
1253 EXPORT_SYMBOL(qeth_osn_register);
1255 void qeth_osn_deregister(struct net_device *dev)
1257 struct qeth_card *card;
1259 QETH_DBF_TEXT(TRACE, 2, "osndereg");
1262 card = dev->ml_priv;
1265 card->osn_info.assist_cb = NULL;
1266 card->osn_info.data_cb = NULL;
1269 EXPORT_SYMBOL(qeth_osn_deregister);
1271 module_init(qeth_l2_init);
1272 module_exit(qeth_l2_exit);
1273 MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1274 MODULE_DESCRIPTION("qeth layer 2 discipline");
1275 MODULE_LICENSE("GPL");