aoecmd.c 17 KB

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