8 #include <linux/slab.h>
12 #include <linux/netdevice.h>
18 #include <asm/unaligned.h>
19 #include <linux/uio.h>
24 static void ktcomplete(
struct frame *,
struct sk_buff *);
26 static struct buf *nextbuf(
struct aoedev *);
28 static int aoe_deadsecs = 60 * 3;
30 MODULE_PARM_DESC(aoe_deadsecs,
"After aoe_deadsecs seconds, give up and fail dev.");
32 static int aoe_maxout = 16;
35 "Only aoe_maxout outstanding packets for every MAC on eX.Y.");
53 skb_reset_mac_header(skb);
54 skb_reset_network_header(skb);
56 skb_checksum_none_assert(skb);
91 return n |= (++d->
lasttag & 0x7fff) << 16;
97 u32 host_tag = newtag(d);
115 ah->
lba1 = lba >>= 8;
116 ah->
lba2 = lba >>= 8;
117 ah->
lba3 = lba >>= 8;
118 ah->
lba4 = lba >>= 8;
119 ah->
lba5 = lba >>= 8;
122 static struct aoeif *
139 __skb_queue_tail(&d->
skbpool, skb);
143 skb_pool_get(
struct aoedev *d)
147 if (skb &&
atomic_read(&skb_shinfo(skb)->dataref) == 1) {
148 __skb_unlink(skb, &d->
skbpool);
170 static struct frame *
177 if (list_empty(&t->
ffree)) {
201 skb = skb_pool_get(d);
204 skb_pool_put(d, f->
skb);
209 skb_shinfo(skb)->nr_frags = skb->
data_len = 0;
214 static struct frame *
215 newframe(
struct aoedev *d)
258 fcnt = bv->bv_len - (off - bv->bv_offset);
261 skb_fill_page_desc(skb, frag++, bv->bv_page, off, fcnt);
271 fhash(
struct frame *f)
281 aoecmd_ata_rw(
struct aoedev *d)
291 char writebit, extbit;
306 if (bcnt > buf->
resid)
312 if (fbcnt < buf->bv_resid) {
319 if (buf->
resid == 0) {
330 h = (
struct aoe_hdr *) skb_mac_header(skb);
332 skb_put(skb,
sizeof *h +
sizeof *ah);
334 f->
tag = aoehdr_atainit(d, t, h);
343 ah->
scnt = bcnt >> 9;
352 if (bio_data_dir(buf->
bio) ==
WRITE) {
353 skb_fillup(skb, f->
bv, f->
bv_off, bcnt);
373 __skb_queue_head_init(&
queue);
374 __skb_queue_tail(&
queue, skb);
397 skb = new_skb(
sizeof *h +
sizeof *ch);
402 skb_put(skb,
sizeof *h +
sizeof *ch);
404 __skb_queue_tail(queue, skb);
405 h = (
struct aoe_hdr *) skb_mac_header(skb);
406 memset(h, 0,
sizeof *h +
sizeof *ch);
436 if (ifrotate(t) ==
NULL) {
438 pr_info(
"aoe: resend: no interfaces to rotate to.\n");
442 h = (
struct aoe_hdr *) skb_mac_header(skb);
446 "%15s e%ld.%d oldtag=%08x@%08lx newtag=%08x s=%pm d=%pm nout=%d\n",
461 __skb_queue_head_init(&queue);
462 __skb_queue_tail(&queue, skb);
478 static struct aoeif *
499 e = t->
ifs + NAOEIFS - 1;
500 n = (e - ifp) *
sizeof *ifp;
555 static inline unsigned char
556 ata_scnt(
unsigned char *
packet) {
566 rexmit_timer(
ulong vp)
582 timeout += timeout >> 1;
587 spin_unlock_irqrestore(&d->
lock, flags);
596 if (tsince(f->
tag) < timeout)
599 list_move_tail(pos, &flist);
605 for (; tt < te && (t = *
tt); tt++) {
606 if (t->nout == t->maxout
607 && t->maxout < t->nframes
608 && (jiffies - t->lastwadj)/
HZ > 10) {
614 if (!list_empty(&flist)) {
621 while (!list_empty(&flist)) {
626 if (n > aoe_deadsecs) {
631 list_splice(&flist, &d->
factive[0]);
638 if (n > aoe_deadsecs/2)
641 if (t->nout == t->maxout) {
647 ifp = getif(t, f->
skb->dev);
648 if (ifp && ++ifp->
lost > (t->nframes << 1)
649 && (ifp != t->ifs || t->ifs[1].
nd)) {
664 spin_unlock_irqrestore(&d->
lock, flags);
673 __rq_for_each_bio(bio, r)
689 bio_pageinc(
struct bio *bio)
695 bio_for_each_segment(bv, bio, i) {
703 pr_crit(
"page tail used for block I/O\n");
711 bio_pagedec(
struct bio *bio)
716 bio_for_each_segment(bv, bio, i)
725 memset(buf, 0,
sizeof(*buf));
728 buf->resid = bio->bi_size;
729 buf->sector = bio->bi_sector;
731 buf->bv = bv = &bio->bi_io_vec[bio->bi_idx];
732 buf->bv_resid = bv->bv_len;
756 d->
ip.nxbio = rq->bio;
757 rq->special = (
void *) rqbiocnt(rq);
761 pr_err(
"aoe: nextbuf: unable to mempool_alloc!\n");
765 bufinit(buf, rq, bio);
770 return d->
ip.buf =
buf;
777 if (d->
htgt && !sthtith(d))
779 while (aoecmd_ata_rw(d))
796 ssize = get_capacity(d->
gd);
800 i_size_write(bd->
bd_inode, (loff_t)ssize<<9);
804 spin_lock_irq(&d->
lock);
807 spin_unlock_irq(&d->
lock);
812 ataid_complete(
struct aoedev *d,
struct aoetgt *t,
unsigned char *
id)
818 n = get_unaligned_le16(&
id[83 << 1]);
821 n |= get_unaligned_le16(&
id[86 << 1]);
830 d->
geo.cylinders = ssize;
831 d->
geo.cylinders /= (255 * 63);
841 d->
geo.cylinders = get_unaligned_le16(&
id[54 << 1]);
842 d->
geo.heads = get_unaligned_le16(&
id[55 << 1]);
843 d->
geo.sectors = get_unaligned_le16(&
id[56 << 1]);
846 if (d->
ssize != ssize)
848 "aoe: %pm e%ld.%d v%04x has %llu sectors\n",
851 d->
fw_ver, (
long long)ssize);
857 set_capacity(d->
gd, ssize);
865 calc_rttavg(
struct aoedev *d,
int rtt)
877 }
else if (n < d->mintimer)
894 for (; t < e && *
t; t++)
895 if (
memcmp((*t)->addr, addr,
sizeof((*t)->addr)) == 0)
901 bvcpy(
struct bio_vec *bv,
ulong off,
struct sk_buff *skb,
long cnt)
907 fcnt = bv->bv_len - (off - bv->bv_offset);
933 bok = !fastfail &&
test_bit(BIO_UPTODATE, &bio->bi_flags);
942 aoe_end_buf(
struct aoedev *d,
struct buf *buf)
947 if (buf == d->
ip.buf)
950 bio_pagedec(buf->
bio);
952 n = (
unsigned long) rq->special;
953 rq->special = (
void *) --
n;
959 ktiocomplete(
struct frame *f)
976 hout = (
struct aoe_hdr *) skb_mac_header(f->
skb);
988 pr_err(
"aoe: ata error cmd=%2.2Xh stat=%2.2Xh from e%ld.%d\n",
996 n = ahout->
scnt << 9;
1001 pr_err(
"aoe: runt data size in read. skb->len=%d need=%ld\n",
1009 spin_lock_irq(&d->
lock);
1010 ifp = getif(t, skb->
dev);
1015 spin_unlock_irq(&d->
lock);
1018 if (skb->
len < 512) {
1019 pr_info(
"aoe: runt data size in ataid. skb->len=%d\n",
1023 if (skb_linearize(skb))
1025 spin_lock_irq(&d->
lock);
1026 ataid_complete(d, t, skb->
data);
1027 spin_unlock_irq(&d->
lock);
1030 pr_info(
"aoe: unrecognized ata command %2.2Xh for %d.%d\n",
1036 spin_lock_irq(&d->
lock);
1041 aoe_end_buf(d, buf);
1045 spin_unlock_irq(&d->
lock);
1060 for (i = 0; ; ++
i) {
1063 if (list_empty(&iocq.head))
1065 pos = iocq.head.next;
1067 spin_unlock_irq(&iocq.lock);
1070 spin_lock_irq(&iocq.lock);
1086 spin_lock_irq(k->
lock);
1092 spin_unlock_irq(k->
lock);
1115 init_completion(&k->
rendez);
1117 if (task ==
NULL || IS_ERR(task))
1121 init_completion(&k->
rendez);
1134 spin_unlock_irqrestore(&iocq.lock, flags);
1154 snprintf(ebuf,
sizeof ebuf,
"aoecmd_ata_rsp: ata response "
1155 "for unknown device %d.%d\n",
1156 aoemajor, h->
minor);
1166 calc_rttavg(d, -tsince(n));
1167 spin_unlock_irqrestore(&d->
lock, flags);
1170 "%15s e%d.%d tag=%08x@%08lx\n",
1172 get_unaligned_be16(&h->
major),
1180 calc_rttavg(d, tsince(f->
tag));
1184 spin_unlock_irqrestore(&d->
lock, flags);
1200 __skb_queue_head_init(&queue);
1201 aoecmd_cfg_pkts(aoemajor, aoeminor, &queue);
1222 h = (
struct aoe_hdr *) skb_mac_header(skb);
1224 skb_put(skb,
sizeof *h +
sizeof *ah);
1226 f->
tag = aoehdr_atainit(d, t, h);
1239 d->
timer.function = rexmit_timer;
1251 for (; tt < te && *
tt; tt++)
1256 "aoe: device addtgt failure; too many targets\n");
1271 INIT_LIST_HEAD(&t->
ffree);
1276 setdbcnt(
struct aoedev *d)
1283 for (; t < e && *
t; t++)
1284 if (bcnt == 0 || bcnt > (*t)->minbcnt)
1285 bcnt = (*t)->minbcnt;
1288 pr_info(
"aoe: e%ld.%d: setting %d byte data frames\n",
1304 for (; p <
e; p++) {
1310 }
else if (minbcnt > p->
bcnt)
1315 pr_err(
"aoe: device setifbcnt failure; too many interfaces.\n");
1339 h = (
struct aoe_hdr *) skb_mac_header(skb);
1346 aoemajor = get_unaligned_be16(&h->
major);
1347 if (aoemajor == 0xfff) {
1349 "Check shelf dip switches.\n");
1352 if (aoemajor == 0xffff) {
1353 pr_info(
"aoe: e%ld.%d: broadcast shelf number invalid\n",
1354 aoemajor, (
int) h->
minor);
1357 if (h->
minor == 0xff) {
1358 pr_info(
"aoe: e%ld.%d: broadcast slot number invalid\n",
1359 aoemajor, (
int) h->
minor);
1369 pr_info(
"aoe: device allocation failure\n");
1375 t = gettgt(d, h->
src);
1377 t = addtgt(d, h->
src, n);
1382 n -=
sizeof(
struct aoe_hdr) + sizeof(struct aoe_atahdr);
1387 setifbcnt(t, skb->
dev, n);
1390 if (d->
nopen == 0) {
1395 spin_unlock_irqrestore(&d->
lock, flags);
1398 __skb_queue_head_init(&queue);
1399 __skb_queue_tail(&queue, sl);
1414 for (; t < te && *
t; t++)
1415 (*t)->maxout = (*t)->nframes;
1426 aoe_end_buf(d, buf);
1440 list_splice_init(&iocq.head, &flist);
1441 spin_unlock_irqrestore(&iocq.lock, flags);
1442 while (!list_empty(&flist)) {
1450 f->
buf->nframesout--;
1454 spin_unlock_irqrestore(&d->
lock, flags);
1463 INIT_LIST_HEAD(&iocq.head);
1466 kts.name =
"aoe_ktio";
1468 kts.waitq = &ktiowq;
1469 kts.lock = &iocq.lock;