mvumi.c 71 KB

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