blob: 3921d1631a78928067fc9b5e90f0f1e676036ee0 [file] [log] [blame]
Frank Blaschka4a71df52008-02-15 09:19:42 +01001/*
2 * drivers/s390/net/qeth_l2_main.c
3 *
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>
9 */
10
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>
18#include <linux/ip.h>
19
20#include <asm/s390_rdev.h>
21
22#include "qeth_core.h"
23#include "qeth_core_offl.h"
24
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +020025#define QETH_DBF_TXT_BUF qeth_l2_dbf_txt_buf
Frank Blaschka4a71df52008-02-15 09:19:42 +010026static DEFINE_PER_CPU(char[256], qeth_l2_dbf_txt_buf);
27
28static int qeth_l2_set_offline(struct ccwgroup_device *);
29static int qeth_l2_stop(struct net_device *);
30static int qeth_l2_send_delmac(struct qeth_card *, __u8 *);
31static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *,
32 enum qeth_ipa_cmds,
33 int (*reply_cb) (struct qeth_card *,
34 struct qeth_reply*,
35 unsigned long));
36static void qeth_l2_set_multicast_list(struct net_device *);
37static int qeth_l2_recover(void *);
38
39static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
40{
41 struct qeth_card *card = netdev_priv(dev);
42 struct mii_ioctl_data *mii_data;
43 int rc = 0;
44
45 if (!card)
46 return -ENODEV;
47
48 if ((card->state != CARD_STATE_UP) &&
49 (card->state != CARD_STATE_SOFTSETUP))
50 return -ENODEV;
51
52 if (card->info.type == QETH_CARD_TYPE_OSN)
53 return -EPERM;
54
55 switch (cmd) {
56 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
57 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
58 break;
59 case SIOC_QETH_GET_CARD_TYPE:
60 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
61 !card->info.guestlan)
62 return 1;
63 return 0;
64 break;
65 case SIOCGMIIPHY:
66 mii_data = if_mii(rq);
67 mii_data->phy_id = 0;
68 break;
69 case SIOCGMIIREG:
70 mii_data = if_mii(rq);
71 if (mii_data->phy_id != 0)
72 rc = -EINVAL;
73 else
74 mii_data->val_out = qeth_mdio_read(dev,
75 mii_data->phy_id, mii_data->reg_num);
76 break;
77 default:
78 rc = -EOPNOTSUPP;
79 }
80 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +020081 QETH_DBF_TEXT_(TRACE, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +010082 return rc;
83}
84
85static int qeth_l2_verify_dev(struct net_device *dev)
86{
87 struct qeth_card *card;
88 unsigned long flags;
89 int rc = 0;
90
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) {
94 rc = QETH_REAL_CARD;
95 break;
96 }
97 }
98 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
99
100 return rc;
101}
102
103static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
104{
105 struct qeth_card *card;
106 struct net_device *ndev;
107 unsigned char *readno;
108 __u16 temp_dev_no, card_dev_no;
109 char *endp;
110 unsigned long flags;
111
112 ndev = NULL;
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) {
120 ndev = card->dev;
121 break;
122 }
123 }
124 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
125 return ndev;
126}
127
128static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card,
129 struct qeth_reply *reply,
130 unsigned long data)
131{
132 struct qeth_ipa_cmd *cmd;
133 __u8 *mac;
134
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200135 QETH_DBF_TEXT(TRACE, 2, "L2Sgmacb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100136 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;
145 }
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);
151 return 0;
152}
153
154static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
155{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200156 QETH_DBF_TEXT(TRACE, 2, "L2Sgmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100157 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
158 qeth_l2_send_setgroupmac_cb);
159}
160
161static int qeth_l2_send_delgroupmac_cb(struct qeth_card *card,
162 struct qeth_reply *reply,
163 unsigned long data)
164{
165 struct qeth_ipa_cmd *cmd;
166 __u8 *mac;
167
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200168 QETH_DBF_TEXT(TRACE, 2, "L2Dgmacb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100169 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);
176 return 0;
177}
178
179static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
180{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200181 QETH_DBF_TEXT(TRACE, 2, "L2Dgmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100182 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
183 qeth_l2_send_delgroupmac_cb);
184}
185
186static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac)
187{
188 struct qeth_mc_mac *mc;
189
190 mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC);
191
192 if (!mc) {
193 PRINT_ERR("no mem vor mc mac address\n");
194 return;
195 }
196
197 memcpy(mc->mc_addr, mac, OSA_ADDR_LEN);
198 mc->mc_addrlen = OSA_ADDR_LEN;
199
200 if (!qeth_l2_send_setgroupmac(card, mac))
201 list_add_tail(&mc->list, &card->mc_list);
202 else
203 kfree(mc);
204}
205
206static void qeth_l2_del_all_mc(struct qeth_card *card)
207{
208 struct qeth_mc_mac *mc, *tmp;
209
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);
213 list_del(&mc->list);
214 kfree(mc);
215 }
216 spin_unlock_bh(&card->mclock);
217}
218
219static void qeth_l2_get_packet_type(struct qeth_card *card,
220 struct qeth_hdr *hdr, struct sk_buff *skb)
221{
222 __u16 hdr_mac;
223
224 if (!memcmp(skb->data + QETH_HEADER_SIZE,
225 skb->dev->broadcast, 6)) {
226 /* broadcast? */
227 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
228 return;
229 }
230 hdr_mac = *((__u16 *)skb->data);
231 /* tr multicast? */
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;
238 else
239 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
240 break;
241 /* eth or so multicast? */
242 default:
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;
246 else
247 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
248 }
249}
250
251static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
252 struct sk_buff *skb, int ipv, int cast_type)
253{
254 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)((skb->data) +
255 QETH_HEADER_SIZE);
256
257 memset(hdr, 0, sizeof(struct qeth_hdr));
258 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
259
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;
265 else
266 qeth_l2_get_packet_type(card, hdr, skb);
267
268 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
269 /* VSWITCH relies on the VLAN
270 * information to be present in
271 * the QDIO header */
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);
275 }
276}
277
278static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
279 struct qeth_reply *reply, unsigned long data)
280{
281 struct qeth_ipa_cmd *cmd;
282
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200283 QETH_DBF_TEXT(TRACE, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100284 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);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200289 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);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100292 }
293 return 0;
294}
295
296static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
297 enum qeth_ipa_cmds ipacmd)
298{
299 struct qeth_ipa_cmd *cmd;
300 struct qeth_cmd_buffer *iob;
301
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200302 QETH_DBF_TEXT_(TRACE, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100303 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);
308}
309
310static void qeth_l2_process_vlans(struct qeth_card *card, int clear)
311{
312 struct qeth_vlan_vid *id;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200313 QETH_DBF_TEXT(TRACE, 3, "L2prcvln");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100314 spin_lock_bh(&card->vlanlock);
315 list_for_each_entry(id, &card->vid_list, list) {
316 if (clear)
317 qeth_l2_send_setdelvlan(card, id->vid,
318 IPA_CMD_DELVLAN);
319 else
320 qeth_l2_send_setdelvlan(card, id->vid,
321 IPA_CMD_SETVLAN);
322 }
323 spin_unlock_bh(&card->vlanlock);
324}
325
326static void qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
327{
328 struct qeth_card *card = netdev_priv(dev);
329 struct qeth_vlan_vid *id;
330
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200331 QETH_DBF_TEXT_(TRACE, 4, "aid:%d", vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100332 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
333 if (id) {
334 id->vid = vid;
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);
339 } else {
340 PRINT_ERR("no memory for vid\n");
341 }
342}
343
344static void qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
345{
346 struct qeth_vlan_vid *id, *tmpid = NULL;
347 struct qeth_card *card = netdev_priv(dev);
348
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200349 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100350 spin_lock_bh(&card->vlanlock);
351 list_for_each_entry(id, &card->vid_list, list) {
352 if (id->vid == vid) {
353 list_del(&id->list);
354 tmpid = id;
355 break;
356 }
357 }
358 spin_unlock_bh(&card->vlanlock);
359 if (tmpid) {
360 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
361 kfree(tmpid);
362 }
363 qeth_l2_set_multicast_list(card->dev);
364}
365
366static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
367{
368 int rc = 0;
369
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200370 QETH_DBF_TEXT(SETUP , 2, "stopcard");
371 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100372
373 qeth_set_allowed_threads(card, 0, 1);
374 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD))
375 return -ERESTARTSYS;
376 if (card->read.state == CH_STATE_UP &&
377 card->write.state == CH_STATE_UP &&
378 (card->state == CARD_STATE_UP)) {
379 if (recovery_mode &&
380 card->info.type != QETH_CARD_TYPE_OSN) {
381 qeth_l2_stop(card->dev);
382 } else {
383 rtnl_lock();
384 dev_close(card->dev);
385 rtnl_unlock();
386 }
387 if (!card->use_hard_stop) {
388 __u8 *mac = &card->dev->dev_addr[0];
389 rc = qeth_l2_send_delmac(card, mac);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200390 QETH_DBF_TEXT_(SETUP, 2, "Lerr%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100391 }
392 card->state = CARD_STATE_SOFTSETUP;
393 }
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;
399 }
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;
405 }
406 if (card->state == CARD_STATE_DOWN) {
407 qeth_clear_cmd_buffers(&card->read);
408 qeth_clear_cmd_buffers(&card->write);
409 }
410 card->use_hard_stop = 0;
411 return rc;
412}
413
414static void qeth_l2_process_inbound_buffer(struct qeth_card *card,
415 struct qeth_qdio_buffer *buf, int index)
416{
417 struct qdio_buffer_element *element;
418 struct sk_buff *skb;
419 struct qeth_hdr *hdr;
420 int offset;
421 unsigned int len;
422
423 /* get first element of current buffer */
424 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
425 offset = 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,
429 &offset, &hdr))) {
430 skb->dev = card->dev;
431 /* is device UP ? */
432 if (!(card->dev->flags & IFF_UP)) {
433 dev_kfree_skb_any(skb);
434 continue;
435 }
436
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;
443 else
444 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun12883722008-04-01 10:26:56 +0200445 if (skb->protocol == htons(ETH_P_802_2))
446 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100447 len = skb->len;
448 netif_rx(skb);
449 break;
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));
454 len = skb->len;
455 card->osn_info.data_cb(skb);
456 break;
457 default:
458 dev_kfree_skb_any(skb);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200459 QETH_DBF_TEXT(TRACE, 3, "inbunkno");
460 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100461 continue;
462 }
463 card->dev->last_rx = jiffies;
464 card->stats.rx_packets++;
465 card->stats.rx_bytes += len;
466 }
467}
468
469static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
470 enum qeth_ipa_cmds ipacmd,
471 int (*reply_cb) (struct qeth_card *,
472 struct qeth_reply*,
473 unsigned long))
474{
475 struct qeth_ipa_cmd *cmd;
476 struct qeth_cmd_buffer *iob;
477
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200478 QETH_DBF_TEXT(TRACE, 2, "L2sdmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100479 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);
484}
485
486static int qeth_l2_send_setmac_cb(struct qeth_card *card,
487 struct qeth_reply *reply,
488 unsigned long data)
489{
490 struct qeth_ipa_cmd *cmd;
491
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200492 QETH_DBF_TEXT(TRACE, 2, "L2Smaccb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100493 cmd = (struct qeth_ipa_cmd *) data;
494 if (cmd->hdr.return_code) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200495 QETH_DBF_TEXT_(TRACE, 2, "L2er%x", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100496 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
497 cmd->hdr.return_code = -EIO;
498 } else {
499 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
500 memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac,
501 OSA_ADDR_LEN);
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],
507 card->dev->name);
508 }
509 return 0;
510}
511
512static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
513{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200514 QETH_DBF_TEXT(TRACE, 2, "L2Setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100515 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
516 qeth_l2_send_setmac_cb);
517}
518
519static int qeth_l2_send_delmac_cb(struct qeth_card *card,
520 struct qeth_reply *reply,
521 unsigned long data)
522{
523 struct qeth_ipa_cmd *cmd;
524
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200525 QETH_DBF_TEXT(TRACE, 2, "L2Dmaccb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100526 cmd = (struct qeth_ipa_cmd *) data;
527 if (cmd->hdr.return_code) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200528 QETH_DBF_TEXT_(TRACE, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100529 cmd->hdr.return_code = -EIO;
530 return 0;
531 }
532 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
533
534 return 0;
535}
536
537static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
538{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200539 QETH_DBF_TEXT(TRACE, 2, "L2Delmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100540 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
541 return 0;
542 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
543 qeth_l2_send_delmac_cb);
544}
545
546static int qeth_l2_request_initial_mac(struct qeth_card *card)
547{
548 int rc = 0;
549 char vendor_pre[] = {0x02, 0x00, 0x00};
550
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200551 QETH_DBF_TEXT(SETUP, 2, "doL2init");
552 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100553
554 rc = qeth_query_setadapterparms(card);
555 if (rc) {
556 PRINT_WARN("could not query adapter parameters on device %s: "
557 "x%x\n", CARD_BUS_ID(card), rc);
558 }
559
560 if (card->info.guestlan) {
561 rc = qeth_setadpparms_change_macaddr(card);
562 if (rc) {
563 PRINT_WARN("couldn't get MAC address on "
564 "device %s: x%x\n",
565 CARD_BUS_ID(card), rc);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200566 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100567 return rc;
568 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200569 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100570 } else {
571 random_ether_addr(card->dev->dev_addr);
572 memcpy(card->dev->dev_addr, vendor_pre, 3);
573 }
574 return 0;
575}
576
577static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
578{
579 struct sockaddr *addr = p;
580 struct qeth_card *card = netdev_priv(dev);
581 int rc = 0;
582
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200583 QETH_DBF_TEXT(TRACE, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100584
585 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200586 QETH_DBF_TEXT(TRACE, 3, "setmcINV");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100587 return -EOPNOTSUPP;
588 }
589
590 if (card->info.type == QETH_CARD_TYPE_OSN) {
591 PRINT_WARN("Setting MAC address on %s is not supported.\n",
592 dev->name);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200593 QETH_DBF_TEXT(TRACE, 3, "setmcOSN");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100594 return -EOPNOTSUPP;
595 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200596 QETH_DBF_TEXT_(TRACE, 3, "%s", CARD_BUS_ID(card));
597 QETH_DBF_HEX(TRACE, 3, addr->sa_data, OSA_ADDR_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100598 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
599 if (!rc)
600 rc = qeth_l2_send_setmac(card, addr->sa_data);
601 return rc;
602}
603
604static void qeth_l2_set_multicast_list(struct net_device *dev)
605{
606 struct qeth_card *card = netdev_priv(dev);
607 struct dev_mc_list *dm;
608
609 if (card->info.type == QETH_CARD_TYPE_OSN)
610 return ;
611
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200612 QETH_DBF_TEXT(TRACE, 3, "setmulti");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100613 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))
619 return;
620 qeth_setadp_promisc_mode(card);
621}
622
623static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
624{
625 int rc;
626 struct qeth_hdr *hdr = NULL;
627 int elements = 0;
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;
637
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200638 QETH_DBF_TEXT(TRACE, 6, "l2xmit");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100639
640 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
641 card->stats.tx_carrier_errors++;
642 goto tx_drop;
643 }
644
645 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
646 (skb->protocol == htons(ETH_P_IPV6)))
647 goto tx_drop;
648
649 if (card->options.performance_stats) {
650 card->perf_stats.outbound_cnt++;
651 card->perf_stats.outbound_start_time = qeth_get_micros();
652 }
653 netif_stop_queue(dev);
654
655 if (skb_is_gso(skb))
656 large_send = QETH_LARGE_SEND_EDDP;
657
658 if (card->info.type == QETH_CARD_TYPE_OSN)
659 hdr = (struct qeth_hdr *)skb->data;
660 else {
661 new_skb = qeth_prepare_skb(card, skb, &hdr);
662 if (!new_skb)
663 goto tx_drop;
664 qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
665 }
666
667 if (large_send == QETH_LARGE_SEND_EDDP) {
668 ctx = qeth_eddp_create_context(card, new_skb, hdr,
669 skb->sk->sk_protocol);
670 if (ctx == NULL) {
671 PRINT_WARN("could not create eddp context\n");
672 goto tx_drop;
673 }
674 } else {
675 elements = qeth_get_elements_no(card, (void *)hdr, new_skb, 0);
676 if (!elements)
677 goto tx_drop;
678 }
679
680 if ((large_send == QETH_LARGE_SEND_NO) &&
681 (skb->ip_summed == CHECKSUM_PARTIAL))
682 qeth_tx_csum(new_skb);
683
684 if (card->info.type != QETH_CARD_TYPE_IQD)
685 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
686 elements, ctx);
687 else
688 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
689 elements, ctx);
690 if (!rc) {
691 card->stats.tx_packets++;
692 card->stats.tx_bytes += tx_bytes;
693 if (new_skb != skb)
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++;
699 }
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;
705 }
706 }
707
708 if (ctx != NULL) {
709 qeth_eddp_put_context(ctx);
710 dev_kfree_skb_any(new_skb);
711 }
712 } else {
713 if (ctx != NULL)
714 qeth_eddp_put_context(ctx);
715
716 if (rc == -EBUSY) {
717 if (new_skb != skb)
718 dev_kfree_skb_any(new_skb);
719 return NETDEV_TX_BUSY;
720 } else
721 goto tx_drop;
722 }
723
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;
728 return rc;
729
730tx_drop:
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);
736 return NETDEV_TX_OK;
737}
738
739static 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)
743{
744 struct net_device *net_dev;
745 struct qeth_card *card;
746 struct qeth_qdio_buffer *buffer;
747 int index;
748 int i;
749
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200750 QETH_DBF_TEXT(TRACE, 6, "qdinput");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100751 card = (struct qeth_card *) card_ptr;
752 net_dev = card->dev;
753 if (card->options.performance_stats) {
754 card->perf_stats.inbound_cnt++;
755 card->perf_stats.inbound_start_time = qeth_get_micros();
756 }
757 if (status & QDIO_STATUS_LOOK_FOR_ERROR) {
758 if (status & QDIO_STATUS_ACTIVATE_CHECK_CONDITION) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200759 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,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100762 count);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200763 QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", queue, status);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100764 qeth_schedule_recovery(card);
765 return;
766 }
767 }
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);
778 }
779 if (card->options.performance_stats)
780 card->perf_stats.inbound_time += qeth_get_micros() -
781 card->perf_stats.inbound_start_time;
782}
783
784static int qeth_l2_open(struct net_device *dev)
785{
786 struct qeth_card *card = netdev_priv(dev);
787
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200788 QETH_DBF_TEXT(TRACE, 4, "qethopen");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100789 if (card->state != CARD_STATE_SOFTSETUP)
790 return -ENODEV;
791
792 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
793 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200794 QETH_DBF_TEXT(TRACE, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100795 return -EPERM;
796 }
797 card->data.state = CH_STATE_UP;
798 card->state = CARD_STATE_UP;
799 card->dev->flags |= IFF_UP;
800 netif_start_queue(dev);
801
802 if (!card->lan_online && netif_carrier_ok(dev))
803 netif_carrier_off(dev);
804 return 0;
805}
806
807
808static int qeth_l2_stop(struct net_device *dev)
809{
810 struct qeth_card *card = netdev_priv(dev);
811
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200812 QETH_DBF_TEXT(TRACE, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100813 netif_tx_disable(dev);
814 card->dev->flags &= ~IFF_UP;
815 if (card->state == CARD_STATE_UP)
816 card->state = CARD_STATE_SOFTSETUP;
817 return 0;
818}
819
820static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
821{
822 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
823
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;
832 return 0;
833}
834
835static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
836{
837 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
838
839 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
840
841 if (cgdev->state == CCWGROUP_ONLINE) {
842 card->use_hard_stop = 1;
843 qeth_l2_set_offline(cgdev);
844 }
845
846 if (card->dev) {
847 unregister_netdev(card->dev);
848 card->dev = NULL;
849 }
850
851 qeth_l2_del_all_mc(card);
852 return;
853}
854
855static 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,
867};
868
869static 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,
874};
875
876static int qeth_l2_setup_netdev(struct qeth_card *card)
877{
878 switch (card->info.type) {
879 case QETH_CARD_TYPE_OSAE:
880 card->dev = alloc_etherdev(0);
881 break;
882 case QETH_CARD_TYPE_IQD:
883 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
884 break;
885 case QETH_CARD_TYPE_OSN:
886 card->dev = alloc_netdev(0, "osn%d", ether_setup);
887 card->dev->flags |= IFF_NOARP;
888 break;
889 default:
890 card->dev = alloc_etherdev(0);
891 }
892
893 if (!card->dev)
894 return -ENODEV;
895
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);
912 else
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);
919}
920
921static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
922{
923 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
924 int rc = 0;
925 enum qeth_card_states recover_flag;
926
927 BUG_ON(!card);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200928 QETH_DBF_TEXT(SETUP, 2, "setonlin");
929 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100930
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",
934 CARD_BUS_ID(card));
935 return -ERESTARTSYS;
936 }
937
938 recover_flag = card->state;
939 rc = ccw_device_set_online(CARD_RDEV(card));
940 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200941 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100942 return -EIO;
943 }
944 rc = ccw_device_set_online(CARD_WDEV(card));
945 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200946 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100947 return -EIO;
948 }
949 rc = ccw_device_set_online(CARD_DDEV(card));
950 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200951 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100952 return -EIO;
953 }
954
955 rc = qeth_core_hardsetup_card(card);
956 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200957 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100958 goto out_remove;
959 }
960
961 if (!card->dev && qeth_l2_setup_netdev(card))
962 goto out_remove;
963
964 if (card->info.type != QETH_CARD_TYPE_OSN)
965 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
966
967 card->state = CARD_STATE_HARDSETUP;
968 qeth_print_status_message(card);
969
970 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200971 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100972
973 rc = qeth_send_startlan(card);
974 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200975 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100976 if (rc == 0xe080) {
977 PRINT_WARN("LAN on card %s if offline! "
978 "Waiting for STARTLAN from card.\n",
979 CARD_BUS_ID(card));
980 card->lan_online = 0;
981 }
982 return rc;
983 } else
984 card->lan_online = 1;
985
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);
989 }
990
991 netif_tx_disable(card->dev);
992
993 rc = qeth_init_qdio_queues(card);
994 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200995 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100996 goto out_remove;
997 }
998 card->state = CARD_STATE_SOFTSETUP;
999 netif_carrier_on(card->dev);
1000
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);
1006 } else {
1007 rtnl_lock();
1008 dev_open(card->dev);
1009 rtnl_unlock();
1010 }
1011 /* this also sets saved unicast addresses */
1012 qeth_l2_set_multicast_list(card->dev);
1013 }
1014 /* let user_space know that device is online */
1015 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
1016 return 0;
1017out_remove:
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;
1025 else
1026 card->state = CARD_STATE_DOWN;
1027 return -ENODEV;
1028}
1029
1030static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1031{
1032 return __qeth_l2_set_online(gdev, 0);
1033}
1034
1035static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1036 int recovery_mode)
1037{
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;
1041
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001042 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1043 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001044
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",
1050 CARD_BUS_ID(card));
1051 return -ERESTARTSYS;
1052 }
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));
1056 if (!rc)
1057 rc = (rc2) ? rc2 : rc3;
1058 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001059 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001060 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);
1064 return 0;
1065}
1066
1067static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1068{
1069 return __qeth_l2_set_offline(cgdev, 0);
1070}
1071
1072static int qeth_l2_recover(void *ptr)
1073{
1074 struct qeth_card *card;
1075 int rc = 0;
1076
1077 card = (struct qeth_card *) ptr;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001078 QETH_DBF_TEXT(TRACE, 2, "recover1");
1079 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001080 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1081 return 0;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001082 QETH_DBF_TEXT(TRACE, 2, "recover2");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001083 PRINT_WARN("Recovery of device %s started ...\n",
1084 CARD_BUS_ID(card));
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);
1091 if (!rc)
1092 PRINT_INFO("Device %s successfully recovered!\n",
1093 CARD_BUS_ID(card));
1094 else
1095 PRINT_INFO("Device %s could not be recovered!\n",
1096 CARD_BUS_ID(card));
1097 return 0;
1098}
1099
1100static int __init qeth_l2_init(void)
1101{
1102 PRINT_INFO("register layer 2 discipline\n");
1103 return 0;
1104}
1105
1106static void __exit qeth_l2_exit(void)
1107{
1108 PRINT_INFO("unregister layer 2 discipline\n");
1109}
1110
1111static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1112{
1113 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1114 qeth_qdio_clear_card(card, 0);
1115 qeth_clear_qdio_buffers(card);
1116}
1117
1118struct 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,
1124};
1125EXPORT_SYMBOL_GPL(qeth_l2_ccwgroup_driver);
1126
1127static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1128 struct qeth_cmd_buffer *iob)
1129{
1130 unsigned long flags;
1131 int rc = 0;
1132
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001133 QETH_DBF_TEXT(TRACE, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001134
1135 wait_event(card->wait_q,
1136 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1137 qeth_prepare_control_data(card, len, iob);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001138 QETH_DBF_TEXT(TRACE, 6, "osnoirqp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001139 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);
1143 if (rc) {
1144 PRINT_WARN("qeth_osn_send_control_data: "
1145 "ccw_device_start rc = %i\n", rc);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001146 QETH_DBF_TEXT_(TRACE, 2, " err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001147 qeth_release_buffer(iob->channel, iob);
1148 atomic_set(&card->write.irq_pending, 0);
1149 wake_up(&card->wait_q);
1150 }
1151 return rc;
1152}
1153
1154static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1155 struct qeth_cmd_buffer *iob, int data_len)
1156{
1157 u16 s1, s2;
1158
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001159 QETH_DBF_TEXT(TRACE, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001160
1161 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1162 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1163 s2 = (u16)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);
1169}
1170
1171int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1172{
1173 struct qeth_cmd_buffer *iob;
1174 struct qeth_card *card;
1175 int rc;
1176
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001177 QETH_DBF_TEXT(TRACE, 2, "osnsdmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001178 if (!dev)
1179 return -ENODEV;
1180 card = netdev_priv(dev);
1181 if (!card)
1182 return -ENODEV;
1183 if ((card->state != CARD_STATE_UP) &&
1184 (card->state != CARD_STATE_SOFTSETUP))
1185 return -ENODEV;
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);
1189 return rc;
1190}
1191EXPORT_SYMBOL(qeth_osn_assist);
1192
1193int 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 *))
1196{
1197 struct qeth_card *card;
1198
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001199 QETH_DBF_TEXT(TRACE, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001200 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1201 if (*dev == NULL)
1202 return -ENODEV;
1203 card = netdev_priv(*dev);
1204 if (!card)
1205 return -ENODEV;
1206 if ((assist_cb == NULL) || (data_cb == NULL))
1207 return -EINVAL;
1208 card->osn_info.assist_cb = assist_cb;
1209 card->osn_info.data_cb = data_cb;
1210 return 0;
1211}
1212EXPORT_SYMBOL(qeth_osn_register);
1213
1214void qeth_osn_deregister(struct net_device *dev)
1215{
1216 struct qeth_card *card;
1217
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001218 QETH_DBF_TEXT(TRACE, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001219 if (!dev)
1220 return;
1221 card = netdev_priv(dev);
1222 if (!card)
1223 return;
1224 card->osn_info.assist_cb = NULL;
1225 card->osn_info.data_cb = NULL;
1226 return;
1227}
1228EXPORT_SYMBOL(qeth_osn_deregister);
1229
1230module_init(qeth_l2_init);
1231module_exit(qeth_l2_exit);
1232MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1233MODULE_DESCRIPTION("qeth layer 2 discipline");
1234MODULE_LICENSE("GPL");