aoecmd.c 16 KB

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