aoecmd.c 18 KB

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