mvumi.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754
  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_EXT, PCI_DEVICE_ID_MARVELL_MV9143) },
  49. { PCI_DEVICE(PCI_VENDOR_ID_MARVELL_EXT, 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. mhba->instancet->disable_intr(mhba);
  2260. free_irq(mhba->pdev->irq, mhba);
  2261. fail_init_irq:
  2262. mvumi_release_fw(mhba);
  2263. fail_init_fw:
  2264. scsi_host_put(host);
  2265. fail_alloc_instance:
  2266. fail_set_dma_mask:
  2267. pci_disable_device(pdev);
  2268. return ret;
  2269. }
  2270. static void mvumi_detach_one(struct pci_dev *pdev)
  2271. {
  2272. struct Scsi_Host *host;
  2273. struct mvumi_hba *mhba;
  2274. mhba = pci_get_drvdata(pdev);
  2275. if (mhba->dm_thread) {
  2276. kthread_stop(mhba->dm_thread);
  2277. mhba->dm_thread = NULL;
  2278. }
  2279. mvumi_detach_devices(mhba);
  2280. host = mhba->shost;
  2281. scsi_remove_host(mhba->shost);
  2282. mvumi_flush_cache(mhba);
  2283. mhba->instancet->disable_intr(mhba);
  2284. free_irq(mhba->pdev->irq, mhba);
  2285. mvumi_release_fw(mhba);
  2286. scsi_host_put(host);
  2287. pci_disable_device(pdev);
  2288. dev_dbg(&pdev->dev, "driver is removed!\n");
  2289. }
  2290. /**
  2291. * mvumi_shutdown - Shutdown entry point
  2292. * @device: Generic device structure
  2293. */
  2294. static void mvumi_shutdown(struct pci_dev *pdev)
  2295. {
  2296. struct mvumi_hba *mhba = pci_get_drvdata(pdev);
  2297. mvumi_flush_cache(mhba);
  2298. }
  2299. static int mvumi_suspend(struct pci_dev *pdev, pm_message_t state)
  2300. {
  2301. struct mvumi_hba *mhba = NULL;
  2302. mhba = pci_get_drvdata(pdev);
  2303. mvumi_flush_cache(mhba);
  2304. pci_set_drvdata(pdev, mhba);
  2305. mhba->instancet->disable_intr(mhba);
  2306. free_irq(mhba->pdev->irq, mhba);
  2307. mvumi_unmap_pci_addr(pdev, mhba->base_addr);
  2308. pci_release_regions(pdev);
  2309. pci_save_state(pdev);
  2310. pci_disable_device(pdev);
  2311. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  2312. return 0;
  2313. }
  2314. static int mvumi_resume(struct pci_dev *pdev)
  2315. {
  2316. int ret;
  2317. struct mvumi_hba *mhba = NULL;
  2318. mhba = pci_get_drvdata(pdev);
  2319. pci_set_power_state(pdev, PCI_D0);
  2320. pci_enable_wake(pdev, PCI_D0, 0);
  2321. pci_restore_state(pdev);
  2322. ret = pci_enable_device(pdev);
  2323. if (ret) {
  2324. dev_err(&pdev->dev, "enable device failed\n");
  2325. return ret;
  2326. }
  2327. pci_set_master(pdev);
  2328. if (IS_DMA64) {
  2329. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  2330. if (ret) {
  2331. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2332. if (ret)
  2333. goto fail;
  2334. }
  2335. } else {
  2336. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2337. if (ret)
  2338. goto fail;
  2339. }
  2340. ret = pci_request_regions(mhba->pdev, MV_DRIVER_NAME);
  2341. if (ret)
  2342. goto fail;
  2343. ret = mvumi_map_pci_addr(mhba->pdev, mhba->base_addr);
  2344. if (ret)
  2345. goto release_regions;
  2346. if (mvumi_cfg_hw_reg(mhba)) {
  2347. ret = -EINVAL;
  2348. goto unmap_pci_addr;
  2349. }
  2350. mhba->mmio = mhba->base_addr[0];
  2351. mvumi_reset(mhba);
  2352. if (mvumi_start(mhba)) {
  2353. ret = -EINVAL;
  2354. goto unmap_pci_addr;
  2355. }
  2356. ret = request_irq(mhba->pdev->irq, mvumi_isr_handler, IRQF_SHARED,
  2357. "mvumi", mhba);
  2358. if (ret) {
  2359. dev_err(&pdev->dev, "failed to register IRQ\n");
  2360. goto unmap_pci_addr;
  2361. }
  2362. mhba->instancet->enable_intr(mhba);
  2363. return 0;
  2364. unmap_pci_addr:
  2365. mvumi_unmap_pci_addr(pdev, mhba->base_addr);
  2366. release_regions:
  2367. pci_release_regions(pdev);
  2368. fail:
  2369. pci_disable_device(pdev);
  2370. return ret;
  2371. }
  2372. static struct pci_driver mvumi_pci_driver = {
  2373. .name = MV_DRIVER_NAME,
  2374. .id_table = mvumi_pci_table,
  2375. .probe = mvumi_probe_one,
  2376. .remove = mvumi_detach_one,
  2377. .shutdown = mvumi_shutdown,
  2378. #ifdef CONFIG_PM
  2379. .suspend = mvumi_suspend,
  2380. .resume = mvumi_resume,
  2381. #endif
  2382. };
  2383. /**
  2384. * mvumi_init - Driver load entry point
  2385. */
  2386. static int __init mvumi_init(void)
  2387. {
  2388. return pci_register_driver(&mvumi_pci_driver);
  2389. }
  2390. /**
  2391. * mvumi_exit - Driver unload entry point
  2392. */
  2393. static void __exit mvumi_exit(void)
  2394. {
  2395. pci_unregister_driver(&mvumi_pci_driver);
  2396. }
  2397. module_init(mvumi_init);
  2398. module_exit(mvumi_exit);