[SK_BUFF]: Introduce skb_reset_mac_header(skb)
[deliverable/linux.git] / drivers / block / aoe / aoecmd.c
CommitLineData
2611464d 1/* Copyright (c) 2006 Coraid, Inc. See COPYING for GPL terms. */
1da177e4
LT
2/*
3 * aoecmd.c
4 * Filesystem request handling methods
5 */
6
7#include <linux/hdreg.h>
8#include <linux/blkdev.h>
9#include <linux/skbuff.h>
10#include <linux/netdevice.h>
3ae1c24e 11#include <linux/genhd.h>
475172fb 12#include <asm/unaligned.h>
1da177e4
LT
13#include "aoe.h"
14
15#define TIMERTICK (HZ / 10)
16#define MINTIMER (2 * TIMERTICK)
17#define MAXTIMER (HZ << 1)
b751e8b6
EC
18
19static int aoe_deadsecs = 60 * 3;
20module_param(aoe_deadsecs, int, 0644);
21MODULE_PARM_DESC(aoe_deadsecs, "After aoe_deadsecs seconds, give up and fail dev.");
1da177e4 22
e407a7f6
EC
23struct sk_buff *
24new_skb(ulong len)
1da177e4
LT
25{
26 struct sk_buff *skb;
27
28 skb = alloc_skb(len, GFP_ATOMIC);
29 if (skb) {
459a98ed
ACM
30 skb_reset_mac_header(skb);
31 skb->nh.raw = skb->data;
1da177e4
LT
32 skb->protocol = __constant_htons(ETH_P_AOE);
33 skb->priority = 0;
1da177e4
LT
34 skb->next = skb->prev = NULL;
35
36 /* tell the network layer not to perform IP checksums
37 * or to get the NIC to do it
38 */
39 skb->ip_summed = CHECKSUM_NONE;
40 }
41 return skb;
42}
43
1da177e4
LT
44static struct frame *
45getframe(struct aoedev *d, int tag)
46{
47 struct frame *f, *e;
48
49 f = d->frames;
50 e = f + d->nframes;
51 for (; f<e; f++)
52 if (f->tag == tag)
53 return f;
54 return NULL;
55}
56
57/*
58 * Leave the top bit clear so we have tagspace for userland.
59 * The bottom 16 bits are the xmit tick for rexmit/rttavg processing.
60 * This driver reserves tag -1 to mean "unused frame."
61 */
62static int
63newtag(struct aoedev *d)
64{
65 register ulong n;
66
67 n = jiffies & 0xffff;
68 return n |= (++d->lasttag & 0x7fff) << 16;
69}
70
71static int
72aoehdr_atainit(struct aoedev *d, struct aoe_hdr *h)
73{
1da177e4 74 u32 host_tag = newtag(d);
1da177e4
LT
75
76 memcpy(h->src, d->ifp->dev_addr, sizeof h->src);
77 memcpy(h->dst, d->addr, sizeof h->dst);
63e9cc5d 78 h->type = __constant_cpu_to_be16(ETH_P_AOE);
1da177e4 79 h->verfl = AOE_HVER;
63e9cc5d 80 h->major = cpu_to_be16(d->aoemajor);
1da177e4
LT
81 h->minor = d->aoeminor;
82 h->cmd = AOECMD_ATA;
63e9cc5d 83 h->tag = cpu_to_be32(host_tag);
1da177e4
LT
84
85 return host_tag;
86}
87
19bf2635
EC
88static inline void
89put_lba(struct aoe_atahdr *ah, sector_t lba)
90{
91 ah->lba0 = lba;
92 ah->lba1 = lba >>= 8;
93 ah->lba2 = lba >>= 8;
94 ah->lba3 = lba >>= 8;
95 ah->lba4 = lba >>= 8;
96 ah->lba5 = lba >>= 8;
97}
98
1da177e4
LT
99static void
100aoecmd_ata_rw(struct aoedev *d, struct frame *f)
101{
102 struct aoe_hdr *h;
103 struct aoe_atahdr *ah;
104 struct buf *buf;
105 struct sk_buff *skb;
106 ulong bcnt;
107 register sector_t sector;
108 char writebit, extbit;
109
110 writebit = 0x10;
111 extbit = 0x4;
112
113 buf = d->inprocess;
114
115 sector = buf->sector;
116 bcnt = buf->bv_resid;
19bf2635
EC
117 if (bcnt > d->maxbcnt)
118 bcnt = d->maxbcnt;
1da177e4
LT
119
120 /* initialize the headers & frame */
e407a7f6 121 skb = f->skb;
029720f1 122 h = aoe_hdr(skb);
1da177e4 123 ah = (struct aoe_atahdr *) (h+1);
19900cde
EC
124 skb_put(skb, sizeof *h + sizeof *ah);
125 memset(h, 0, skb->len);
1da177e4
LT
126 f->tag = aoehdr_atainit(d, h);
127 f->waited = 0;
128 f->buf = buf;
129 f->bufaddr = buf->bufaddr;
19bf2635
EC
130 f->bcnt = bcnt;
131 f->lba = sector;
1da177e4
LT
132
133 /* set up ata header */
134 ah->scnt = bcnt >> 9;
19bf2635 135 put_lba(ah, sector);
1da177e4
LT
136 if (d->flags & DEVFL_EXT) {
137 ah->aflags |= AOEAFL_EXT;
1da177e4
LT
138 } else {
139 extbit = 0;
140 ah->lba3 &= 0x0f;
141 ah->lba3 |= 0xe0; /* LBA bit + obsolete 0xa0 */
142 }
143
144 if (bio_data_dir(buf->bio) == WRITE) {
e407a7f6
EC
145 skb_fill_page_desc(skb, 0, virt_to_page(f->bufaddr),
146 offset_in_page(f->bufaddr), bcnt);
1da177e4 147 ah->aflags |= AOEAFL_WRITE;
4f51dc5e
EC
148 skb->len += bcnt;
149 skb->data_len = bcnt;
1da177e4
LT
150 } else {
151 writebit = 0;
1da177e4
LT
152 }
153
154 ah->cmdstat = WIN_READ | writebit | extbit;
155
156 /* mark all tracking fields and load out */
157 buf->nframesout += 1;
158 buf->bufaddr += bcnt;
159 buf->bv_resid -= bcnt;
a12c93f0 160/* printk(KERN_DEBUG "aoe: bv_resid=%ld\n", buf->bv_resid); */
1da177e4
LT
161 buf->resid -= bcnt;
162 buf->sector += bcnt >> 9;
163 if (buf->resid == 0) {
164 d->inprocess = NULL;
165 } else if (buf->bv_resid == 0) {
166 buf->bv++;
392e4845 167 WARN_ON(buf->bv->bv_len == 0);
1da177e4
LT
168 buf->bv_resid = buf->bv->bv_len;
169 buf->bufaddr = page_address(buf->bv->bv_page) + buf->bv->bv_offset;
170 }
171
e407a7f6 172 skb->dev = d->ifp;
4f51dc5e
EC
173 skb = skb_clone(skb, GFP_ATOMIC);
174 if (skb == NULL)
175 return;
e407a7f6
EC
176 if (d->sendq_hd)
177 d->sendq_tl->next = skb;
178 else
179 d->sendq_hd = skb;
180 d->sendq_tl = skb;
1da177e4
LT
181}
182
3ae1c24e
EC
183/* some callers cannot sleep, and they can call this function,
184 * transmitting the packets later, when interrupts are on
185 */
186static struct sk_buff *
187aoecmd_cfg_pkts(ushort aoemajor, unsigned char aoeminor, struct sk_buff **tail)
188{
189 struct aoe_hdr *h;
190 struct aoe_cfghdr *ch;
191 struct sk_buff *skb, *sl, *sl_tail;
192 struct net_device *ifp;
193
194 sl = sl_tail = NULL;
195
196 read_lock(&dev_base_lock);
197 for (ifp = dev_base; ifp; dev_put(ifp), ifp = ifp->next) {
198 dev_hold(ifp);
199 if (!is_aoe_netif(ifp))
200 continue;
201
e407a7f6 202 skb = new_skb(sizeof *h + sizeof *ch);
3ae1c24e 203 if (skb == NULL) {
a12c93f0 204 printk(KERN_INFO "aoe: skb alloc failure\n");
3ae1c24e
EC
205 continue;
206 }
19900cde 207 skb_put(skb, sizeof *h + sizeof *ch);
e407a7f6 208 skb->dev = ifp;
3ae1c24e
EC
209 if (sl_tail == NULL)
210 sl_tail = skb;
029720f1 211 h = aoe_hdr(skb);
3ae1c24e
EC
212 memset(h, 0, sizeof *h + sizeof *ch);
213
214 memset(h->dst, 0xff, sizeof h->dst);
215 memcpy(h->src, ifp->dev_addr, sizeof h->src);
216 h->type = __constant_cpu_to_be16(ETH_P_AOE);
217 h->verfl = AOE_HVER;
218 h->major = cpu_to_be16(aoemajor);
219 h->minor = aoeminor;
220 h->cmd = AOECMD_CFG;
221
222 skb->next = sl;
223 sl = skb;
224 }
225 read_unlock(&dev_base_lock);
226
227 if (tail != NULL)
228 *tail = sl_tail;
229 return sl;
230}
231
4f51dc5e
EC
232static struct frame *
233freeframe(struct aoedev *d)
234{
235 struct frame *f, *e;
236 int n = 0;
237
238 f = d->frames;
239 e = f + d->nframes;
240 for (; f<e; f++) {
241 if (f->tag != FREETAG)
242 continue;
243 if (atomic_read(&skb_shinfo(f->skb)->dataref) == 1) {
244 skb_shinfo(f->skb)->nr_frags = f->skb->data_len = 0;
19900cde 245 skb_trim(f->skb, 0);
4f51dc5e
EC
246 return f;
247 }
248 n++;
249 }
250 if (n == d->nframes) /* wait for network layer */
251 d->flags |= DEVFL_KICKME;
252
253 return NULL;
254}
255
1da177e4
LT
256/* enters with d->lock held */
257void
258aoecmd_work(struct aoedev *d)
259{
260 struct frame *f;
261 struct buf *buf;
3ae1c24e
EC
262
263 if (d->flags & DEVFL_PAUSE) {
264 if (!aoedev_isbusy(d))
265 d->sendq_hd = aoecmd_cfg_pkts(d->aoemajor,
266 d->aoeminor, &d->sendq_tl);
267 return;
268 }
269
1da177e4 270loop:
4f51dc5e 271 f = freeframe(d);
1da177e4
LT
272 if (f == NULL)
273 return;
274 if (d->inprocess == NULL) {
275 if (list_empty(&d->bufq))
276 return;
277 buf = container_of(d->bufq.next, struct buf, bufs);
278 list_del(d->bufq.next);
a12c93f0 279/*printk(KERN_DEBUG "aoe: bi_size=%ld\n", buf->bio->bi_size); */
1da177e4
LT
280 d->inprocess = buf;
281 }
282 aoecmd_ata_rw(d, f);
283 goto loop;
284}
285
286static void
287rexmit(struct aoedev *d, struct frame *f)
288{
289 struct sk_buff *skb;
290 struct aoe_hdr *h;
19bf2635 291 struct aoe_atahdr *ah;
1da177e4
LT
292 char buf[128];
293 u32 n;
1da177e4
LT
294
295 n = newtag(d);
296
297 snprintf(buf, sizeof buf,
298 "%15s e%ld.%ld oldtag=%08x@%08lx newtag=%08x\n",
299 "retransmit",
300 d->aoemajor, d->aoeminor, f->tag, jiffies, n);
301 aoechr_error(buf);
302
e407a7f6 303 skb = f->skb;
029720f1 304 h = aoe_hdr(skb);
19bf2635 305 ah = (struct aoe_atahdr *) (h+1);
1da177e4 306 f->tag = n;
63e9cc5d 307 h->tag = cpu_to_be32(n);
2dd5e422
EC
308 memcpy(h->dst, d->addr, sizeof h->dst);
309 memcpy(h->src, d->ifp->dev_addr, sizeof h->src);
1da177e4 310
19bf2635
EC
311 n = DEFAULTBCNT / 512;
312 if (ah->scnt > n) {
313 ah->scnt = n;
4f51dc5e 314 if (ah->aflags & AOEAFL_WRITE) {
19bf2635
EC
315 skb_fill_page_desc(skb, 0, virt_to_page(f->bufaddr),
316 offset_in_page(f->bufaddr), DEFAULTBCNT);
4f51dc5e
EC
317 skb->len = sizeof *h + sizeof *ah + DEFAULTBCNT;
318 skb->data_len = DEFAULTBCNT;
319 }
19bf2635
EC
320 if (++d->lostjumbo > (d->nframes << 1))
321 if (d->maxbcnt != DEFAULTBCNT) {
a12c93f0 322 printk(KERN_INFO "aoe: e%ld.%ld: too many lost jumbo on %s - using 1KB frames.\n",
4f51dc5e 323 d->aoemajor, d->aoeminor, d->ifp->name);
19bf2635
EC
324 d->maxbcnt = DEFAULTBCNT;
325 d->flags |= DEVFL_MAXBCNT;
326 }
327 }
328
e407a7f6 329 skb->dev = d->ifp;
4f51dc5e
EC
330 skb = skb_clone(skb, GFP_ATOMIC);
331 if (skb == NULL)
332 return;
e407a7f6
EC
333 if (d->sendq_hd)
334 d->sendq_tl->next = skb;
335 else
336 d->sendq_hd = skb;
337 d->sendq_tl = skb;
1da177e4
LT
338}
339
340static int
341tsince(int tag)
342{
343 int n;
344
345 n = jiffies & 0xffff;
346 n -= tag & 0xffff;
347 if (n < 0)
348 n += 1<<16;
349 return n;
350}
351
352static void
353rexmit_timer(ulong vp)
354{
355 struct aoedev *d;
356 struct frame *f, *e;
357 struct sk_buff *sl;
358 register long timeout;
359 ulong flags, n;
360
361 d = (struct aoedev *) vp;
362 sl = NULL;
363
364 /* timeout is always ~150% of the moving average */
365 timeout = d->rttavg;
366 timeout += timeout >> 1;
367
368 spin_lock_irqsave(&d->lock, flags);
369
370 if (d->flags & DEVFL_TKILL) {
1c6f3fca 371 spin_unlock_irqrestore(&d->lock, flags);
1da177e4
LT
372 return;
373 }
374 f = d->frames;
375 e = f + d->nframes;
376 for (; f<e; f++) {
377 if (f->tag != FREETAG && tsince(f->tag) >= timeout) {
378 n = f->waited += timeout;
379 n /= HZ;
b751e8b6 380 if (n > aoe_deadsecs) { /* waited too long for response */
1da177e4 381 aoedev_downdev(d);
1c6f3fca 382 break;
1da177e4
LT
383 }
384 rexmit(d, f);
385 }
386 }
4f51dc5e
EC
387 if (d->flags & DEVFL_KICKME) {
388 d->flags &= ~DEVFL_KICKME;
389 aoecmd_work(d);
390 }
1da177e4 391
a4b38364 392 sl = d->sendq_hd;
393 d->sendq_hd = d->sendq_tl = NULL;
1da177e4
LT
394 if (sl) {
395 n = d->rttavg <<= 1;
396 if (n > MAXTIMER)
397 d->rttavg = MAXTIMER;
398 }
399
400 d->timer.expires = jiffies + TIMERTICK;
401 add_timer(&d->timer);
402
403 spin_unlock_irqrestore(&d->lock, flags);
404
405 aoenet_xmit(sl);
406}
407
3ae1c24e
EC
408/* this function performs work that has been deferred until sleeping is OK
409 */
410void
c4028958 411aoecmd_sleepwork(struct work_struct *work)
3ae1c24e 412{
c4028958 413 struct aoedev *d = container_of(work, struct aoedev, work);
3ae1c24e
EC
414
415 if (d->flags & DEVFL_GDALLOC)
416 aoeblk_gdalloc(d);
417
418 if (d->flags & DEVFL_NEWSIZE) {
419 struct block_device *bd;
420 unsigned long flags;
421 u64 ssize;
422
423 ssize = d->gd->capacity;
424 bd = bdget_disk(d->gd, 0);
425
426 if (bd) {
427 mutex_lock(&bd->bd_inode->i_mutex);
428 i_size_write(bd->bd_inode, (loff_t)ssize<<9);
429 mutex_unlock(&bd->bd_inode->i_mutex);
430 bdput(bd);
431 }
432 spin_lock_irqsave(&d->lock, flags);
433 d->flags |= DEVFL_UP;
434 d->flags &= ~DEVFL_NEWSIZE;
435 spin_unlock_irqrestore(&d->lock, flags);
436 }
437}
438
1da177e4
LT
439static void
440ataid_complete(struct aoedev *d, unsigned char *id)
441{
442 u64 ssize;
443 u16 n;
444
445 /* word 83: command set supported */
475172fb 446 n = le16_to_cpu(get_unaligned((__le16 *) &id[83<<1]));
1da177e4
LT
447
448 /* word 86: command set/feature enabled */
475172fb 449 n |= le16_to_cpu(get_unaligned((__le16 *) &id[86<<1]));
1da177e4
LT
450
451 if (n & (1<<10)) { /* bit 10: LBA 48 */
452 d->flags |= DEVFL_EXT;
453
454 /* word 100: number lba48 sectors */
475172fb 455 ssize = le64_to_cpu(get_unaligned((__le64 *) &id[100<<1]));
1da177e4
LT
456
457 /* set as in ide-disk.c:init_idedisk_capacity */
458 d->geo.cylinders = ssize;
459 d->geo.cylinders /= (255 * 63);
460 d->geo.heads = 255;
461 d->geo.sectors = 63;
462 } else {
463 d->flags &= ~DEVFL_EXT;
464
465 /* number lba28 sectors */
475172fb 466 ssize = le32_to_cpu(get_unaligned((__le32 *) &id[60<<1]));
1da177e4
LT
467
468 /* NOTE: obsolete in ATA 6 */
475172fb
EC
469 d->geo.cylinders = le16_to_cpu(get_unaligned((__le16 *) &id[54<<1]));
470 d->geo.heads = le16_to_cpu(get_unaligned((__le16 *) &id[55<<1]));
471 d->geo.sectors = le16_to_cpu(get_unaligned((__le16 *) &id[56<<1]));
1da177e4 472 }
3ae1c24e
EC
473
474 if (d->ssize != ssize)
a12c93f0 475 printk(KERN_INFO "aoe: %012llx e%lu.%lu v%04x has %llu sectors\n",
6bb6285f 476 (unsigned long long)mac_addr(d->addr),
3ae1c24e
EC
477 d->aoemajor, d->aoeminor,
478 d->fw_ver, (long long)ssize);
1da177e4
LT
479 d->ssize = ssize;
480 d->geo.start = 0;
481 if (d->gd != NULL) {
482 d->gd->capacity = ssize;
3ae1c24e
EC
483 d->flags |= DEVFL_NEWSIZE;
484 } else {
485 if (d->flags & DEVFL_GDALLOC) {
a12c93f0 486 printk(KERN_ERR "aoe: can't schedule work for e%lu.%lu, %s\n",
3ae1c24e 487 d->aoemajor, d->aoeminor,
6bb6285f 488 "it's already on! This shouldn't happen.\n");
3ae1c24e
EC
489 return;
490 }
491 d->flags |= DEVFL_GDALLOC;
1da177e4 492 }
1da177e4 493 schedule_work(&d->work);
1da177e4
LT
494}
495
496static void
497calc_rttavg(struct aoedev *d, int rtt)
498{
499 register long n;
500
501 n = rtt;
dced3a05
EC
502 if (n < 0) {
503 n = -rtt;
504 if (n < MINTIMER)
505 n = MINTIMER;
506 else if (n > MAXTIMER)
507 n = MAXTIMER;
508 d->mintimer += (n - d->mintimer) >> 1;
509 } else if (n < d->mintimer)
510 n = d->mintimer;
1da177e4
LT
511 else if (n > MAXTIMER)
512 n = MAXTIMER;
513
514 /* g == .25; cf. Congestion Avoidance and Control, Jacobson & Karels; 1988 */
515 n -= d->rttavg;
516 d->rttavg += n >> 2;
517}
518
519void
520aoecmd_ata_rsp(struct sk_buff *skb)
521{
522 struct aoedev *d;
ddec63e8 523 struct aoe_hdr *hin, *hout;
1da177e4
LT
524 struct aoe_atahdr *ahin, *ahout;
525 struct frame *f;
526 struct buf *buf;
527 struct sk_buff *sl;
528 register long n;
529 ulong flags;
530 char ebuf[128];
32465c65 531 u16 aoemajor;
532
029720f1 533 hin = aoe_hdr(skb);
43ecf529 534 aoemajor = be16_to_cpu(get_unaligned(&hin->major));
32465c65 535 d = aoedev_by_aoeaddr(aoemajor, hin->minor);
1da177e4
LT
536 if (d == NULL) {
537 snprintf(ebuf, sizeof ebuf, "aoecmd_ata_rsp: ata response "
538 "for unknown device %d.%d\n",
32465c65 539 aoemajor, hin->minor);
1da177e4
LT
540 aoechr_error(ebuf);
541 return;
542 }
543
544 spin_lock_irqsave(&d->lock, flags);
545
43ecf529 546 n = be32_to_cpu(get_unaligned(&hin->tag));
dced3a05 547 f = getframe(d, n);
1da177e4 548 if (f == NULL) {
dced3a05 549 calc_rttavg(d, -tsince(n));
1da177e4
LT
550 spin_unlock_irqrestore(&d->lock, flags);
551 snprintf(ebuf, sizeof ebuf,
552 "%15s e%d.%d tag=%08x@%08lx\n",
553 "unexpected rsp",
43ecf529 554 be16_to_cpu(get_unaligned(&hin->major)),
1da177e4 555 hin->minor,
43ecf529 556 be32_to_cpu(get_unaligned(&hin->tag)),
1da177e4
LT
557 jiffies);
558 aoechr_error(ebuf);
559 return;
560 }
561
562 calc_rttavg(d, tsince(f->tag));
563
564 ahin = (struct aoe_atahdr *) (hin+1);
029720f1 565 hout = aoe_hdr(f->skb);
ddec63e8 566 ahout = (struct aoe_atahdr *) (hout+1);
1da177e4
LT
567 buf = f->buf;
568
9d41965b
EC
569 if (ahout->cmdstat == WIN_IDENTIFY)
570 d->flags &= ~DEVFL_PAUSE;
1da177e4 571 if (ahin->cmdstat & 0xa9) { /* these bits cleared on success */
a12c93f0
EC
572 printk(KERN_ERR
573 "aoe: ata error cmd=%2.2Xh stat=%2.2Xh from e%ld.%ld\n",
1da177e4
LT
574 ahout->cmdstat, ahin->cmdstat,
575 d->aoemajor, d->aoeminor);
576 if (buf)
577 buf->flags |= BUFFL_FAIL;
578 } else {
19bf2635 579 n = ahout->scnt << 9;
1da177e4
LT
580 switch (ahout->cmdstat) {
581 case WIN_READ:
582 case WIN_READ_EXT:
1da177e4 583 if (skb->len - sizeof *hin - sizeof *ahin < n) {
a12c93f0
EC
584 printk(KERN_ERR
585 "aoe: runt data size in read. skb->len=%d\n",
1da177e4
LT
586 skb->len);
587 /* fail frame f? just returning will rexmit. */
588 spin_unlock_irqrestore(&d->lock, flags);
589 return;
590 }
591 memcpy(f->bufaddr, ahin+1, n);
592 case WIN_WRITE:
593 case WIN_WRITE_EXT:
19bf2635 594 if (f->bcnt -= n) {
4f51dc5e 595 skb = f->skb;
19bf2635
EC
596 f->bufaddr += n;
597 put_lba(ahout, f->lba += ahout->scnt);
6bb6285f
EC
598 n = f->bcnt;
599 if (n > DEFAULTBCNT)
600 n = DEFAULTBCNT;
19bf2635 601 ahout->scnt = n >> 9;
4f51dc5e
EC
602 if (ahout->aflags & AOEAFL_WRITE) {
603 skb_fill_page_desc(skb, 0,
6bb6285f 604 virt_to_page(f->bufaddr),
19bf2635 605 offset_in_page(f->bufaddr), n);
4f51dc5e
EC
606 skb->len = sizeof *hout + sizeof *ahout + n;
607 skb->data_len = n;
608 }
ddec63e8
EC
609 f->tag = newtag(d);
610 hout->tag = cpu_to_be32(f->tag);
611 skb->dev = d->ifp;
4f51dc5e 612 skb = skb_clone(skb, GFP_ATOMIC);
19bf2635 613 spin_unlock_irqrestore(&d->lock, flags);
4f51dc5e
EC
614 if (skb)
615 aoenet_xmit(skb);
19bf2635
EC
616 return;
617 }
618 if (n > DEFAULTBCNT)
619 d->lostjumbo = 0;
1da177e4
LT
620 break;
621 case WIN_IDENTIFY:
622 if (skb->len - sizeof *hin - sizeof *ahin < 512) {
a12c93f0
EC
623 printk(KERN_INFO
624 "aoe: runt data size in ataid. skb->len=%d\n",
6bb6285f 625 skb->len);
1da177e4
LT
626 spin_unlock_irqrestore(&d->lock, flags);
627 return;
628 }
629 ataid_complete(d, (char *) (ahin+1));
1da177e4
LT
630 break;
631 default:
a12c93f0
EC
632 printk(KERN_INFO
633 "aoe: unrecognized ata command %2.2Xh for %d.%d\n",
6bb6285f 634 ahout->cmdstat,
43ecf529 635 be16_to_cpu(get_unaligned(&hin->major)),
6bb6285f 636 hin->minor);
1da177e4
LT
637 }
638 }
639
640 if (buf) {
641 buf->nframesout -= 1;
642 if (buf->nframesout == 0 && buf->resid == 0) {
0c6f0e79 643 unsigned long duration = jiffies - buf->start_time;
644 unsigned long n_sect = buf->bio->bi_size >> 9;
645 struct gendisk *disk = d->gd;
496456c2 646 const int rw = bio_data_dir(buf->bio);
0c6f0e79 647
496456c2
JA
648 disk_stat_inc(disk, ios[rw]);
649 disk_stat_add(disk, ticks[rw], duration);
650 disk_stat_add(disk, sectors[rw], n_sect);
0c6f0e79 651 disk_stat_add(disk, io_ticks, duration);
1da177e4
LT
652 n = (buf->flags & BUFFL_FAIL) ? -EIO : 0;
653 bio_endio(buf->bio, buf->bio->bi_size, n);
654 mempool_free(buf, d->bufpool);
655 }
656 }
657
658 f->buf = NULL;
659 f->tag = FREETAG;
660
661 aoecmd_work(d);
a4b38364 662 sl = d->sendq_hd;
663 d->sendq_hd = d->sendq_tl = NULL;
1da177e4
LT
664
665 spin_unlock_irqrestore(&d->lock, flags);
1da177e4
LT
666 aoenet_xmit(sl);
667}
668
669void
670aoecmd_cfg(ushort aoemajor, unsigned char aoeminor)
671{
3ae1c24e 672 struct sk_buff *sl;
1da177e4 673
3ae1c24e 674 sl = aoecmd_cfg_pkts(aoemajor, aoeminor, NULL);
1da177e4
LT
675
676 aoenet_xmit(sl);
677}
678
679/*
680 * Since we only call this in one place (and it only prepares one frame)
a4b38364 681 * we just return the skb. Usually we'd chain it up to the aoedev sendq.
1da177e4
LT
682 */
683static struct sk_buff *
684aoecmd_ata_id(struct aoedev *d)
685{
686 struct aoe_hdr *h;
687 struct aoe_atahdr *ah;
688 struct frame *f;
689 struct sk_buff *skb;
690
4f51dc5e 691 f = freeframe(d);
1da177e4 692 if (f == NULL) {
a12c93f0 693 printk(KERN_ERR "aoe: can't get a frame. This shouldn't happen.\n");
1da177e4
LT
694 return NULL;
695 }
696
697 /* initialize the headers & frame */
e407a7f6 698 skb = f->skb;
029720f1 699 h = aoe_hdr(skb);
1da177e4 700 ah = (struct aoe_atahdr *) (h+1);
19900cde
EC
701 skb_put(skb, sizeof *h + sizeof *ah);
702 memset(h, 0, skb->len);
1da177e4
LT
703 f->tag = aoehdr_atainit(d, h);
704 f->waited = 0;
1da177e4 705
1da177e4
LT
706 /* set up ata header */
707 ah->scnt = 1;
708 ah->cmdstat = WIN_IDENTIFY;
709 ah->lba3 = 0xa0;
710
e407a7f6 711 skb->dev = d->ifp;
1da177e4 712
3ae1c24e 713 d->rttavg = MAXTIMER;
1da177e4 714 d->timer.function = rexmit_timer;
1da177e4 715
4f51dc5e 716 return skb_clone(skb, GFP_ATOMIC);
1da177e4
LT
717}
718
719void
720aoecmd_cfg_rsp(struct sk_buff *skb)
721{
722 struct aoedev *d;
723 struct aoe_hdr *h;
724 struct aoe_cfghdr *ch;
63e9cc5d 725 ulong flags, sysminor, aoemajor;
1da177e4 726 struct sk_buff *sl;
eaf0a3cb 727 enum { MAXFRAMES = 16 };
19bf2635 728 u16 n;
1da177e4 729
029720f1 730 h = aoe_hdr(skb);
1da177e4
LT
731 ch = (struct aoe_cfghdr *) (h+1);
732
733 /*
734 * Enough people have their dip switches set backwards to
735 * warrant a loud message for this special case.
736 */
43ecf529 737 aoemajor = be16_to_cpu(get_unaligned(&h->major));
1da177e4 738 if (aoemajor == 0xfff) {
a12c93f0 739 printk(KERN_ERR "aoe: Warning: shelf address is all ones. "
6bb6285f 740 "Check shelf dip switches.\n");
1da177e4
LT
741 return;
742 }
743
744 sysminor = SYSMINOR(aoemajor, h->minor);
fc458dcd 745 if (sysminor * AOE_PARTITIONS + AOE_PARTITIONS > MINORMASK) {
a12c93f0 746 printk(KERN_INFO "aoe: e%ld.%d: minor number too large\n",
fc458dcd 747 aoemajor, (int) h->minor);
1da177e4
LT
748 return;
749 }
750
19bf2635
EC
751 n = be16_to_cpu(ch->bufcnt);
752 if (n > MAXFRAMES) /* keep it reasonable */
753 n = MAXFRAMES;
1da177e4 754
19bf2635 755 d = aoedev_by_sysminor_m(sysminor, n);
1da177e4 756 if (d == NULL) {
a12c93f0 757 printk(KERN_INFO "aoe: device sysminor_m failure\n");
1da177e4
LT
758 return;
759 }
760
761 spin_lock_irqsave(&d->lock, flags);
762
3ae1c24e
EC
763 /* permit device to migrate mac and network interface */
764 d->ifp = skb->dev;
765 memcpy(d->addr, h->src, sizeof d->addr);
19bf2635
EC
766 if (!(d->flags & DEVFL_MAXBCNT)) {
767 n = d->ifp->mtu;
768 n -= sizeof (struct aoe_hdr) + sizeof (struct aoe_atahdr);
769 n /= 512;
770 if (n > ch->scnt)
771 n = ch->scnt;
4f51dc5e
EC
772 n = n ? n * 512 : DEFAULTBCNT;
773 if (n != d->maxbcnt) {
a12c93f0
EC
774 printk(KERN_INFO
775 "aoe: e%ld.%ld: setting %d byte data frames on %s\n",
4f51dc5e
EC
776 d->aoemajor, d->aoeminor, n, d->ifp->name);
777 d->maxbcnt = n;
778 }
19bf2635 779 }
3ae1c24e
EC
780
781 /* don't change users' perspective */
782 if (d->nopen && !(d->flags & DEVFL_PAUSE)) {
1da177e4
LT
783 spin_unlock_irqrestore(&d->lock, flags);
784 return;
785 }
3ae1c24e 786 d->flags |= DEVFL_PAUSE; /* force pause */
dced3a05 787 d->mintimer = MINTIMER;
63e9cc5d 788 d->fw_ver = be16_to_cpu(ch->fwver);
1da177e4 789
3ae1c24e
EC
790 /* check for already outstanding ataid */
791 sl = aoedev_isbusy(d) == 0 ? aoecmd_ata_id(d) : NULL;
1da177e4
LT
792
793 spin_unlock_irqrestore(&d->lock, flags);
794
795 aoenet_xmit(sl);
796}
797
This page took 0.241036 seconds and 5 git commands to generate.