aoecmd.c 17 KB

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