1 /* Copyright (c) 2007 Coraid, Inc. See COPYING for GPL terms. */
4 * Filesystem request handling methods
8 #include <linux/slab.h>
9 #include <linux/hdreg.h>
10 #include <linux/blkdev.h>
11 #include <linux/skbuff.h>
12 #include <linux/netdevice.h>
13 #include <linux/genhd.h>
14 #include <linux/moduleparam.h>
15 #include <linux/workqueue.h>
16 #include <linux/kthread.h>
17 #include <net/net_namespace.h>
18 #include <asm/unaligned.h>
19 #include <linux/uio.h>
22 #define MAXIOC (8192) /* default meant to avoid most soft lockups */
24 static void ktcomplete(struct frame *, struct sk_buff *);
26 static int aoe_deadsecs = 60 * 3;
27 module_param(aoe_deadsecs, int, 0644);
28 MODULE_PARM_DESC(aoe_deadsecs, "After aoe_deadsecs seconds, give up and fail dev.");
30 static int aoe_maxout = 16;
31 module_param(aoe_maxout, int, 0644);
32 MODULE_PARM_DESC(aoe_maxout,
33 "Only aoe_maxout outstanding packets for every MAC on eX.Y.");
35 static wait_queue_head_t ktiowq;
36 static struct ktstate kts;
38 /* io completion queue */
40 struct list_head head;
44 static struct sk_buff *
49 skb = alloc_skb(len, GFP_ATOMIC);
51 skb_reset_mac_header(skb);
52 skb_reset_network_header(skb);
53 skb->protocol = __constant_htons(ETH_P_AOE);
54 skb_checksum_none_assert(skb);
60 getframe(struct aoetgt *t, u32 tag)
63 struct list_head *head, *pos, *nx;
67 head = &t->factive[n];
68 list_for_each_safe(pos, nx, head) {
69 f = list_entry(pos, struct frame, head);
79 * Leave the top bit clear so we have tagspace for userland.
80 * The bottom 16 bits are the xmit tick for rexmit/rttavg processing.
81 * This driver reserves tag -1 to mean "unused frame."
84 newtag(struct aoetgt *t)
89 return n |= (++t->lasttag & 0x7fff) << 16;
93 aoehdr_atainit(struct aoedev *d, struct aoetgt *t, struct aoe_hdr *h)
95 u32 host_tag = newtag(t);
97 memcpy(h->src, t->ifp->nd->dev_addr, sizeof h->src);
98 memcpy(h->dst, t->addr, sizeof h->dst);
99 h->type = __constant_cpu_to_be16(ETH_P_AOE);
101 h->major = cpu_to_be16(d->aoemajor);
102 h->minor = d->aoeminor;
104 h->tag = cpu_to_be32(host_tag);
110 put_lba(struct aoe_atahdr *ah, sector_t lba)
113 ah->lba1 = lba >>= 8;
114 ah->lba2 = lba >>= 8;
115 ah->lba3 = lba >>= 8;
116 ah->lba4 = lba >>= 8;
117 ah->lba5 = lba >>= 8;
121 ifrotate(struct aoetgt *t)
124 if (t->ifp >= &t->ifs[NAOEIFS] || t->ifp->nd == NULL)
126 if (t->ifp->nd == NULL) {
127 printk(KERN_INFO "aoe: no interface to rotate to\n");
133 skb_pool_put(struct aoedev *d, struct sk_buff *skb)
135 __skb_queue_tail(&d->skbpool, skb);
138 static struct sk_buff *
139 skb_pool_get(struct aoedev *d)
141 struct sk_buff *skb = skb_peek(&d->skbpool);
143 if (skb && atomic_read(&skb_shinfo(skb)->dataref) == 1) {
144 __skb_unlink(skb, &d->skbpool);
147 if (skb_queue_len(&d->skbpool) < NSKBPOOLMAX &&
148 (skb = new_skb(ETH_ZLEN)))
155 aoe_freetframe(struct frame *f)
163 list_add(&f->head, &t->ffree);
166 static struct frame *
167 newtframe(struct aoedev *d, struct aoetgt *t)
171 struct list_head *pos;
173 if (list_empty(&t->ffree)) {
174 if (t->falloc >= NSKBPOOLMAX*2)
176 f = kcalloc(1, sizeof(*f), GFP_ATOMIC);
184 f = list_entry(pos, struct frame, head);
189 f->skb = skb = new_skb(ETH_ZLEN);
191 bail: aoe_freetframe(f);
196 if (atomic_read(&skb_shinfo(skb)->dataref) != 1) {
197 skb = skb_pool_get(d);
200 skb_pool_put(d, f->skb);
204 skb->truesize -= skb->data_len;
205 skb_shinfo(skb)->nr_frags = skb->data_len = 0;
210 static struct frame *
211 newframe(struct aoedev *d)
214 struct aoetgt *t, **tt;
217 if (d->targets[0] == NULL) { /* shouldn't happen, but I'm paranoid */
218 printk(KERN_ERR "aoe: NULL TARGETS!\n");
221 tt = d->tgt; /* last used target */
224 if (tt >= &d->targets[NTARGETS] || !*tt)
228 if (t->nout < t->maxout
238 if (tt == d->tgt) /* we've looped and found nada */
243 d->flags |= DEVFL_KICKME;
249 skb_fillup(struct sk_buff *skb, struct bio_vec *bv, ulong off, ulong cnt)
254 fcnt = bv->bv_len - (off - bv->bv_offset);
257 skb_fill_page_desc(skb, frag++, bv->bv_page, off, fcnt);
267 fhash(struct frame *f)
269 struct aoetgt *t = f->t;
272 n = f->tag % NFACTIVE;
273 list_add_tail(&f->head, &t->factive[n]);
277 aoecmd_ata_rw(struct aoedev *d)
281 struct aoe_atahdr *ah;
287 char writebit, extbit;
298 bcnt = t->ifp->maxbcnt;
301 if (bcnt > buf->resid)
305 f->bv_off = f->bv->bv_offset + (f->bv->bv_len - buf->bv_resid);
307 if (fbcnt < buf->bv_resid) {
308 buf->bv_resid -= fbcnt;
312 fbcnt -= buf->bv_resid;
313 buf->resid -= buf->bv_resid;
314 if (buf->resid == 0) {
319 buf->bv_resid = buf->bv->bv_len;
320 WARN_ON(buf->bv_resid == 0);
323 /* initialize the headers & frame */
325 h = (struct aoe_hdr *) skb_mac_header(skb);
326 ah = (struct aoe_atahdr *) (h+1);
327 skb_put(skb, sizeof *h + sizeof *ah);
328 memset(h, 0, skb->len);
329 f->tag = aoehdr_atainit(d, t, h);
335 f->lba = buf->sector;
337 /* set up ata header */
338 ah->scnt = bcnt >> 9;
339 put_lba(ah, buf->sector);
340 if (d->flags & DEVFL_EXT) {
341 ah->aflags |= AOEAFL_EXT;
345 ah->lba3 |= 0xe0; /* LBA bit + obsolete 0xa0 */
347 if (bio_data_dir(buf->bio) == WRITE) {
348 skb_fillup(skb, f->bv, f->bv_off, bcnt);
349 ah->aflags |= AOEAFL_WRITE;
351 skb->data_len = bcnt;
352 skb->truesize += bcnt;
359 ah->cmdstat = ATA_CMD_PIO_READ | writebit | extbit;
361 /* mark all tracking fields and load out */
362 buf->nframesout += 1;
363 buf->sector += bcnt >> 9;
365 skb->dev = t->ifp->nd;
366 skb = skb_clone(skb, GFP_ATOMIC);
368 __skb_queue_tail(&d->sendq, skb);
372 /* some callers cannot sleep, and they can call this function,
373 * transmitting the packets later, when interrupts are on
376 aoecmd_cfg_pkts(ushort aoemajor, unsigned char aoeminor, struct sk_buff_head *queue)
379 struct aoe_cfghdr *ch;
381 struct net_device *ifp;
384 for_each_netdev_rcu(&init_net, ifp) {
386 if (!is_aoe_netif(ifp))
389 skb = new_skb(sizeof *h + sizeof *ch);
391 printk(KERN_INFO "aoe: skb alloc failure\n");
394 skb_put(skb, sizeof *h + sizeof *ch);
396 __skb_queue_tail(queue, skb);
397 h = (struct aoe_hdr *) skb_mac_header(skb);
398 memset(h, 0, sizeof *h + sizeof *ch);
400 memset(h->dst, 0xff, sizeof h->dst);
401 memcpy(h->src, ifp->dev_addr, sizeof h->src);
402 h->type = __constant_cpu_to_be16(ETH_P_AOE);
404 h->major = cpu_to_be16(aoemajor);
415 resend(struct aoedev *d, struct frame *f)
419 struct aoe_atahdr *ah;
428 h = (struct aoe_hdr *) skb_mac_header(skb);
429 ah = (struct aoe_atahdr *) (h+1);
431 snprintf(buf, sizeof buf,
432 "%15s e%ld.%d oldtag=%08x@%08lx newtag=%08x s=%pm d=%pm nout=%d\n",
433 "retransmit", d->aoemajor, d->aoeminor, f->tag, jiffies, n,
434 h->src, h->dst, t->nout);
439 h->tag = cpu_to_be32(n);
440 memcpy(h->dst, t->addr, sizeof h->dst);
441 memcpy(h->src, t->ifp->nd->dev_addr, sizeof h->src);
443 skb->dev = t->ifp->nd;
444 skb = skb_clone(skb, GFP_ATOMIC);
447 __skb_queue_tail(&d->sendq, skb);
455 n = jiffies & 0xffff;
462 static struct aoeif *
463 getif(struct aoetgt *t, struct net_device *nd)
475 static struct aoeif *
476 addif(struct aoetgt *t, struct net_device *nd)
484 p->maxbcnt = DEFAULTBCNT;
491 ejectif(struct aoetgt *t, struct aoeif *ifp)
496 e = t->ifs + NAOEIFS - 1;
497 n = (e - ifp) * sizeof *ifp;
498 memmove(ifp, ifp+1, n);
503 sthtith(struct aoedev *d)
505 struct frame *f, *nf;
506 struct list_head *nx, *pos, *head;
508 struct aoetgt *ht = d->htgt;
511 for (i = 0; i < NFACTIVE; i++) {
512 head = &ht->factive[i];
513 list_for_each_safe(pos, nx, head) {
514 f = list_entry(pos, struct frame, head);
519 /* remove frame from active list */
522 /* reassign all pertinent bits to new outbound frame */
529 nf->bv_off = f->bv_off;
538 /* he's clean, he's useless. take away his interfaces */
539 memset(ht->ifs, 0, sizeof ht->ifs);
544 static inline unsigned char
545 ata_scnt(unsigned char *packet) {
547 struct aoe_atahdr *ah;
549 h = (struct aoe_hdr *) packet;
550 ah = (struct aoe_atahdr *) (h+1);
555 rexmit_timer(ulong vp)
557 struct sk_buff_head queue;
559 struct aoetgt *t, **tt, **te;
562 struct list_head *head, *pos, *nx;
564 register long timeout;
568 d = (struct aoedev *) vp;
570 /* timeout is always ~150% of the moving average */
572 timeout += timeout >> 1;
574 spin_lock_irqsave(&d->lock, flags);
576 if (d->flags & DEVFL_TKILL) {
577 spin_unlock_irqrestore(&d->lock, flags);
581 /* collect all frames to rexmit into flist */
584 for (; tt < te && *tt; tt++) {
586 for (i = 0; i < NFACTIVE; i++) {
587 head = &t->factive[i];
588 list_for_each_safe(pos, nx, head) {
589 f = list_entry(pos, struct frame, head);
590 if (tsince(f->tag) < timeout)
592 /* move to flist for later processing */
593 list_move_tail(pos, &flist);
598 if (t->nout == t->maxout
599 && t->maxout < t->nframes
600 && (jiffies - t->lastwadj)/HZ > 10) {
602 t->lastwadj = jiffies;
606 /* process expired frames */
607 while (!list_empty(&flist)) {
609 f = list_entry(pos, struct frame, head);
610 n = f->waited += timeout;
612 if (n > aoe_deadsecs) {
613 /* Waited too long. Device failure.
614 * Hang all frames on first hash bucket for downdev
617 list_splice(&flist, &f->t->factive[0]);
625 /* see if another target can help */
629 if (t->nout == t->maxout) {
632 t->lastwadj = jiffies;
635 ifp = getif(t, f->skb->dev);
636 if (ifp && ++ifp->lost > (t->nframes << 1)
637 && (ifp != t->ifs || t->ifs[1].nd)) {
644 if (!skb_queue_empty(&d->sendq)) {
647 d->rttavg = MAXTIMER;
650 if (d->flags & DEVFL_KICKME || d->htgt) {
651 d->flags &= ~DEVFL_KICKME;
655 __skb_queue_head_init(&queue);
656 skb_queue_splice_init(&d->sendq, &queue);
658 d->timer.expires = jiffies + TIMERTICK;
659 add_timer(&d->timer);
661 spin_unlock_irqrestore(&d->lock, flags);
666 /* enters with d->lock held */
668 aoecmd_work(struct aoedev *d)
672 if (d->htgt && !sthtith(d))
674 if (d->inprocess == NULL) {
675 if (list_empty(&d->bufq))
677 buf = container_of(d->bufq.next, struct buf, bufs);
678 list_del(d->bufq.next);
681 if (aoecmd_ata_rw(d))
685 /* this function performs work that has been deferred until sleeping is OK
688 aoecmd_sleepwork(struct work_struct *work)
690 struct aoedev *d = container_of(work, struct aoedev, work);
692 if (d->flags & DEVFL_GDALLOC)
695 if (d->flags & DEVFL_NEWSIZE) {
696 struct block_device *bd;
700 ssize = get_capacity(d->gd);
701 bd = bdget_disk(d->gd, 0);
704 mutex_lock(&bd->bd_inode->i_mutex);
705 i_size_write(bd->bd_inode, (loff_t)ssize<<9);
706 mutex_unlock(&bd->bd_inode->i_mutex);
709 spin_lock_irqsave(&d->lock, flags);
710 d->flags |= DEVFL_UP;
711 d->flags &= ~DEVFL_NEWSIZE;
712 spin_unlock_irqrestore(&d->lock, flags);
717 ataid_complete(struct aoedev *d, struct aoetgt *t, unsigned char *id)
722 /* word 83: command set supported */
723 n = get_unaligned_le16(&id[83 << 1]);
725 /* word 86: command set/feature enabled */
726 n |= get_unaligned_le16(&id[86 << 1]);
728 if (n & (1<<10)) { /* bit 10: LBA 48 */
729 d->flags |= DEVFL_EXT;
731 /* word 100: number lba48 sectors */
732 ssize = get_unaligned_le64(&id[100 << 1]);
734 /* set as in ide-disk.c:init_idedisk_capacity */
735 d->geo.cylinders = ssize;
736 d->geo.cylinders /= (255 * 63);
740 d->flags &= ~DEVFL_EXT;
742 /* number lba28 sectors */
743 ssize = get_unaligned_le32(&id[60 << 1]);
745 /* NOTE: obsolete in ATA 6 */
746 d->geo.cylinders = get_unaligned_le16(&id[54 << 1]);
747 d->geo.heads = get_unaligned_le16(&id[55 << 1]);
748 d->geo.sectors = get_unaligned_le16(&id[56 << 1]);
751 if (d->ssize != ssize)
753 "aoe: %pm e%ld.%d v%04x has %llu sectors\n",
755 d->aoemajor, d->aoeminor,
756 d->fw_ver, (long long)ssize);
759 if (d->flags & (DEVFL_GDALLOC|DEVFL_NEWSIZE))
762 set_capacity(d->gd, ssize);
763 d->flags |= DEVFL_NEWSIZE;
765 d->flags |= DEVFL_GDALLOC;
766 schedule_work(&d->work);
770 calc_rttavg(struct aoedev *d, int rtt)
779 else if (n > MAXTIMER)
781 d->mintimer += (n - d->mintimer) >> 1;
782 } else if (n < d->mintimer)
784 else if (n > MAXTIMER)
787 /* g == .25; cf. Congestion Avoidance and Control, Jacobson & Karels; 1988 */
792 static struct aoetgt *
793 gettgt(struct aoedev *d, char *addr)
795 struct aoetgt **t, **e;
799 for (; t < e && *t; t++)
800 if (memcmp((*t)->addr, addr, sizeof((*t)->addr)) == 0)
806 diskstats(struct gendisk *disk, struct bio *bio, ulong duration, sector_t sector)
808 unsigned long n_sect = bio->bi_size >> 9;
809 const int rw = bio_data_dir(bio);
810 struct hd_struct *part;
813 cpu = part_stat_lock();
814 part = disk_map_sector_rcu(disk, sector);
816 part_stat_inc(cpu, part, ios[rw]);
817 part_stat_add(cpu, part, ticks[rw], duration);
818 part_stat_add(cpu, part, sectors[rw], n_sect);
819 part_stat_add(cpu, part, io_ticks, duration);
825 bvcpy(struct bio_vec *bv, ulong off, struct sk_buff *skb, long cnt)
831 fcnt = bv->bv_len - (off - bv->bv_offset);
834 p = page_address(bv->bv_page) + off;
835 skb_copy_bits(skb, soff, p, fcnt);
846 ktiocomplete(struct frame *f)
848 struct aoe_hdr *hin, *hout;
849 struct aoe_atahdr *ahin, *ahout;
863 hout = (struct aoe_hdr *) skb_mac_header(f->skb);
864 ahout = (struct aoe_atahdr *) (hout+1);
868 goto noskb; /* just fail the buf. */
870 hin = (struct aoe_hdr *) skb->data;
871 skb_pull(skb, sizeof(*hin));
872 ahin = (struct aoe_atahdr *) skb->data;
873 skb_pull(skb, sizeof(*ahin));
874 if (ahin->cmdstat & 0xa9) { /* these bits cleared on success */
875 pr_err("aoe: ata error cmd=%2.2Xh stat=%2.2Xh from e%ld.%d\n",
876 ahout->cmdstat, ahin->cmdstat,
877 d->aoemajor, d->aoeminor);
879 buf->flags |= BUFFL_FAIL;
883 n = ahout->scnt << 9;
884 switch (ahout->cmdstat) {
885 case ATA_CMD_PIO_READ:
886 case ATA_CMD_PIO_READ_EXT:
888 pr_err("aoe: runt data size in read. skb->len=%d need=%ld\n",
890 buf->flags |= BUFFL_FAIL;
893 bvcpy(f->bv, f->bv_off, skb, n);
894 case ATA_CMD_PIO_WRITE:
895 case ATA_CMD_PIO_WRITE_EXT:
896 spin_lock_irq(&d->lock);
897 ifp = getif(t, skb->dev);
903 if (d->htgt == t) /* I'll help myself, thank you. */
905 spin_unlock_irq(&d->lock);
908 if (skb->len < 512) {
909 pr_info("aoe: runt data size in ataid. skb->len=%d\n",
913 if (skb_linearize(skb))
915 spin_lock_irq(&d->lock);
916 ataid_complete(d, t, skb->data);
917 spin_unlock_irq(&d->lock);
920 pr_info("aoe: unrecognized ata command %2.2Xh for %d.%d\n",
922 be16_to_cpu(get_unaligned(&hin->major)),
926 spin_lock_irq(&d->lock);
930 if (buf && --buf->nframesout == 0 && buf->resid == 0) {
931 struct bio *bio = buf->bio;
933 diskstats(d->gd, bio, jiffies - buf->stime, buf->sector);
934 n = (buf->flags & BUFFL_FAIL) ? -EIO : 0;
935 mempool_free(buf, d->bufpool);
936 spin_unlock_irq(&d->lock);
938 bio_flush_dcache_pages(buf->bio);
941 spin_unlock_irq(&d->lock);
945 /* Enters with iocq.lock held.
946 * Returns true iff responses needing processing remain.
952 struct list_head *pos;
958 if (list_empty(&iocq.head))
960 pos = iocq.head.next;
962 spin_unlock_irq(&iocq.lock);
963 f = list_entry(pos, struct frame, head);
965 spin_lock_irq(&iocq.lock);
973 DECLARE_WAITQUEUE(wait, current);
977 current->flags |= PF_NOFREEZE;
978 set_user_nice(current, -10);
979 complete(&k->rendez); /* tell spawner we're running */
981 spin_lock_irq(k->lock);
984 add_wait_queue(k->waitq, &wait);
985 __set_current_state(TASK_INTERRUPTIBLE);
987 spin_unlock_irq(k->lock);
990 remove_wait_queue(k->waitq, &wait);
993 } while (!kthread_should_stop());
994 complete(&k->rendez); /* tell spawner we're stopping */
999 aoe_ktstop(struct ktstate *k)
1001 kthread_stop(k->task);
1002 wait_for_completion(&k->rendez);
1006 aoe_ktstart(struct ktstate *k)
1008 struct task_struct *task;
1010 init_completion(&k->rendez);
1011 task = kthread_run(kthread, k, k->name);
1012 if (task == NULL || IS_ERR(task))
1015 wait_for_completion(&k->rendez); /* allow kthread to start */
1016 init_completion(&k->rendez); /* for waiting for exit later */
1020 /* pass it off to kthreads for processing */
1022 ktcomplete(struct frame *f, struct sk_buff *skb)
1027 spin_lock_irqsave(&iocq.lock, flags);
1028 list_add_tail(&f->head, &iocq.head);
1029 spin_unlock_irqrestore(&iocq.lock, flags);
1034 aoecmd_ata_rsp(struct sk_buff *skb)
1045 h = (struct aoe_hdr *) skb->data;
1046 aoemajor = be16_to_cpu(get_unaligned(&h->major));
1047 d = aoedev_by_aoeaddr(aoemajor, h->minor);
1049 snprintf(ebuf, sizeof ebuf, "aoecmd_ata_rsp: ata response "
1050 "for unknown device %d.%d\n",
1051 aoemajor, h->minor);
1056 spin_lock_irqsave(&d->lock, flags);
1058 n = be32_to_cpu(get_unaligned(&h->tag));
1059 t = gettgt(d, h->src);
1061 printk(KERN_INFO "aoe: can't find target e%ld.%d:%pm\n",
1062 d->aoemajor, d->aoeminor, h->src);
1063 spin_unlock_irqrestore(&d->lock, flags);
1068 calc_rttavg(d, -tsince(n));
1069 spin_unlock_irqrestore(&d->lock, flags);
1070 snprintf(ebuf, sizeof ebuf,
1071 "%15s e%d.%d tag=%08x@%08lx\n",
1073 get_unaligned_be16(&h->major),
1075 get_unaligned_be32(&h->tag),
1080 calc_rttavg(d, tsince(f->tag));
1084 spin_unlock_irqrestore(&d->lock, flags);
1089 * Note here that we do not perform an aoedev_put, as we are
1090 * leaving this reference for the ktio to release.
1096 aoecmd_cfg(ushort aoemajor, unsigned char aoeminor)
1098 struct sk_buff_head queue;
1100 __skb_queue_head_init(&queue);
1101 aoecmd_cfg_pkts(aoemajor, aoeminor, &queue);
1102 aoenet_xmit(&queue);
1106 aoecmd_ata_id(struct aoedev *d)
1109 struct aoe_atahdr *ah;
1111 struct sk_buff *skb;
1120 /* initialize the headers & frame */
1122 h = (struct aoe_hdr *) skb_mac_header(skb);
1123 ah = (struct aoe_atahdr *) (h+1);
1124 skb_put(skb, sizeof *h + sizeof *ah);
1125 memset(h, 0, skb->len);
1126 f->tag = aoehdr_atainit(d, t, h);
1131 /* set up ata header */
1133 ah->cmdstat = ATA_CMD_ID_ATA;
1136 skb->dev = t->ifp->nd;
1138 d->rttavg = MAXTIMER;
1139 d->timer.function = rexmit_timer;
1141 return skb_clone(skb, GFP_ATOMIC);
1144 static struct aoetgt *
1145 addtgt(struct aoedev *d, char *addr, ulong nframes)
1147 struct aoetgt *t, **tt, **te;
1152 for (; tt < te && *tt; tt++)
1157 "aoe: device addtgt failure; too many targets\n");
1160 t = kzalloc(sizeof(*t), GFP_ATOMIC);
1162 printk(KERN_INFO "aoe: cannot allocate memory to add target\n");
1167 t->nframes = nframes;
1169 memcpy(t->addr, addr, sizeof t->addr);
1171 t->maxout = t->nframes;
1172 INIT_LIST_HEAD(&t->ffree);
1173 for (i = 0; i < NFACTIVE; ++i)
1174 INIT_LIST_HEAD(&t->factive[i]);
1179 aoecmd_cfg_rsp(struct sk_buff *skb)
1183 struct aoe_cfghdr *ch;
1186 ulong flags, sysminor, aoemajor;
1190 h = (struct aoe_hdr *) skb_mac_header(skb);
1191 ch = (struct aoe_cfghdr *) (h+1);
1194 * Enough people have their dip switches set backwards to
1195 * warrant a loud message for this special case.
1197 aoemajor = get_unaligned_be16(&h->major);
1198 if (aoemajor == 0xfff) {
1199 printk(KERN_ERR "aoe: Warning: shelf address is all ones. "
1200 "Check shelf dip switches.\n");
1204 sysminor = SYSMINOR(aoemajor, h->minor);
1205 if (sysminor * AOE_PARTITIONS + AOE_PARTITIONS > MINORMASK) {
1206 printk(KERN_INFO "aoe: e%ld.%d: minor number too large\n",
1207 aoemajor, (int) h->minor);
1211 n = be16_to_cpu(ch->bufcnt);
1212 if (n > aoe_maxout) /* keep it reasonable */
1215 d = aoedev_by_sysminor_m(sysminor);
1217 printk(KERN_INFO "aoe: device sysminor_m failure\n");
1221 spin_lock_irqsave(&d->lock, flags);
1223 t = gettgt(d, h->src);
1225 t = addtgt(d, h->src, n);
1227 spin_unlock_irqrestore(&d->lock, flags);
1231 ifp = getif(t, skb->dev);
1233 ifp = addif(t, skb->dev);
1236 "aoe: device addif failure; "
1237 "too many interfaces?\n");
1238 spin_unlock_irqrestore(&d->lock, flags);
1244 n -= sizeof (struct aoe_hdr) + sizeof (struct aoe_atahdr);
1248 n = n ? n * 512 : DEFAULTBCNT;
1249 if (n != ifp->maxbcnt) {
1251 "aoe: e%ld.%d: setting %d%s%s:%pm\n",
1252 d->aoemajor, d->aoeminor, n,
1253 " byte data frames on ", ifp->nd->name,
1259 /* don't change users' perspective */
1261 spin_unlock_irqrestore(&d->lock, flags);
1264 d->fw_ver = be16_to_cpu(ch->fwver);
1266 sl = aoecmd_ata_id(d);
1268 spin_unlock_irqrestore(&d->lock, flags);
1271 struct sk_buff_head queue;
1272 __skb_queue_head_init(&queue);
1273 __skb_queue_tail(&queue, sl);
1274 aoenet_xmit(&queue);
1279 aoecmd_cleanslate(struct aoedev *d)
1281 struct aoetgt **t, **te;
1282 struct aoeif *p, *e;
1284 d->mintimer = MINTIMER;
1288 for (; t < te && *t; t++) {
1289 (*t)->maxout = (*t)->nframes;
1292 for (; p < e; p++) {
1295 p->maxbcnt = DEFAULTBCNT;
1306 struct list_head *pos;
1307 struct sk_buff *skb;
1310 spin_lock_irqsave(&iocq.lock, flags);
1311 list_splice_init(&iocq.head, &flist);
1312 spin_unlock_irqrestore(&iocq.lock, flags);
1313 while (!list_empty(&flist)) {
1316 f = list_entry(pos, struct frame, head);
1319 spin_lock_irqsave(&d->lock, flags);
1321 f->buf->nframesout--;
1322 aoe_failbuf(d, f->buf);
1325 spin_unlock_irqrestore(&d->lock, flags);
1333 INIT_LIST_HEAD(&iocq.head);
1334 spin_lock_init(&iocq.lock);
1335 init_waitqueue_head(&ktiowq);
1336 kts.name = "aoe_ktio";
1338 kts.waitq = &ktiowq;
1339 kts.lock = &iocq.lock;
1340 return aoe_ktstart(&kts);