aoecmd.c 18 KB

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