blob: 573b5e564edd450e3a44eb13b1967613c6ef6652 [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
Frank Blaschka4a71df52008-02-15 09:19:42 +010025static int qeth_l2_set_offline(struct ccwgroup_device *);
26static int qeth_l2_stop(struct net_device *);
27static int qeth_l2_send_delmac(struct qeth_card *, __u8 *);
28static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *,
29 enum qeth_ipa_cmds,
30 int (*reply_cb) (struct qeth_card *,
31 struct qeth_reply*,
32 unsigned long));
33static void qeth_l2_set_multicast_list(struct net_device *);
34static int qeth_l2_recover(void *);
35
36static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37{
Heiko Carstens509e2562008-07-26 02:24:10 -070038 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +010039 struct mii_ioctl_data *mii_data;
40 int rc = 0;
41
42 if (!card)
43 return -ENODEV;
44
45 if ((card->state != CARD_STATE_UP) &&
46 (card->state != CARD_STATE_SOFTSETUP))
47 return -ENODEV;
48
49 if (card->info.type == QETH_CARD_TYPE_OSN)
50 return -EPERM;
51
52 switch (cmd) {
53 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
54 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
55 break;
56 case SIOC_QETH_GET_CARD_TYPE:
57 if ((card->info.type == QETH_CARD_TYPE_OSAE) &&
58 !card->info.guestlan)
59 return 1;
60 return 0;
61 break;
62 case SIOCGMIIPHY:
63 mii_data = if_mii(rq);
64 mii_data->phy_id = 0;
65 break;
66 case SIOCGMIIREG:
67 mii_data = if_mii(rq);
68 if (mii_data->phy_id != 0)
69 rc = -EINVAL;
70 else
71 mii_data->val_out = qeth_mdio_read(dev,
72 mii_data->phy_id, mii_data->reg_num);
73 break;
74 default:
75 rc = -EOPNOTSUPP;
76 }
77 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +020078 QETH_DBF_TEXT_(TRACE, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +010079 return rc;
80}
81
82static int qeth_l2_verify_dev(struct net_device *dev)
83{
84 struct qeth_card *card;
85 unsigned long flags;
86 int rc = 0;
87
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) {
91 rc = QETH_REAL_CARD;
92 break;
93 }
94 }
95 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
96
97 return rc;
98}
99
100static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
101{
102 struct qeth_card *card;
103 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200104 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100105 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200106 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100107
108 ndev = NULL;
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) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200112 ccw_device_get_id(CARD_RDEV(card), &read_devid);
113 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100114 ndev = card->dev;
115 break;
116 }
117 }
118 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
119 return ndev;
120}
121
122static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card,
123 struct qeth_reply *reply,
124 unsigned long data)
125{
126 struct qeth_ipa_cmd *cmd;
127 __u8 *mac;
128
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200129 QETH_DBF_TEXT(TRACE, 2, "L2Sgmacb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100130 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) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200134 QETH_DBF_MESSAGE(2, "Group MAC %02x:%02x:%02x:%02x:%02x:%02x "
Frank Blaschka4a71df52008-02-15 09:19:42 +0100135 "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;
139 }
140 if (cmd->hdr.return_code)
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200141 QETH_DBF_MESSAGE(2, "Could not set group MAC "
Frank Blaschka4a71df52008-02-15 09:19:42 +0100142 "%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);
145 return 0;
146}
147
148static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
149{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200150 QETH_DBF_TEXT(TRACE, 2, "L2Sgmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100151 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
152 qeth_l2_send_setgroupmac_cb);
153}
154
155static int qeth_l2_send_delgroupmac_cb(struct qeth_card *card,
156 struct qeth_reply *reply,
157 unsigned long data)
158{
159 struct qeth_ipa_cmd *cmd;
160 __u8 *mac;
161
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200162 QETH_DBF_TEXT(TRACE, 2, "L2Dgmacb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100163 cmd = (struct qeth_ipa_cmd *) data;
164 mac = &cmd->data.setdelmac.mac[0];
165 if (cmd->hdr.return_code)
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200166 QETH_DBF_MESSAGE(2, "Could not delete group MAC "
Frank Blaschka4a71df52008-02-15 09:19:42 +0100167 "%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);
170 return 0;
171}
172
173static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
174{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200175 QETH_DBF_TEXT(TRACE, 2, "L2Dgmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100176 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
177 qeth_l2_send_delgroupmac_cb);
178}
179
Frank Blaschka7db22662008-08-15 08:02:59 +0200180static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac, int vmac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100181{
182 struct qeth_mc_mac *mc;
Frank Blaschka7db22662008-08-15 08:02:59 +0200183 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100184
185 mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC);
186
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200187 if (!mc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100188 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100189
190 memcpy(mc->mc_addr, mac, OSA_ADDR_LEN);
191 mc->mc_addrlen = OSA_ADDR_LEN;
Frank Blaschka7db22662008-08-15 08:02:59 +0200192 mc->is_vmac = vmac;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100193
Frank Blaschka7db22662008-08-15 08:02:59 +0200194 if (vmac) {
195 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
196 NULL);
197 } else {
198 rc = qeth_l2_send_setgroupmac(card, mac);
199 }
200
201 if (!rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100202 list_add_tail(&mc->list, &card->mc_list);
203 else
204 kfree(mc);
205}
206
207static void qeth_l2_del_all_mc(struct qeth_card *card)
208{
209 struct qeth_mc_mac *mc, *tmp;
210
211 spin_lock_bh(&card->mclock);
212 list_for_each_entry_safe(mc, tmp, &card->mc_list, list) {
Frank Blaschka7db22662008-08-15 08:02:59 +0200213 if (mc->is_vmac)
214 qeth_l2_send_setdelmac(card, mc->mc_addr,
215 IPA_CMD_DELVMAC, NULL);
216 else
217 qeth_l2_send_delgroupmac(card, mc->mc_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100218 list_del(&mc->list);
219 kfree(mc);
220 }
221 spin_unlock_bh(&card->mclock);
222}
223
224static void qeth_l2_get_packet_type(struct qeth_card *card,
225 struct qeth_hdr *hdr, struct sk_buff *skb)
226{
227 __u16 hdr_mac;
228
229 if (!memcmp(skb->data + QETH_HEADER_SIZE,
230 skb->dev->broadcast, 6)) {
231 /* broadcast? */
232 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
233 return;
234 }
235 hdr_mac = *((__u16 *)skb->data);
236 /* tr multicast? */
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;
243 else
244 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
245 break;
246 /* eth or so multicast? */
247 default:
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;
251 else
252 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
253 }
254}
255
256static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
257 struct sk_buff *skb, int ipv, int cast_type)
258{
Frank Blaschka683d7182008-08-01 16:39:13 +0200259 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100260
261 memset(hdr, 0, sizeof(struct qeth_hdr));
262 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
263
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;
269 else
270 qeth_l2_get_packet_type(card, hdr, skb);
271
272 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
273 /* VSWITCH relies on the VLAN
274 * information to be present in
275 * the QDIO header */
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);
279 }
280}
281
282static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
283 struct qeth_reply *reply, unsigned long data)
284{
285 struct qeth_ipa_cmd *cmd;
286
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200287 QETH_DBF_TEXT(TRACE, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100288 cmd = (struct qeth_ipa_cmd *) data;
289 if (cmd->hdr.return_code) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200290 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
Frank Blaschka4a71df52008-02-15 09:19:42 +0100291 "Continuing\n", cmd->data.setdelvlan.vlan_id,
292 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200293 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);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100296 }
297 return 0;
298}
299
300static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
301 enum qeth_ipa_cmds ipacmd)
302{
303 struct qeth_ipa_cmd *cmd;
304 struct qeth_cmd_buffer *iob;
305
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200306 QETH_DBF_TEXT_(TRACE, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100307 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);
312}
313
314static void qeth_l2_process_vlans(struct qeth_card *card, int clear)
315{
316 struct qeth_vlan_vid *id;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200317 QETH_DBF_TEXT(TRACE, 3, "L2prcvln");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100318 spin_lock_bh(&card->vlanlock);
319 list_for_each_entry(id, &card->vid_list, list) {
320 if (clear)
321 qeth_l2_send_setdelvlan(card, id->vid,
322 IPA_CMD_DELVLAN);
323 else
324 qeth_l2_send_setdelvlan(card, id->vid,
325 IPA_CMD_SETVLAN);
326 }
327 spin_unlock_bh(&card->vlanlock);
328}
329
330static void qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
331{
Heiko Carstens509e2562008-07-26 02:24:10 -0700332 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100333 struct qeth_vlan_vid *id;
334
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200335 QETH_DBF_TEXT_(TRACE, 4, "aid:%d", vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100336 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
337 if (id) {
338 id->vid = vid;
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);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100343 }
344}
345
346static void qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
347{
348 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700349 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100350
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200351 QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100352 spin_lock_bh(&card->vlanlock);
353 list_for_each_entry(id, &card->vid_list, list) {
354 if (id->vid == vid) {
355 list_del(&id->list);
356 tmpid = id;
357 break;
358 }
359 }
360 spin_unlock_bh(&card->vlanlock);
361 if (tmpid) {
362 qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
363 kfree(tmpid);
364 }
365 qeth_l2_set_multicast_list(card->dev);
366}
367
368static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
369{
370 int rc = 0;
371
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200372 QETH_DBF_TEXT(SETUP , 2, "stopcard");
373 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100374
375 qeth_set_allowed_threads(card, 0, 1);
376 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD))
377 return -ERESTARTSYS;
378 if (card->read.state == CH_STATE_UP &&
379 card->write.state == CH_STATE_UP &&
380 (card->state == CARD_STATE_UP)) {
381 if (recovery_mode &&
382 card->info.type != QETH_CARD_TYPE_OSN) {
383 qeth_l2_stop(card->dev);
384 } else {
385 rtnl_lock();
386 dev_close(card->dev);
387 rtnl_unlock();
388 }
389 if (!card->use_hard_stop) {
390 __u8 *mac = &card->dev->dev_addr[0];
391 rc = qeth_l2_send_delmac(card, mac);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200392 QETH_DBF_TEXT_(SETUP, 2, "Lerr%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100393 }
394 card->state = CARD_STATE_SOFTSETUP;
395 }
396 if (card->state == CARD_STATE_SOFTSETUP) {
397 qeth_l2_process_vlans(card, 1);
398 qeth_l2_del_all_mc(card);
399 qeth_clear_ipacmd_list(card);
400 card->state = CARD_STATE_HARDSETUP;
401 }
402 if (card->state == CARD_STATE_HARDSETUP) {
403 qeth_qdio_clear_card(card, 0);
404 qeth_clear_qdio_buffers(card);
405 qeth_clear_working_pool_list(card);
406 card->state = CARD_STATE_DOWN;
407 }
408 if (card->state == CARD_STATE_DOWN) {
409 qeth_clear_cmd_buffers(&card->read);
410 qeth_clear_cmd_buffers(&card->write);
411 }
412 card->use_hard_stop = 0;
413 return rc;
414}
415
416static void qeth_l2_process_inbound_buffer(struct qeth_card *card,
417 struct qeth_qdio_buffer *buf, int index)
418{
419 struct qdio_buffer_element *element;
420 struct sk_buff *skb;
421 struct qeth_hdr *hdr;
422 int offset;
423 unsigned int len;
424
425 /* get first element of current buffer */
426 element = (struct qdio_buffer_element *)&buf->buffer->element[0];
427 offset = 0;
428 if (card->options.performance_stats)
429 card->perf_stats.bufs_rec++;
430 while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element,
431 &offset, &hdr))) {
432 skb->dev = card->dev;
433 /* is device UP ? */
434 if (!(card->dev->flags & IFF_UP)) {
435 dev_kfree_skb_any(skb);
436 continue;
437 }
438
439 switch (hdr->hdr.l2.id) {
440 case QETH_HEADER_TYPE_LAYER2:
441 skb->pkt_type = PACKET_HOST;
442 skb->protocol = eth_type_trans(skb, skb->dev);
443 if (card->options.checksum_type == NO_CHECKSUMMING)
444 skb->ip_summed = CHECKSUM_UNNECESSARY;
445 else
446 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun12883722008-04-01 10:26:56 +0200447 if (skb->protocol == htons(ETH_P_802_2))
448 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100449 len = skb->len;
450 netif_rx(skb);
451 break;
452 case QETH_HEADER_TYPE_OSN:
453 skb_push(skb, sizeof(struct qeth_hdr));
454 skb_copy_to_linear_data(skb, hdr,
455 sizeof(struct qeth_hdr));
456 len = skb->len;
457 card->osn_info.data_cb(skb);
458 break;
459 default:
460 dev_kfree_skb_any(skb);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200461 QETH_DBF_TEXT(TRACE, 3, "inbunkno");
462 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100463 continue;
464 }
465 card->dev->last_rx = jiffies;
466 card->stats.rx_packets++;
467 card->stats.rx_bytes += len;
468 }
469}
470
471static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
472 enum qeth_ipa_cmds ipacmd,
473 int (*reply_cb) (struct qeth_card *,
474 struct qeth_reply*,
475 unsigned long))
476{
477 struct qeth_ipa_cmd *cmd;
478 struct qeth_cmd_buffer *iob;
479
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200480 QETH_DBF_TEXT(TRACE, 2, "L2sdmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100481 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
482 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
483 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
484 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
485 return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
486}
487
488static int qeth_l2_send_setmac_cb(struct qeth_card *card,
489 struct qeth_reply *reply,
490 unsigned long data)
491{
492 struct qeth_ipa_cmd *cmd;
493
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200494 QETH_DBF_TEXT(TRACE, 2, "L2Smaccb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100495 cmd = (struct qeth_ipa_cmd *) data;
496 if (cmd->hdr.return_code) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200497 QETH_DBF_TEXT_(TRACE, 2, "L2er%x", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100498 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
499 cmd->hdr.return_code = -EIO;
500 } else {
501 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
502 memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac,
503 OSA_ADDR_LEN);
504 PRINT_INFO("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],
509 card->dev->name);
510 }
511 return 0;
512}
513
514static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
515{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200516 QETH_DBF_TEXT(TRACE, 2, "L2Setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100517 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
518 qeth_l2_send_setmac_cb);
519}
520
521static int qeth_l2_send_delmac_cb(struct qeth_card *card,
522 struct qeth_reply *reply,
523 unsigned long data)
524{
525 struct qeth_ipa_cmd *cmd;
526
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200527 QETH_DBF_TEXT(TRACE, 2, "L2Dmaccb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100528 cmd = (struct qeth_ipa_cmd *) data;
529 if (cmd->hdr.return_code) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200530 QETH_DBF_TEXT_(TRACE, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100531 cmd->hdr.return_code = -EIO;
532 return 0;
533 }
534 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
535
536 return 0;
537}
538
539static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
540{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200541 QETH_DBF_TEXT(TRACE, 2, "L2Delmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100542 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
543 return 0;
544 return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
545 qeth_l2_send_delmac_cb);
546}
547
548static int qeth_l2_request_initial_mac(struct qeth_card *card)
549{
550 int rc = 0;
551 char vendor_pre[] = {0x02, 0x00, 0x00};
552
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200553 QETH_DBF_TEXT(SETUP, 2, "doL2init");
554 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100555
556 rc = qeth_query_setadapterparms(card);
557 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200558 QETH_DBF_MESSAGE(2, "could not query adapter parameters on "
559 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100560 }
561
Ursula Braunf1d58672008-09-19 12:56:02 +0200562 if ((card->info.type == QETH_CARD_TYPE_IQD) ||
563 (card->info.guestlan)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100564 rc = qeth_setadpparms_change_macaddr(card);
565 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200566 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
567 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200568 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100569 return rc;
570 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200571 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100572 } else {
573 random_ether_addr(card->dev->dev_addr);
574 memcpy(card->dev->dev_addr, vendor_pre, 3);
575 }
576 return 0;
577}
578
579static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
580{
581 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700582 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100583 int rc = 0;
584
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200585 QETH_DBF_TEXT(TRACE, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100586
587 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200588 QETH_DBF_TEXT(TRACE, 3, "setmcINV");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100589 return -EOPNOTSUPP;
590 }
591
592 if (card->info.type == QETH_CARD_TYPE_OSN) {
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{
Heiko Carstens509e2562008-07-26 02:24:10 -0700606 struct qeth_card *card = dev->ml_priv;
Frank Blaschka7db22662008-08-15 08:02:59 +0200607 struct dev_addr_list *dm;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100608
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)
Frank Blaschka7db22662008-08-15 08:02:59 +0200616 qeth_l2_add_mc(card, dm->da_addr, 0);
617
618 for (dm = dev->uc_list; dm; dm = dm->next)
619 qeth_l2_add_mc(card, dm->da_addr, 1);
620
Frank Blaschka4a71df52008-02-15 09:19:42 +0100621 spin_unlock_bh(&card->mclock);
622 if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
623 return;
624 qeth_setadp_promisc_mode(card);
625}
626
627static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
628{
629 int rc;
630 struct qeth_hdr *hdr = NULL;
631 int elements = 0;
Heiko Carstens509e2562008-07-26 02:24:10 -0700632 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100633 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;
Frank Blaschka683d7182008-08-01 16:39:13 +0200641 int data_offset = -1;
642 int elements_needed = 0;
643 int hd_len = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100644
Frank Blaschka4a71df52008-02-15 09:19:42 +0100645 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
646 card->stats.tx_carrier_errors++;
647 goto tx_drop;
648 }
649
650 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
651 (skb->protocol == htons(ETH_P_IPV6)))
652 goto tx_drop;
653
654 if (card->options.performance_stats) {
655 card->perf_stats.outbound_cnt++;
656 card->perf_stats.outbound_start_time = qeth_get_micros();
657 }
658 netif_stop_queue(dev);
659
660 if (skb_is_gso(skb))
661 large_send = QETH_LARGE_SEND_EDDP;
662
663 if (card->info.type == QETH_CARD_TYPE_OSN)
664 hdr = (struct qeth_hdr *)skb->data;
665 else {
Frank Blaschka683d7182008-08-01 16:39:13 +0200666 if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) &&
667 (skb_shinfo(skb)->nr_frags == 0)) {
668 new_skb = skb;
669 data_offset = ETH_HLEN;
670 hd_len = ETH_HLEN;
671 hdr = kmem_cache_alloc(qeth_core_header_cache,
672 GFP_ATOMIC);
673 if (!hdr)
674 goto tx_drop;
675 elements_needed++;
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);
681 } else {
682 /* create a clone with writeable headroom */
683 new_skb = skb_realloc_headroom(skb,
Frank Blaschkaf90b7442008-04-24 10:15:24 +0200684 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +0200685 if (!new_skb)
686 goto tx_drop;
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);
691 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100692 }
693
694 if (large_send == QETH_LARGE_SEND_EDDP) {
695 ctx = qeth_eddp_create_context(card, new_skb, hdr,
696 skb->sk->sk_protocol);
697 if (ctx == NULL) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200698 QETH_DBF_MESSAGE(2, "could not create eddp context\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100699 goto tx_drop;
700 }
701 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +0200702 elements = qeth_get_elements_no(card, (void *)hdr, new_skb,
703 elements_needed);
704 if (!elements) {
705 if (data_offset >= 0)
706 kmem_cache_free(qeth_core_header_cache, hdr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100707 goto tx_drop;
Frank Blaschka683d7182008-08-01 16:39:13 +0200708 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100709 }
710
711 if ((large_send == QETH_LARGE_SEND_NO) &&
712 (skb->ip_summed == CHECKSUM_PARTIAL))
713 qeth_tx_csum(new_skb);
714
715 if (card->info.type != QETH_CARD_TYPE_IQD)
716 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
717 elements, ctx);
718 else
719 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka683d7182008-08-01 16:39:13 +0200720 elements, ctx, data_offset, hd_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100721 if (!rc) {
722 card->stats.tx_packets++;
723 card->stats.tx_bytes += tx_bytes;
724 if (new_skb != skb)
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++;
730 }
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;
736 }
737 }
738
739 if (ctx != NULL) {
740 qeth_eddp_put_context(ctx);
741 dev_kfree_skb_any(new_skb);
742 }
743 } else {
744 if (ctx != NULL)
745 qeth_eddp_put_context(ctx);
746
Frank Blaschka683d7182008-08-01 16:39:13 +0200747 if (data_offset >= 0)
748 kmem_cache_free(qeth_core_header_cache, hdr);
749
Frank Blaschka4a71df52008-02-15 09:19:42 +0100750 if (rc == -EBUSY) {
751 if (new_skb != skb)
752 dev_kfree_skb_any(new_skb);
753 return NETDEV_TX_BUSY;
754 } else
755 goto tx_drop;
756 }
757
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;
762 return rc;
763
764tx_drop:
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);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200770 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100771 return NETDEV_TX_OK;
772}
773
774static void qeth_l2_qdio_input_handler(struct ccw_device *ccwdev,
Jan Glauber779e6e12008-07-17 17:16:48 +0200775 unsigned int qdio_err, unsigned int queue,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100776 int first_element, int count, unsigned long card_ptr)
777{
778 struct net_device *net_dev;
779 struct qeth_card *card;
780 struct qeth_qdio_buffer *buffer;
781 int index;
782 int i;
783
Frank Blaschka4a71df52008-02-15 09:19:42 +0100784 card = (struct qeth_card *) card_ptr;
785 net_dev = card->dev;
786 if (card->options.performance_stats) {
787 card->perf_stats.inbound_cnt++;
788 card->perf_stats.inbound_start_time = qeth_get_micros();
789 }
Jan Glauber779e6e12008-07-17 17:16:48 +0200790 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,
794 count);
795 QETH_DBF_TEXT_(TRACE, 1, "%04X", queue);
796 qeth_schedule_recovery(card);
797 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100798 }
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];
Jan Glauber779e6e12008-07-17 17:16:48 +0200802 if (!(qdio_err &&
803 qeth_check_qdio_errors(buffer->buffer, qdio_err, "qinerr")))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100804 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);
808 }
809 if (card->options.performance_stats)
810 card->perf_stats.inbound_time += qeth_get_micros() -
811 card->perf_stats.inbound_start_time;
812}
813
814static int qeth_l2_open(struct net_device *dev)
815{
Heiko Carstens509e2562008-07-26 02:24:10 -0700816 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100817
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200818 QETH_DBF_TEXT(TRACE, 4, "qethopen");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100819 if (card->state != CARD_STATE_SOFTSETUP)
820 return -ENODEV;
821
822 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
823 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200824 QETH_DBF_TEXT(TRACE, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100825 return -EPERM;
826 }
827 card->data.state = CH_STATE_UP;
828 card->state = CARD_STATE_UP;
829 card->dev->flags |= IFF_UP;
830 netif_start_queue(dev);
831
832 if (!card->lan_online && netif_carrier_ok(dev))
833 netif_carrier_off(dev);
834 return 0;
835}
836
837
838static int qeth_l2_stop(struct net_device *dev)
839{
Heiko Carstens509e2562008-07-26 02:24:10 -0700840 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100841
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200842 QETH_DBF_TEXT(TRACE, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100843 netif_tx_disable(dev);
844 card->dev->flags &= ~IFF_UP;
845 if (card->state == CARD_STATE_UP)
846 card->state = CARD_STATE_SOFTSETUP;
847 return 0;
848}
849
850static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
851{
852 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
853
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;
862 return 0;
863}
864
865static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
866{
867 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
868
869 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
870
871 if (cgdev->state == CCWGROUP_ONLINE) {
872 card->use_hard_stop = 1;
873 qeth_l2_set_offline(cgdev);
874 }
875
876 if (card->dev) {
877 unregister_netdev(card->dev);
878 card->dev = NULL;
879 }
880
881 qeth_l2_del_all_mc(card);
882 return;
883}
884
Frank Blaschkaefe3df62008-04-24 10:15:27 +0200885static int qeth_l2_ethtool_set_tso(struct net_device *dev, u32 data)
886{
Heiko Carstens509e2562008-07-26 02:24:10 -0700887 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaefe3df62008-04-24 10:15:27 +0200888
889 if (data) {
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;
893 }
894 } else {
895 dev->features &= ~NETIF_F_TSO;
896 card->options.large_send = QETH_LARGE_SEND_NO;
897 }
898 return 0;
899}
900
Frank Blaschka4a71df52008-02-15 09:19:42 +0100901static 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,
Frank Blaschkaefe3df62008-04-24 10:15:27 +0200908 .set_tso = qeth_l2_ethtool_set_tso,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100909 .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,
Frank Blaschka3f9975a2008-04-24 10:15:23 +0200913 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100914};
915
916static 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,
921};
922
923static int qeth_l2_setup_netdev(struct qeth_card *card)
924{
925 switch (card->info.type) {
926 case QETH_CARD_TYPE_OSAE:
927 card->dev = alloc_etherdev(0);
928 break;
929 case QETH_CARD_TYPE_IQD:
930 card->dev = alloc_netdev(0, "hsi%d", ether_setup);
931 break;
932 case QETH_CARD_TYPE_OSN:
933 card->dev = alloc_netdev(0, "osn%d", ether_setup);
934 card->dev->flags |= IFF_NOARP;
935 break;
936 default:
937 card->dev = alloc_etherdev(0);
938 }
939
940 if (!card->dev)
941 return -ENODEV;
942
Heiko Carstens509e2562008-07-26 02:24:10 -0700943 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100944 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);
959 else
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);
966}
967
968static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
969{
970 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
971 int rc = 0;
972 enum qeth_card_states recover_flag;
973
974 BUG_ON(!card);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200975 QETH_DBF_TEXT(SETUP, 2, "setonlin");
976 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100977
978 qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1);
979 if (qeth_wait_for_threads(card, ~QETH_RECOVER_THREAD)) {
980 PRINT_WARN("set_online of card %s interrupted by user!\n",
981 CARD_BUS_ID(card));
982 return -ERESTARTSYS;
983 }
984
985 recover_flag = card->state;
986 rc = ccw_device_set_online(CARD_RDEV(card));
987 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200988 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100989 return -EIO;
990 }
991 rc = ccw_device_set_online(CARD_WDEV(card));
992 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200993 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100994 return -EIO;
995 }
996 rc = ccw_device_set_online(CARD_DDEV(card));
997 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200998 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100999 return -EIO;
1000 }
1001
1002 rc = qeth_core_hardsetup_card(card);
1003 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001004 QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001005 goto out_remove;
1006 }
1007
1008 if (!card->dev && qeth_l2_setup_netdev(card))
1009 goto out_remove;
1010
1011 if (card->info.type != QETH_CARD_TYPE_OSN)
1012 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
1013
1014 card->state = CARD_STATE_HARDSETUP;
1015 qeth_print_status_message(card);
1016
1017 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001018 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001019
1020 rc = qeth_send_startlan(card);
1021 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001022 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001023 if (rc == 0xe080) {
1024 PRINT_WARN("LAN on card %s if offline! "
1025 "Waiting for STARTLAN from card.\n",
1026 CARD_BUS_ID(card));
1027 card->lan_online = 0;
1028 }
1029 return rc;
1030 } else
1031 card->lan_online = 1;
1032
1033 if (card->info.type != QETH_CARD_TYPE_OSN) {
1034 qeth_set_large_send(card, card->options.large_send);
1035 qeth_l2_process_vlans(card, 0);
1036 }
1037
1038 netif_tx_disable(card->dev);
1039
1040 rc = qeth_init_qdio_queues(card);
1041 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001042 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001043 goto out_remove;
1044 }
1045 card->state = CARD_STATE_SOFTSETUP;
1046 netif_carrier_on(card->dev);
1047
1048 qeth_set_allowed_threads(card, 0xffffffff, 0);
1049 if (recover_flag == CARD_STATE_RECOVER) {
1050 if (recovery_mode &&
1051 card->info.type != QETH_CARD_TYPE_OSN) {
1052 qeth_l2_open(card->dev);
1053 } else {
1054 rtnl_lock();
1055 dev_open(card->dev);
1056 rtnl_unlock();
1057 }
1058 /* this also sets saved unicast addresses */
1059 qeth_l2_set_multicast_list(card->dev);
1060 }
1061 /* let user_space know that device is online */
1062 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
1063 return 0;
1064out_remove:
1065 card->use_hard_stop = 1;
1066 qeth_l2_stop_card(card, 0);
1067 ccw_device_set_offline(CARD_DDEV(card));
1068 ccw_device_set_offline(CARD_WDEV(card));
1069 ccw_device_set_offline(CARD_RDEV(card));
1070 if (recover_flag == CARD_STATE_RECOVER)
1071 card->state = CARD_STATE_RECOVER;
1072 else
1073 card->state = CARD_STATE_DOWN;
1074 return -ENODEV;
1075}
1076
1077static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1078{
1079 return __qeth_l2_set_online(gdev, 0);
1080}
1081
1082static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1083 int recovery_mode)
1084{
1085 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1086 int rc = 0, rc2 = 0, rc3 = 0;
1087 enum qeth_card_states recover_flag;
1088
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001089 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1090 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001091
1092 if (card->dev && netif_carrier_ok(card->dev))
1093 netif_carrier_off(card->dev);
1094 recover_flag = card->state;
1095 if (qeth_l2_stop_card(card, recovery_mode) == -ERESTARTSYS) {
1096 PRINT_WARN("Stopping card %s interrupted by user!\n",
1097 CARD_BUS_ID(card));
1098 return -ERESTARTSYS;
1099 }
1100 rc = ccw_device_set_offline(CARD_DDEV(card));
1101 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1102 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1103 if (!rc)
1104 rc = (rc2) ? rc2 : rc3;
1105 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001106 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001107 if (recover_flag == CARD_STATE_UP)
1108 card->state = CARD_STATE_RECOVER;
1109 /* let user_space know that device is offline */
1110 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
1111 return 0;
1112}
1113
1114static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1115{
1116 return __qeth_l2_set_offline(cgdev, 0);
1117}
1118
1119static int qeth_l2_recover(void *ptr)
1120{
1121 struct qeth_card *card;
1122 int rc = 0;
1123
1124 card = (struct qeth_card *) ptr;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001125 QETH_DBF_TEXT(TRACE, 2, "recover1");
1126 QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001127 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1128 return 0;
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001129 QETH_DBF_TEXT(TRACE, 2, "recover2");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001130 PRINT_WARN("Recovery of device %s started ...\n",
1131 CARD_BUS_ID(card));
1132 card->use_hard_stop = 1;
1133 __qeth_l2_set_offline(card->gdev, 1);
1134 rc = __qeth_l2_set_online(card->gdev, 1);
1135 /* don't run another scheduled recovery */
1136 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1137 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
1138 if (!rc)
1139 PRINT_INFO("Device %s successfully recovered!\n",
1140 CARD_BUS_ID(card));
1141 else
1142 PRINT_INFO("Device %s could not be recovered!\n",
1143 CARD_BUS_ID(card));
1144 return 0;
1145}
1146
1147static int __init qeth_l2_init(void)
1148{
1149 PRINT_INFO("register layer 2 discipline\n");
1150 return 0;
1151}
1152
1153static void __exit qeth_l2_exit(void)
1154{
1155 PRINT_INFO("unregister layer 2 discipline\n");
1156}
1157
1158static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1159{
1160 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1161 qeth_qdio_clear_card(card, 0);
1162 qeth_clear_qdio_buffers(card);
1163}
1164
1165struct ccwgroup_driver qeth_l2_ccwgroup_driver = {
1166 .probe = qeth_l2_probe_device,
1167 .remove = qeth_l2_remove_device,
1168 .set_online = qeth_l2_set_online,
1169 .set_offline = qeth_l2_set_offline,
1170 .shutdown = qeth_l2_shutdown,
1171};
1172EXPORT_SYMBOL_GPL(qeth_l2_ccwgroup_driver);
1173
1174static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1175 struct qeth_cmd_buffer *iob)
1176{
1177 unsigned long flags;
1178 int rc = 0;
1179
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001180 QETH_DBF_TEXT(TRACE, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001181
1182 wait_event(card->wait_q,
1183 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1184 qeth_prepare_control_data(card, len, iob);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001185 QETH_DBF_TEXT(TRACE, 6, "osnoirqp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001186 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1187 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1188 (addr_t) iob, 0, 0);
1189 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1190 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001191 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001192 "ccw_device_start rc = %i\n", rc);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001193 QETH_DBF_TEXT_(TRACE, 2, " err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001194 qeth_release_buffer(iob->channel, iob);
1195 atomic_set(&card->write.irq_pending, 0);
1196 wake_up(&card->wait_q);
1197 }
1198 return rc;
1199}
1200
1201static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1202 struct qeth_cmd_buffer *iob, int data_len)
1203{
1204 u16 s1, s2;
1205
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001206 QETH_DBF_TEXT(TRACE, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001207
1208 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1209 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1210 s2 = (u16)data_len;
1211 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1212 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1213 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1214 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1215 return qeth_osn_send_control_data(card, s1, iob);
1216}
1217
1218int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1219{
1220 struct qeth_cmd_buffer *iob;
1221 struct qeth_card *card;
1222 int rc;
1223
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001224 QETH_DBF_TEXT(TRACE, 2, "osnsdmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001225 if (!dev)
1226 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001227 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001228 if (!card)
1229 return -ENODEV;
1230 if ((card->state != CARD_STATE_UP) &&
1231 (card->state != CARD_STATE_SOFTSETUP))
1232 return -ENODEV;
1233 iob = qeth_wait_for_buffer(&card->write);
1234 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1235 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1236 return rc;
1237}
1238EXPORT_SYMBOL(qeth_osn_assist);
1239
1240int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1241 int (*assist_cb)(struct net_device *, void *),
1242 int (*data_cb)(struct sk_buff *))
1243{
1244 struct qeth_card *card;
1245
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001246 QETH_DBF_TEXT(TRACE, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001247 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1248 if (*dev == NULL)
1249 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001250 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001251 if (!card)
1252 return -ENODEV;
1253 if ((assist_cb == NULL) || (data_cb == NULL))
1254 return -EINVAL;
1255 card->osn_info.assist_cb = assist_cb;
1256 card->osn_info.data_cb = data_cb;
1257 return 0;
1258}
1259EXPORT_SYMBOL(qeth_osn_register);
1260
1261void qeth_osn_deregister(struct net_device *dev)
1262{
1263 struct qeth_card *card;
1264
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001265 QETH_DBF_TEXT(TRACE, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001266 if (!dev)
1267 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001268 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001269 if (!card)
1270 return;
1271 card->osn_info.assist_cb = NULL;
1272 card->osn_info.data_cb = NULL;
1273 return;
1274}
1275EXPORT_SYMBOL(qeth_osn_deregister);
1276
1277module_init(qeth_l2_init);
1278module_exit(qeth_l2_exit);
1279MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
1280MODULE_DESCRIPTION("qeth layer 2 discipline");
1281MODULE_LICENSE("GPL");