aoecmd.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  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, ETH_ZLEN);
  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. skb->len += bcnt;
  127. skb->data_len = bcnt;
  128. } else {
  129. skb->len = ETH_ZLEN;
  130. writebit = 0;
  131. }
  132. ah->cmdstat = WIN_READ | writebit | extbit;
  133. /* mark all tracking fields and load out */
  134. buf->nframesout += 1;
  135. buf->bufaddr += bcnt;
  136. buf->bv_resid -= bcnt;
  137. /* dprintk("bv_resid=%ld\n", buf->bv_resid); */
  138. buf->resid -= bcnt;
  139. buf->sector += bcnt >> 9;
  140. if (buf->resid == 0) {
  141. d->inprocess = NULL;
  142. } else if (buf->bv_resid == 0) {
  143. buf->bv++;
  144. buf->bv_resid = buf->bv->bv_len;
  145. buf->bufaddr = page_address(buf->bv->bv_page) + buf->bv->bv_offset;
  146. }
  147. skb->dev = d->ifp;
  148. skb = skb_clone(skb, GFP_ATOMIC);
  149. if (skb == NULL)
  150. return;
  151. if (d->sendq_hd)
  152. d->sendq_tl->next = skb;
  153. else
  154. d->sendq_hd = skb;
  155. d->sendq_tl = skb;
  156. }
  157. /* some callers cannot sleep, and they can call this function,
  158. * transmitting the packets later, when interrupts are on
  159. */
  160. static struct sk_buff *
  161. aoecmd_cfg_pkts(ushort aoemajor, unsigned char aoeminor, struct sk_buff **tail)
  162. {
  163. struct aoe_hdr *h;
  164. struct aoe_cfghdr *ch;
  165. struct sk_buff *skb, *sl, *sl_tail;
  166. struct net_device *ifp;
  167. sl = sl_tail = NULL;
  168. read_lock(&dev_base_lock);
  169. for (ifp = dev_base; ifp; dev_put(ifp), ifp = ifp->next) {
  170. dev_hold(ifp);
  171. if (!is_aoe_netif(ifp))
  172. continue;
  173. skb = new_skb(sizeof *h + sizeof *ch);
  174. if (skb == NULL) {
  175. iprintk("skb alloc failure\n");
  176. continue;
  177. }
  178. skb->dev = ifp;
  179. if (sl_tail == NULL)
  180. sl_tail = skb;
  181. h = (struct aoe_hdr *) skb->mac.raw;
  182. memset(h, 0, sizeof *h + sizeof *ch);
  183. memset(h->dst, 0xff, sizeof h->dst);
  184. memcpy(h->src, ifp->dev_addr, sizeof h->src);
  185. h->type = __constant_cpu_to_be16(ETH_P_AOE);
  186. h->verfl = AOE_HVER;
  187. h->major = cpu_to_be16(aoemajor);
  188. h->minor = aoeminor;
  189. h->cmd = AOECMD_CFG;
  190. skb->next = sl;
  191. sl = skb;
  192. }
  193. read_unlock(&dev_base_lock);
  194. if (tail != NULL)
  195. *tail = sl_tail;
  196. return sl;
  197. }
  198. static struct frame *
  199. freeframe(struct aoedev *d)
  200. {
  201. struct frame *f, *e;
  202. int n = 0;
  203. f = d->frames;
  204. e = f + d->nframes;
  205. for (; f<e; f++) {
  206. if (f->tag != FREETAG)
  207. continue;
  208. if (atomic_read(&skb_shinfo(f->skb)->dataref) == 1) {
  209. skb_shinfo(f->skb)->nr_frags = f->skb->data_len = 0;
  210. return f;
  211. }
  212. n++;
  213. }
  214. if (n == d->nframes) /* wait for network layer */
  215. d->flags |= DEVFL_KICKME;
  216. return NULL;
  217. }
  218. /* enters with d->lock held */
  219. void
  220. aoecmd_work(struct aoedev *d)
  221. {
  222. struct frame *f;
  223. struct buf *buf;
  224. if (d->flags & DEVFL_PAUSE) {
  225. if (!aoedev_isbusy(d))
  226. d->sendq_hd = aoecmd_cfg_pkts(d->aoemajor,
  227. d->aoeminor, &d->sendq_tl);
  228. return;
  229. }
  230. loop:
  231. f = freeframe(d);
  232. if (f == NULL)
  233. return;
  234. if (d->inprocess == NULL) {
  235. if (list_empty(&d->bufq))
  236. return;
  237. buf = container_of(d->bufq.next, struct buf, bufs);
  238. list_del(d->bufq.next);
  239. /*dprintk("bi_size=%ld\n", buf->bio->bi_size); */
  240. d->inprocess = buf;
  241. }
  242. aoecmd_ata_rw(d, f);
  243. goto loop;
  244. }
  245. static void
  246. rexmit(struct aoedev *d, struct frame *f)
  247. {
  248. struct sk_buff *skb;
  249. struct aoe_hdr *h;
  250. struct aoe_atahdr *ah;
  251. char buf[128];
  252. u32 n;
  253. n = newtag(d);
  254. snprintf(buf, sizeof buf,
  255. "%15s e%ld.%ld oldtag=%08x@%08lx newtag=%08x\n",
  256. "retransmit",
  257. d->aoemajor, d->aoeminor, f->tag, jiffies, n);
  258. aoechr_error(buf);
  259. skb = f->skb;
  260. h = (struct aoe_hdr *) skb->mac.raw;
  261. ah = (struct aoe_atahdr *) (h+1);
  262. f->tag = n;
  263. h->tag = cpu_to_be32(n);
  264. memcpy(h->dst, d->addr, sizeof h->dst);
  265. memcpy(h->src, d->ifp->dev_addr, sizeof h->src);
  266. n = DEFAULTBCNT / 512;
  267. if (ah->scnt > n) {
  268. ah->scnt = n;
  269. if (ah->aflags & AOEAFL_WRITE) {
  270. skb_fill_page_desc(skb, 0, virt_to_page(f->bufaddr),
  271. offset_in_page(f->bufaddr), DEFAULTBCNT);
  272. skb->len = sizeof *h + sizeof *ah + DEFAULTBCNT;
  273. skb->data_len = DEFAULTBCNT;
  274. }
  275. if (++d->lostjumbo > (d->nframes << 1))
  276. if (d->maxbcnt != DEFAULTBCNT) {
  277. iprintk("e%ld.%ld: too many lost jumbo on %s - using 1KB frames.\n",
  278. d->aoemajor, d->aoeminor, d->ifp->name);
  279. d->maxbcnt = DEFAULTBCNT;
  280. d->flags |= DEVFL_MAXBCNT;
  281. }
  282. }
  283. skb->dev = d->ifp;
  284. skb = skb_clone(skb, GFP_ATOMIC);
  285. if (skb == NULL)
  286. return;
  287. if (d->sendq_hd)
  288. d->sendq_tl->next = skb;
  289. else
  290. d->sendq_hd = skb;
  291. d->sendq_tl = skb;
  292. }
  293. static int
  294. tsince(int tag)
  295. {
  296. int n;
  297. n = jiffies & 0xffff;
  298. n -= tag & 0xffff;
  299. if (n < 0)
  300. n += 1<<16;
  301. return n;
  302. }
  303. static void
  304. rexmit_timer(ulong vp)
  305. {
  306. struct aoedev *d;
  307. struct frame *f, *e;
  308. struct sk_buff *sl;
  309. register long timeout;
  310. ulong flags, n;
  311. d = (struct aoedev *) vp;
  312. sl = NULL;
  313. /* timeout is always ~150% of the moving average */
  314. timeout = d->rttavg;
  315. timeout += timeout >> 1;
  316. spin_lock_irqsave(&d->lock, flags);
  317. if (d->flags & DEVFL_TKILL) {
  318. spin_unlock_irqrestore(&d->lock, flags);
  319. return;
  320. }
  321. f = d->frames;
  322. e = f + d->nframes;
  323. for (; f<e; f++) {
  324. if (f->tag != FREETAG && tsince(f->tag) >= timeout) {
  325. n = f->waited += timeout;
  326. n /= HZ;
  327. if (n > MAXWAIT) { /* waited too long. device failure. */
  328. aoedev_downdev(d);
  329. break;
  330. }
  331. rexmit(d, f);
  332. }
  333. }
  334. if (d->flags & DEVFL_KICKME) {
  335. d->flags &= ~DEVFL_KICKME;
  336. aoecmd_work(d);
  337. }
  338. sl = d->sendq_hd;
  339. d->sendq_hd = d->sendq_tl = NULL;
  340. if (sl) {
  341. n = d->rttavg <<= 1;
  342. if (n > MAXTIMER)
  343. d->rttavg = MAXTIMER;
  344. }
  345. d->timer.expires = jiffies + TIMERTICK;
  346. add_timer(&d->timer);
  347. spin_unlock_irqrestore(&d->lock, flags);
  348. aoenet_xmit(sl);
  349. }
  350. /* this function performs work that has been deferred until sleeping is OK
  351. */
  352. void
  353. aoecmd_sleepwork(void *vp)
  354. {
  355. struct aoedev *d = (struct aoedev *) vp;
  356. if (d->flags & DEVFL_GDALLOC)
  357. aoeblk_gdalloc(d);
  358. if (d->flags & DEVFL_NEWSIZE) {
  359. struct block_device *bd;
  360. unsigned long flags;
  361. u64 ssize;
  362. ssize = d->gd->capacity;
  363. bd = bdget_disk(d->gd, 0);
  364. if (bd) {
  365. mutex_lock(&bd->bd_inode->i_mutex);
  366. i_size_write(bd->bd_inode, (loff_t)ssize<<9);
  367. mutex_unlock(&bd->bd_inode->i_mutex);
  368. bdput(bd);
  369. }
  370. spin_lock_irqsave(&d->lock, flags);
  371. d->flags |= DEVFL_UP;
  372. d->flags &= ~DEVFL_NEWSIZE;
  373. spin_unlock_irqrestore(&d->lock, flags);
  374. }
  375. }
  376. static void
  377. ataid_complete(struct aoedev *d, unsigned char *id)
  378. {
  379. u64 ssize;
  380. u16 n;
  381. /* word 83: command set supported */
  382. n = le16_to_cpu(get_unaligned((__le16 *) &id[83<<1]));
  383. /* word 86: command set/feature enabled */
  384. n |= le16_to_cpu(get_unaligned((__le16 *) &id[86<<1]));
  385. if (n & (1<<10)) { /* bit 10: LBA 48 */
  386. d->flags |= DEVFL_EXT;
  387. /* word 100: number lba48 sectors */
  388. ssize = le64_to_cpu(get_unaligned((__le64 *) &id[100<<1]));
  389. /* set as in ide-disk.c:init_idedisk_capacity */
  390. d->geo.cylinders = ssize;
  391. d->geo.cylinders /= (255 * 63);
  392. d->geo.heads = 255;
  393. d->geo.sectors = 63;
  394. } else {
  395. d->flags &= ~DEVFL_EXT;
  396. /* number lba28 sectors */
  397. ssize = le32_to_cpu(get_unaligned((__le32 *) &id[60<<1]));
  398. /* NOTE: obsolete in ATA 6 */
  399. d->geo.cylinders = le16_to_cpu(get_unaligned((__le16 *) &id[54<<1]));
  400. d->geo.heads = le16_to_cpu(get_unaligned((__le16 *) &id[55<<1]));
  401. d->geo.sectors = le16_to_cpu(get_unaligned((__le16 *) &id[56<<1]));
  402. }
  403. if (d->ssize != ssize)
  404. iprintk("%012llx e%lu.%lu v%04x has %llu sectors\n",
  405. (unsigned long long)mac_addr(d->addr),
  406. d->aoemajor, d->aoeminor,
  407. d->fw_ver, (long long)ssize);
  408. d->ssize = ssize;
  409. d->geo.start = 0;
  410. if (d->gd != NULL) {
  411. d->gd->capacity = ssize;
  412. d->flags |= DEVFL_NEWSIZE;
  413. } else {
  414. if (d->flags & DEVFL_GDALLOC) {
  415. eprintk("can't schedule work for e%lu.%lu, %s\n",
  416. d->aoemajor, d->aoeminor,
  417. "it's already on! This shouldn't happen.\n");
  418. return;
  419. }
  420. d->flags |= DEVFL_GDALLOC;
  421. }
  422. schedule_work(&d->work);
  423. }
  424. static void
  425. calc_rttavg(struct aoedev *d, int rtt)
  426. {
  427. register long n;
  428. n = rtt;
  429. if (n < 0) {
  430. n = -rtt;
  431. if (n < MINTIMER)
  432. n = MINTIMER;
  433. else if (n > MAXTIMER)
  434. n = MAXTIMER;
  435. d->mintimer += (n - d->mintimer) >> 1;
  436. } else if (n < d->mintimer)
  437. n = d->mintimer;
  438. else if (n > MAXTIMER)
  439. n = MAXTIMER;
  440. /* g == .25; cf. Congestion Avoidance and Control, Jacobson & Karels; 1988 */
  441. n -= d->rttavg;
  442. d->rttavg += n >> 2;
  443. }
  444. void
  445. aoecmd_ata_rsp(struct sk_buff *skb)
  446. {
  447. struct aoedev *d;
  448. struct aoe_hdr *hin, *hout;
  449. struct aoe_atahdr *ahin, *ahout;
  450. struct frame *f;
  451. struct buf *buf;
  452. struct sk_buff *sl;
  453. register long n;
  454. ulong flags;
  455. char ebuf[128];
  456. u16 aoemajor;
  457. hin = (struct aoe_hdr *) skb->mac.raw;
  458. aoemajor = be16_to_cpu(hin->major);
  459. d = aoedev_by_aoeaddr(aoemajor, hin->minor);
  460. if (d == NULL) {
  461. snprintf(ebuf, sizeof ebuf, "aoecmd_ata_rsp: ata response "
  462. "for unknown device %d.%d\n",
  463. aoemajor, hin->minor);
  464. aoechr_error(ebuf);
  465. return;
  466. }
  467. spin_lock_irqsave(&d->lock, flags);
  468. n = be32_to_cpu(hin->tag);
  469. f = getframe(d, n);
  470. if (f == NULL) {
  471. calc_rttavg(d, -tsince(n));
  472. spin_unlock_irqrestore(&d->lock, flags);
  473. snprintf(ebuf, sizeof ebuf,
  474. "%15s e%d.%d tag=%08x@%08lx\n",
  475. "unexpected rsp",
  476. be16_to_cpu(hin->major),
  477. hin->minor,
  478. be32_to_cpu(hin->tag),
  479. jiffies);
  480. aoechr_error(ebuf);
  481. return;
  482. }
  483. calc_rttavg(d, tsince(f->tag));
  484. ahin = (struct aoe_atahdr *) (hin+1);
  485. hout = (struct aoe_hdr *) f->skb->mac.raw;
  486. ahout = (struct aoe_atahdr *) (hout+1);
  487. buf = f->buf;
  488. if (ahout->cmdstat == WIN_IDENTIFY)
  489. d->flags &= ~DEVFL_PAUSE;
  490. if (ahin->cmdstat & 0xa9) { /* these bits cleared on success */
  491. eprintk("ata error cmd=%2.2Xh stat=%2.2Xh from e%ld.%ld\n",
  492. ahout->cmdstat, ahin->cmdstat,
  493. d->aoemajor, d->aoeminor);
  494. if (buf)
  495. buf->flags |= BUFFL_FAIL;
  496. } else {
  497. n = ahout->scnt << 9;
  498. switch (ahout->cmdstat) {
  499. case WIN_READ:
  500. case WIN_READ_EXT:
  501. if (skb->len - sizeof *hin - sizeof *ahin < n) {
  502. eprintk("runt data size in read. skb->len=%d\n",
  503. skb->len);
  504. /* fail frame f? just returning will rexmit. */
  505. spin_unlock_irqrestore(&d->lock, flags);
  506. return;
  507. }
  508. memcpy(f->bufaddr, ahin+1, n);
  509. case WIN_WRITE:
  510. case WIN_WRITE_EXT:
  511. if (f->bcnt -= n) {
  512. skb = f->skb;
  513. f->bufaddr += n;
  514. put_lba(ahout, f->lba += ahout->scnt);
  515. n = f->bcnt;
  516. if (n > DEFAULTBCNT)
  517. n = DEFAULTBCNT;
  518. ahout->scnt = n >> 9;
  519. if (ahout->aflags & AOEAFL_WRITE) {
  520. skb_fill_page_desc(skb, 0,
  521. virt_to_page(f->bufaddr),
  522. offset_in_page(f->bufaddr), n);
  523. skb->len = sizeof *hout + sizeof *ahout + n;
  524. skb->data_len = n;
  525. }
  526. f->tag = newtag(d);
  527. hout->tag = cpu_to_be32(f->tag);
  528. skb->dev = d->ifp;
  529. skb = skb_clone(skb, GFP_ATOMIC);
  530. spin_unlock_irqrestore(&d->lock, flags);
  531. if (skb)
  532. aoenet_xmit(skb);
  533. return;
  534. }
  535. if (n > DEFAULTBCNT)
  536. d->lostjumbo = 0;
  537. break;
  538. case WIN_IDENTIFY:
  539. if (skb->len - sizeof *hin - sizeof *ahin < 512) {
  540. iprintk("runt data size in ataid. skb->len=%d\n",
  541. skb->len);
  542. spin_unlock_irqrestore(&d->lock, flags);
  543. return;
  544. }
  545. ataid_complete(d, (char *) (ahin+1));
  546. break;
  547. default:
  548. iprintk("unrecognized ata command %2.2Xh for %d.%d\n",
  549. ahout->cmdstat,
  550. be16_to_cpu(hin->major),
  551. hin->minor);
  552. }
  553. }
  554. if (buf) {
  555. buf->nframesout -= 1;
  556. if (buf->nframesout == 0 && buf->resid == 0) {
  557. unsigned long duration = jiffies - buf->start_time;
  558. unsigned long n_sect = buf->bio->bi_size >> 9;
  559. struct gendisk *disk = d->gd;
  560. const int rw = bio_data_dir(buf->bio);
  561. disk_stat_inc(disk, ios[rw]);
  562. disk_stat_add(disk, ticks[rw], duration);
  563. disk_stat_add(disk, sectors[rw], n_sect);
  564. disk_stat_add(disk, io_ticks, duration);
  565. n = (buf->flags & BUFFL_FAIL) ? -EIO : 0;
  566. bio_endio(buf->bio, buf->bio->bi_size, n);
  567. mempool_free(buf, d->bufpool);
  568. }
  569. }
  570. f->buf = NULL;
  571. f->tag = FREETAG;
  572. aoecmd_work(d);
  573. sl = d->sendq_hd;
  574. d->sendq_hd = d->sendq_tl = NULL;
  575. spin_unlock_irqrestore(&d->lock, flags);
  576. aoenet_xmit(sl);
  577. }
  578. void
  579. aoecmd_cfg(ushort aoemajor, unsigned char aoeminor)
  580. {
  581. struct sk_buff *sl;
  582. sl = aoecmd_cfg_pkts(aoemajor, aoeminor, NULL);
  583. aoenet_xmit(sl);
  584. }
  585. /*
  586. * Since we only call this in one place (and it only prepares one frame)
  587. * we just return the skb. Usually we'd chain it up to the aoedev sendq.
  588. */
  589. static struct sk_buff *
  590. aoecmd_ata_id(struct aoedev *d)
  591. {
  592. struct aoe_hdr *h;
  593. struct aoe_atahdr *ah;
  594. struct frame *f;
  595. struct sk_buff *skb;
  596. f = freeframe(d);
  597. if (f == NULL) {
  598. eprintk("can't get a frame. This shouldn't happen.\n");
  599. return NULL;
  600. }
  601. /* initialize the headers & frame */
  602. skb = f->skb;
  603. h = (struct aoe_hdr *) skb->mac.raw;
  604. ah = (struct aoe_atahdr *) (h+1);
  605. skb->len = ETH_ZLEN;
  606. memset(h, 0, ETH_ZLEN);
  607. f->tag = aoehdr_atainit(d, h);
  608. f->waited = 0;
  609. /* set up ata header */
  610. ah->scnt = 1;
  611. ah->cmdstat = WIN_IDENTIFY;
  612. ah->lba3 = 0xa0;
  613. skb->dev = d->ifp;
  614. d->rttavg = MAXTIMER;
  615. d->timer.function = rexmit_timer;
  616. return skb_clone(skb, GFP_ATOMIC);
  617. }
  618. void
  619. aoecmd_cfg_rsp(struct sk_buff *skb)
  620. {
  621. struct aoedev *d;
  622. struct aoe_hdr *h;
  623. struct aoe_cfghdr *ch;
  624. ulong flags, sysminor, aoemajor;
  625. struct sk_buff *sl;
  626. enum { MAXFRAMES = 16 };
  627. u16 n;
  628. h = (struct aoe_hdr *) skb->mac.raw;
  629. ch = (struct aoe_cfghdr *) (h+1);
  630. /*
  631. * Enough people have their dip switches set backwards to
  632. * warrant a loud message for this special case.
  633. */
  634. aoemajor = be16_to_cpu(h->major);
  635. if (aoemajor == 0xfff) {
  636. eprintk("Warning: shelf address is all ones. "
  637. "Check shelf dip switches.\n");
  638. return;
  639. }
  640. sysminor = SYSMINOR(aoemajor, h->minor);
  641. if (sysminor * AOE_PARTITIONS + AOE_PARTITIONS > MINORMASK) {
  642. iprintk("e%ld.%d: minor number too large\n",
  643. aoemajor, (int) h->minor);
  644. return;
  645. }
  646. n = be16_to_cpu(ch->bufcnt);
  647. if (n > MAXFRAMES) /* keep it reasonable */
  648. n = MAXFRAMES;
  649. d = aoedev_by_sysminor_m(sysminor, n);
  650. if (d == NULL) {
  651. iprintk("device sysminor_m failure\n");
  652. return;
  653. }
  654. spin_lock_irqsave(&d->lock, flags);
  655. /* permit device to migrate mac and network interface */
  656. d->ifp = skb->dev;
  657. memcpy(d->addr, h->src, sizeof d->addr);
  658. if (!(d->flags & DEVFL_MAXBCNT)) {
  659. n = d->ifp->mtu;
  660. n -= sizeof (struct aoe_hdr) + sizeof (struct aoe_atahdr);
  661. n /= 512;
  662. if (n > ch->scnt)
  663. n = ch->scnt;
  664. n = n ? n * 512 : DEFAULTBCNT;
  665. if (n != d->maxbcnt) {
  666. iprintk("e%ld.%ld: setting %d byte data frames on %s\n",
  667. d->aoemajor, d->aoeminor, n, d->ifp->name);
  668. d->maxbcnt = n;
  669. }
  670. }
  671. /* don't change users' perspective */
  672. if (d->nopen && !(d->flags & DEVFL_PAUSE)) {
  673. spin_unlock_irqrestore(&d->lock, flags);
  674. return;
  675. }
  676. d->flags |= DEVFL_PAUSE; /* force pause */
  677. d->mintimer = MINTIMER;
  678. d->fw_ver = be16_to_cpu(ch->fwver);
  679. /* check for already outstanding ataid */
  680. sl = aoedev_isbusy(d) == 0 ? aoecmd_ata_id(d) : NULL;
  681. spin_unlock_irqrestore(&d->lock, flags);
  682. aoenet_xmit(sl);
  683. }