mvumi.c 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756
  1. /*
  2. * Marvell UMI driver
  3. *
  4. * Copyright 2011 Marvell. <jyli@marvell.com>
  5. *
  6. * This file is licensed under GPLv2.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; version 2 of the
  11. * License.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. * USA
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/moduleparam.h>
  26. #include <linux/init.h>
  27. #include <linux/device.h>
  28. #include <linux/pci.h>
  29. #include <linux/list.h>
  30. #include <linux/spinlock.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/delay.h>
  33. #include <linux/blkdev.h>
  34. #include <linux/io.h>
  35. #include <scsi/scsi.h>
  36. #include <scsi/scsi_cmnd.h>
  37. #include <scsi/scsi_device.h>
  38. #include <scsi/scsi_host.h>
  39. #include <scsi/scsi_transport.h>
  40. #include <scsi/scsi_eh.h>
  41. #include <linux/uaccess.h>
  42. #include <linux/kthread.h>
  43. #include "mvumi.h"
  44. MODULE_LICENSE("GPL");
  45. MODULE_AUTHOR("jyli@marvell.com");
  46. MODULE_DESCRIPTION("Marvell UMI Driver");
  47. static DEFINE_PCI_DEVICE_TABLE(mvumi_pci_table) = {
  48. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_2, PCI_DEVICE_ID_MARVELL_MV9143) },
  49. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_2, PCI_DEVICE_ID_MARVELL_MV9580) },
  50. { 0 }
  51. };
  52. MODULE_DEVICE_TABLE(pci, mvumi_pci_table);
  53. static void tag_init(struct mvumi_tag *st, unsigned short size)
  54. {
  55. unsigned short i;
  56. BUG_ON(size != st->size);
  57. st->top = size;
  58. for (i = 0; i < size; i++)
  59. st->stack[i] = size - 1 - i;
  60. }
  61. static unsigned short tag_get_one(struct mvumi_hba *mhba, struct mvumi_tag *st)
  62. {
  63. BUG_ON(st->top <= 0);
  64. return st->stack[--st->top];
  65. }
  66. static void tag_release_one(struct mvumi_hba *mhba, struct mvumi_tag *st,
  67. unsigned short tag)
  68. {
  69. BUG_ON(st->top >= st->size);
  70. st->stack[st->top++] = tag;
  71. }
  72. static bool tag_is_empty(struct mvumi_tag *st)
  73. {
  74. if (st->top == 0)
  75. return 1;
  76. else
  77. return 0;
  78. }
  79. static void mvumi_unmap_pci_addr(struct pci_dev *dev, void **addr_array)
  80. {
  81. int i;
  82. for (i = 0; i < MAX_BASE_ADDRESS; i++)
  83. if ((pci_resource_flags(dev, i) & IORESOURCE_MEM) &&
  84. addr_array[i])
  85. pci_iounmap(dev, addr_array[i]);
  86. }
  87. static int mvumi_map_pci_addr(struct pci_dev *dev, void **addr_array)
  88. {
  89. int i;
  90. for (i = 0; i < MAX_BASE_ADDRESS; i++) {
  91. if (pci_resource_flags(dev, i) & IORESOURCE_MEM) {
  92. addr_array[i] = pci_iomap(dev, i, 0);
  93. if (!addr_array[i]) {
  94. dev_err(&dev->dev, "failed to map Bar[%d]\n",
  95. i);
  96. mvumi_unmap_pci_addr(dev, addr_array);
  97. return -ENOMEM;
  98. }
  99. } else
  100. addr_array[i] = NULL;
  101. dev_dbg(&dev->dev, "Bar %d : %p.\n", i, addr_array[i]);
  102. }
  103. return 0;
  104. }
  105. static struct mvumi_res *mvumi_alloc_mem_resource(struct mvumi_hba *mhba,
  106. enum resource_type type, unsigned int size)
  107. {
  108. struct mvumi_res *res = kzalloc(sizeof(*res), GFP_ATOMIC);
  109. if (!res) {
  110. dev_err(&mhba->pdev->dev,
  111. "Failed to allocate memory for resource manager.\n");
  112. return NULL;
  113. }
  114. switch (type) {
  115. case RESOURCE_CACHED_MEMORY:
  116. res->virt_addr = kzalloc(size, GFP_ATOMIC);
  117. if (!res->virt_addr) {
  118. dev_err(&mhba->pdev->dev,
  119. "unable to allocate memory,size = %d.\n", size);
  120. kfree(res);
  121. return NULL;
  122. }
  123. break;
  124. case RESOURCE_UNCACHED_MEMORY:
  125. size = round_up(size, 8);
  126. res->virt_addr = pci_alloc_consistent(mhba->pdev, size,
  127. &res->bus_addr);
  128. if (!res->virt_addr) {
  129. dev_err(&mhba->pdev->dev,
  130. "unable to allocate consistent mem,"
  131. "size = %d.\n", size);
  132. kfree(res);
  133. return NULL;
  134. }
  135. memset(res->virt_addr, 0, size);
  136. break;
  137. default:
  138. dev_err(&mhba->pdev->dev, "unknown resource type %d.\n", type);
  139. kfree(res);
  140. return NULL;
  141. }
  142. res->type = type;
  143. res->size = size;
  144. INIT_LIST_HEAD(&res->entry);
  145. list_add_tail(&res->entry, &mhba->res_list);
  146. return res;
  147. }
  148. static void mvumi_release_mem_resource(struct mvumi_hba *mhba)
  149. {
  150. struct mvumi_res *res, *tmp;
  151. list_for_each_entry_safe(res, tmp, &mhba->res_list, entry) {
  152. switch (res->type) {
  153. case RESOURCE_UNCACHED_MEMORY:
  154. pci_free_consistent(mhba->pdev, res->size,
  155. res->virt_addr, res->bus_addr);
  156. break;
  157. case RESOURCE_CACHED_MEMORY:
  158. kfree(res->virt_addr);
  159. break;
  160. default:
  161. dev_err(&mhba->pdev->dev,
  162. "unknown resource type %d\n", res->type);
  163. break;
  164. }
  165. list_del(&res->entry);
  166. kfree(res);
  167. }
  168. mhba->fw_flag &= ~MVUMI_FW_ALLOC;
  169. }
  170. /**
  171. * mvumi_make_sgl - Prepares SGL
  172. * @mhba: Adapter soft state
  173. * @scmd: SCSI command from the mid-layer
  174. * @sgl_p: SGL to be filled in
  175. * @sg_count return the number of SG elements
  176. *
  177. * If successful, this function returns 0. otherwise, it returns -1.
  178. */
  179. static int mvumi_make_sgl(struct mvumi_hba *mhba, struct scsi_cmnd *scmd,
  180. void *sgl_p, unsigned char *sg_count)
  181. {
  182. struct scatterlist *sg;
  183. struct mvumi_sgl *m_sg = (struct mvumi_sgl *) sgl_p;
  184. unsigned int i;
  185. unsigned int sgnum = scsi_sg_count(scmd);
  186. dma_addr_t busaddr;
  187. if (sgnum) {
  188. sg = scsi_sglist(scmd);
  189. *sg_count = pci_map_sg(mhba->pdev, sg, sgnum,
  190. (int) scmd->sc_data_direction);
  191. if (*sg_count > mhba->max_sge) {
  192. dev_err(&mhba->pdev->dev, "sg count[0x%x] is bigger "
  193. "than max sg[0x%x].\n",
  194. *sg_count, mhba->max_sge);
  195. return -1;
  196. }
  197. for (i = 0; i < *sg_count; i++) {
  198. busaddr = sg_dma_address(&sg[i]);
  199. m_sg->baseaddr_l = cpu_to_le32(lower_32_bits(busaddr));
  200. m_sg->baseaddr_h = cpu_to_le32(upper_32_bits(busaddr));
  201. m_sg->flags = 0;
  202. sgd_setsz(mhba, m_sg, cpu_to_le32(sg_dma_len(&sg[i])));
  203. if ((i + 1) == *sg_count)
  204. m_sg->flags |= 1U << mhba->eot_flag;
  205. sgd_inc(mhba, m_sg);
  206. }
  207. } else {
  208. scmd->SCp.dma_handle = scsi_bufflen(scmd) ?
  209. pci_map_single(mhba->pdev, scsi_sglist(scmd),
  210. scsi_bufflen(scmd),
  211. (int) scmd->sc_data_direction)
  212. : 0;
  213. busaddr = scmd->SCp.dma_handle;
  214. m_sg->baseaddr_l = cpu_to_le32(lower_32_bits(busaddr));
  215. m_sg->baseaddr_h = cpu_to_le32(upper_32_bits(busaddr));
  216. m_sg->flags = 1U << mhba->eot_flag;
  217. sgd_setsz(mhba, m_sg, cpu_to_le32(scsi_bufflen(scmd)));
  218. *sg_count = 1;
  219. }
  220. return 0;
  221. }
  222. static int mvumi_internal_cmd_sgl(struct mvumi_hba *mhba, struct mvumi_cmd *cmd,
  223. unsigned int size)
  224. {
  225. struct mvumi_sgl *m_sg;
  226. void *virt_addr;
  227. dma_addr_t phy_addr;
  228. if (size == 0)
  229. return 0;
  230. virt_addr = pci_alloc_consistent(mhba->pdev, size, &phy_addr);
  231. if (!virt_addr)
  232. return -1;
  233. memset(virt_addr, 0, size);
  234. m_sg = (struct mvumi_sgl *) &cmd->frame->payload[0];
  235. cmd->frame->sg_counts = 1;
  236. cmd->data_buf = virt_addr;
  237. m_sg->baseaddr_l = cpu_to_le32(lower_32_bits(phy_addr));
  238. m_sg->baseaddr_h = cpu_to_le32(upper_32_bits(phy_addr));
  239. m_sg->flags = 1U << mhba->eot_flag;
  240. sgd_setsz(mhba, m_sg, cpu_to_le32(size));
  241. return 0;
  242. }
  243. static struct mvumi_cmd *mvumi_create_internal_cmd(struct mvumi_hba *mhba,
  244. unsigned int buf_size)
  245. {
  246. struct mvumi_cmd *cmd;
  247. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  248. if (!cmd) {
  249. dev_err(&mhba->pdev->dev, "failed to create a internal cmd\n");
  250. return NULL;
  251. }
  252. INIT_LIST_HEAD(&cmd->queue_pointer);
  253. cmd->frame = pci_alloc_consistent(mhba->pdev,
  254. mhba->ib_max_size, &cmd->frame_phys);
  255. if (!cmd->frame) {
  256. dev_err(&mhba->pdev->dev, "failed to allocate memory for FW"
  257. " frame,size = %d.\n", mhba->ib_max_size);
  258. kfree(cmd);
  259. return NULL;
  260. }
  261. if (buf_size) {
  262. if (mvumi_internal_cmd_sgl(mhba, cmd, buf_size)) {
  263. dev_err(&mhba->pdev->dev, "failed to allocate memory"
  264. " for internal frame\n");
  265. pci_free_consistent(mhba->pdev, mhba->ib_max_size,
  266. cmd->frame, cmd->frame_phys);
  267. kfree(cmd);
  268. return NULL;
  269. }
  270. } else
  271. cmd->frame->sg_counts = 0;
  272. return cmd;
  273. }
  274. static void mvumi_delete_internal_cmd(struct mvumi_hba *mhba,
  275. struct mvumi_cmd *cmd)
  276. {
  277. struct mvumi_sgl *m_sg;
  278. unsigned int size;
  279. dma_addr_t phy_addr;
  280. if (cmd && cmd->frame) {
  281. if (cmd->frame->sg_counts) {
  282. m_sg = (struct mvumi_sgl *) &cmd->frame->payload[0];
  283. sgd_getsz(mhba, m_sg, size);
  284. phy_addr = (dma_addr_t) m_sg->baseaddr_l |
  285. (dma_addr_t) ((m_sg->baseaddr_h << 16) << 16);
  286. pci_free_consistent(mhba->pdev, size, cmd->data_buf,
  287. phy_addr);
  288. }
  289. pci_free_consistent(mhba->pdev, mhba->ib_max_size,
  290. cmd->frame, cmd->frame_phys);
  291. kfree(cmd);
  292. }
  293. }
  294. /**
  295. * mvumi_get_cmd - Get a command from the free pool
  296. * @mhba: Adapter soft state
  297. *
  298. * Returns a free command from the pool
  299. */
  300. static struct mvumi_cmd *mvumi_get_cmd(struct mvumi_hba *mhba)
  301. {
  302. struct mvumi_cmd *cmd = NULL;
  303. if (likely(!list_empty(&mhba->cmd_pool))) {
  304. cmd = list_entry((&mhba->cmd_pool)->next,
  305. struct mvumi_cmd, queue_pointer);
  306. list_del_init(&cmd->queue_pointer);
  307. } else
  308. dev_warn(&mhba->pdev->dev, "command pool is empty!\n");
  309. return cmd;
  310. }
  311. /**
  312. * mvumi_return_cmd - Return a cmd to free command pool
  313. * @mhba: Adapter soft state
  314. * @cmd: Command packet to be returned to free command pool
  315. */
  316. static inline void mvumi_return_cmd(struct mvumi_hba *mhba,
  317. struct mvumi_cmd *cmd)
  318. {
  319. cmd->scmd = NULL;
  320. list_add_tail(&cmd->queue_pointer, &mhba->cmd_pool);
  321. }
  322. /**
  323. * mvumi_free_cmds - Free all the cmds in the free cmd pool
  324. * @mhba: Adapter soft state
  325. */
  326. static void mvumi_free_cmds(struct mvumi_hba *mhba)
  327. {
  328. struct mvumi_cmd *cmd;
  329. while (!list_empty(&mhba->cmd_pool)) {
  330. cmd = list_first_entry(&mhba->cmd_pool, struct mvumi_cmd,
  331. queue_pointer);
  332. list_del(&cmd->queue_pointer);
  333. if (!(mhba->hba_capability & HS_CAPABILITY_SUPPORT_DYN_SRC))
  334. kfree(cmd->frame);
  335. kfree(cmd);
  336. }
  337. }
  338. /**
  339. * mvumi_alloc_cmds - Allocates the command packets
  340. * @mhba: Adapter soft state
  341. *
  342. */
  343. static int mvumi_alloc_cmds(struct mvumi_hba *mhba)
  344. {
  345. int i;
  346. struct mvumi_cmd *cmd;
  347. for (i = 0; i < mhba->max_io; i++) {
  348. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  349. if (!cmd)
  350. goto err_exit;
  351. INIT_LIST_HEAD(&cmd->queue_pointer);
  352. list_add_tail(&cmd->queue_pointer, &mhba->cmd_pool);
  353. if (mhba->hba_capability & HS_CAPABILITY_SUPPORT_DYN_SRC) {
  354. cmd->frame = mhba->ib_frame + i * mhba->ib_max_size;
  355. cmd->frame_phys = mhba->ib_frame_phys
  356. + i * mhba->ib_max_size;
  357. } else
  358. cmd->frame = kzalloc(mhba->ib_max_size, GFP_KERNEL);
  359. if (!cmd->frame)
  360. goto err_exit;
  361. }
  362. return 0;
  363. err_exit:
  364. dev_err(&mhba->pdev->dev,
  365. "failed to allocate memory for cmd[0x%x].\n", i);
  366. while (!list_empty(&mhba->cmd_pool)) {
  367. cmd = list_first_entry(&mhba->cmd_pool, struct mvumi_cmd,
  368. queue_pointer);
  369. list_del(&cmd->queue_pointer);
  370. if (!(mhba->hba_capability & HS_CAPABILITY_SUPPORT_DYN_SRC))
  371. kfree(cmd->frame);
  372. kfree(cmd);
  373. }
  374. return -ENOMEM;
  375. }
  376. static unsigned int mvumi_check_ib_list_9143(struct mvumi_hba *mhba)
  377. {
  378. unsigned int ib_rp_reg;
  379. struct mvumi_hw_regs *regs = mhba->regs;
  380. ib_rp_reg = ioread32(mhba->regs->inb_read_pointer);
  381. if (unlikely(((ib_rp_reg & regs->cl_slot_num_mask) ==
  382. (mhba->ib_cur_slot & regs->cl_slot_num_mask)) &&
  383. ((ib_rp_reg & regs->cl_pointer_toggle)
  384. != (mhba->ib_cur_slot & regs->cl_pointer_toggle)))) {
  385. dev_warn(&mhba->pdev->dev, "no free slot to use.\n");
  386. return 0;
  387. }
  388. if (atomic_read(&mhba->fw_outstanding) >= mhba->max_io) {
  389. dev_warn(&mhba->pdev->dev, "firmware io overflow.\n");
  390. return 0;
  391. } else {
  392. return mhba->max_io - atomic_read(&mhba->fw_outstanding);
  393. }
  394. }
  395. static unsigned int mvumi_check_ib_list_9580(struct mvumi_hba *mhba)
  396. {
  397. unsigned int count;
  398. if (atomic_read(&mhba->fw_outstanding) >= (mhba->max_io - 1))
  399. return 0;
  400. count = ioread32(mhba->ib_shadow);
  401. if (count == 0xffff)
  402. return 0;
  403. return count;
  404. }
  405. static void mvumi_get_ib_list_entry(struct mvumi_hba *mhba, void **ib_entry)
  406. {
  407. unsigned int cur_ib_entry;
  408. cur_ib_entry = mhba->ib_cur_slot & mhba->regs->cl_slot_num_mask;
  409. cur_ib_entry++;
  410. if (cur_ib_entry >= mhba->list_num_io) {
  411. cur_ib_entry -= mhba->list_num_io;
  412. mhba->ib_cur_slot ^= mhba->regs->cl_pointer_toggle;
  413. }
  414. mhba->ib_cur_slot &= ~mhba->regs->cl_slot_num_mask;
  415. mhba->ib_cur_slot |= (cur_ib_entry & mhba->regs->cl_slot_num_mask);
  416. if (mhba->hba_capability & HS_CAPABILITY_SUPPORT_DYN_SRC) {
  417. *ib_entry = mhba->ib_list + cur_ib_entry *
  418. sizeof(struct mvumi_dyn_list_entry);
  419. } else {
  420. *ib_entry = mhba->ib_list + cur_ib_entry * mhba->ib_max_size;
  421. }
  422. atomic_inc(&mhba->fw_outstanding);
  423. }
  424. static void mvumi_send_ib_list_entry(struct mvumi_hba *mhba)
  425. {
  426. iowrite32(0xffff, mhba->ib_shadow);
  427. iowrite32(mhba->ib_cur_slot, mhba->regs->inb_write_pointer);
  428. }
  429. static char mvumi_check_ob_frame(struct mvumi_hba *mhba,
  430. unsigned int cur_obf, struct mvumi_rsp_frame *p_outb_frame)
  431. {
  432. unsigned short tag, request_id;
  433. udelay(1);
  434. p_outb_frame = mhba->ob_list + cur_obf * mhba->ob_max_size;
  435. request_id = p_outb_frame->request_id;
  436. tag = p_outb_frame->tag;
  437. if (tag > mhba->tag_pool.size) {
  438. dev_err(&mhba->pdev->dev, "ob frame data error\n");
  439. return -1;
  440. }
  441. if (mhba->tag_cmd[tag] == NULL) {
  442. dev_err(&mhba->pdev->dev, "tag[0x%x] with NO command\n", tag);
  443. return -1;
  444. } else if (mhba->tag_cmd[tag]->request_id != request_id &&
  445. mhba->request_id_enabled) {
  446. dev_err(&mhba->pdev->dev, "request ID from FW:0x%x,"
  447. "cmd request ID:0x%x\n", request_id,
  448. mhba->tag_cmd[tag]->request_id);
  449. return -1;
  450. }
  451. return 0;
  452. }
  453. static int mvumi_check_ob_list_9143(struct mvumi_hba *mhba,
  454. unsigned int *cur_obf, unsigned int *assign_obf_end)
  455. {
  456. unsigned int ob_write, ob_write_shadow;
  457. struct mvumi_hw_regs *regs = mhba->regs;
  458. do {
  459. ob_write = ioread32(regs->outb_copy_pointer);
  460. ob_write_shadow = ioread32(mhba->ob_shadow);
  461. } while ((ob_write & regs->cl_slot_num_mask) != ob_write_shadow);
  462. *cur_obf = mhba->ob_cur_slot & mhba->regs->cl_slot_num_mask;
  463. *assign_obf_end = ob_write & mhba->regs->cl_slot_num_mask;
  464. if ((ob_write & regs->cl_pointer_toggle) !=
  465. (mhba->ob_cur_slot & regs->cl_pointer_toggle)) {
  466. *assign_obf_end += mhba->list_num_io;
  467. }
  468. return 0;
  469. }
  470. static int mvumi_check_ob_list_9580(struct mvumi_hba *mhba,
  471. unsigned int *cur_obf, unsigned int *assign_obf_end)
  472. {
  473. unsigned int ob_write;
  474. struct mvumi_hw_regs *regs = mhba->regs;
  475. ob_write = ioread32(regs->outb_read_pointer);
  476. ob_write = ioread32(regs->outb_copy_pointer);
  477. *cur_obf = mhba->ob_cur_slot & mhba->regs->cl_slot_num_mask;
  478. *assign_obf_end = ob_write & mhba->regs->cl_slot_num_mask;
  479. if (*assign_obf_end < *cur_obf)
  480. *assign_obf_end += mhba->list_num_io;
  481. else if (*assign_obf_end == *cur_obf)
  482. return -1;
  483. return 0;
  484. }
  485. static void mvumi_receive_ob_list_entry(struct mvumi_hba *mhba)
  486. {
  487. unsigned int cur_obf, assign_obf_end, i;
  488. struct mvumi_ob_data *ob_data;
  489. struct mvumi_rsp_frame *p_outb_frame;
  490. struct mvumi_hw_regs *regs = mhba->regs;
  491. if (mhba->instancet->check_ob_list(mhba, &cur_obf, &assign_obf_end))
  492. return;
  493. for (i = (assign_obf_end - cur_obf); i != 0; i--) {
  494. cur_obf++;
  495. if (cur_obf >= mhba->list_num_io) {
  496. cur_obf -= mhba->list_num_io;
  497. mhba->ob_cur_slot ^= regs->cl_pointer_toggle;
  498. }
  499. p_outb_frame = mhba->ob_list + cur_obf * mhba->ob_max_size;
  500. /* Copy pointer may point to entry in outbound list
  501. * before entry has valid data
  502. */
  503. if (unlikely(p_outb_frame->tag > mhba->tag_pool.size ||
  504. mhba->tag_cmd[p_outb_frame->tag] == NULL ||
  505. p_outb_frame->request_id !=
  506. mhba->tag_cmd[p_outb_frame->tag]->request_id))
  507. if (mvumi_check_ob_frame(mhba, cur_obf, p_outb_frame))
  508. continue;
  509. if (!list_empty(&mhba->ob_data_list)) {
  510. ob_data = (struct mvumi_ob_data *)
  511. list_first_entry(&mhba->ob_data_list,
  512. struct mvumi_ob_data, list);
  513. list_del_init(&ob_data->list);
  514. } else {
  515. ob_data = NULL;
  516. if (cur_obf == 0) {
  517. cur_obf = mhba->list_num_io - 1;
  518. mhba->ob_cur_slot ^= regs->cl_pointer_toggle;
  519. } else
  520. cur_obf -= 1;
  521. break;
  522. }
  523. memcpy(ob_data->data, p_outb_frame, mhba->ob_max_size);
  524. p_outb_frame->tag = 0xff;
  525. list_add_tail(&ob_data->list, &mhba->free_ob_list);
  526. }
  527. mhba->ob_cur_slot &= ~regs->cl_slot_num_mask;
  528. mhba->ob_cur_slot |= (cur_obf & regs->cl_slot_num_mask);
  529. iowrite32(mhba->ob_cur_slot, regs->outb_read_pointer);
  530. }
  531. static void mvumi_reset(struct mvumi_hba *mhba)
  532. {
  533. struct mvumi_hw_regs *regs = mhba->regs;
  534. iowrite32(0, regs->enpointa_mask_reg);
  535. if (ioread32(regs->arm_to_pciea_msg1) != HANDSHAKE_DONESTATE)
  536. return;
  537. iowrite32(DRBL_SOFT_RESET, regs->pciea_to_arm_drbl_reg);
  538. }
  539. static unsigned char mvumi_start(struct mvumi_hba *mhba);
  540. static int mvumi_wait_for_outstanding(struct mvumi_hba *mhba)
  541. {
  542. mhba->fw_state = FW_STATE_ABORT;
  543. mvumi_reset(mhba);
  544. if (mvumi_start(mhba))
  545. return FAILED;
  546. else
  547. return SUCCESS;
  548. }
  549. static int mvumi_wait_for_fw(struct mvumi_hba *mhba)
  550. {
  551. struct mvumi_hw_regs *regs = mhba->regs;
  552. u32 tmp;
  553. unsigned long before;
  554. before = jiffies;
  555. iowrite32(0, regs->enpointa_mask_reg);
  556. tmp = ioread32(regs->arm_to_pciea_msg1);
  557. while (tmp != HANDSHAKE_READYSTATE) {
  558. iowrite32(DRBL_MU_RESET, regs->pciea_to_arm_drbl_reg);
  559. if (time_after(jiffies, before + FW_MAX_DELAY * HZ)) {
  560. dev_err(&mhba->pdev->dev,
  561. "FW reset failed [0x%x].\n", tmp);
  562. return FAILED;
  563. }
  564. msleep(500);
  565. rmb();
  566. tmp = ioread32(regs->arm_to_pciea_msg1);
  567. }
  568. return SUCCESS;
  569. }
  570. static void mvumi_backup_bar_addr(struct mvumi_hba *mhba)
  571. {
  572. unsigned char i;
  573. for (i = 0; i < MAX_BASE_ADDRESS; i++) {
  574. pci_read_config_dword(mhba->pdev, 0x10 + i * 4,
  575. &mhba->pci_base[i]);
  576. }
  577. }
  578. static void mvumi_restore_bar_addr(struct mvumi_hba *mhba)
  579. {
  580. unsigned char i;
  581. for (i = 0; i < MAX_BASE_ADDRESS; i++) {
  582. if (mhba->pci_base[i])
  583. pci_write_config_dword(mhba->pdev, 0x10 + i * 4,
  584. mhba->pci_base[i]);
  585. }
  586. }
  587. static unsigned int mvumi_pci_set_master(struct pci_dev *pdev)
  588. {
  589. unsigned int ret = 0;
  590. pci_set_master(pdev);
  591. if (IS_DMA64) {
  592. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)))
  593. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  594. } else
  595. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  596. return ret;
  597. }
  598. static int mvumi_reset_host_9580(struct mvumi_hba *mhba)
  599. {
  600. mhba->fw_state = FW_STATE_ABORT;
  601. iowrite32(0, mhba->regs->reset_enable);
  602. iowrite32(0xf, mhba->regs->reset_request);
  603. iowrite32(0x10, mhba->regs->reset_enable);
  604. iowrite32(0x10, mhba->regs->reset_request);
  605. msleep(100);
  606. pci_disable_device(mhba->pdev);
  607. if (pci_enable_device(mhba->pdev)) {
  608. dev_err(&mhba->pdev->dev, "enable device failed\n");
  609. return FAILED;
  610. }
  611. if (mvumi_pci_set_master(mhba->pdev)) {
  612. dev_err(&mhba->pdev->dev, "set master failed\n");
  613. return FAILED;
  614. }
  615. mvumi_restore_bar_addr(mhba);
  616. if (mvumi_wait_for_fw(mhba) == FAILED)
  617. return FAILED;
  618. return mvumi_wait_for_outstanding(mhba);
  619. }
  620. static int mvumi_reset_host_9143(struct mvumi_hba *mhba)
  621. {
  622. return mvumi_wait_for_outstanding(mhba);
  623. }
  624. static int mvumi_host_reset(struct scsi_cmnd *scmd)
  625. {
  626. struct mvumi_hba *mhba;
  627. mhba = (struct mvumi_hba *) scmd->device->host->hostdata;
  628. scmd_printk(KERN_NOTICE, scmd, "RESET -%ld cmd=%x retries=%x\n",
  629. scmd->serial_number, scmd->cmnd[0], scmd->retries);
  630. return mhba->instancet->reset_host(mhba);
  631. }
  632. static int mvumi_issue_blocked_cmd(struct mvumi_hba *mhba,
  633. struct mvumi_cmd *cmd)
  634. {
  635. unsigned long flags;
  636. cmd->cmd_status = REQ_STATUS_PENDING;
  637. if (atomic_read(&cmd->sync_cmd)) {
  638. dev_err(&mhba->pdev->dev,
  639. "last blocked cmd not finished, sync_cmd = %d\n",
  640. atomic_read(&cmd->sync_cmd));
  641. BUG_ON(1);
  642. return -1;
  643. }
  644. atomic_inc(&cmd->sync_cmd);
  645. spin_lock_irqsave(mhba->shost->host_lock, flags);
  646. mhba->instancet->fire_cmd(mhba, cmd);
  647. spin_unlock_irqrestore(mhba->shost->host_lock, flags);
  648. wait_event_timeout(mhba->int_cmd_wait_q,
  649. (cmd->cmd_status != REQ_STATUS_PENDING),
  650. MVUMI_INTERNAL_CMD_WAIT_TIME * HZ);
  651. /* command timeout */
  652. if (atomic_read(&cmd->sync_cmd)) {
  653. spin_lock_irqsave(mhba->shost->host_lock, flags);
  654. atomic_dec(&cmd->sync_cmd);
  655. if (mhba->tag_cmd[cmd->frame->tag]) {
  656. mhba->tag_cmd[cmd->frame->tag] = 0;
  657. dev_warn(&mhba->pdev->dev, "TIMEOUT:release tag [%d]\n",
  658. cmd->frame->tag);
  659. tag_release_one(mhba, &mhba->tag_pool, cmd->frame->tag);
  660. }
  661. if (!list_empty(&cmd->queue_pointer)) {
  662. dev_warn(&mhba->pdev->dev,
  663. "TIMEOUT:A internal command doesn't send!\n");
  664. list_del_init(&cmd->queue_pointer);
  665. } else
  666. atomic_dec(&mhba->fw_outstanding);
  667. spin_unlock_irqrestore(mhba->shost->host_lock, flags);
  668. }
  669. return 0;
  670. }
  671. static void mvumi_release_fw(struct mvumi_hba *mhba)
  672. {
  673. mvumi_free_cmds(mhba);
  674. mvumi_release_mem_resource(mhba);
  675. mvumi_unmap_pci_addr(mhba->pdev, mhba->base_addr);
  676. pci_free_consistent(mhba->pdev, HSP_MAX_SIZE,
  677. mhba->handshake_page, mhba->handshake_page_phys);
  678. kfree(mhba->regs);
  679. pci_release_regions(mhba->pdev);
  680. }
  681. static unsigned char mvumi_flush_cache(struct mvumi_hba *mhba)
  682. {
  683. struct mvumi_cmd *cmd;
  684. struct mvumi_msg_frame *frame;
  685. unsigned char device_id, retry = 0;
  686. unsigned char bitcount = sizeof(unsigned char) * 8;
  687. for (device_id = 0; device_id < mhba->max_target_id; device_id++) {
  688. if (!(mhba->target_map[device_id / bitcount] &
  689. (1 << (device_id % bitcount))))
  690. continue;
  691. get_cmd: cmd = mvumi_create_internal_cmd(mhba, 0);
  692. if (!cmd) {
  693. if (retry++ >= 5) {
  694. dev_err(&mhba->pdev->dev, "failed to get memory"
  695. " for internal flush cache cmd for "
  696. "device %d", device_id);
  697. retry = 0;
  698. continue;
  699. } else
  700. goto get_cmd;
  701. }
  702. cmd->scmd = NULL;
  703. cmd->cmd_status = REQ_STATUS_PENDING;
  704. atomic_set(&cmd->sync_cmd, 0);
  705. frame = cmd->frame;
  706. frame->req_function = CL_FUN_SCSI_CMD;
  707. frame->device_id = device_id;
  708. frame->cmd_flag = CMD_FLAG_NON_DATA;
  709. frame->data_transfer_length = 0;
  710. frame->cdb_length = MAX_COMMAND_SIZE;
  711. memset(frame->cdb, 0, MAX_COMMAND_SIZE);
  712. frame->cdb[0] = SCSI_CMD_MARVELL_SPECIFIC;
  713. frame->cdb[1] = CDB_CORE_MODULE;
  714. frame->cdb[2] = CDB_CORE_SHUTDOWN;
  715. mvumi_issue_blocked_cmd(mhba, cmd);
  716. if (cmd->cmd_status != SAM_STAT_GOOD) {
  717. dev_err(&mhba->pdev->dev,
  718. "device %d flush cache failed, status=0x%x.\n",
  719. device_id, cmd->cmd_status);
  720. }
  721. mvumi_delete_internal_cmd(mhba, cmd);
  722. }
  723. return 0;
  724. }
  725. static unsigned char
  726. mvumi_calculate_checksum(struct mvumi_hs_header *p_header,
  727. unsigned short len)
  728. {
  729. unsigned char *ptr;
  730. unsigned char ret = 0, i;
  731. ptr = (unsigned char *) p_header->frame_content;
  732. for (i = 0; i < len; i++) {
  733. ret ^= *ptr;
  734. ptr++;
  735. }
  736. return ret;
  737. }
  738. static void mvumi_hs_build_page(struct mvumi_hba *mhba,
  739. struct mvumi_hs_header *hs_header)
  740. {
  741. struct mvumi_hs_page2 *hs_page2;
  742. struct mvumi_hs_page4 *hs_page4;
  743. struct mvumi_hs_page3 *hs_page3;
  744. struct timeval time;
  745. unsigned int local_time;
  746. switch (hs_header->page_code) {
  747. case HS_PAGE_HOST_INFO:
  748. hs_page2 = (struct mvumi_hs_page2 *) hs_header;
  749. hs_header->frame_length = sizeof(*hs_page2) - 4;
  750. memset(hs_header->frame_content, 0, hs_header->frame_length);
  751. hs_page2->host_type = 3; /* 3 mean linux*/
  752. if (mhba->hba_capability & HS_CAPABILITY_SUPPORT_DYN_SRC)
  753. hs_page2->host_cap = 0x08;/* host dynamic source mode */
  754. hs_page2->host_ver.ver_major = VER_MAJOR;
  755. hs_page2->host_ver.ver_minor = VER_MINOR;
  756. hs_page2->host_ver.ver_oem = VER_OEM;
  757. hs_page2->host_ver.ver_build = VER_BUILD;
  758. hs_page2->system_io_bus = 0;
  759. hs_page2->slot_number = 0;
  760. hs_page2->intr_level = 0;
  761. hs_page2->intr_vector = 0;
  762. do_gettimeofday(&time);
  763. local_time = (unsigned int) (time.tv_sec -
  764. (sys_tz.tz_minuteswest * 60));
  765. hs_page2->seconds_since1970 = local_time;
  766. hs_header->checksum = mvumi_calculate_checksum(hs_header,
  767. hs_header->frame_length);
  768. break;
  769. case HS_PAGE_FIRM_CTL:
  770. hs_page3 = (struct mvumi_hs_page3 *) hs_header;
  771. hs_header->frame_length = sizeof(*hs_page3) - 4;
  772. memset(hs_header->frame_content, 0, hs_header->frame_length);
  773. hs_header->checksum = mvumi_calculate_checksum(hs_header,
  774. hs_header->frame_length);
  775. break;
  776. case HS_PAGE_CL_INFO:
  777. hs_page4 = (struct mvumi_hs_page4 *) hs_header;
  778. hs_header->frame_length = sizeof(*hs_page4) - 4;
  779. memset(hs_header->frame_content, 0, hs_header->frame_length);
  780. hs_page4->ib_baseaddr_l = lower_32_bits(mhba->ib_list_phys);
  781. hs_page4->ib_baseaddr_h = upper_32_bits(mhba->ib_list_phys);
  782. hs_page4->ob_baseaddr_l = lower_32_bits(mhba->ob_list_phys);
  783. hs_page4->ob_baseaddr_h = upper_32_bits(mhba->ob_list_phys);
  784. hs_page4->ib_entry_size = mhba->ib_max_size_setting;
  785. hs_page4->ob_entry_size = mhba->ob_max_size_setting;
  786. if (mhba->hba_capability
  787. & HS_CAPABILITY_NEW_PAGE_IO_DEPTH_DEF) {
  788. hs_page4->ob_depth = find_first_bit((unsigned long *)
  789. &mhba->list_num_io,
  790. BITS_PER_LONG);
  791. hs_page4->ib_depth = find_first_bit((unsigned long *)
  792. &mhba->list_num_io,
  793. BITS_PER_LONG);
  794. } else {
  795. hs_page4->ob_depth = (u8) mhba->list_num_io;
  796. hs_page4->ib_depth = (u8) mhba->list_num_io;
  797. }
  798. hs_header->checksum = mvumi_calculate_checksum(hs_header,
  799. hs_header->frame_length);
  800. break;
  801. default:
  802. dev_err(&mhba->pdev->dev, "cannot build page, code[0x%x]\n",
  803. hs_header->page_code);
  804. break;
  805. }
  806. }
  807. /**
  808. * mvumi_init_data - Initialize requested date for FW
  809. * @mhba: Adapter soft state
  810. */
  811. static int mvumi_init_data(struct mvumi_hba *mhba)
  812. {
  813. struct mvumi_ob_data *ob_pool;
  814. struct mvumi_res *res_mgnt;
  815. unsigned int tmp_size, offset, i;
  816. void *virmem, *v;
  817. dma_addr_t p;
  818. if (mhba->fw_flag & MVUMI_FW_ALLOC)
  819. return 0;
  820. tmp_size = mhba->ib_max_size * mhba->max_io;
  821. if (mhba->hba_capability & HS_CAPABILITY_SUPPORT_DYN_SRC)
  822. tmp_size += sizeof(struct mvumi_dyn_list_entry) * mhba->max_io;
  823. tmp_size += 128 + mhba->ob_max_size * mhba->max_io;
  824. tmp_size += 8 + sizeof(u32)*2 + 16;
  825. res_mgnt = mvumi_alloc_mem_resource(mhba,
  826. RESOURCE_UNCACHED_MEMORY, tmp_size);
  827. if (!res_mgnt) {
  828. dev_err(&mhba->pdev->dev,
  829. "failed to allocate memory for inbound list\n");
  830. goto fail_alloc_dma_buf;
  831. }
  832. p = res_mgnt->bus_addr;
  833. v = res_mgnt->virt_addr;
  834. /* ib_list */
  835. offset = round_up(p, 128) - p;
  836. p += offset;
  837. v += offset;
  838. mhba->ib_list = v;
  839. mhba->ib_list_phys = p;
  840. if (mhba->hba_capability & HS_CAPABILITY_SUPPORT_DYN_SRC) {
  841. v += sizeof(struct mvumi_dyn_list_entry) * mhba->max_io;
  842. p += sizeof(struct mvumi_dyn_list_entry) * mhba->max_io;
  843. mhba->ib_frame = v;
  844. mhba->ib_frame_phys = p;
  845. }
  846. v += mhba->ib_max_size * mhba->max_io;
  847. p += mhba->ib_max_size * mhba->max_io;
  848. /* ib shadow */
  849. offset = round_up(p, 8) - p;
  850. p += offset;
  851. v += offset;
  852. mhba->ib_shadow = v;
  853. mhba->ib_shadow_phys = p;
  854. p += sizeof(u32)*2;
  855. v += sizeof(u32)*2;
  856. /* ob shadow */
  857. if (mhba->pdev->device == PCI_DEVICE_ID_MARVELL_MV9580) {
  858. offset = round_up(p, 8) - p;
  859. p += offset;
  860. v += offset;
  861. mhba->ob_shadow = v;
  862. mhba->ob_shadow_phys = p;
  863. p += 8;
  864. v += 8;
  865. } else {
  866. offset = round_up(p, 4) - p;
  867. p += offset;
  868. v += offset;
  869. mhba->ob_shadow = v;
  870. mhba->ob_shadow_phys = p;
  871. p += 4;
  872. v += 4;
  873. }
  874. /* ob list */
  875. offset = round_up(p, 128) - p;
  876. p += offset;
  877. v += offset;
  878. mhba->ob_list = v;
  879. mhba->ob_list_phys = p;
  880. /* ob data pool */
  881. tmp_size = mhba->max_io * (mhba->ob_max_size + sizeof(*ob_pool));
  882. tmp_size = round_up(tmp_size, 8);
  883. res_mgnt = mvumi_alloc_mem_resource(mhba,
  884. RESOURCE_CACHED_MEMORY, tmp_size);
  885. if (!res_mgnt) {
  886. dev_err(&mhba->pdev->dev,
  887. "failed to allocate memory for outbound data buffer\n");
  888. goto fail_alloc_dma_buf;
  889. }
  890. virmem = res_mgnt->virt_addr;
  891. for (i = mhba->max_io; i != 0; i--) {
  892. ob_pool = (struct mvumi_ob_data *) virmem;
  893. list_add_tail(&ob_pool->list, &mhba->ob_data_list);
  894. virmem += mhba->ob_max_size + sizeof(*ob_pool);
  895. }
  896. tmp_size = sizeof(unsigned short) * mhba->max_io +
  897. sizeof(struct mvumi_cmd *) * mhba->max_io;
  898. tmp_size += round_up(mhba->max_target_id, sizeof(unsigned char) * 8) /
  899. (sizeof(unsigned char) * 8);
  900. res_mgnt = mvumi_alloc_mem_resource(mhba,
  901. RESOURCE_CACHED_MEMORY, tmp_size);
  902. if (!res_mgnt) {
  903. dev_err(&mhba->pdev->dev,
  904. "failed to allocate memory for tag and target map\n");
  905. goto fail_alloc_dma_buf;
  906. }
  907. virmem = res_mgnt->virt_addr;
  908. mhba->tag_pool.stack = virmem;
  909. mhba->tag_pool.size = mhba->max_io;
  910. tag_init(&mhba->tag_pool, mhba->max_io);
  911. virmem += sizeof(unsigned short) * mhba->max_io;
  912. mhba->tag_cmd = virmem;
  913. virmem += sizeof(struct mvumi_cmd *) * mhba->max_io;
  914. mhba->target_map = virmem;
  915. mhba->fw_flag |= MVUMI_FW_ALLOC;
  916. return 0;
  917. fail_alloc_dma_buf:
  918. mvumi_release_mem_resource(mhba);
  919. return -1;
  920. }
  921. static int mvumi_hs_process_page(struct mvumi_hba *mhba,
  922. struct mvumi_hs_header *hs_header)
  923. {
  924. struct mvumi_hs_page1 *hs_page1;
  925. unsigned char page_checksum;
  926. page_checksum = mvumi_calculate_checksum(hs_header,
  927. hs_header->frame_length);
  928. if (page_checksum != hs_header->checksum) {
  929. dev_err(&mhba->pdev->dev, "checksum error\n");
  930. return -1;
  931. }
  932. switch (hs_header->page_code) {
  933. case HS_PAGE_FIRM_CAP:
  934. hs_page1 = (struct mvumi_hs_page1 *) hs_header;
  935. mhba->max_io = hs_page1->max_io_support;
  936. mhba->list_num_io = hs_page1->cl_inout_list_depth;
  937. mhba->max_transfer_size = hs_page1->max_transfer_size;
  938. mhba->max_target_id = hs_page1->max_devices_support;
  939. mhba->hba_capability = hs_page1->capability;
  940. mhba->ib_max_size_setting = hs_page1->cl_in_max_entry_size;
  941. mhba->ib_max_size = (1 << hs_page1->cl_in_max_entry_size) << 2;
  942. mhba->ob_max_size_setting = hs_page1->cl_out_max_entry_size;
  943. mhba->ob_max_size = (1 << hs_page1->cl_out_max_entry_size) << 2;
  944. dev_dbg(&mhba->pdev->dev, "FW version:%d\n",
  945. hs_page1->fw_ver.ver_build);
  946. if (mhba->hba_capability & HS_CAPABILITY_SUPPORT_COMPACT_SG)
  947. mhba->eot_flag = 22;
  948. else
  949. mhba->eot_flag = 27;
  950. if (mhba->hba_capability & HS_CAPABILITY_NEW_PAGE_IO_DEPTH_DEF)
  951. mhba->list_num_io = 1 << hs_page1->cl_inout_list_depth;
  952. break;
  953. default:
  954. dev_err(&mhba->pdev->dev, "handshake: page code error\n");
  955. return -1;
  956. }
  957. return 0;
  958. }
  959. /**
  960. * mvumi_handshake - Move the FW to READY state
  961. * @mhba: Adapter soft state
  962. *
  963. * During the initialization, FW passes can potentially be in any one of
  964. * several possible states. If the FW in operational, waiting-for-handshake
  965. * states, driver must take steps to bring it to ready state. Otherwise, it
  966. * has to wait for the ready state.
  967. */
  968. static int mvumi_handshake(struct mvumi_hba *mhba)
  969. {
  970. unsigned int hs_state, tmp, hs_fun;
  971. struct mvumi_hs_header *hs_header;
  972. struct mvumi_hw_regs *regs = mhba->regs;
  973. if (mhba->fw_state == FW_STATE_STARTING)
  974. hs_state = HS_S_START;
  975. else {
  976. tmp = ioread32(regs->arm_to_pciea_msg0);
  977. hs_state = HS_GET_STATE(tmp);
  978. dev_dbg(&mhba->pdev->dev, "handshake state[0x%x].\n", hs_state);
  979. if (HS_GET_STATUS(tmp) != HS_STATUS_OK) {
  980. mhba->fw_state = FW_STATE_STARTING;
  981. return -1;
  982. }
  983. }
  984. hs_fun = 0;
  985. switch (hs_state) {
  986. case HS_S_START:
  987. mhba->fw_state = FW_STATE_HANDSHAKING;
  988. HS_SET_STATUS(hs_fun, HS_STATUS_OK);
  989. HS_SET_STATE(hs_fun, HS_S_RESET);
  990. iowrite32(HANDSHAKE_SIGNATURE, regs->pciea_to_arm_msg1);
  991. iowrite32(hs_fun, regs->pciea_to_arm_msg0);
  992. iowrite32(DRBL_HANDSHAKE, regs->pciea_to_arm_drbl_reg);
  993. break;
  994. case HS_S_RESET:
  995. iowrite32(lower_32_bits(mhba->handshake_page_phys),
  996. regs->pciea_to_arm_msg1);
  997. iowrite32(upper_32_bits(mhba->handshake_page_phys),
  998. regs->arm_to_pciea_msg1);
  999. HS_SET_STATUS(hs_fun, HS_STATUS_OK);
  1000. HS_SET_STATE(hs_fun, HS_S_PAGE_ADDR);
  1001. iowrite32(hs_fun, regs->pciea_to_arm_msg0);
  1002. iowrite32(DRBL_HANDSHAKE, regs->pciea_to_arm_drbl_reg);
  1003. break;
  1004. case HS_S_PAGE_ADDR:
  1005. case HS_S_QUERY_PAGE:
  1006. case HS_S_SEND_PAGE:
  1007. hs_header = (struct mvumi_hs_header *) mhba->handshake_page;
  1008. if (hs_header->page_code == HS_PAGE_FIRM_CAP) {
  1009. mhba->hba_total_pages =
  1010. ((struct mvumi_hs_page1 *) hs_header)->total_pages;
  1011. if (mhba->hba_total_pages == 0)
  1012. mhba->hba_total_pages = HS_PAGE_TOTAL-1;
  1013. }
  1014. if (hs_state == HS_S_QUERY_PAGE) {
  1015. if (mvumi_hs_process_page(mhba, hs_header)) {
  1016. HS_SET_STATE(hs_fun, HS_S_ABORT);
  1017. return -1;
  1018. }
  1019. if (mvumi_init_data(mhba)) {
  1020. HS_SET_STATE(hs_fun, HS_S_ABORT);
  1021. return -1;
  1022. }
  1023. } else if (hs_state == HS_S_PAGE_ADDR) {
  1024. hs_header->page_code = 0;
  1025. mhba->hba_total_pages = HS_PAGE_TOTAL-1;
  1026. }
  1027. if ((hs_header->page_code + 1) <= mhba->hba_total_pages) {
  1028. hs_header->page_code++;
  1029. if (hs_header->page_code != HS_PAGE_FIRM_CAP) {
  1030. mvumi_hs_build_page(mhba, hs_header);
  1031. HS_SET_STATE(hs_fun, HS_S_SEND_PAGE);
  1032. } else
  1033. HS_SET_STATE(hs_fun, HS_S_QUERY_PAGE);
  1034. } else
  1035. HS_SET_STATE(hs_fun, HS_S_END);
  1036. HS_SET_STATUS(hs_fun, HS_STATUS_OK);
  1037. iowrite32(hs_fun, regs->pciea_to_arm_msg0);
  1038. iowrite32(DRBL_HANDSHAKE, regs->pciea_to_arm_drbl_reg);
  1039. break;
  1040. case HS_S_END:
  1041. /* Set communication list ISR */
  1042. tmp = ioread32(regs->enpointa_mask_reg);
  1043. tmp |= regs->int_comaout | regs->int_comaerr;
  1044. iowrite32(tmp, regs->enpointa_mask_reg);
  1045. iowrite32(mhba->list_num_io, mhba->ib_shadow);
  1046. /* Set InBound List Available count shadow */
  1047. iowrite32(lower_32_bits(mhba->ib_shadow_phys),
  1048. regs->inb_aval_count_basel);
  1049. iowrite32(upper_32_bits(mhba->ib_shadow_phys),
  1050. regs->inb_aval_count_baseh);
  1051. if (mhba->pdev->device == PCI_DEVICE_ID_MARVELL_MV9143) {
  1052. /* Set OutBound List Available count shadow */
  1053. iowrite32((mhba->list_num_io-1) |
  1054. regs->cl_pointer_toggle,
  1055. mhba->ob_shadow);
  1056. iowrite32(lower_32_bits(mhba->ob_shadow_phys),
  1057. regs->outb_copy_basel);
  1058. iowrite32(upper_32_bits(mhba->ob_shadow_phys),
  1059. regs->outb_copy_baseh);
  1060. }
  1061. mhba->ib_cur_slot = (mhba->list_num_io - 1) |
  1062. regs->cl_pointer_toggle;
  1063. mhba->ob_cur_slot = (mhba->list_num_io - 1) |
  1064. regs->cl_pointer_toggle;
  1065. mhba->fw_state = FW_STATE_STARTED;
  1066. break;
  1067. default:
  1068. dev_err(&mhba->pdev->dev, "unknown handshake state [0x%x].\n",
  1069. hs_state);
  1070. return -1;
  1071. }
  1072. return 0;
  1073. }
  1074. static unsigned char mvumi_handshake_event(struct mvumi_hba *mhba)
  1075. {
  1076. unsigned int isr_status;
  1077. unsigned long before;
  1078. before = jiffies;
  1079. mvumi_handshake(mhba);
  1080. do {
  1081. isr_status = mhba->instancet->read_fw_status_reg(mhba);
  1082. if (mhba->fw_state == FW_STATE_STARTED)
  1083. return 0;
  1084. if (time_after(jiffies, before + FW_MAX_DELAY * HZ)) {
  1085. dev_err(&mhba->pdev->dev,
  1086. "no handshake response at state 0x%x.\n",
  1087. mhba->fw_state);
  1088. dev_err(&mhba->pdev->dev,
  1089. "isr : global=0x%x,status=0x%x.\n",
  1090. mhba->global_isr, isr_status);
  1091. return -1;
  1092. }
  1093. rmb();
  1094. usleep_range(1000, 2000);
  1095. } while (!(isr_status & DRBL_HANDSHAKE_ISR));
  1096. return 0;
  1097. }
  1098. static unsigned char mvumi_check_handshake(struct mvumi_hba *mhba)
  1099. {
  1100. unsigned int tmp;
  1101. unsigned long before;
  1102. before = jiffies;
  1103. tmp = ioread32(mhba->regs->arm_to_pciea_msg1);
  1104. while ((tmp != HANDSHAKE_READYSTATE) && (tmp != HANDSHAKE_DONESTATE)) {
  1105. if (tmp != HANDSHAKE_READYSTATE)
  1106. iowrite32(DRBL_MU_RESET,
  1107. mhba->regs->pciea_to_arm_drbl_reg);
  1108. if (time_after(jiffies, before + FW_MAX_DELAY * HZ)) {
  1109. dev_err(&mhba->pdev->dev,
  1110. "invalid signature [0x%x].\n", tmp);
  1111. return -1;
  1112. }
  1113. usleep_range(1000, 2000);
  1114. rmb();
  1115. tmp = ioread32(mhba->regs->arm_to_pciea_msg1);
  1116. }
  1117. mhba->fw_state = FW_STATE_STARTING;
  1118. dev_dbg(&mhba->pdev->dev, "start firmware handshake...\n");
  1119. do {
  1120. if (mvumi_handshake_event(mhba)) {
  1121. dev_err(&mhba->pdev->dev,
  1122. "handshake failed at state 0x%x.\n",
  1123. mhba->fw_state);
  1124. return -1;
  1125. }
  1126. } while (mhba->fw_state != FW_STATE_STARTED);
  1127. dev_dbg(&mhba->pdev->dev, "firmware handshake done\n");
  1128. return 0;
  1129. }
  1130. static unsigned char mvumi_start(struct mvumi_hba *mhba)
  1131. {
  1132. unsigned int tmp;
  1133. struct mvumi_hw_regs *regs = mhba->regs;
  1134. /* clear Door bell */
  1135. tmp = ioread32(regs->arm_to_pciea_drbl_reg);
  1136. iowrite32(tmp, regs->arm_to_pciea_drbl_reg);
  1137. iowrite32(regs->int_drbl_int_mask, regs->arm_to_pciea_mask_reg);
  1138. tmp = ioread32(regs->enpointa_mask_reg) | regs->int_dl_cpu2pciea;
  1139. iowrite32(tmp, regs->enpointa_mask_reg);
  1140. msleep(100);
  1141. if (mvumi_check_handshake(mhba))
  1142. return -1;
  1143. return 0;
  1144. }
  1145. /**
  1146. * mvumi_complete_cmd - Completes a command
  1147. * @mhba: Adapter soft state
  1148. * @cmd: Command to be completed
  1149. */
  1150. static void mvumi_complete_cmd(struct mvumi_hba *mhba, struct mvumi_cmd *cmd,
  1151. struct mvumi_rsp_frame *ob_frame)
  1152. {
  1153. struct scsi_cmnd *scmd = cmd->scmd;
  1154. cmd->scmd->SCp.ptr = NULL;
  1155. scmd->result = ob_frame->req_status;
  1156. switch (ob_frame->req_status) {
  1157. case SAM_STAT_GOOD:
  1158. scmd->result |= DID_OK << 16;
  1159. break;
  1160. case SAM_STAT_BUSY:
  1161. scmd->result |= DID_BUS_BUSY << 16;
  1162. break;
  1163. case SAM_STAT_CHECK_CONDITION:
  1164. scmd->result |= (DID_OK << 16);
  1165. if (ob_frame->rsp_flag & CL_RSP_FLAG_SENSEDATA) {
  1166. memcpy(cmd->scmd->sense_buffer, ob_frame->payload,
  1167. sizeof(struct mvumi_sense_data));
  1168. scmd->result |= (DRIVER_SENSE << 24);
  1169. }
  1170. break;
  1171. default:
  1172. scmd->result |= (DRIVER_INVALID << 24) | (DID_ABORT << 16);
  1173. break;
  1174. }
  1175. if (scsi_bufflen(scmd)) {
  1176. if (scsi_sg_count(scmd)) {
  1177. pci_unmap_sg(mhba->pdev,
  1178. scsi_sglist(scmd),
  1179. scsi_sg_count(scmd),
  1180. (int) scmd->sc_data_direction);
  1181. } else {
  1182. pci_unmap_single(mhba->pdev,
  1183. scmd->SCp.dma_handle,
  1184. scsi_bufflen(scmd),
  1185. (int) scmd->sc_data_direction);
  1186. scmd->SCp.dma_handle = 0;
  1187. }
  1188. }
  1189. cmd->scmd->scsi_done(scmd);
  1190. mvumi_return_cmd(mhba, cmd);
  1191. }
  1192. static void mvumi_complete_internal_cmd(struct mvumi_hba *mhba,
  1193. struct mvumi_cmd *cmd,
  1194. struct mvumi_rsp_frame *ob_frame)
  1195. {
  1196. if (atomic_read(&cmd->sync_cmd)) {
  1197. cmd->cmd_status = ob_frame->req_status;
  1198. if ((ob_frame->req_status == SAM_STAT_CHECK_CONDITION) &&
  1199. (ob_frame->rsp_flag & CL_RSP_FLAG_SENSEDATA) &&
  1200. cmd->data_buf) {
  1201. memcpy(cmd->data_buf, ob_frame->payload,
  1202. sizeof(struct mvumi_sense_data));
  1203. }
  1204. atomic_dec(&cmd->sync_cmd);
  1205. wake_up(&mhba->int_cmd_wait_q);
  1206. }
  1207. }
  1208. static void mvumi_show_event(struct mvumi_hba *mhba,
  1209. struct mvumi_driver_event *ptr)
  1210. {
  1211. unsigned int i;
  1212. dev_warn(&mhba->pdev->dev,
  1213. "Event[0x%x] id[0x%x] severity[0x%x] device id[0x%x]\n",
  1214. ptr->sequence_no, ptr->event_id, ptr->severity, ptr->device_id);
  1215. if (ptr->param_count) {
  1216. printk(KERN_WARNING "Event param(len 0x%x): ",
  1217. ptr->param_count);
  1218. for (i = 0; i < ptr->param_count; i++)
  1219. printk(KERN_WARNING "0x%x ", ptr->params[i]);
  1220. printk(KERN_WARNING "\n");
  1221. }
  1222. if (ptr->sense_data_length) {
  1223. printk(KERN_WARNING "Event sense data(len 0x%x): ",
  1224. ptr->sense_data_length);
  1225. for (i = 0; i < ptr->sense_data_length; i++)
  1226. printk(KERN_WARNING "0x%x ", ptr->sense_data[i]);
  1227. printk(KERN_WARNING "\n");
  1228. }
  1229. }
  1230. static int mvumi_handle_hotplug(struct mvumi_hba *mhba, u16 devid, int status)
  1231. {
  1232. struct scsi_device *sdev;
  1233. int ret = -1;
  1234. if (status == DEVICE_OFFLINE) {
  1235. sdev = scsi_device_lookup(mhba->shost, 0, devid, 0);
  1236. if (sdev) {
  1237. dev_dbg(&mhba->pdev->dev, "remove disk %d-%d-%d.\n", 0,
  1238. sdev->id, 0);
  1239. scsi_remove_device(sdev);
  1240. scsi_device_put(sdev);
  1241. ret = 0;
  1242. } else
  1243. dev_err(&mhba->pdev->dev, " no disk[%d] to remove\n",
  1244. devid);
  1245. } else if (status == DEVICE_ONLINE) {
  1246. sdev = scsi_device_lookup(mhba->shost, 0, devid, 0);
  1247. if (!sdev) {
  1248. scsi_add_device(mhba->shost, 0, devid, 0);
  1249. dev_dbg(&mhba->pdev->dev, " add disk %d-%d-%d.\n", 0,
  1250. devid, 0);
  1251. ret = 0;
  1252. } else {
  1253. dev_err(&mhba->pdev->dev, " don't add disk %d-%d-%d.\n",
  1254. 0, devid, 0);
  1255. scsi_device_put(sdev);
  1256. }
  1257. }
  1258. return ret;
  1259. }
  1260. static u64 mvumi_inquiry(struct mvumi_hba *mhba,
  1261. unsigned int id, struct mvumi_cmd *cmd)
  1262. {
  1263. struct mvumi_msg_frame *frame;
  1264. u64 wwid = 0;
  1265. int cmd_alloc = 0;
  1266. int data_buf_len = 64;
  1267. if (!cmd) {
  1268. cmd = mvumi_create_internal_cmd(mhba, data_buf_len);
  1269. if (cmd)
  1270. cmd_alloc = 1;
  1271. else
  1272. return 0;
  1273. } else {
  1274. memset(cmd->data_buf, 0, data_buf_len);
  1275. }
  1276. cmd->scmd = NULL;
  1277. cmd->cmd_status = REQ_STATUS_PENDING;
  1278. atomic_set(&cmd->sync_cmd, 0);
  1279. frame = cmd->frame;
  1280. frame->device_id = (u16) id;
  1281. frame->cmd_flag = CMD_FLAG_DATA_IN;
  1282. frame->req_function = CL_FUN_SCSI_CMD;
  1283. frame->cdb_length = 6;
  1284. frame->data_transfer_length = MVUMI_INQUIRY_LENGTH;
  1285. memset(frame->cdb, 0, frame->cdb_length);
  1286. frame->cdb[0] = INQUIRY;
  1287. frame->cdb[4] = frame->data_transfer_length;
  1288. mvumi_issue_blocked_cmd(mhba, cmd);
  1289. if (cmd->cmd_status == SAM_STAT_GOOD) {
  1290. if (mhba->pdev->device == PCI_DEVICE_ID_MARVELL_MV9143)
  1291. wwid = id + 1;
  1292. else
  1293. memcpy((void *)&wwid,
  1294. (cmd->data_buf + MVUMI_INQUIRY_UUID_OFF),
  1295. MVUMI_INQUIRY_UUID_LEN);
  1296. dev_dbg(&mhba->pdev->dev,
  1297. "inquiry device(0:%d:0) wwid(%llx)\n", id, wwid);
  1298. } else {
  1299. wwid = 0;
  1300. }
  1301. if (cmd_alloc)
  1302. mvumi_delete_internal_cmd(mhba, cmd);
  1303. return wwid;
  1304. }
  1305. static void mvumi_detach_devices(struct mvumi_hba *mhba)
  1306. {
  1307. struct mvumi_device *mv_dev = NULL , *dev_next;
  1308. struct scsi_device *sdev = NULL;
  1309. mutex_lock(&mhba->device_lock);
  1310. /* detach Hard Disk */
  1311. list_for_each_entry_safe(mv_dev, dev_next,
  1312. &mhba->shost_dev_list, list) {
  1313. mvumi_handle_hotplug(mhba, mv_dev->id, DEVICE_OFFLINE);
  1314. list_del_init(&mv_dev->list);
  1315. dev_dbg(&mhba->pdev->dev, "release device(0:%d:0) wwid(%llx)\n",
  1316. mv_dev->id, mv_dev->wwid);
  1317. kfree(mv_dev);
  1318. }
  1319. list_for_each_entry_safe(mv_dev, dev_next, &mhba->mhba_dev_list, list) {
  1320. list_del_init(&mv_dev->list);
  1321. dev_dbg(&mhba->pdev->dev, "release device(0:%d:0) wwid(%llx)\n",
  1322. mv_dev->id, mv_dev->wwid);
  1323. kfree(mv_dev);
  1324. }
  1325. /* detach virtual device */
  1326. if (mhba->pdev->device == PCI_DEVICE_ID_MARVELL_MV9580)
  1327. sdev = scsi_device_lookup(mhba->shost, 0,
  1328. mhba->max_target_id - 1, 0);
  1329. if (sdev) {
  1330. scsi_remove_device(sdev);
  1331. scsi_device_put(sdev);
  1332. }
  1333. mutex_unlock(&mhba->device_lock);
  1334. }
  1335. static void mvumi_rescan_devices(struct mvumi_hba *mhba, int id)
  1336. {
  1337. struct scsi_device *sdev;
  1338. sdev = scsi_device_lookup(mhba->shost, 0, id, 0);
  1339. if (sdev) {
  1340. scsi_rescan_device(&sdev->sdev_gendev);
  1341. scsi_device_put(sdev);
  1342. }
  1343. }
  1344. static int mvumi_match_devices(struct mvumi_hba *mhba, int id, u64 wwid)
  1345. {
  1346. struct mvumi_device *mv_dev = NULL;
  1347. list_for_each_entry(mv_dev, &mhba->shost_dev_list, list) {
  1348. if (mv_dev->wwid == wwid) {
  1349. if (mv_dev->id != id) {
  1350. dev_err(&mhba->pdev->dev,
  1351. "%s has same wwid[%llx] ,"
  1352. " but different id[%d %d]\n",
  1353. __func__, mv_dev->wwid, mv_dev->id, id);
  1354. return -1;
  1355. } else {
  1356. if (mhba->pdev->device ==
  1357. PCI_DEVICE_ID_MARVELL_MV9143)
  1358. mvumi_rescan_devices(mhba, id);
  1359. return 1;
  1360. }
  1361. }
  1362. }
  1363. return 0;
  1364. }
  1365. static void mvumi_remove_devices(struct mvumi_hba *mhba, int id)
  1366. {
  1367. struct mvumi_device *mv_dev = NULL, *dev_next;
  1368. list_for_each_entry_safe(mv_dev, dev_next,
  1369. &mhba->shost_dev_list, list) {
  1370. if (mv_dev->id == id) {
  1371. dev_dbg(&mhba->pdev->dev,
  1372. "detach device(0:%d:0) wwid(%llx) from HOST\n",
  1373. mv_dev->id, mv_dev->wwid);
  1374. mvumi_handle_hotplug(mhba, mv_dev->id, DEVICE_OFFLINE);
  1375. list_del_init(&mv_dev->list);
  1376. kfree(mv_dev);
  1377. }
  1378. }
  1379. }
  1380. static int mvumi_probe_devices(struct mvumi_hba *mhba)
  1381. {
  1382. int id, maxid;
  1383. u64 wwid = 0;
  1384. struct mvumi_device *mv_dev = NULL;
  1385. struct mvumi_cmd *cmd = NULL;
  1386. int found = 0;
  1387. cmd = mvumi_create_internal_cmd(mhba, 64);
  1388. if (!cmd)
  1389. return -1;
  1390. if (mhba->pdev->device == PCI_DEVICE_ID_MARVELL_MV9143)
  1391. maxid = mhba->max_target_id;
  1392. else
  1393. maxid = mhba->max_target_id - 1;
  1394. for (id = 0; id < maxid; id++) {
  1395. wwid = mvumi_inquiry(mhba, id, cmd);
  1396. if (!wwid) {
  1397. /* device no response, remove it */
  1398. mvumi_remove_devices(mhba, id);
  1399. } else {
  1400. /* device response, add it */
  1401. found = mvumi_match_devices(mhba, id, wwid);
  1402. if (!found) {
  1403. mvumi_remove_devices(mhba, id);
  1404. mv_dev = kzalloc(sizeof(struct mvumi_device),
  1405. GFP_KERNEL);
  1406. if (!mv_dev) {
  1407. dev_err(&mhba->pdev->dev,
  1408. "%s alloc mv_dev failed\n",
  1409. __func__);
  1410. continue;
  1411. }
  1412. mv_dev->id = id;
  1413. mv_dev->wwid = wwid;
  1414. mv_dev->sdev = NULL;
  1415. INIT_LIST_HEAD(&mv_dev->list);
  1416. list_add_tail(&mv_dev->list,
  1417. &mhba->mhba_dev_list);
  1418. dev_dbg(&mhba->pdev->dev,
  1419. "probe a new device(0:%d:0)"
  1420. " wwid(%llx)\n", id, mv_dev->wwid);
  1421. } else if (found == -1)
  1422. return -1;
  1423. else
  1424. continue;
  1425. }
  1426. }
  1427. if (cmd)
  1428. mvumi_delete_internal_cmd(mhba, cmd);
  1429. return 0;
  1430. }
  1431. static int mvumi_rescan_bus(void *data)
  1432. {
  1433. int ret = 0;
  1434. struct mvumi_hba *mhba = (struct mvumi_hba *) data;
  1435. struct mvumi_device *mv_dev = NULL , *dev_next;
  1436. while (!kthread_should_stop()) {
  1437. set_current_state(TASK_INTERRUPTIBLE);
  1438. if (!atomic_read(&mhba->pnp_count))
  1439. schedule();
  1440. msleep(1000);
  1441. atomic_set(&mhba->pnp_count, 0);
  1442. __set_current_state(TASK_RUNNING);
  1443. mutex_lock(&mhba->device_lock);
  1444. ret = mvumi_probe_devices(mhba);
  1445. if (!ret) {
  1446. list_for_each_entry_safe(mv_dev, dev_next,
  1447. &mhba->mhba_dev_list, list) {
  1448. if (mvumi_handle_hotplug(mhba, mv_dev->id,
  1449. DEVICE_ONLINE)) {
  1450. dev_err(&mhba->pdev->dev,
  1451. "%s add device(0:%d:0) failed"
  1452. "wwid(%llx) has exist\n",
  1453. __func__,
  1454. mv_dev->id, mv_dev->wwid);
  1455. list_del_init(&mv_dev->list);
  1456. kfree(mv_dev);
  1457. } else {
  1458. list_move_tail(&mv_dev->list,
  1459. &mhba->shost_dev_list);
  1460. }
  1461. }
  1462. }
  1463. mutex_unlock(&mhba->device_lock);
  1464. }
  1465. return 0;
  1466. }
  1467. static void mvumi_proc_msg(struct mvumi_hba *mhba,
  1468. struct mvumi_hotplug_event *param)
  1469. {
  1470. u16 size = param->size;
  1471. const unsigned long *ar_bitmap;
  1472. const unsigned long *re_bitmap;
  1473. int index;
  1474. if (mhba->fw_flag & MVUMI_FW_ATTACH) {
  1475. index = -1;
  1476. ar_bitmap = (const unsigned long *) param->bitmap;
  1477. re_bitmap = (const unsigned long *) &param->bitmap[size >> 3];
  1478. mutex_lock(&mhba->sas_discovery_mutex);
  1479. do {
  1480. index = find_next_zero_bit(ar_bitmap, size, index + 1);
  1481. if (index >= size)
  1482. break;
  1483. mvumi_handle_hotplug(mhba, index, DEVICE_ONLINE);
  1484. } while (1);
  1485. index = -1;
  1486. do {
  1487. index = find_next_zero_bit(re_bitmap, size, index + 1);
  1488. if (index >= size)
  1489. break;
  1490. mvumi_handle_hotplug(mhba, index, DEVICE_OFFLINE);
  1491. } while (1);
  1492. mutex_unlock(&mhba->sas_discovery_mutex);
  1493. }
  1494. }
  1495. static void mvumi_notification(struct mvumi_hba *mhba, u8 msg, void *buffer)
  1496. {
  1497. if (msg == APICDB1_EVENT_GETEVENT) {
  1498. int i, count;
  1499. struct mvumi_driver_event *param = NULL;
  1500. struct mvumi_event_req *er = buffer;
  1501. count = er->count;
  1502. if (count > MAX_EVENTS_RETURNED) {
  1503. dev_err(&mhba->pdev->dev, "event count[0x%x] is bigger"
  1504. " than max event count[0x%x].\n",
  1505. count, MAX_EVENTS_RETURNED);
  1506. return;
  1507. }
  1508. for (i = 0; i < count; i++) {
  1509. param = &er->events[i];
  1510. mvumi_show_event(mhba, param);
  1511. }
  1512. } else if (msg == APICDB1_HOST_GETEVENT) {
  1513. mvumi_proc_msg(mhba, buffer);
  1514. }
  1515. }
  1516. static int mvumi_get_event(struct mvumi_hba *mhba, unsigned char msg)
  1517. {
  1518. struct mvumi_cmd *cmd;
  1519. struct mvumi_msg_frame *frame;
  1520. cmd = mvumi_create_internal_cmd(mhba, 512);
  1521. if (!cmd)
  1522. return -1;
  1523. cmd->scmd = NULL;
  1524. cmd->cmd_status = REQ_STATUS_PENDING;
  1525. atomic_set(&cmd->sync_cmd, 0);
  1526. frame = cmd->frame;
  1527. frame->device_id = 0;
  1528. frame->cmd_flag = CMD_FLAG_DATA_IN;
  1529. frame->req_function = CL_FUN_SCSI_CMD;
  1530. frame->cdb_length = MAX_COMMAND_SIZE;
  1531. frame->data_transfer_length = sizeof(struct mvumi_event_req);
  1532. memset(frame->cdb, 0, MAX_COMMAND_SIZE);
  1533. frame->cdb[0] = APICDB0_EVENT;
  1534. frame->cdb[1] = msg;
  1535. mvumi_issue_blocked_cmd(mhba, cmd);
  1536. if (cmd->cmd_status != SAM_STAT_GOOD)
  1537. dev_err(&mhba->pdev->dev, "get event failed, status=0x%x.\n",
  1538. cmd->cmd_status);
  1539. else
  1540. mvumi_notification(mhba, cmd->frame->cdb[1], cmd->data_buf);
  1541. mvumi_delete_internal_cmd(mhba, cmd);
  1542. return 0;
  1543. }
  1544. static void mvumi_scan_events(struct work_struct *work)
  1545. {
  1546. struct mvumi_events_wq *mu_ev =
  1547. container_of(work, struct mvumi_events_wq, work_q);
  1548. mvumi_get_event(mu_ev->mhba, mu_ev->event);
  1549. kfree(mu_ev);
  1550. }
  1551. static void mvumi_launch_events(struct mvumi_hba *mhba, u32 isr_status)
  1552. {
  1553. struct mvumi_events_wq *mu_ev;
  1554. while (isr_status & (DRBL_BUS_CHANGE | DRBL_EVENT_NOTIFY)) {
  1555. if (isr_status & DRBL_BUS_CHANGE) {
  1556. atomic_inc(&mhba->pnp_count);
  1557. wake_up_process(mhba->dm_thread);
  1558. isr_status &= ~(DRBL_BUS_CHANGE);
  1559. continue;
  1560. }
  1561. mu_ev = kzalloc(sizeof(*mu_ev), GFP_ATOMIC);
  1562. if (mu_ev) {
  1563. INIT_WORK(&mu_ev->work_q, mvumi_scan_events);
  1564. mu_ev->mhba = mhba;
  1565. mu_ev->event = APICDB1_EVENT_GETEVENT;
  1566. isr_status &= ~(DRBL_EVENT_NOTIFY);
  1567. mu_ev->param = NULL;
  1568. schedule_work(&mu_ev->work_q);
  1569. }
  1570. }
  1571. }
  1572. static void mvumi_handle_clob(struct mvumi_hba *mhba)
  1573. {
  1574. struct mvumi_rsp_frame *ob_frame;
  1575. struct mvumi_cmd *cmd;
  1576. struct mvumi_ob_data *pool;
  1577. while (!list_empty(&mhba->free_ob_list)) {
  1578. pool = list_first_entry(&mhba->free_ob_list,
  1579. struct mvumi_ob_data, list);
  1580. list_del_init(&pool->list);
  1581. list_add_tail(&pool->list, &mhba->ob_data_list);
  1582. ob_frame = (struct mvumi_rsp_frame *) &pool->data[0];
  1583. cmd = mhba->tag_cmd[ob_frame->tag];
  1584. atomic_dec(&mhba->fw_outstanding);
  1585. mhba->tag_cmd[ob_frame->tag] = 0;
  1586. tag_release_one(mhba, &mhba->tag_pool, ob_frame->tag);
  1587. if (cmd->scmd)
  1588. mvumi_complete_cmd(mhba, cmd, ob_frame);
  1589. else
  1590. mvumi_complete_internal_cmd(mhba, cmd, ob_frame);
  1591. }
  1592. mhba->instancet->fire_cmd(mhba, NULL);
  1593. }
  1594. static irqreturn_t mvumi_isr_handler(int irq, void *devp)
  1595. {
  1596. struct mvumi_hba *mhba = (struct mvumi_hba *) devp;
  1597. unsigned long flags;
  1598. spin_lock_irqsave(mhba->shost->host_lock, flags);
  1599. if (unlikely(mhba->instancet->clear_intr(mhba) || !mhba->global_isr)) {
  1600. spin_unlock_irqrestore(mhba->shost->host_lock, flags);
  1601. return IRQ_NONE;
  1602. }
  1603. if (mhba->global_isr & mhba->regs->int_dl_cpu2pciea) {
  1604. if (mhba->isr_status & (DRBL_BUS_CHANGE | DRBL_EVENT_NOTIFY))
  1605. mvumi_launch_events(mhba, mhba->isr_status);
  1606. if (mhba->isr_status & DRBL_HANDSHAKE_ISR) {
  1607. dev_warn(&mhba->pdev->dev, "enter handshake again!\n");
  1608. mvumi_handshake(mhba);
  1609. }
  1610. }
  1611. if (mhba->global_isr & mhba->regs->int_comaout)
  1612. mvumi_receive_ob_list_entry(mhba);
  1613. mhba->global_isr = 0;
  1614. mhba->isr_status = 0;
  1615. if (mhba->fw_state == FW_STATE_STARTED)
  1616. mvumi_handle_clob(mhba);
  1617. spin_unlock_irqrestore(mhba->shost->host_lock, flags);
  1618. return IRQ_HANDLED;
  1619. }
  1620. static enum mvumi_qc_result mvumi_send_command(struct mvumi_hba *mhba,
  1621. struct mvumi_cmd *cmd)
  1622. {
  1623. void *ib_entry;
  1624. struct mvumi_msg_frame *ib_frame;
  1625. unsigned int frame_len;
  1626. ib_frame = cmd->frame;
  1627. if (unlikely(mhba->fw_state != FW_STATE_STARTED)) {
  1628. dev_dbg(&mhba->pdev->dev, "firmware not ready.\n");
  1629. return MV_QUEUE_COMMAND_RESULT_NO_RESOURCE;
  1630. }
  1631. if (tag_is_empty(&mhba->tag_pool)) {
  1632. dev_dbg(&mhba->pdev->dev, "no free tag.\n");
  1633. return MV_QUEUE_COMMAND_RESULT_NO_RESOURCE;
  1634. }
  1635. mvumi_get_ib_list_entry(mhba, &ib_entry);
  1636. cmd->frame->tag = tag_get_one(mhba, &mhba->tag_pool);
  1637. cmd->frame->request_id = mhba->io_seq++;
  1638. cmd->request_id = cmd->frame->request_id;
  1639. mhba->tag_cmd[cmd->frame->tag] = cmd;
  1640. frame_len = sizeof(*ib_frame) - 4 +
  1641. ib_frame->sg_counts * sizeof(struct mvumi_sgl);
  1642. if (mhba->hba_capability & HS_CAPABILITY_SUPPORT_DYN_SRC) {
  1643. struct mvumi_dyn_list_entry *dle;
  1644. dle = ib_entry;
  1645. dle->src_low_addr =
  1646. cpu_to_le32(lower_32_bits(cmd->frame_phys));
  1647. dle->src_high_addr =
  1648. cpu_to_le32(upper_32_bits(cmd->frame_phys));
  1649. dle->if_length = (frame_len >> 2) & 0xFFF;
  1650. } else {
  1651. memcpy(ib_entry, ib_frame, frame_len);
  1652. }
  1653. return MV_QUEUE_COMMAND_RESULT_SENT;
  1654. }
  1655. static void mvumi_fire_cmd(struct mvumi_hba *mhba, struct mvumi_cmd *cmd)
  1656. {
  1657. unsigned short num_of_cl_sent = 0;
  1658. unsigned int count;
  1659. enum mvumi_qc_result result;
  1660. if (cmd)
  1661. list_add_tail(&cmd->queue_pointer, &mhba->waiting_req_list);
  1662. count = mhba->instancet->check_ib_list(mhba);
  1663. if (list_empty(&mhba->waiting_req_list) || !count)
  1664. return;
  1665. do {
  1666. cmd = list_first_entry(&mhba->waiting_req_list,
  1667. struct mvumi_cmd, queue_pointer);
  1668. list_del_init(&cmd->queue_pointer);
  1669. result = mvumi_send_command(mhba, cmd);
  1670. switch (result) {
  1671. case MV_QUEUE_COMMAND_RESULT_SENT:
  1672. num_of_cl_sent++;
  1673. break;
  1674. case MV_QUEUE_COMMAND_RESULT_NO_RESOURCE:
  1675. list_add(&cmd->queue_pointer, &mhba->waiting_req_list);
  1676. if (num_of_cl_sent > 0)
  1677. mvumi_send_ib_list_entry(mhba);
  1678. return;
  1679. }
  1680. } while (!list_empty(&mhba->waiting_req_list) && count--);
  1681. if (num_of_cl_sent > 0)
  1682. mvumi_send_ib_list_entry(mhba);
  1683. }
  1684. /**
  1685. * mvumi_enable_intr - Enables interrupts
  1686. * @mhba: Adapter soft state
  1687. */
  1688. static void mvumi_enable_intr(struct mvumi_hba *mhba)
  1689. {
  1690. unsigned int mask;
  1691. struct mvumi_hw_regs *regs = mhba->regs;
  1692. iowrite32(regs->int_drbl_int_mask, regs->arm_to_pciea_mask_reg);
  1693. mask = ioread32(regs->enpointa_mask_reg);
  1694. mask |= regs->int_dl_cpu2pciea | regs->int_comaout | regs->int_comaerr;
  1695. iowrite32(mask, regs->enpointa_mask_reg);
  1696. }
  1697. /**
  1698. * mvumi_disable_intr -Disables interrupt
  1699. * @mhba: Adapter soft state
  1700. */
  1701. static void mvumi_disable_intr(struct mvumi_hba *mhba)
  1702. {
  1703. unsigned int mask;
  1704. struct mvumi_hw_regs *regs = mhba->regs;
  1705. iowrite32(0, regs->arm_to_pciea_mask_reg);
  1706. mask = ioread32(regs->enpointa_mask_reg);
  1707. mask &= ~(regs->int_dl_cpu2pciea | regs->int_comaout |
  1708. regs->int_comaerr);
  1709. iowrite32(mask, regs->enpointa_mask_reg);
  1710. }
  1711. static int mvumi_clear_intr(void *extend)
  1712. {
  1713. struct mvumi_hba *mhba = (struct mvumi_hba *) extend;
  1714. unsigned int status, isr_status = 0, tmp = 0;
  1715. struct mvumi_hw_regs *regs = mhba->regs;
  1716. status = ioread32(regs->main_int_cause_reg);
  1717. if (!(status & regs->int_mu) || status == 0xFFFFFFFF)
  1718. return 1;
  1719. if (unlikely(status & regs->int_comaerr)) {
  1720. tmp = ioread32(regs->outb_isr_cause);
  1721. if (mhba->pdev->device == PCI_DEVICE_ID_MARVELL_MV9580) {
  1722. if (tmp & regs->clic_out_err) {
  1723. iowrite32(tmp & regs->clic_out_err,
  1724. regs->outb_isr_cause);
  1725. }
  1726. } else {
  1727. if (tmp & (regs->clic_in_err | regs->clic_out_err))
  1728. iowrite32(tmp & (regs->clic_in_err |
  1729. regs->clic_out_err),
  1730. regs->outb_isr_cause);
  1731. }
  1732. status ^= mhba->regs->int_comaerr;
  1733. /* inbound or outbound parity error, command will timeout */
  1734. }
  1735. if (status & regs->int_comaout) {
  1736. tmp = ioread32(regs->outb_isr_cause);
  1737. if (tmp & regs->clic_irq)
  1738. iowrite32(tmp & regs->clic_irq, regs->outb_isr_cause);
  1739. }
  1740. if (status & regs->int_dl_cpu2pciea) {
  1741. isr_status = ioread32(regs->arm_to_pciea_drbl_reg);
  1742. if (isr_status)
  1743. iowrite32(isr_status, regs->arm_to_pciea_drbl_reg);
  1744. }
  1745. mhba->global_isr = status;
  1746. mhba->isr_status = isr_status;
  1747. return 0;
  1748. }
  1749. /**
  1750. * mvumi_read_fw_status_reg - returns the current FW status value
  1751. * @mhba: Adapter soft state
  1752. */
  1753. static unsigned int mvumi_read_fw_status_reg(struct mvumi_hba *mhba)
  1754. {
  1755. unsigned int status;
  1756. status = ioread32(mhba->regs->arm_to_pciea_drbl_reg);
  1757. if (status)
  1758. iowrite32(status, mhba->regs->arm_to_pciea_drbl_reg);
  1759. return status;
  1760. }
  1761. static struct mvumi_instance_template mvumi_instance_9143 = {
  1762. .fire_cmd = mvumi_fire_cmd,
  1763. .enable_intr = mvumi_enable_intr,
  1764. .disable_intr = mvumi_disable_intr,
  1765. .clear_intr = mvumi_clear_intr,
  1766. .read_fw_status_reg = mvumi_read_fw_status_reg,
  1767. .check_ib_list = mvumi_check_ib_list_9143,
  1768. .check_ob_list = mvumi_check_ob_list_9143,
  1769. .reset_host = mvumi_reset_host_9143,
  1770. };
  1771. static struct mvumi_instance_template mvumi_instance_9580 = {
  1772. .fire_cmd = mvumi_fire_cmd,
  1773. .enable_intr = mvumi_enable_intr,
  1774. .disable_intr = mvumi_disable_intr,
  1775. .clear_intr = mvumi_clear_intr,
  1776. .read_fw_status_reg = mvumi_read_fw_status_reg,
  1777. .check_ib_list = mvumi_check_ib_list_9580,
  1778. .check_ob_list = mvumi_check_ob_list_9580,
  1779. .reset_host = mvumi_reset_host_9580,
  1780. };
  1781. static int mvumi_slave_configure(struct scsi_device *sdev)
  1782. {
  1783. struct mvumi_hba *mhba;
  1784. unsigned char bitcount = sizeof(unsigned char) * 8;
  1785. mhba = (struct mvumi_hba *) sdev->host->hostdata;
  1786. if (sdev->id >= mhba->max_target_id)
  1787. return -EINVAL;
  1788. mhba->target_map[sdev->id / bitcount] |= (1 << (sdev->id % bitcount));
  1789. return 0;
  1790. }
  1791. /**
  1792. * mvumi_build_frame - Prepares a direct cdb (DCDB) command
  1793. * @mhba: Adapter soft state
  1794. * @scmd: SCSI command
  1795. * @cmd: Command to be prepared in
  1796. *
  1797. * This function prepares CDB commands. These are typcially pass-through
  1798. * commands to the devices.
  1799. */
  1800. static unsigned char mvumi_build_frame(struct mvumi_hba *mhba,
  1801. struct scsi_cmnd *scmd, struct mvumi_cmd *cmd)
  1802. {
  1803. struct mvumi_msg_frame *pframe;
  1804. cmd->scmd = scmd;
  1805. cmd->cmd_status = REQ_STATUS_PENDING;
  1806. pframe = cmd->frame;
  1807. pframe->device_id = ((unsigned short) scmd->device->id) |
  1808. (((unsigned short) scmd->device->lun) << 8);
  1809. pframe->cmd_flag = 0;
  1810. switch (scmd->sc_data_direction) {
  1811. case DMA_NONE:
  1812. pframe->cmd_flag |= CMD_FLAG_NON_DATA;
  1813. break;
  1814. case DMA_FROM_DEVICE:
  1815. pframe->cmd_flag |= CMD_FLAG_DATA_IN;
  1816. break;
  1817. case DMA_TO_DEVICE:
  1818. pframe->cmd_flag |= CMD_FLAG_DATA_OUT;
  1819. break;
  1820. case DMA_BIDIRECTIONAL:
  1821. default:
  1822. dev_warn(&mhba->pdev->dev, "unexpected data direction[%d] "
  1823. "cmd[0x%x]\n", scmd->sc_data_direction, scmd->cmnd[0]);
  1824. goto error;
  1825. }
  1826. pframe->cdb_length = scmd->cmd_len;
  1827. memcpy(pframe->cdb, scmd->cmnd, pframe->cdb_length);
  1828. pframe->req_function = CL_FUN_SCSI_CMD;
  1829. if (scsi_bufflen(scmd)) {
  1830. if (mvumi_make_sgl(mhba, scmd, &pframe->payload[0],
  1831. &pframe->sg_counts))
  1832. goto error;
  1833. pframe->data_transfer_length = scsi_bufflen(scmd);
  1834. } else {
  1835. pframe->sg_counts = 0;
  1836. pframe->data_transfer_length = 0;
  1837. }
  1838. return 0;
  1839. error:
  1840. scmd->result = (DID_OK << 16) | (DRIVER_SENSE << 24) |
  1841. SAM_STAT_CHECK_CONDITION;
  1842. scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x24,
  1843. 0);
  1844. return -1;
  1845. }
  1846. /**
  1847. * mvumi_queue_command - Queue entry point
  1848. * @scmd: SCSI command to be queued
  1849. * @done: Callback entry point
  1850. */
  1851. static int mvumi_queue_command(struct Scsi_Host *shost,
  1852. struct scsi_cmnd *scmd)
  1853. {
  1854. struct mvumi_cmd *cmd;
  1855. struct mvumi_hba *mhba;
  1856. unsigned long irq_flags;
  1857. spin_lock_irqsave(shost->host_lock, irq_flags);
  1858. scsi_cmd_get_serial(shost, scmd);
  1859. mhba = (struct mvumi_hba *) shost->hostdata;
  1860. scmd->result = 0;
  1861. cmd = mvumi_get_cmd(mhba);
  1862. if (unlikely(!cmd)) {
  1863. spin_unlock_irqrestore(shost->host_lock, irq_flags);
  1864. return SCSI_MLQUEUE_HOST_BUSY;
  1865. }
  1866. if (unlikely(mvumi_build_frame(mhba, scmd, cmd)))
  1867. goto out_return_cmd;
  1868. cmd->scmd = scmd;
  1869. scmd->SCp.ptr = (char *) cmd;
  1870. mhba->instancet->fire_cmd(mhba, cmd);
  1871. spin_unlock_irqrestore(shost->host_lock, irq_flags);
  1872. return 0;
  1873. out_return_cmd:
  1874. mvumi_return_cmd(mhba, cmd);
  1875. scmd->scsi_done(scmd);
  1876. spin_unlock_irqrestore(shost->host_lock, irq_flags);
  1877. return 0;
  1878. }
  1879. static enum blk_eh_timer_return mvumi_timed_out(struct scsi_cmnd *scmd)
  1880. {
  1881. struct mvumi_cmd *cmd = (struct mvumi_cmd *) scmd->SCp.ptr;
  1882. struct Scsi_Host *host = scmd->device->host;
  1883. struct mvumi_hba *mhba = shost_priv(host);
  1884. unsigned long flags;
  1885. spin_lock_irqsave(mhba->shost->host_lock, flags);
  1886. if (mhba->tag_cmd[cmd->frame->tag]) {
  1887. mhba->tag_cmd[cmd->frame->tag] = 0;
  1888. tag_release_one(mhba, &mhba->tag_pool, cmd->frame->tag);
  1889. }
  1890. if (!list_empty(&cmd->queue_pointer))
  1891. list_del_init(&cmd->queue_pointer);
  1892. else
  1893. atomic_dec(&mhba->fw_outstanding);
  1894. scmd->result = (DRIVER_INVALID << 24) | (DID_ABORT << 16);
  1895. scmd->SCp.ptr = NULL;
  1896. if (scsi_bufflen(scmd)) {
  1897. if (scsi_sg_count(scmd)) {
  1898. pci_unmap_sg(mhba->pdev,
  1899. scsi_sglist(scmd),
  1900. scsi_sg_count(scmd),
  1901. (int)scmd->sc_data_direction);
  1902. } else {
  1903. pci_unmap_single(mhba->pdev,
  1904. scmd->SCp.dma_handle,
  1905. scsi_bufflen(scmd),
  1906. (int)scmd->sc_data_direction);
  1907. scmd->SCp.dma_handle = 0;
  1908. }
  1909. }
  1910. mvumi_return_cmd(mhba, cmd);
  1911. spin_unlock_irqrestore(mhba->shost->host_lock, flags);
  1912. return BLK_EH_NOT_HANDLED;
  1913. }
  1914. static int
  1915. mvumi_bios_param(struct scsi_device *sdev, struct block_device *bdev,
  1916. sector_t capacity, int geom[])
  1917. {
  1918. int heads, sectors;
  1919. sector_t cylinders;
  1920. unsigned long tmp;
  1921. heads = 64;
  1922. sectors = 32;
  1923. tmp = heads * sectors;
  1924. cylinders = capacity;
  1925. sector_div(cylinders, tmp);
  1926. if (capacity >= 0x200000) {
  1927. heads = 255;
  1928. sectors = 63;
  1929. tmp = heads * sectors;
  1930. cylinders = capacity;
  1931. sector_div(cylinders, tmp);
  1932. }
  1933. geom[0] = heads;
  1934. geom[1] = sectors;
  1935. geom[2] = cylinders;
  1936. return 0;
  1937. }
  1938. static struct scsi_host_template mvumi_template = {
  1939. .module = THIS_MODULE,
  1940. .name = "Marvell Storage Controller",
  1941. .slave_configure = mvumi_slave_configure,
  1942. .queuecommand = mvumi_queue_command,
  1943. .eh_host_reset_handler = mvumi_host_reset,
  1944. .bios_param = mvumi_bios_param,
  1945. .this_id = -1,
  1946. };
  1947. static struct scsi_transport_template mvumi_transport_template = {
  1948. .eh_timed_out = mvumi_timed_out,
  1949. };
  1950. static int mvumi_cfg_hw_reg(struct mvumi_hba *mhba)
  1951. {
  1952. void *base = NULL;
  1953. struct mvumi_hw_regs *regs;
  1954. switch (mhba->pdev->device) {
  1955. case PCI_DEVICE_ID_MARVELL_MV9143:
  1956. mhba->mmio = mhba->base_addr[0];
  1957. base = mhba->mmio;
  1958. if (!mhba->regs) {
  1959. mhba->regs = kzalloc(sizeof(*regs), GFP_KERNEL);
  1960. if (mhba->regs == NULL)
  1961. return -ENOMEM;
  1962. }
  1963. regs = mhba->regs;
  1964. /* For Arm */
  1965. regs->ctrl_sts_reg = base + 0x20104;
  1966. regs->rstoutn_mask_reg = base + 0x20108;
  1967. regs->sys_soft_rst_reg = base + 0x2010C;
  1968. regs->main_int_cause_reg = base + 0x20200;
  1969. regs->enpointa_mask_reg = base + 0x2020C;
  1970. regs->rstoutn_en_reg = base + 0xF1400;
  1971. /* For Doorbell */
  1972. regs->pciea_to_arm_drbl_reg = base + 0x20400;
  1973. regs->arm_to_pciea_drbl_reg = base + 0x20408;
  1974. regs->arm_to_pciea_mask_reg = base + 0x2040C;
  1975. regs->pciea_to_arm_msg0 = base + 0x20430;
  1976. regs->pciea_to_arm_msg1 = base + 0x20434;
  1977. regs->arm_to_pciea_msg0 = base + 0x20438;
  1978. regs->arm_to_pciea_msg1 = base + 0x2043C;
  1979. /* For Message Unit */
  1980. regs->inb_aval_count_basel = base + 0x508;
  1981. regs->inb_aval_count_baseh = base + 0x50C;
  1982. regs->inb_write_pointer = base + 0x518;
  1983. regs->inb_read_pointer = base + 0x51C;
  1984. regs->outb_coal_cfg = base + 0x568;
  1985. regs->outb_copy_basel = base + 0x5B0;
  1986. regs->outb_copy_baseh = base + 0x5B4;
  1987. regs->outb_copy_pointer = base + 0x544;
  1988. regs->outb_read_pointer = base + 0x548;
  1989. regs->outb_isr_cause = base + 0x560;
  1990. regs->outb_coal_cfg = base + 0x568;
  1991. /* Bit setting for HW */
  1992. regs->int_comaout = 1 << 8;
  1993. regs->int_comaerr = 1 << 6;
  1994. regs->int_dl_cpu2pciea = 1 << 1;
  1995. regs->cl_pointer_toggle = 1 << 12;
  1996. regs->clic_irq = 1 << 1;
  1997. regs->clic_in_err = 1 << 8;
  1998. regs->clic_out_err = 1 << 12;
  1999. regs->cl_slot_num_mask = 0xFFF;
  2000. regs->int_drbl_int_mask = 0x3FFFFFFF;
  2001. regs->int_mu = regs->int_dl_cpu2pciea | regs->int_comaout |
  2002. regs->int_comaerr;
  2003. break;
  2004. case PCI_DEVICE_ID_MARVELL_MV9580:
  2005. mhba->mmio = mhba->base_addr[2];
  2006. base = mhba->mmio;
  2007. if (!mhba->regs) {
  2008. mhba->regs = kzalloc(sizeof(*regs), GFP_KERNEL);
  2009. if (mhba->regs == NULL)
  2010. return -ENOMEM;
  2011. }
  2012. regs = mhba->regs;
  2013. /* For Arm */
  2014. regs->ctrl_sts_reg = base + 0x20104;
  2015. regs->rstoutn_mask_reg = base + 0x1010C;
  2016. regs->sys_soft_rst_reg = base + 0x10108;
  2017. regs->main_int_cause_reg = base + 0x10200;
  2018. regs->enpointa_mask_reg = base + 0x1020C;
  2019. regs->rstoutn_en_reg = base + 0xF1400;
  2020. /* For Doorbell */
  2021. regs->pciea_to_arm_drbl_reg = base + 0x10460;
  2022. regs->arm_to_pciea_drbl_reg = base + 0x10480;
  2023. regs->arm_to_pciea_mask_reg = base + 0x10484;
  2024. regs->pciea_to_arm_msg0 = base + 0x10400;
  2025. regs->pciea_to_arm_msg1 = base + 0x10404;
  2026. regs->arm_to_pciea_msg0 = base + 0x10420;
  2027. regs->arm_to_pciea_msg1 = base + 0x10424;
  2028. /* For reset*/
  2029. regs->reset_request = base + 0x10108;
  2030. regs->reset_enable = base + 0x1010c;
  2031. /* For Message Unit */
  2032. regs->inb_aval_count_basel = base + 0x4008;
  2033. regs->inb_aval_count_baseh = base + 0x400C;
  2034. regs->inb_write_pointer = base + 0x4018;
  2035. regs->inb_read_pointer = base + 0x401C;
  2036. regs->outb_copy_basel = base + 0x4058;
  2037. regs->outb_copy_baseh = base + 0x405C;
  2038. regs->outb_copy_pointer = base + 0x406C;
  2039. regs->outb_read_pointer = base + 0x4070;
  2040. regs->outb_coal_cfg = base + 0x4080;
  2041. regs->outb_isr_cause = base + 0x4088;
  2042. /* Bit setting for HW */
  2043. regs->int_comaout = 1 << 4;
  2044. regs->int_dl_cpu2pciea = 1 << 12;
  2045. regs->int_comaerr = 1 << 29;
  2046. regs->cl_pointer_toggle = 1 << 14;
  2047. regs->cl_slot_num_mask = 0x3FFF;
  2048. regs->clic_irq = 1 << 0;
  2049. regs->clic_out_err = 1 << 1;
  2050. regs->int_drbl_int_mask = 0x3FFFFFFF;
  2051. regs->int_mu = regs->int_dl_cpu2pciea | regs->int_comaout;
  2052. break;
  2053. default:
  2054. return -1;
  2055. break;
  2056. }
  2057. return 0;
  2058. }
  2059. /**
  2060. * mvumi_init_fw - Initializes the FW
  2061. * @mhba: Adapter soft state
  2062. *
  2063. * This is the main function for initializing firmware.
  2064. */
  2065. static int mvumi_init_fw(struct mvumi_hba *mhba)
  2066. {
  2067. int ret = 0;
  2068. if (pci_request_regions(mhba->pdev, MV_DRIVER_NAME)) {
  2069. dev_err(&mhba->pdev->dev, "IO memory region busy!\n");
  2070. return -EBUSY;
  2071. }
  2072. ret = mvumi_map_pci_addr(mhba->pdev, mhba->base_addr);
  2073. if (ret)
  2074. goto fail_ioremap;
  2075. switch (mhba->pdev->device) {
  2076. case PCI_DEVICE_ID_MARVELL_MV9143:
  2077. mhba->instancet = &mvumi_instance_9143;
  2078. mhba->io_seq = 0;
  2079. mhba->max_sge = MVUMI_MAX_SG_ENTRY;
  2080. mhba->request_id_enabled = 1;
  2081. break;
  2082. case PCI_DEVICE_ID_MARVELL_MV9580:
  2083. mhba->instancet = &mvumi_instance_9580;
  2084. mhba->io_seq = 0;
  2085. mhba->max_sge = MVUMI_MAX_SG_ENTRY;
  2086. break;
  2087. default:
  2088. dev_err(&mhba->pdev->dev, "device 0x%x not supported!\n",
  2089. mhba->pdev->device);
  2090. mhba->instancet = NULL;
  2091. ret = -EINVAL;
  2092. goto fail_alloc_mem;
  2093. }
  2094. dev_dbg(&mhba->pdev->dev, "device id : %04X is found.\n",
  2095. mhba->pdev->device);
  2096. ret = mvumi_cfg_hw_reg(mhba);
  2097. if (ret) {
  2098. dev_err(&mhba->pdev->dev,
  2099. "failed to allocate memory for reg\n");
  2100. ret = -ENOMEM;
  2101. goto fail_alloc_mem;
  2102. }
  2103. mhba->handshake_page = pci_alloc_consistent(mhba->pdev, HSP_MAX_SIZE,
  2104. &mhba->handshake_page_phys);
  2105. if (!mhba->handshake_page) {
  2106. dev_err(&mhba->pdev->dev,
  2107. "failed to allocate memory for handshake\n");
  2108. ret = -ENOMEM;
  2109. goto fail_alloc_page;
  2110. }
  2111. if (mvumi_start(mhba)) {
  2112. ret = -EINVAL;
  2113. goto fail_ready_state;
  2114. }
  2115. ret = mvumi_alloc_cmds(mhba);
  2116. if (ret)
  2117. goto fail_ready_state;
  2118. return 0;
  2119. fail_ready_state:
  2120. mvumi_release_mem_resource(mhba);
  2121. pci_free_consistent(mhba->pdev, HSP_MAX_SIZE,
  2122. mhba->handshake_page, mhba->handshake_page_phys);
  2123. fail_alloc_page:
  2124. kfree(mhba->regs);
  2125. fail_alloc_mem:
  2126. mvumi_unmap_pci_addr(mhba->pdev, mhba->base_addr);
  2127. fail_ioremap:
  2128. pci_release_regions(mhba->pdev);
  2129. return ret;
  2130. }
  2131. /**
  2132. * mvumi_io_attach - Attaches this driver to SCSI mid-layer
  2133. * @mhba: Adapter soft state
  2134. */
  2135. static int mvumi_io_attach(struct mvumi_hba *mhba)
  2136. {
  2137. struct Scsi_Host *host = mhba->shost;
  2138. struct scsi_device *sdev = NULL;
  2139. int ret;
  2140. unsigned int max_sg = (mhba->ib_max_size + 4 -
  2141. sizeof(struct mvumi_msg_frame)) / sizeof(struct mvumi_sgl);
  2142. host->irq = mhba->pdev->irq;
  2143. host->unique_id = mhba->unique_id;
  2144. host->can_queue = (mhba->max_io - 1) ? (mhba->max_io - 1) : 1;
  2145. host->sg_tablesize = mhba->max_sge > max_sg ? max_sg : mhba->max_sge;
  2146. host->max_sectors = mhba->max_transfer_size / 512;
  2147. host->cmd_per_lun = (mhba->max_io - 1) ? (mhba->max_io - 1) : 1;
  2148. host->max_id = mhba->max_target_id;
  2149. host->max_cmd_len = MAX_COMMAND_SIZE;
  2150. host->transportt = &mvumi_transport_template;
  2151. ret = scsi_add_host(host, &mhba->pdev->dev);
  2152. if (ret) {
  2153. dev_err(&mhba->pdev->dev, "scsi_add_host failed\n");
  2154. return ret;
  2155. }
  2156. mhba->fw_flag |= MVUMI_FW_ATTACH;
  2157. mutex_lock(&mhba->sas_discovery_mutex);
  2158. if (mhba->pdev->device == PCI_DEVICE_ID_MARVELL_MV9580)
  2159. ret = scsi_add_device(host, 0, mhba->max_target_id - 1, 0);
  2160. else
  2161. ret = 0;
  2162. if (ret) {
  2163. dev_err(&mhba->pdev->dev, "add virtual device failed\n");
  2164. mutex_unlock(&mhba->sas_discovery_mutex);
  2165. goto fail_add_device;
  2166. }
  2167. mhba->dm_thread = kthread_create(mvumi_rescan_bus,
  2168. mhba, "mvumi_scanthread");
  2169. if (IS_ERR(mhba->dm_thread)) {
  2170. dev_err(&mhba->pdev->dev,
  2171. "failed to create device scan thread\n");
  2172. mutex_unlock(&mhba->sas_discovery_mutex);
  2173. goto fail_create_thread;
  2174. }
  2175. atomic_set(&mhba->pnp_count, 1);
  2176. wake_up_process(mhba->dm_thread);
  2177. mutex_unlock(&mhba->sas_discovery_mutex);
  2178. return 0;
  2179. fail_create_thread:
  2180. if (mhba->pdev->device == PCI_DEVICE_ID_MARVELL_MV9580)
  2181. sdev = scsi_device_lookup(mhba->shost, 0,
  2182. mhba->max_target_id - 1, 0);
  2183. if (sdev) {
  2184. scsi_remove_device(sdev);
  2185. scsi_device_put(sdev);
  2186. }
  2187. fail_add_device:
  2188. scsi_remove_host(mhba->shost);
  2189. return ret;
  2190. }
  2191. /**
  2192. * mvumi_probe_one - PCI hotplug entry point
  2193. * @pdev: PCI device structure
  2194. * @id: PCI ids of supported hotplugged adapter
  2195. */
  2196. static int mvumi_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  2197. {
  2198. struct Scsi_Host *host;
  2199. struct mvumi_hba *mhba;
  2200. int ret;
  2201. dev_dbg(&pdev->dev, " %#4.04x:%#4.04x:%#4.04x:%#4.04x: ",
  2202. pdev->vendor, pdev->device, pdev->subsystem_vendor,
  2203. pdev->subsystem_device);
  2204. ret = pci_enable_device(pdev);
  2205. if (ret)
  2206. return ret;
  2207. pci_set_master(pdev);
  2208. if (IS_DMA64) {
  2209. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  2210. if (ret) {
  2211. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2212. if (ret)
  2213. goto fail_set_dma_mask;
  2214. }
  2215. } else {
  2216. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2217. if (ret)
  2218. goto fail_set_dma_mask;
  2219. }
  2220. host = scsi_host_alloc(&mvumi_template, sizeof(*mhba));
  2221. if (!host) {
  2222. dev_err(&pdev->dev, "scsi_host_alloc failed\n");
  2223. ret = -ENOMEM;
  2224. goto fail_alloc_instance;
  2225. }
  2226. mhba = shost_priv(host);
  2227. INIT_LIST_HEAD(&mhba->cmd_pool);
  2228. INIT_LIST_HEAD(&mhba->ob_data_list);
  2229. INIT_LIST_HEAD(&mhba->free_ob_list);
  2230. INIT_LIST_HEAD(&mhba->res_list);
  2231. INIT_LIST_HEAD(&mhba->waiting_req_list);
  2232. mutex_init(&mhba->device_lock);
  2233. INIT_LIST_HEAD(&mhba->mhba_dev_list);
  2234. INIT_LIST_HEAD(&mhba->shost_dev_list);
  2235. atomic_set(&mhba->fw_outstanding, 0);
  2236. init_waitqueue_head(&mhba->int_cmd_wait_q);
  2237. mutex_init(&mhba->sas_discovery_mutex);
  2238. mhba->pdev = pdev;
  2239. mhba->shost = host;
  2240. mhba->unique_id = pdev->bus->number << 8 | pdev->devfn;
  2241. ret = mvumi_init_fw(mhba);
  2242. if (ret)
  2243. goto fail_init_fw;
  2244. ret = request_irq(mhba->pdev->irq, mvumi_isr_handler, IRQF_SHARED,
  2245. "mvumi", mhba);
  2246. if (ret) {
  2247. dev_err(&pdev->dev, "failed to register IRQ\n");
  2248. goto fail_init_irq;
  2249. }
  2250. mhba->instancet->enable_intr(mhba);
  2251. pci_set_drvdata(pdev, mhba);
  2252. ret = mvumi_io_attach(mhba);
  2253. if (ret)
  2254. goto fail_io_attach;
  2255. mvumi_backup_bar_addr(mhba);
  2256. dev_dbg(&pdev->dev, "probe mvumi driver successfully.\n");
  2257. return 0;
  2258. fail_io_attach:
  2259. pci_set_drvdata(pdev, NULL);
  2260. mhba->instancet->disable_intr(mhba);
  2261. free_irq(mhba->pdev->irq, mhba);
  2262. fail_init_irq:
  2263. mvumi_release_fw(mhba);
  2264. fail_init_fw:
  2265. scsi_host_put(host);
  2266. fail_alloc_instance:
  2267. fail_set_dma_mask:
  2268. pci_disable_device(pdev);
  2269. return ret;
  2270. }
  2271. static void mvumi_detach_one(struct pci_dev *pdev)
  2272. {
  2273. struct Scsi_Host *host;
  2274. struct mvumi_hba *mhba;
  2275. mhba = pci_get_drvdata(pdev);
  2276. if (mhba->dm_thread) {
  2277. kthread_stop(mhba->dm_thread);
  2278. mhba->dm_thread = NULL;
  2279. }
  2280. mvumi_detach_devices(mhba);
  2281. host = mhba->shost;
  2282. scsi_remove_host(mhba->shost);
  2283. mvumi_flush_cache(mhba);
  2284. mhba->instancet->disable_intr(mhba);
  2285. free_irq(mhba->pdev->irq, mhba);
  2286. mvumi_release_fw(mhba);
  2287. scsi_host_put(host);
  2288. pci_set_drvdata(pdev, NULL);
  2289. pci_disable_device(pdev);
  2290. dev_dbg(&pdev->dev, "driver is removed!\n");
  2291. }
  2292. /**
  2293. * mvumi_shutdown - Shutdown entry point
  2294. * @device: Generic device structure
  2295. */
  2296. static void mvumi_shutdown(struct pci_dev *pdev)
  2297. {
  2298. struct mvumi_hba *mhba = pci_get_drvdata(pdev);
  2299. mvumi_flush_cache(mhba);
  2300. }
  2301. static int mvumi_suspend(struct pci_dev *pdev, pm_message_t state)
  2302. {
  2303. struct mvumi_hba *mhba = NULL;
  2304. mhba = pci_get_drvdata(pdev);
  2305. mvumi_flush_cache(mhba);
  2306. pci_set_drvdata(pdev, mhba);
  2307. mhba->instancet->disable_intr(mhba);
  2308. free_irq(mhba->pdev->irq, mhba);
  2309. mvumi_unmap_pci_addr(pdev, mhba->base_addr);
  2310. pci_release_regions(pdev);
  2311. pci_save_state(pdev);
  2312. pci_disable_device(pdev);
  2313. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  2314. return 0;
  2315. }
  2316. static int mvumi_resume(struct pci_dev *pdev)
  2317. {
  2318. int ret;
  2319. struct mvumi_hba *mhba = NULL;
  2320. mhba = pci_get_drvdata(pdev);
  2321. pci_set_power_state(pdev, PCI_D0);
  2322. pci_enable_wake(pdev, PCI_D0, 0);
  2323. pci_restore_state(pdev);
  2324. ret = pci_enable_device(pdev);
  2325. if (ret) {
  2326. dev_err(&pdev->dev, "enable device failed\n");
  2327. return ret;
  2328. }
  2329. pci_set_master(pdev);
  2330. if (IS_DMA64) {
  2331. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  2332. if (ret) {
  2333. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2334. if (ret)
  2335. goto fail;
  2336. }
  2337. } else {
  2338. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2339. if (ret)
  2340. goto fail;
  2341. }
  2342. ret = pci_request_regions(mhba->pdev, MV_DRIVER_NAME);
  2343. if (ret)
  2344. goto fail;
  2345. ret = mvumi_map_pci_addr(mhba->pdev, mhba->base_addr);
  2346. if (ret)
  2347. goto release_regions;
  2348. if (mvumi_cfg_hw_reg(mhba)) {
  2349. ret = -EINVAL;
  2350. goto unmap_pci_addr;
  2351. }
  2352. mhba->mmio = mhba->base_addr[0];
  2353. mvumi_reset(mhba);
  2354. if (mvumi_start(mhba)) {
  2355. ret = -EINVAL;
  2356. goto unmap_pci_addr;
  2357. }
  2358. ret = request_irq(mhba->pdev->irq, mvumi_isr_handler, IRQF_SHARED,
  2359. "mvumi", mhba);
  2360. if (ret) {
  2361. dev_err(&pdev->dev, "failed to register IRQ\n");
  2362. goto unmap_pci_addr;
  2363. }
  2364. mhba->instancet->enable_intr(mhba);
  2365. return 0;
  2366. unmap_pci_addr:
  2367. mvumi_unmap_pci_addr(pdev, mhba->base_addr);
  2368. release_regions:
  2369. pci_release_regions(pdev);
  2370. fail:
  2371. pci_disable_device(pdev);
  2372. return ret;
  2373. }
  2374. static struct pci_driver mvumi_pci_driver = {
  2375. .name = MV_DRIVER_NAME,
  2376. .id_table = mvumi_pci_table,
  2377. .probe = mvumi_probe_one,
  2378. .remove = mvumi_detach_one,
  2379. .shutdown = mvumi_shutdown,
  2380. #ifdef CONFIG_PM
  2381. .suspend = mvumi_suspend,
  2382. .resume = mvumi_resume,
  2383. #endif
  2384. };
  2385. /**
  2386. * mvumi_init - Driver load entry point
  2387. */
  2388. static int __init mvumi_init(void)
  2389. {
  2390. return pci_register_driver(&mvumi_pci_driver);
  2391. }
  2392. /**
  2393. * mvumi_exit - Driver unload entry point
  2394. */
  2395. static void __exit mvumi_exit(void)
  2396. {
  2397. pci_unregister_driver(&mvumi_pci_driver);
  2398. }
  2399. module_init(mvumi_init);
  2400. module_exit(mvumi_exit);