qla_os.c 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2008 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/moduleparam.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/delay.h>
  11. #include <linux/kthread.h>
  12. #include <linux/mutex.h>
  13. #include <scsi/scsi_tcq.h>
  14. #include <scsi/scsicam.h>
  15. #include <scsi/scsi_transport.h>
  16. #include <scsi/scsi_transport_fc.h>
  17. /*
  18. * Driver version
  19. */
  20. char qla2x00_version_str[40];
  21. /*
  22. * SRB allocation cache
  23. */
  24. static struct kmem_cache *srb_cachep;
  25. int ql2xlogintimeout = 20;
  26. module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
  27. MODULE_PARM_DESC(ql2xlogintimeout,
  28. "Login timeout value in seconds.");
  29. int qlport_down_retry;
  30. module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
  31. MODULE_PARM_DESC(qlport_down_retry,
  32. "Maximum number of command retries to a port that returns "
  33. "a PORT-DOWN status.");
  34. int ql2xplogiabsentdevice;
  35. module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
  36. MODULE_PARM_DESC(ql2xplogiabsentdevice,
  37. "Option to enable PLOGI to devices that are not present after "
  38. "a Fabric scan. This is needed for several broken switches. "
  39. "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
  40. int ql2xloginretrycount = 0;
  41. module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
  42. MODULE_PARM_DESC(ql2xloginretrycount,
  43. "Specify an alternate value for the NVRAM login retry count.");
  44. int ql2xallocfwdump = 1;
  45. module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
  46. MODULE_PARM_DESC(ql2xallocfwdump,
  47. "Option to enable allocation of memory for a firmware dump "
  48. "during HBA initialization. Memory allocation requirements "
  49. "vary by ISP type. Default is 1 - allocate memory.");
  50. int ql2xextended_error_logging;
  51. module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
  52. MODULE_PARM_DESC(ql2xextended_error_logging,
  53. "Option to enable extended error logging, "
  54. "Default is 0 - no logging. 1 - log errors.");
  55. static void qla2x00_free_device(scsi_qla_host_t *);
  56. static void qla2x00_config_dma_addressing(scsi_qla_host_t *ha);
  57. int ql2xfdmienable=1;
  58. module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
  59. MODULE_PARM_DESC(ql2xfdmienable,
  60. "Enables FDMI registratons "
  61. "Default is 0 - no FDMI. 1 - perfom FDMI.");
  62. #define MAX_Q_DEPTH 32
  63. static int ql2xmaxqdepth = MAX_Q_DEPTH;
  64. module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
  65. MODULE_PARM_DESC(ql2xmaxqdepth,
  66. "Maximum queue depth to report for target devices.");
  67. int ql2xqfullrampup = 120;
  68. module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR);
  69. MODULE_PARM_DESC(ql2xqfullrampup,
  70. "Number of seconds to wait to begin to ramp-up the queue "
  71. "depth for a device after a queue-full condition has been "
  72. "detected. Default is 120 seconds.");
  73. int ql2xiidmaenable=1;
  74. module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
  75. MODULE_PARM_DESC(ql2xiidmaenable,
  76. "Enables iIDMA settings "
  77. "Default is 1 - perform iIDMA. 0 - no iIDMA.");
  78. int ql2xmaxqueues = 1;
  79. module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
  80. MODULE_PARM_DESC(ql2xmaxqueues,
  81. "Enables MQ settings "
  82. "Default is 1 for single queue. Set it to number \
  83. of queues in MQ mode.");
  84. /*
  85. * SCSI host template entry points
  86. */
  87. static int qla2xxx_slave_configure(struct scsi_device * device);
  88. static int qla2xxx_slave_alloc(struct scsi_device *);
  89. static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
  90. static void qla2xxx_scan_start(struct Scsi_Host *);
  91. static void qla2xxx_slave_destroy(struct scsi_device *);
  92. static int qla2x00_queuecommand(struct scsi_cmnd *cmd,
  93. void (*fn)(struct scsi_cmnd *));
  94. static int qla24xx_queuecommand(struct scsi_cmnd *cmd,
  95. void (*fn)(struct scsi_cmnd *));
  96. static int qla2xxx_eh_abort(struct scsi_cmnd *);
  97. static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
  98. static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
  99. static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
  100. static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
  101. static int qla2x00_change_queue_depth(struct scsi_device *, int);
  102. static int qla2x00_change_queue_type(struct scsi_device *, int);
  103. static struct scsi_host_template qla2x00_driver_template = {
  104. .module = THIS_MODULE,
  105. .name = QLA2XXX_DRIVER_NAME,
  106. .queuecommand = qla2x00_queuecommand,
  107. .eh_abort_handler = qla2xxx_eh_abort,
  108. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  109. .eh_target_reset_handler = qla2xxx_eh_target_reset,
  110. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  111. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  112. .slave_configure = qla2xxx_slave_configure,
  113. .slave_alloc = qla2xxx_slave_alloc,
  114. .slave_destroy = qla2xxx_slave_destroy,
  115. .scan_finished = qla2xxx_scan_finished,
  116. .scan_start = qla2xxx_scan_start,
  117. .change_queue_depth = qla2x00_change_queue_depth,
  118. .change_queue_type = qla2x00_change_queue_type,
  119. .this_id = -1,
  120. .cmd_per_lun = 3,
  121. .use_clustering = ENABLE_CLUSTERING,
  122. .sg_tablesize = SG_ALL,
  123. /*
  124. * The RISC allows for each command to transfer (2^32-1) bytes of data,
  125. * which equates to 0x800000 sectors.
  126. */
  127. .max_sectors = 0xFFFF,
  128. .shost_attrs = qla2x00_host_attrs,
  129. };
  130. struct scsi_host_template qla24xx_driver_template = {
  131. .module = THIS_MODULE,
  132. .name = QLA2XXX_DRIVER_NAME,
  133. .queuecommand = qla24xx_queuecommand,
  134. .eh_abort_handler = qla2xxx_eh_abort,
  135. .eh_device_reset_handler = qla2xxx_eh_device_reset,
  136. .eh_target_reset_handler = qla2xxx_eh_target_reset,
  137. .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
  138. .eh_host_reset_handler = qla2xxx_eh_host_reset,
  139. .slave_configure = qla2xxx_slave_configure,
  140. .slave_alloc = qla2xxx_slave_alloc,
  141. .slave_destroy = qla2xxx_slave_destroy,
  142. .scan_finished = qla2xxx_scan_finished,
  143. .scan_start = qla2xxx_scan_start,
  144. .change_queue_depth = qla2x00_change_queue_depth,
  145. .change_queue_type = qla2x00_change_queue_type,
  146. .this_id = -1,
  147. .cmd_per_lun = 3,
  148. .use_clustering = ENABLE_CLUSTERING,
  149. .sg_tablesize = SG_ALL,
  150. .max_sectors = 0xFFFF,
  151. .shost_attrs = qla2x00_host_attrs,
  152. };
  153. static struct scsi_transport_template *qla2xxx_transport_template = NULL;
  154. struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
  155. /* TODO Convert to inlines
  156. *
  157. * Timer routines
  158. */
  159. __inline__ void
  160. qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
  161. {
  162. init_timer(&vha->timer);
  163. vha->timer.expires = jiffies + interval * HZ;
  164. vha->timer.data = (unsigned long)vha;
  165. vha->timer.function = (void (*)(unsigned long))func;
  166. add_timer(&vha->timer);
  167. vha->timer_active = 1;
  168. }
  169. static inline void
  170. qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
  171. {
  172. mod_timer(&vha->timer, jiffies + interval * HZ);
  173. }
  174. static __inline__ void
  175. qla2x00_stop_timer(scsi_qla_host_t *vha)
  176. {
  177. del_timer_sync(&vha->timer);
  178. vha->timer_active = 0;
  179. }
  180. static int qla2x00_do_dpc(void *data);
  181. static void qla2x00_rst_aen(scsi_qla_host_t *);
  182. static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
  183. struct req_que **, struct rsp_que **);
  184. static void qla2x00_mem_free(struct qla_hw_data *);
  185. static void qla2x00_sp_free_dma(srb_t *);
  186. /* -------------------------------------------------------------------------- */
  187. static int qla2x00_alloc_queues(struct qla_hw_data *ha)
  188. {
  189. ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_queues,
  190. GFP_KERNEL);
  191. if (!ha->req_q_map) {
  192. qla_printk(KERN_WARNING, ha,
  193. "Unable to allocate memory for request queue ptrs\n");
  194. goto fail_req_map;
  195. }
  196. ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_queues,
  197. GFP_KERNEL);
  198. if (!ha->rsp_q_map) {
  199. qla_printk(KERN_WARNING, ha,
  200. "Unable to allocate memory for response queue ptrs\n");
  201. goto fail_rsp_map;
  202. }
  203. set_bit(0, ha->rsp_qid_map);
  204. set_bit(0, ha->req_qid_map);
  205. return 1;
  206. fail_rsp_map:
  207. kfree(ha->req_q_map);
  208. ha->req_q_map = NULL;
  209. fail_req_map:
  210. return -ENOMEM;
  211. }
  212. static void qla2x00_free_que(struct qla_hw_data *ha, struct req_que *req,
  213. struct rsp_que *rsp)
  214. {
  215. if (rsp && rsp->ring)
  216. dma_free_coherent(&ha->pdev->dev,
  217. (rsp->length + 1) * sizeof(response_t),
  218. rsp->ring, rsp->dma);
  219. kfree(rsp);
  220. rsp = NULL;
  221. if (req && req->ring)
  222. dma_free_coherent(&ha->pdev->dev,
  223. (req->length + 1) * sizeof(request_t),
  224. req->ring, req->dma);
  225. kfree(req);
  226. req = NULL;
  227. }
  228. static void qla2x00_free_queues(struct qla_hw_data *ha)
  229. {
  230. struct req_que *req;
  231. struct rsp_que *rsp;
  232. int cnt;
  233. for (cnt = 0; cnt < ha->max_queues; cnt++) {
  234. rsp = ha->rsp_q_map[cnt];
  235. req = ha->req_q_map[cnt];
  236. qla2x00_free_que(ha, req, rsp);
  237. }
  238. kfree(ha->rsp_q_map);
  239. ha->rsp_q_map = NULL;
  240. kfree(ha->req_q_map);
  241. ha->req_q_map = NULL;
  242. }
  243. static char *
  244. qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
  245. {
  246. struct qla_hw_data *ha = vha->hw;
  247. static char *pci_bus_modes[] = {
  248. "33", "66", "100", "133",
  249. };
  250. uint16_t pci_bus;
  251. strcpy(str, "PCI");
  252. pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
  253. if (pci_bus) {
  254. strcat(str, "-X (");
  255. strcat(str, pci_bus_modes[pci_bus]);
  256. } else {
  257. pci_bus = (ha->pci_attr & BIT_8) >> 8;
  258. strcat(str, " (");
  259. strcat(str, pci_bus_modes[pci_bus]);
  260. }
  261. strcat(str, " MHz)");
  262. return (str);
  263. }
  264. static char *
  265. qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
  266. {
  267. static char *pci_bus_modes[] = { "33", "66", "100", "133", };
  268. struct qla_hw_data *ha = vha->hw;
  269. uint32_t pci_bus;
  270. int pcie_reg;
  271. pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
  272. if (pcie_reg) {
  273. char lwstr[6];
  274. uint16_t pcie_lstat, lspeed, lwidth;
  275. pcie_reg += 0x12;
  276. pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
  277. lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
  278. lwidth = (pcie_lstat &
  279. (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
  280. strcpy(str, "PCIe (");
  281. if (lspeed == 1)
  282. strcat(str, "2.5GT/s ");
  283. else if (lspeed == 2)
  284. strcat(str, "5.0GT/s ");
  285. else
  286. strcat(str, "<unknown> ");
  287. snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
  288. strcat(str, lwstr);
  289. return str;
  290. }
  291. strcpy(str, "PCI");
  292. pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
  293. if (pci_bus == 0 || pci_bus == 8) {
  294. strcat(str, " (");
  295. strcat(str, pci_bus_modes[pci_bus >> 3]);
  296. } else {
  297. strcat(str, "-X ");
  298. if (pci_bus & BIT_2)
  299. strcat(str, "Mode 2");
  300. else
  301. strcat(str, "Mode 1");
  302. strcat(str, " (");
  303. strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
  304. }
  305. strcat(str, " MHz)");
  306. return str;
  307. }
  308. static char *
  309. qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
  310. {
  311. char un_str[10];
  312. struct qla_hw_data *ha = vha->hw;
  313. sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
  314. ha->fw_minor_version,
  315. ha->fw_subminor_version);
  316. if (ha->fw_attributes & BIT_9) {
  317. strcat(str, "FLX");
  318. return (str);
  319. }
  320. switch (ha->fw_attributes & 0xFF) {
  321. case 0x7:
  322. strcat(str, "EF");
  323. break;
  324. case 0x17:
  325. strcat(str, "TP");
  326. break;
  327. case 0x37:
  328. strcat(str, "IP");
  329. break;
  330. case 0x77:
  331. strcat(str, "VI");
  332. break;
  333. default:
  334. sprintf(un_str, "(%x)", ha->fw_attributes);
  335. strcat(str, un_str);
  336. break;
  337. }
  338. if (ha->fw_attributes & 0x100)
  339. strcat(str, "X");
  340. return (str);
  341. }
  342. static char *
  343. qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
  344. {
  345. struct qla_hw_data *ha = vha->hw;
  346. sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
  347. ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
  348. return str;
  349. }
  350. static inline srb_t *
  351. qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
  352. struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  353. {
  354. srb_t *sp;
  355. struct qla_hw_data *ha = vha->hw;
  356. sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
  357. if (!sp)
  358. return sp;
  359. sp->fcport = fcport;
  360. sp->cmd = cmd;
  361. sp->que = ha->req_q_map[0];
  362. sp->flags = 0;
  363. CMD_SP(cmd) = (void *)sp;
  364. cmd->scsi_done = done;
  365. return sp;
  366. }
  367. static int
  368. qla2x00_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  369. {
  370. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  371. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  372. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  373. struct qla_hw_data *ha = vha->hw;
  374. srb_t *sp;
  375. int rval;
  376. if (unlikely(pci_channel_offline(ha->pdev))) {
  377. cmd->result = DID_REQUEUE << 16;
  378. goto qc_fail_command;
  379. }
  380. rval = fc_remote_port_chkready(rport);
  381. if (rval) {
  382. cmd->result = rval;
  383. goto qc_fail_command;
  384. }
  385. /* Close window on fcport/rport state-transitioning. */
  386. if (fcport->drport)
  387. goto qc_target_busy;
  388. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  389. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  390. atomic_read(&vha->loop_state) == LOOP_DEAD) {
  391. cmd->result = DID_NO_CONNECT << 16;
  392. goto qc_fail_command;
  393. }
  394. goto qc_target_busy;
  395. }
  396. spin_unlock_irq(vha->host->host_lock);
  397. sp = qla2x00_get_new_sp(vha, fcport, cmd, done);
  398. if (!sp)
  399. goto qc_host_busy_lock;
  400. rval = ha->isp_ops->start_scsi(sp);
  401. if (rval != QLA_SUCCESS)
  402. goto qc_host_busy_free_sp;
  403. spin_lock_irq(vha->host->host_lock);
  404. return 0;
  405. qc_host_busy_free_sp:
  406. qla2x00_sp_free_dma(sp);
  407. mempool_free(sp, ha->srb_mempool);
  408. qc_host_busy_lock:
  409. spin_lock_irq(vha->host->host_lock);
  410. return SCSI_MLQUEUE_HOST_BUSY;
  411. qc_target_busy:
  412. return SCSI_MLQUEUE_TARGET_BUSY;
  413. qc_fail_command:
  414. done(cmd);
  415. return 0;
  416. }
  417. static int
  418. qla24xx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
  419. {
  420. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  421. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  422. struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
  423. struct qla_hw_data *ha = vha->hw;
  424. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  425. srb_t *sp;
  426. int rval;
  427. if (unlikely(pci_channel_offline(ha->pdev))) {
  428. cmd->result = DID_REQUEUE << 16;
  429. goto qc24_fail_command;
  430. }
  431. rval = fc_remote_port_chkready(rport);
  432. if (rval) {
  433. cmd->result = rval;
  434. goto qc24_fail_command;
  435. }
  436. /* Close window on fcport/rport state-transitioning. */
  437. if (fcport->drport)
  438. goto qc24_target_busy;
  439. if (atomic_read(&fcport->state) != FCS_ONLINE) {
  440. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
  441. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  442. cmd->result = DID_NO_CONNECT << 16;
  443. goto qc24_fail_command;
  444. }
  445. goto qc24_target_busy;
  446. }
  447. spin_unlock_irq(vha->host->host_lock);
  448. sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
  449. if (!sp)
  450. goto qc24_host_busy_lock;
  451. rval = ha->isp_ops->start_scsi(sp);
  452. if (rval != QLA_SUCCESS)
  453. goto qc24_host_busy_free_sp;
  454. spin_lock_irq(vha->host->host_lock);
  455. return 0;
  456. qc24_host_busy_free_sp:
  457. qla2x00_sp_free_dma(sp);
  458. mempool_free(sp, ha->srb_mempool);
  459. qc24_host_busy_lock:
  460. spin_lock_irq(vha->host->host_lock);
  461. return SCSI_MLQUEUE_HOST_BUSY;
  462. qc24_target_busy:
  463. return SCSI_MLQUEUE_TARGET_BUSY;
  464. qc24_fail_command:
  465. done(cmd);
  466. return 0;
  467. }
  468. /*
  469. * qla2x00_eh_wait_on_command
  470. * Waits for the command to be returned by the Firmware for some
  471. * max time.
  472. *
  473. * Input:
  474. * cmd = Scsi Command to wait on.
  475. *
  476. * Return:
  477. * Not Found : 0
  478. * Found : 1
  479. */
  480. static int
  481. qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
  482. {
  483. #define ABORT_POLLING_PERIOD 1000
  484. #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
  485. unsigned long wait_iter = ABORT_WAIT_ITER;
  486. int ret = QLA_SUCCESS;
  487. while (CMD_SP(cmd)) {
  488. msleep(ABORT_POLLING_PERIOD);
  489. if (--wait_iter)
  490. break;
  491. }
  492. if (CMD_SP(cmd))
  493. ret = QLA_FUNCTION_FAILED;
  494. return ret;
  495. }
  496. /*
  497. * qla2x00_wait_for_hba_online
  498. * Wait till the HBA is online after going through
  499. * <= MAX_RETRIES_OF_ISP_ABORT or
  500. * finally HBA is disabled ie marked offline
  501. *
  502. * Input:
  503. * ha - pointer to host adapter structure
  504. *
  505. * Note:
  506. * Does context switching-Release SPIN_LOCK
  507. * (if any) before calling this routine.
  508. *
  509. * Return:
  510. * Success (Adapter is online) : 0
  511. * Failed (Adapter is offline/disabled) : 1
  512. */
  513. int
  514. qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
  515. {
  516. int return_status;
  517. unsigned long wait_online;
  518. struct qla_hw_data *ha = vha->hw;
  519. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  520. wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  521. while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
  522. test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
  523. test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
  524. ha->dpc_active) && time_before(jiffies, wait_online)) {
  525. msleep(1000);
  526. }
  527. if (base_vha->flags.online)
  528. return_status = QLA_SUCCESS;
  529. else
  530. return_status = QLA_FUNCTION_FAILED;
  531. return (return_status);
  532. }
  533. /*
  534. * qla2x00_wait_for_loop_ready
  535. * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
  536. * to be in LOOP_READY state.
  537. * Input:
  538. * ha - pointer to host adapter structure
  539. *
  540. * Note:
  541. * Does context switching-Release SPIN_LOCK
  542. * (if any) before calling this routine.
  543. *
  544. *
  545. * Return:
  546. * Success (LOOP_READY) : 0
  547. * Failed (LOOP_NOT_READY) : 1
  548. */
  549. static inline int
  550. qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
  551. {
  552. int return_status = QLA_SUCCESS;
  553. unsigned long loop_timeout ;
  554. struct qla_hw_data *ha = vha->hw;
  555. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  556. /* wait for 5 min at the max for loop to be ready */
  557. loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
  558. while ((!atomic_read(&base_vha->loop_down_timer) &&
  559. atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
  560. atomic_read(&base_vha->loop_state) != LOOP_READY) {
  561. if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  562. return_status = QLA_FUNCTION_FAILED;
  563. break;
  564. }
  565. msleep(1000);
  566. if (time_after_eq(jiffies, loop_timeout)) {
  567. return_status = QLA_FUNCTION_FAILED;
  568. break;
  569. }
  570. }
  571. return (return_status);
  572. }
  573. void
  574. qla2x00_abort_fcport_cmds(fc_port_t *fcport)
  575. {
  576. int cnt, que, id;
  577. unsigned long flags;
  578. srb_t *sp;
  579. scsi_qla_host_t *vha = fcport->vha;
  580. struct qla_hw_data *ha = vha->hw;
  581. struct req_que *req;
  582. spin_lock_irqsave(&ha->hardware_lock, flags);
  583. for (que = 0; que < QLA_MAX_HOST_QUES; que++) {
  584. id = vha->req_ques[que];
  585. req = ha->req_q_map[id];
  586. if (!req)
  587. continue;
  588. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  589. sp = req->outstanding_cmds[cnt];
  590. if (!sp)
  591. continue;
  592. if (sp->fcport != fcport)
  593. continue;
  594. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  595. if (ha->isp_ops->abort_command(vha, sp, req)) {
  596. DEBUG2(qla_printk(KERN_WARNING, ha,
  597. "Abort failed -- %lx\n",
  598. sp->cmd->serial_number));
  599. } else {
  600. if (qla2x00_eh_wait_on_command(sp->cmd) !=
  601. QLA_SUCCESS)
  602. DEBUG2(qla_printk(KERN_WARNING, ha,
  603. "Abort failed while waiting -- %lx\n",
  604. sp->cmd->serial_number));
  605. }
  606. spin_lock_irqsave(&ha->hardware_lock, flags);
  607. }
  608. }
  609. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  610. }
  611. static void
  612. qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
  613. {
  614. struct Scsi_Host *shost = cmnd->device->host;
  615. struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
  616. unsigned long flags;
  617. spin_lock_irqsave(shost->host_lock, flags);
  618. while (rport->port_state == FC_PORTSTATE_BLOCKED) {
  619. spin_unlock_irqrestore(shost->host_lock, flags);
  620. msleep(1000);
  621. spin_lock_irqsave(shost->host_lock, flags);
  622. }
  623. spin_unlock_irqrestore(shost->host_lock, flags);
  624. return;
  625. }
  626. /**************************************************************************
  627. * qla2xxx_eh_abort
  628. *
  629. * Description:
  630. * The abort function will abort the specified command.
  631. *
  632. * Input:
  633. * cmd = Linux SCSI command packet to be aborted.
  634. *
  635. * Returns:
  636. * Either SUCCESS or FAILED.
  637. *
  638. * Note:
  639. * Only return FAILED if command not returned by firmware.
  640. **************************************************************************/
  641. static int
  642. qla2xxx_eh_abort(struct scsi_cmnd *cmd)
  643. {
  644. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  645. srb_t *sp;
  646. int ret, i;
  647. unsigned int id, lun;
  648. unsigned long serial;
  649. unsigned long flags;
  650. int wait = 0;
  651. struct qla_hw_data *ha = vha->hw;
  652. struct req_que *req;
  653. srb_t *spt;
  654. qla2x00_block_error_handler(cmd);
  655. if (!CMD_SP(cmd))
  656. return SUCCESS;
  657. ret = SUCCESS;
  658. id = cmd->device->id;
  659. lun = cmd->device->lun;
  660. serial = cmd->serial_number;
  661. spt = (srb_t *) CMD_SP(cmd);
  662. if (!spt)
  663. return SUCCESS;
  664. req = spt->que;
  665. /* Check active list for command command. */
  666. spin_lock_irqsave(&ha->hardware_lock, flags);
  667. for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
  668. sp = req->outstanding_cmds[i];
  669. if (sp == NULL)
  670. continue;
  671. if (sp->cmd != cmd)
  672. continue;
  673. DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
  674. " pid=%ld.\n", __func__, vha->host_no, sp, serial));
  675. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  676. if (ha->isp_ops->abort_command(vha, sp, req)) {
  677. DEBUG2(printk("%s(%ld): abort_command "
  678. "mbx failed.\n", __func__, vha->host_no));
  679. } else {
  680. DEBUG3(printk("%s(%ld): abort_command "
  681. "mbx success.\n", __func__, vha->host_no));
  682. wait = 1;
  683. }
  684. spin_lock_irqsave(&ha->hardware_lock, flags);
  685. break;
  686. }
  687. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  688. /* Wait for the command to be returned. */
  689. if (wait) {
  690. if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
  691. qla_printk(KERN_ERR, ha,
  692. "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
  693. "%x.\n", vha->host_no, id, lun, serial, ret);
  694. ret = FAILED;
  695. }
  696. }
  697. qla_printk(KERN_INFO, ha,
  698. "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
  699. vha->host_no, id, lun, wait, serial, ret);
  700. return ret;
  701. }
  702. enum nexus_wait_type {
  703. WAIT_HOST = 0,
  704. WAIT_TARGET,
  705. WAIT_LUN,
  706. };
  707. static int
  708. qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
  709. unsigned int l, srb_t *sp, enum nexus_wait_type type)
  710. {
  711. int cnt, match, status;
  712. unsigned long flags;
  713. struct qla_hw_data *ha = vha->hw;
  714. struct req_que *req;
  715. status = QLA_SUCCESS;
  716. if (!sp)
  717. return status;
  718. spin_lock_irqsave(&ha->hardware_lock, flags);
  719. req = sp->que;
  720. for (cnt = 1; status == QLA_SUCCESS &&
  721. cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  722. sp = req->outstanding_cmds[cnt];
  723. if (!sp)
  724. continue;
  725. if (vha->vp_idx != sp->fcport->vha->vp_idx)
  726. continue;
  727. match = 0;
  728. switch (type) {
  729. case WAIT_HOST:
  730. match = 1;
  731. break;
  732. case WAIT_TARGET:
  733. match = sp->cmd->device->id == t;
  734. break;
  735. case WAIT_LUN:
  736. match = (sp->cmd->device->id == t &&
  737. sp->cmd->device->lun == l);
  738. break;
  739. }
  740. if (!match)
  741. continue;
  742. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  743. status = qla2x00_eh_wait_on_command(sp->cmd);
  744. spin_lock_irqsave(&ha->hardware_lock, flags);
  745. }
  746. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  747. return status;
  748. }
  749. static char *reset_errors[] = {
  750. "HBA not online",
  751. "HBA not ready",
  752. "Task management failed",
  753. "Waiting for command completions",
  754. };
  755. static int
  756. __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
  757. struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int))
  758. {
  759. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  760. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  761. int err;
  762. qla2x00_block_error_handler(cmd);
  763. if (!fcport)
  764. return FAILED;
  765. qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
  766. vha->host_no, cmd->device->id, cmd->device->lun, name);
  767. err = 0;
  768. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
  769. goto eh_reset_failed;
  770. err = 1;
  771. if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
  772. goto eh_reset_failed;
  773. err = 2;
  774. if (do_reset(fcport, cmd->device->lun) != QLA_SUCCESS)
  775. goto eh_reset_failed;
  776. err = 3;
  777. if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
  778. cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
  779. goto eh_reset_failed;
  780. qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
  781. vha->host_no, cmd->device->id, cmd->device->lun, name);
  782. return SUCCESS;
  783. eh_reset_failed:
  784. qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
  785. , vha->host_no, cmd->device->id, cmd->device->lun, name,
  786. reset_errors[err]);
  787. return FAILED;
  788. }
  789. static int
  790. qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
  791. {
  792. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  793. struct qla_hw_data *ha = vha->hw;
  794. return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
  795. ha->isp_ops->lun_reset);
  796. }
  797. static int
  798. qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
  799. {
  800. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  801. struct qla_hw_data *ha = vha->hw;
  802. return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
  803. ha->isp_ops->target_reset);
  804. }
  805. /**************************************************************************
  806. * qla2xxx_eh_bus_reset
  807. *
  808. * Description:
  809. * The bus reset function will reset the bus and abort any executing
  810. * commands.
  811. *
  812. * Input:
  813. * cmd = Linux SCSI command packet of the command that cause the
  814. * bus reset.
  815. *
  816. * Returns:
  817. * SUCCESS/FAILURE (defined as macro in scsi.h).
  818. *
  819. **************************************************************************/
  820. static int
  821. qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
  822. {
  823. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  824. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  825. int ret = FAILED;
  826. unsigned int id, lun;
  827. unsigned long serial;
  828. srb_t *sp = (srb_t *) CMD_SP(cmd);
  829. qla2x00_block_error_handler(cmd);
  830. id = cmd->device->id;
  831. lun = cmd->device->lun;
  832. serial = cmd->serial_number;
  833. if (!fcport)
  834. return ret;
  835. qla_printk(KERN_INFO, vha->hw,
  836. "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
  837. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  838. DEBUG2(printk("%s failed:board disabled\n",__func__));
  839. goto eh_bus_reset_done;
  840. }
  841. if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
  842. if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
  843. ret = SUCCESS;
  844. }
  845. if (ret == FAILED)
  846. goto eh_bus_reset_done;
  847. /* Flush outstanding commands. */
  848. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
  849. QLA_SUCCESS)
  850. ret = FAILED;
  851. eh_bus_reset_done:
  852. qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
  853. (ret == FAILED) ? "failed" : "succeded");
  854. return ret;
  855. }
  856. /**************************************************************************
  857. * qla2xxx_eh_host_reset
  858. *
  859. * Description:
  860. * The reset function will reset the Adapter.
  861. *
  862. * Input:
  863. * cmd = Linux SCSI command packet of the command that cause the
  864. * adapter reset.
  865. *
  866. * Returns:
  867. * Either SUCCESS or FAILED.
  868. *
  869. * Note:
  870. **************************************************************************/
  871. static int
  872. qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
  873. {
  874. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  875. fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
  876. struct qla_hw_data *ha = vha->hw;
  877. int ret = FAILED;
  878. unsigned int id, lun;
  879. unsigned long serial;
  880. srb_t *sp = (srb_t *) CMD_SP(cmd);
  881. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  882. qla2x00_block_error_handler(cmd);
  883. id = cmd->device->id;
  884. lun = cmd->device->lun;
  885. serial = cmd->serial_number;
  886. if (!fcport)
  887. return ret;
  888. qla_printk(KERN_INFO, ha,
  889. "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
  890. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
  891. goto eh_host_reset_lock;
  892. /*
  893. * Fixme-may be dpc thread is active and processing
  894. * loop_resync,so wait a while for it to
  895. * be completed and then issue big hammer.Otherwise
  896. * it may cause I/O failure as big hammer marks the
  897. * devices as lost kicking of the port_down_timer
  898. * while dpc is stuck for the mailbox to complete.
  899. */
  900. qla2x00_wait_for_loop_ready(vha);
  901. if (vha != base_vha) {
  902. if (qla2x00_vp_abort_isp(vha))
  903. goto eh_host_reset_lock;
  904. } else {
  905. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  906. if (qla2x00_abort_isp(base_vha)) {
  907. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  908. /* failed. schedule dpc to try */
  909. set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
  910. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
  911. goto eh_host_reset_lock;
  912. }
  913. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  914. }
  915. /* Waiting for command to be returned to OS.*/
  916. if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
  917. QLA_SUCCESS)
  918. ret = SUCCESS;
  919. eh_host_reset_lock:
  920. qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
  921. (ret == FAILED) ? "failed" : "succeded");
  922. return ret;
  923. }
  924. /*
  925. * qla2x00_loop_reset
  926. * Issue loop reset.
  927. *
  928. * Input:
  929. * ha = adapter block pointer.
  930. *
  931. * Returns:
  932. * 0 = success
  933. */
  934. int
  935. qla2x00_loop_reset(scsi_qla_host_t *vha)
  936. {
  937. int ret;
  938. struct fc_port *fcport;
  939. struct qla_hw_data *ha = vha->hw;
  940. if (ha->flags.enable_lip_full_login && !vha->vp_idx) {
  941. ret = qla2x00_full_login_lip(vha);
  942. if (ret != QLA_SUCCESS) {
  943. DEBUG2_3(printk("%s(%ld): failed: "
  944. "full_login_lip=%d.\n", __func__, vha->host_no,
  945. ret));
  946. }
  947. atomic_set(&vha->loop_state, LOOP_DOWN);
  948. atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
  949. qla2x00_mark_all_devices_lost(vha, 0);
  950. qla2x00_wait_for_loop_ready(vha);
  951. }
  952. if (ha->flags.enable_lip_reset && !vha->vp_idx) {
  953. ret = qla2x00_lip_reset(vha);
  954. if (ret != QLA_SUCCESS) {
  955. DEBUG2_3(printk("%s(%ld): failed: "
  956. "lip_reset=%d.\n", __func__, vha->host_no, ret));
  957. } else
  958. qla2x00_wait_for_loop_ready(vha);
  959. }
  960. if (ha->flags.enable_target_reset) {
  961. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  962. if (fcport->port_type != FCT_TARGET)
  963. continue;
  964. ret = ha->isp_ops->target_reset(fcport, 0);
  965. if (ret != QLA_SUCCESS) {
  966. DEBUG2_3(printk("%s(%ld): bus_reset failed: "
  967. "target_reset=%d d_id=%x.\n", __func__,
  968. vha->host_no, ret, fcport->d_id.b24));
  969. }
  970. }
  971. }
  972. /* Issue marker command only when we are going to start the I/O */
  973. vha->marker_needed = 1;
  974. return QLA_SUCCESS;
  975. }
  976. void
  977. qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
  978. {
  979. int que, cnt;
  980. unsigned long flags;
  981. srb_t *sp;
  982. struct qla_hw_data *ha = vha->hw;
  983. struct req_que *req;
  984. spin_lock_irqsave(&ha->hardware_lock, flags);
  985. for (que = 0; que < ha->max_queues; que++) {
  986. req = ha->req_q_map[que];
  987. if (!req)
  988. continue;
  989. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  990. sp = req->outstanding_cmds[cnt];
  991. if (sp && sp->fcport->vha == vha) {
  992. req->outstanding_cmds[cnt] = NULL;
  993. sp->cmd->result = res;
  994. qla2x00_sp_compl(ha, sp);
  995. }
  996. }
  997. }
  998. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  999. }
  1000. static int
  1001. qla2xxx_slave_alloc(struct scsi_device *sdev)
  1002. {
  1003. struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
  1004. if (!rport || fc_remote_port_chkready(rport))
  1005. return -ENXIO;
  1006. sdev->hostdata = *(fc_port_t **)rport->dd_data;
  1007. return 0;
  1008. }
  1009. static int
  1010. qla2xxx_slave_configure(struct scsi_device *sdev)
  1011. {
  1012. scsi_qla_host_t *vha = shost_priv(sdev->host);
  1013. struct qla_hw_data *ha = vha->hw;
  1014. struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
  1015. struct req_que *req = ha->req_q_map[vha->req_ques[0]];
  1016. if (sdev->tagged_supported)
  1017. scsi_activate_tcq(sdev, req->max_q_depth);
  1018. else
  1019. scsi_deactivate_tcq(sdev, req->max_q_depth);
  1020. rport->dev_loss_tmo = ha->port_down_retry_count;
  1021. return 0;
  1022. }
  1023. static void
  1024. qla2xxx_slave_destroy(struct scsi_device *sdev)
  1025. {
  1026. sdev->hostdata = NULL;
  1027. }
  1028. static int
  1029. qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
  1030. {
  1031. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  1032. return sdev->queue_depth;
  1033. }
  1034. static int
  1035. qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
  1036. {
  1037. if (sdev->tagged_supported) {
  1038. scsi_set_tag_type(sdev, tag_type);
  1039. if (tag_type)
  1040. scsi_activate_tcq(sdev, sdev->queue_depth);
  1041. else
  1042. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  1043. } else
  1044. tag_type = 0;
  1045. return tag_type;
  1046. }
  1047. /**
  1048. * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
  1049. * @ha: HA context
  1050. *
  1051. * At exit, the @ha's flags.enable_64bit_addressing set to indicated
  1052. * supported addressing method.
  1053. */
  1054. static void
  1055. qla2x00_config_dma_addressing(scsi_qla_host_t *vha)
  1056. {
  1057. struct qla_hw_data *ha = vha->hw;
  1058. /* Assume a 32bit DMA mask. */
  1059. ha->flags.enable_64bit_addressing = 0;
  1060. if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
  1061. /* Any upper-dword bits set? */
  1062. if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
  1063. !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
  1064. /* Ok, a 64bit DMA mask is applicable. */
  1065. ha->flags.enable_64bit_addressing = 1;
  1066. ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
  1067. ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
  1068. return;
  1069. }
  1070. }
  1071. dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
  1072. pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
  1073. }
  1074. static void
  1075. qla2x00_enable_intrs(struct qla_hw_data *ha)
  1076. {
  1077. unsigned long flags = 0;
  1078. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1079. spin_lock_irqsave(&ha->hardware_lock, flags);
  1080. ha->interrupts_on = 1;
  1081. /* enable risc and host interrupts */
  1082. WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
  1083. RD_REG_WORD(&reg->ictrl);
  1084. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1085. }
  1086. static void
  1087. qla2x00_disable_intrs(struct qla_hw_data *ha)
  1088. {
  1089. unsigned long flags = 0;
  1090. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  1091. spin_lock_irqsave(&ha->hardware_lock, flags);
  1092. ha->interrupts_on = 0;
  1093. /* disable risc and host interrupts */
  1094. WRT_REG_WORD(&reg->ictrl, 0);
  1095. RD_REG_WORD(&reg->ictrl);
  1096. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1097. }
  1098. static void
  1099. qla24xx_enable_intrs(struct qla_hw_data *ha)
  1100. {
  1101. unsigned long flags = 0;
  1102. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1103. spin_lock_irqsave(&ha->hardware_lock, flags);
  1104. ha->interrupts_on = 1;
  1105. WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
  1106. RD_REG_DWORD(&reg->ictrl);
  1107. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1108. }
  1109. static void
  1110. qla24xx_disable_intrs(struct qla_hw_data *ha)
  1111. {
  1112. unsigned long flags = 0;
  1113. struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
  1114. if (IS_NOPOLLING_TYPE(ha))
  1115. return;
  1116. spin_lock_irqsave(&ha->hardware_lock, flags);
  1117. ha->interrupts_on = 0;
  1118. WRT_REG_DWORD(&reg->ictrl, 0);
  1119. RD_REG_DWORD(&reg->ictrl);
  1120. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1121. }
  1122. static struct isp_operations qla2100_isp_ops = {
  1123. .pci_config = qla2100_pci_config,
  1124. .reset_chip = qla2x00_reset_chip,
  1125. .chip_diag = qla2x00_chip_diag,
  1126. .config_rings = qla2x00_config_rings,
  1127. .reset_adapter = qla2x00_reset_adapter,
  1128. .nvram_config = qla2x00_nvram_config,
  1129. .update_fw_options = qla2x00_update_fw_options,
  1130. .load_risc = qla2x00_load_risc,
  1131. .pci_info_str = qla2x00_pci_info_str,
  1132. .fw_version_str = qla2x00_fw_version_str,
  1133. .intr_handler = qla2100_intr_handler,
  1134. .enable_intrs = qla2x00_enable_intrs,
  1135. .disable_intrs = qla2x00_disable_intrs,
  1136. .abort_command = qla2x00_abort_command,
  1137. .target_reset = qla2x00_abort_target,
  1138. .lun_reset = qla2x00_lun_reset,
  1139. .fabric_login = qla2x00_login_fabric,
  1140. .fabric_logout = qla2x00_fabric_logout,
  1141. .calc_req_entries = qla2x00_calc_iocbs_32,
  1142. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1143. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1144. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1145. .read_nvram = qla2x00_read_nvram_data,
  1146. .write_nvram = qla2x00_write_nvram_data,
  1147. .fw_dump = qla2100_fw_dump,
  1148. .beacon_on = NULL,
  1149. .beacon_off = NULL,
  1150. .beacon_blink = NULL,
  1151. .read_optrom = qla2x00_read_optrom_data,
  1152. .write_optrom = qla2x00_write_optrom_data,
  1153. .get_flash_version = qla2x00_get_flash_version,
  1154. .start_scsi = qla2x00_start_scsi,
  1155. .wrt_req_reg = NULL,
  1156. .wrt_rsp_reg = NULL,
  1157. .rd_req_reg = NULL,
  1158. };
  1159. static struct isp_operations qla2300_isp_ops = {
  1160. .pci_config = qla2300_pci_config,
  1161. .reset_chip = qla2x00_reset_chip,
  1162. .chip_diag = qla2x00_chip_diag,
  1163. .config_rings = qla2x00_config_rings,
  1164. .reset_adapter = qla2x00_reset_adapter,
  1165. .nvram_config = qla2x00_nvram_config,
  1166. .update_fw_options = qla2x00_update_fw_options,
  1167. .load_risc = qla2x00_load_risc,
  1168. .pci_info_str = qla2x00_pci_info_str,
  1169. .fw_version_str = qla2x00_fw_version_str,
  1170. .intr_handler = qla2300_intr_handler,
  1171. .enable_intrs = qla2x00_enable_intrs,
  1172. .disable_intrs = qla2x00_disable_intrs,
  1173. .abort_command = qla2x00_abort_command,
  1174. .target_reset = qla2x00_abort_target,
  1175. .lun_reset = qla2x00_lun_reset,
  1176. .fabric_login = qla2x00_login_fabric,
  1177. .fabric_logout = qla2x00_fabric_logout,
  1178. .calc_req_entries = qla2x00_calc_iocbs_32,
  1179. .build_iocbs = qla2x00_build_scsi_iocbs_32,
  1180. .prep_ms_iocb = qla2x00_prep_ms_iocb,
  1181. .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
  1182. .read_nvram = qla2x00_read_nvram_data,
  1183. .write_nvram = qla2x00_write_nvram_data,
  1184. .fw_dump = qla2300_fw_dump,
  1185. .beacon_on = qla2x00_beacon_on,
  1186. .beacon_off = qla2x00_beacon_off,
  1187. .beacon_blink = qla2x00_beacon_blink,
  1188. .read_optrom = qla2x00_read_optrom_data,
  1189. .write_optrom = qla2x00_write_optrom_data,
  1190. .get_flash_version = qla2x00_get_flash_version,
  1191. .start_scsi = qla2x00_start_scsi,
  1192. .wrt_req_reg = NULL,
  1193. .wrt_rsp_reg = NULL,
  1194. .rd_req_reg = NULL,
  1195. };
  1196. static struct isp_operations qla24xx_isp_ops = {
  1197. .pci_config = qla24xx_pci_config,
  1198. .reset_chip = qla24xx_reset_chip,
  1199. .chip_diag = qla24xx_chip_diag,
  1200. .config_rings = qla24xx_config_rings,
  1201. .reset_adapter = qla24xx_reset_adapter,
  1202. .nvram_config = qla24xx_nvram_config,
  1203. .update_fw_options = qla24xx_update_fw_options,
  1204. .load_risc = qla24xx_load_risc,
  1205. .pci_info_str = qla24xx_pci_info_str,
  1206. .fw_version_str = qla24xx_fw_version_str,
  1207. .intr_handler = qla24xx_intr_handler,
  1208. .enable_intrs = qla24xx_enable_intrs,
  1209. .disable_intrs = qla24xx_disable_intrs,
  1210. .abort_command = qla24xx_abort_command,
  1211. .target_reset = qla24xx_abort_target,
  1212. .lun_reset = qla24xx_lun_reset,
  1213. .fabric_login = qla24xx_login_fabric,
  1214. .fabric_logout = qla24xx_fabric_logout,
  1215. .calc_req_entries = NULL,
  1216. .build_iocbs = NULL,
  1217. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1218. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1219. .read_nvram = qla24xx_read_nvram_data,
  1220. .write_nvram = qla24xx_write_nvram_data,
  1221. .fw_dump = qla24xx_fw_dump,
  1222. .beacon_on = qla24xx_beacon_on,
  1223. .beacon_off = qla24xx_beacon_off,
  1224. .beacon_blink = qla24xx_beacon_blink,
  1225. .read_optrom = qla24xx_read_optrom_data,
  1226. .write_optrom = qla24xx_write_optrom_data,
  1227. .get_flash_version = qla24xx_get_flash_version,
  1228. .start_scsi = qla24xx_start_scsi,
  1229. .wrt_req_reg = qla24xx_wrt_req_reg,
  1230. .wrt_rsp_reg = qla24xx_wrt_rsp_reg,
  1231. .rd_req_reg = qla24xx_rd_req_reg,
  1232. };
  1233. static struct isp_operations qla25xx_isp_ops = {
  1234. .pci_config = qla25xx_pci_config,
  1235. .reset_chip = qla24xx_reset_chip,
  1236. .chip_diag = qla24xx_chip_diag,
  1237. .config_rings = qla24xx_config_rings,
  1238. .reset_adapter = qla24xx_reset_adapter,
  1239. .nvram_config = qla24xx_nvram_config,
  1240. .update_fw_options = qla24xx_update_fw_options,
  1241. .load_risc = qla24xx_load_risc,
  1242. .pci_info_str = qla24xx_pci_info_str,
  1243. .fw_version_str = qla24xx_fw_version_str,
  1244. .intr_handler = qla24xx_intr_handler,
  1245. .enable_intrs = qla24xx_enable_intrs,
  1246. .disable_intrs = qla24xx_disable_intrs,
  1247. .abort_command = qla24xx_abort_command,
  1248. .target_reset = qla24xx_abort_target,
  1249. .lun_reset = qla24xx_lun_reset,
  1250. .fabric_login = qla24xx_login_fabric,
  1251. .fabric_logout = qla24xx_fabric_logout,
  1252. .calc_req_entries = NULL,
  1253. .build_iocbs = NULL,
  1254. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1255. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1256. .read_nvram = qla25xx_read_nvram_data,
  1257. .write_nvram = qla25xx_write_nvram_data,
  1258. .fw_dump = qla25xx_fw_dump,
  1259. .beacon_on = qla24xx_beacon_on,
  1260. .beacon_off = qla24xx_beacon_off,
  1261. .beacon_blink = qla24xx_beacon_blink,
  1262. .read_optrom = qla25xx_read_optrom_data,
  1263. .write_optrom = qla24xx_write_optrom_data,
  1264. .get_flash_version = qla24xx_get_flash_version,
  1265. .start_scsi = qla24xx_start_scsi,
  1266. .wrt_req_reg = qla24xx_wrt_req_reg,
  1267. .wrt_rsp_reg = qla24xx_wrt_rsp_reg,
  1268. .rd_req_reg = qla24xx_rd_req_reg,
  1269. };
  1270. static struct isp_operations qla81xx_isp_ops = {
  1271. .pci_config = qla25xx_pci_config,
  1272. .reset_chip = qla24xx_reset_chip,
  1273. .chip_diag = qla24xx_chip_diag,
  1274. .config_rings = qla24xx_config_rings,
  1275. .reset_adapter = qla24xx_reset_adapter,
  1276. .nvram_config = qla81xx_nvram_config,
  1277. .update_fw_options = qla81xx_update_fw_options,
  1278. .load_risc = qla24xx_load_risc,
  1279. .pci_info_str = qla24xx_pci_info_str,
  1280. .fw_version_str = qla24xx_fw_version_str,
  1281. .intr_handler = qla24xx_intr_handler,
  1282. .enable_intrs = qla24xx_enable_intrs,
  1283. .disable_intrs = qla24xx_disable_intrs,
  1284. .abort_command = qla24xx_abort_command,
  1285. .target_reset = qla24xx_abort_target,
  1286. .lun_reset = qla24xx_lun_reset,
  1287. .fabric_login = qla24xx_login_fabric,
  1288. .fabric_logout = qla24xx_fabric_logout,
  1289. .calc_req_entries = NULL,
  1290. .build_iocbs = NULL,
  1291. .prep_ms_iocb = qla24xx_prep_ms_iocb,
  1292. .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
  1293. .read_nvram = qla25xx_read_nvram_data,
  1294. .write_nvram = qla25xx_write_nvram_data,
  1295. .fw_dump = qla81xx_fw_dump,
  1296. .beacon_on = qla24xx_beacon_on,
  1297. .beacon_off = qla24xx_beacon_off,
  1298. .beacon_blink = qla24xx_beacon_blink,
  1299. .read_optrom = qla25xx_read_optrom_data,
  1300. .write_optrom = qla24xx_write_optrom_data,
  1301. .get_flash_version = qla24xx_get_flash_version,
  1302. .start_scsi = qla24xx_start_scsi,
  1303. .wrt_req_reg = qla24xx_wrt_req_reg,
  1304. .wrt_rsp_reg = qla24xx_wrt_rsp_reg,
  1305. .rd_req_reg = qla24xx_rd_req_reg,
  1306. };
  1307. static inline void
  1308. qla2x00_set_isp_flags(struct qla_hw_data *ha)
  1309. {
  1310. ha->device_type = DT_EXTENDED_IDS;
  1311. switch (ha->pdev->device) {
  1312. case PCI_DEVICE_ID_QLOGIC_ISP2100:
  1313. ha->device_type |= DT_ISP2100;
  1314. ha->device_type &= ~DT_EXTENDED_IDS;
  1315. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1316. break;
  1317. case PCI_DEVICE_ID_QLOGIC_ISP2200:
  1318. ha->device_type |= DT_ISP2200;
  1319. ha->device_type &= ~DT_EXTENDED_IDS;
  1320. ha->fw_srisc_address = RISC_START_ADDRESS_2100;
  1321. break;
  1322. case PCI_DEVICE_ID_QLOGIC_ISP2300:
  1323. ha->device_type |= DT_ISP2300;
  1324. ha->device_type |= DT_ZIO_SUPPORTED;
  1325. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1326. break;
  1327. case PCI_DEVICE_ID_QLOGIC_ISP2312:
  1328. ha->device_type |= DT_ISP2312;
  1329. ha->device_type |= DT_ZIO_SUPPORTED;
  1330. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1331. break;
  1332. case PCI_DEVICE_ID_QLOGIC_ISP2322:
  1333. ha->device_type |= DT_ISP2322;
  1334. ha->device_type |= DT_ZIO_SUPPORTED;
  1335. if (ha->pdev->subsystem_vendor == 0x1028 &&
  1336. ha->pdev->subsystem_device == 0x0170)
  1337. ha->device_type |= DT_OEM_001;
  1338. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1339. break;
  1340. case PCI_DEVICE_ID_QLOGIC_ISP6312:
  1341. ha->device_type |= DT_ISP6312;
  1342. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1343. break;
  1344. case PCI_DEVICE_ID_QLOGIC_ISP6322:
  1345. ha->device_type |= DT_ISP6322;
  1346. ha->fw_srisc_address = RISC_START_ADDRESS_2300;
  1347. break;
  1348. case PCI_DEVICE_ID_QLOGIC_ISP2422:
  1349. ha->device_type |= DT_ISP2422;
  1350. ha->device_type |= DT_ZIO_SUPPORTED;
  1351. ha->device_type |= DT_FWI2;
  1352. ha->device_type |= DT_IIDMA;
  1353. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1354. break;
  1355. case PCI_DEVICE_ID_QLOGIC_ISP2432:
  1356. ha->device_type |= DT_ISP2432;
  1357. ha->device_type |= DT_ZIO_SUPPORTED;
  1358. ha->device_type |= DT_FWI2;
  1359. ha->device_type |= DT_IIDMA;
  1360. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1361. break;
  1362. case PCI_DEVICE_ID_QLOGIC_ISP8432:
  1363. ha->device_type |= DT_ISP8432;
  1364. ha->device_type |= DT_ZIO_SUPPORTED;
  1365. ha->device_type |= DT_FWI2;
  1366. ha->device_type |= DT_IIDMA;
  1367. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1368. break;
  1369. case PCI_DEVICE_ID_QLOGIC_ISP5422:
  1370. ha->device_type |= DT_ISP5422;
  1371. ha->device_type |= DT_FWI2;
  1372. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1373. break;
  1374. case PCI_DEVICE_ID_QLOGIC_ISP5432:
  1375. ha->device_type |= DT_ISP5432;
  1376. ha->device_type |= DT_FWI2;
  1377. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1378. break;
  1379. case PCI_DEVICE_ID_QLOGIC_ISP2532:
  1380. ha->device_type |= DT_ISP2532;
  1381. ha->device_type |= DT_ZIO_SUPPORTED;
  1382. ha->device_type |= DT_FWI2;
  1383. ha->device_type |= DT_IIDMA;
  1384. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1385. break;
  1386. case PCI_DEVICE_ID_QLOGIC_ISP8001:
  1387. ha->device_type |= DT_ISP8001;
  1388. ha->device_type |= DT_ZIO_SUPPORTED;
  1389. ha->device_type |= DT_FWI2;
  1390. ha->device_type |= DT_IIDMA;
  1391. ha->fw_srisc_address = RISC_START_ADDRESS_2400;
  1392. break;
  1393. }
  1394. }
  1395. static int
  1396. qla2x00_iospace_config(struct qla_hw_data *ha)
  1397. {
  1398. resource_size_t pio;
  1399. uint16_t msix;
  1400. if (pci_request_selected_regions(ha->pdev, ha->bars,
  1401. QLA2XXX_DRIVER_NAME)) {
  1402. qla_printk(KERN_WARNING, ha,
  1403. "Failed to reserve PIO/MMIO regions (%s)\n",
  1404. pci_name(ha->pdev));
  1405. goto iospace_error_exit;
  1406. }
  1407. if (!(ha->bars & 1))
  1408. goto skip_pio;
  1409. /* We only need PIO for Flash operations on ISP2312 v2 chips. */
  1410. pio = pci_resource_start(ha->pdev, 0);
  1411. if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
  1412. if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
  1413. qla_printk(KERN_WARNING, ha,
  1414. "Invalid PCI I/O region size (%s)...\n",
  1415. pci_name(ha->pdev));
  1416. pio = 0;
  1417. }
  1418. } else {
  1419. qla_printk(KERN_WARNING, ha,
  1420. "region #0 not a PIO resource (%s)...\n",
  1421. pci_name(ha->pdev));
  1422. pio = 0;
  1423. }
  1424. ha->pio_address = pio;
  1425. skip_pio:
  1426. /* Use MMIO operations for all accesses. */
  1427. if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
  1428. qla_printk(KERN_ERR, ha,
  1429. "region #1 not an MMIO resource (%s), aborting\n",
  1430. pci_name(ha->pdev));
  1431. goto iospace_error_exit;
  1432. }
  1433. if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
  1434. qla_printk(KERN_ERR, ha,
  1435. "Invalid PCI mem region size (%s), aborting\n",
  1436. pci_name(ha->pdev));
  1437. goto iospace_error_exit;
  1438. }
  1439. ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
  1440. if (!ha->iobase) {
  1441. qla_printk(KERN_ERR, ha,
  1442. "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
  1443. goto iospace_error_exit;
  1444. }
  1445. /* Determine queue resources */
  1446. ha->max_queues = 1;
  1447. if (ql2xmaxqueues <= 1 || (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
  1448. goto mqiobase_exit;
  1449. ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
  1450. pci_resource_len(ha->pdev, 3));
  1451. if (ha->mqiobase) {
  1452. /* Read MSIX vector size of the board */
  1453. pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
  1454. ha->msix_count = msix;
  1455. /* Max queues are bounded by available msix vectors */
  1456. /* queue 0 uses two msix vectors */
  1457. if (ha->msix_count - 1 < ql2xmaxqueues)
  1458. ha->max_queues = ha->msix_count - 1;
  1459. else if (ql2xmaxqueues > QLA_MQ_SIZE)
  1460. ha->max_queues = QLA_MQ_SIZE;
  1461. else
  1462. ha->max_queues = ql2xmaxqueues;
  1463. qla_printk(KERN_INFO, ha,
  1464. "MSI-X vector count: %d\n", msix);
  1465. }
  1466. mqiobase_exit:
  1467. ha->msix_count = ha->max_queues + 1;
  1468. return (0);
  1469. iospace_error_exit:
  1470. return (-ENOMEM);
  1471. }
  1472. static void
  1473. qla2xxx_scan_start(struct Scsi_Host *shost)
  1474. {
  1475. scsi_qla_host_t *vha = shost_priv(shost);
  1476. set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
  1477. set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
  1478. set_bit(RSCN_UPDATE, &vha->dpc_flags);
  1479. set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
  1480. }
  1481. static int
  1482. qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
  1483. {
  1484. scsi_qla_host_t *vha = shost_priv(shost);
  1485. if (!vha->host)
  1486. return 1;
  1487. if (time > vha->hw->loop_reset_delay * HZ)
  1488. return 1;
  1489. return atomic_read(&vha->loop_state) == LOOP_READY;
  1490. }
  1491. /*
  1492. * PCI driver interface
  1493. */
  1494. static int __devinit
  1495. qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  1496. {
  1497. int ret = -ENODEV;
  1498. struct Scsi_Host *host;
  1499. scsi_qla_host_t *base_vha = NULL;
  1500. struct qla_hw_data *ha;
  1501. char pci_info[30];
  1502. char fw_str[30];
  1503. struct scsi_host_template *sht;
  1504. int bars, max_id, mem_only = 0;
  1505. uint16_t req_length = 0, rsp_length = 0;
  1506. struct req_que *req = NULL;
  1507. struct rsp_que *rsp = NULL;
  1508. bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
  1509. sht = &qla2x00_driver_template;
  1510. if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
  1511. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
  1512. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
  1513. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
  1514. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
  1515. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
  1516. pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
  1517. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1518. sht = &qla24xx_driver_template;
  1519. mem_only = 1;
  1520. }
  1521. if (mem_only) {
  1522. if (pci_enable_device_mem(pdev))
  1523. goto probe_out;
  1524. } else {
  1525. if (pci_enable_device(pdev))
  1526. goto probe_out;
  1527. }
  1528. /* This may fail but that's ok */
  1529. pci_enable_pcie_error_reporting(pdev);
  1530. ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
  1531. if (!ha) {
  1532. DEBUG(printk("Unable to allocate memory for ha\n"));
  1533. goto probe_out;
  1534. }
  1535. ha->pdev = pdev;
  1536. /* Clear our data area */
  1537. ha->bars = bars;
  1538. ha->mem_only = mem_only;
  1539. spin_lock_init(&ha->hardware_lock);
  1540. /* Set ISP-type information. */
  1541. qla2x00_set_isp_flags(ha);
  1542. /* Configure PCI I/O space */
  1543. ret = qla2x00_iospace_config(ha);
  1544. if (ret)
  1545. goto probe_hw_failed;
  1546. qla_printk(KERN_INFO, ha,
  1547. "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
  1548. ha->iobase);
  1549. ha->prev_topology = 0;
  1550. ha->init_cb_size = sizeof(init_cb_t);
  1551. ha->link_data_rate = PORT_SPEED_UNKNOWN;
  1552. ha->optrom_size = OPTROM_SIZE_2300;
  1553. /* Assign ISP specific operations. */
  1554. max_id = MAX_TARGETS_2200;
  1555. if (IS_QLA2100(ha)) {
  1556. max_id = MAX_TARGETS_2100;
  1557. ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
  1558. req_length = REQUEST_ENTRY_CNT_2100;
  1559. rsp_length = RESPONSE_ENTRY_CNT_2100;
  1560. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  1561. ha->gid_list_info_size = 4;
  1562. ha->flash_conf_off = ~0;
  1563. ha->flash_data_off = ~0;
  1564. ha->nvram_conf_off = ~0;
  1565. ha->nvram_data_off = ~0;
  1566. ha->isp_ops = &qla2100_isp_ops;
  1567. } else if (IS_QLA2200(ha)) {
  1568. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1569. req_length = REQUEST_ENTRY_CNT_2200;
  1570. rsp_length = RESPONSE_ENTRY_CNT_2100;
  1571. ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
  1572. ha->gid_list_info_size = 4;
  1573. ha->flash_conf_off = ~0;
  1574. ha->flash_data_off = ~0;
  1575. ha->nvram_conf_off = ~0;
  1576. ha->nvram_data_off = ~0;
  1577. ha->isp_ops = &qla2100_isp_ops;
  1578. } else if (IS_QLA23XX(ha)) {
  1579. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1580. req_length = REQUEST_ENTRY_CNT_2200;
  1581. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1582. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1583. ha->gid_list_info_size = 6;
  1584. if (IS_QLA2322(ha) || IS_QLA6322(ha))
  1585. ha->optrom_size = OPTROM_SIZE_2322;
  1586. ha->flash_conf_off = ~0;
  1587. ha->flash_data_off = ~0;
  1588. ha->nvram_conf_off = ~0;
  1589. ha->nvram_data_off = ~0;
  1590. ha->isp_ops = &qla2300_isp_ops;
  1591. } else if (IS_QLA24XX_TYPE(ha)) {
  1592. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1593. req_length = REQUEST_ENTRY_CNT_24XX;
  1594. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1595. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1596. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1597. ha->gid_list_info_size = 8;
  1598. ha->optrom_size = OPTROM_SIZE_24XX;
  1599. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
  1600. ha->isp_ops = &qla24xx_isp_ops;
  1601. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1602. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1603. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1604. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1605. } else if (IS_QLA25XX(ha)) {
  1606. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1607. req_length = REQUEST_ENTRY_CNT_24XX;
  1608. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1609. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1610. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1611. ha->gid_list_info_size = 8;
  1612. ha->optrom_size = OPTROM_SIZE_25XX;
  1613. ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
  1614. ha->isp_ops = &qla25xx_isp_ops;
  1615. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
  1616. ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
  1617. ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
  1618. ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
  1619. } else if (IS_QLA81XX(ha)) {
  1620. ha->mbx_count = MAILBOX_REGISTER_COUNT;
  1621. req_length = REQUEST_ENTRY_CNT_24XX;
  1622. rsp_length = RESPONSE_ENTRY_CNT_2300;
  1623. ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
  1624. ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
  1625. ha->gid_list_info_size = 8;
  1626. ha->optrom_size = OPTROM_SIZE_81XX;
  1627. ha->isp_ops = &qla81xx_isp_ops;
  1628. ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
  1629. ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
  1630. ha->nvram_conf_off = ~0;
  1631. ha->nvram_data_off = ~0;
  1632. }
  1633. mutex_init(&ha->vport_lock);
  1634. init_completion(&ha->mbx_cmd_comp);
  1635. complete(&ha->mbx_cmd_comp);
  1636. init_completion(&ha->mbx_intr_comp);
  1637. set_bit(0, (unsigned long *) ha->vp_idx_map);
  1638. ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
  1639. if (!ret) {
  1640. qla_printk(KERN_WARNING, ha,
  1641. "[ERROR] Failed to allocate memory for adapter\n");
  1642. goto probe_hw_failed;
  1643. }
  1644. req->max_q_depth = MAX_Q_DEPTH;
  1645. if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
  1646. req->max_q_depth = ql2xmaxqdepth;
  1647. base_vha = qla2x00_create_host(sht, ha);
  1648. if (!base_vha) {
  1649. qla_printk(KERN_WARNING, ha,
  1650. "[ERROR] Failed to allocate memory for scsi_host\n");
  1651. ret = -ENOMEM;
  1652. goto probe_hw_failed;
  1653. }
  1654. pci_set_drvdata(pdev, base_vha);
  1655. qla2x00_config_dma_addressing(base_vha);
  1656. host = base_vha->host;
  1657. base_vha->req_ques[0] = req->id;
  1658. host->can_queue = req->length + 128;
  1659. if (IS_QLA2XXX_MIDTYPE(ha))
  1660. base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
  1661. else
  1662. base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
  1663. base_vha->vp_idx;
  1664. if (IS_QLA2100(ha))
  1665. host->sg_tablesize = 32;
  1666. host->max_id = max_id;
  1667. host->this_id = 255;
  1668. host->cmd_per_lun = 3;
  1669. host->unique_id = host->host_no;
  1670. host->max_cmd_len = MAX_CMDSZ;
  1671. host->max_channel = MAX_BUSES - 1;
  1672. host->max_lun = MAX_LUNS;
  1673. host->transportt = qla2xxx_transport_template;
  1674. /* Set up the irqs */
  1675. ret = qla2x00_request_irqs(ha, rsp);
  1676. if (ret)
  1677. goto probe_failed;
  1678. /* Alloc arrays of request and response ring ptrs */
  1679. if (!qla2x00_alloc_queues(ha)) {
  1680. qla_printk(KERN_WARNING, ha,
  1681. "[ERROR] Failed to allocate memory for queue"
  1682. " pointers\n");
  1683. goto probe_failed;
  1684. }
  1685. ha->rsp_q_map[0] = rsp;
  1686. ha->req_q_map[0] = req;
  1687. if (ha->mqenable) {
  1688. ha->isp_ops->wrt_req_reg = qla25xx_wrt_req_reg;
  1689. ha->isp_ops->wrt_rsp_reg = qla25xx_wrt_rsp_reg;
  1690. ha->isp_ops->rd_req_reg = qla25xx_rd_req_reg;
  1691. }
  1692. if (qla2x00_initialize_adapter(base_vha)) {
  1693. qla_printk(KERN_WARNING, ha,
  1694. "Failed to initialize adapter\n");
  1695. DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
  1696. "Adapter flags %x.\n",
  1697. base_vha->host_no, base_vha->device_flags));
  1698. ret = -ENODEV;
  1699. goto probe_failed;
  1700. }
  1701. /*
  1702. * Startup the kernel thread for this host adapter
  1703. */
  1704. ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
  1705. "%s_dpc", base_vha->host_str);
  1706. if (IS_ERR(ha->dpc_thread)) {
  1707. qla_printk(KERN_WARNING, ha,
  1708. "Unable to start DPC thread!\n");
  1709. ret = PTR_ERR(ha->dpc_thread);
  1710. goto probe_failed;
  1711. }
  1712. list_add_tail(&base_vha->list, &ha->vp_list);
  1713. base_vha->host->irq = ha->pdev->irq;
  1714. /* Initialized the timer */
  1715. qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
  1716. DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
  1717. base_vha->host_no, ha));
  1718. base_vha->flags.init_done = 1;
  1719. base_vha->flags.online = 1;
  1720. ret = scsi_add_host(host, &pdev->dev);
  1721. if (ret)
  1722. goto probe_failed;
  1723. ha->isp_ops->enable_intrs(ha);
  1724. scsi_scan_host(host);
  1725. qla2x00_alloc_sysfs_attr(base_vha);
  1726. qla2x00_init_host_attr(base_vha);
  1727. qla2x00_dfs_setup(base_vha);
  1728. qla_printk(KERN_INFO, ha, "\n"
  1729. " QLogic Fibre Channel HBA Driver: %s\n"
  1730. " QLogic %s - %s\n"
  1731. " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
  1732. qla2x00_version_str, ha->model_number,
  1733. ha->model_desc ? ha->model_desc : "", pdev->device,
  1734. ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
  1735. ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
  1736. ha->isp_ops->fw_version_str(base_vha, fw_str));
  1737. return 0;
  1738. probe_failed:
  1739. qla2x00_free_device(base_vha);
  1740. scsi_host_put(base_vha->host);
  1741. probe_hw_failed:
  1742. if (ha->iobase)
  1743. iounmap(ha->iobase);
  1744. pci_release_selected_regions(ha->pdev, ha->bars);
  1745. kfree(ha);
  1746. ha = NULL;
  1747. probe_out:
  1748. pci_disable_device(pdev);
  1749. return ret;
  1750. }
  1751. static void
  1752. qla2x00_remove_one(struct pci_dev *pdev)
  1753. {
  1754. scsi_qla_host_t *base_vha, *vha, *temp;
  1755. struct qla_hw_data *ha;
  1756. base_vha = pci_get_drvdata(pdev);
  1757. ha = base_vha->hw;
  1758. list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
  1759. if (vha && vha->fc_vport)
  1760. fc_vport_terminate(vha->fc_vport);
  1761. }
  1762. set_bit(UNLOADING, &base_vha->dpc_flags);
  1763. qla2x00_dfs_remove(base_vha);
  1764. qla84xx_put_chip(base_vha);
  1765. qla2x00_free_sysfs_attr(base_vha);
  1766. fc_remove_host(base_vha->host);
  1767. scsi_remove_host(base_vha->host);
  1768. qla2x00_free_device(base_vha);
  1769. scsi_host_put(base_vha->host);
  1770. if (ha->iobase)
  1771. iounmap(ha->iobase);
  1772. if (ha->mqiobase)
  1773. iounmap(ha->mqiobase);
  1774. pci_release_selected_regions(ha->pdev, ha->bars);
  1775. kfree(ha);
  1776. ha = NULL;
  1777. pci_disable_device(pdev);
  1778. pci_set_drvdata(pdev, NULL);
  1779. }
  1780. static void
  1781. qla2x00_free_device(scsi_qla_host_t *vha)
  1782. {
  1783. struct qla_hw_data *ha = vha->hw;
  1784. qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
  1785. /* Disable timer */
  1786. if (vha->timer_active)
  1787. qla2x00_stop_timer(vha);
  1788. vha->flags.online = 0;
  1789. /* Kill the kernel thread for this host */
  1790. if (ha->dpc_thread) {
  1791. struct task_struct *t = ha->dpc_thread;
  1792. /*
  1793. * qla2xxx_wake_dpc checks for ->dpc_thread
  1794. * so we need to zero it out.
  1795. */
  1796. ha->dpc_thread = NULL;
  1797. kthread_stop(t);
  1798. }
  1799. if (ha->flags.fce_enabled)
  1800. qla2x00_disable_fce_trace(vha, NULL, NULL);
  1801. if (ha->eft)
  1802. qla2x00_disable_eft_trace(vha);
  1803. /* Stop currently executing firmware. */
  1804. qla2x00_try_to_stop_firmware(vha);
  1805. /* turn-off interrupts on the card */
  1806. if (ha->interrupts_on)
  1807. ha->isp_ops->disable_intrs(ha);
  1808. qla2x00_free_irqs(vha);
  1809. qla2x00_mem_free(ha);
  1810. qla2x00_free_queues(ha);
  1811. }
  1812. static inline void
  1813. qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
  1814. int defer)
  1815. {
  1816. struct fc_rport *rport;
  1817. if (!fcport->rport)
  1818. return;
  1819. rport = fcport->rport;
  1820. if (defer) {
  1821. spin_lock_irq(vha->host->host_lock);
  1822. fcport->drport = rport;
  1823. spin_unlock_irq(vha->host->host_lock);
  1824. set_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
  1825. qla2xxx_wake_dpc(vha);
  1826. } else
  1827. fc_remote_port_delete(rport);
  1828. }
  1829. /*
  1830. * qla2x00_mark_device_lost Updates fcport state when device goes offline.
  1831. *
  1832. * Input: ha = adapter block pointer. fcport = port structure pointer.
  1833. *
  1834. * Return: None.
  1835. *
  1836. * Context:
  1837. */
  1838. void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
  1839. int do_login, int defer)
  1840. {
  1841. if (atomic_read(&fcport->state) == FCS_ONLINE &&
  1842. vha->vp_idx == fcport->vp_idx) {
  1843. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1844. qla2x00_schedule_rport_del(vha, fcport, defer);
  1845. }
  1846. /*
  1847. * We may need to retry the login, so don't change the state of the
  1848. * port but do the retries.
  1849. */
  1850. if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
  1851. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1852. if (!do_login)
  1853. return;
  1854. if (fcport->login_retry == 0) {
  1855. fcport->login_retry = vha->hw->login_retry_count;
  1856. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  1857. DEBUG(printk("scsi(%ld): Port login retry: "
  1858. "%02x%02x%02x%02x%02x%02x%02x%02x, "
  1859. "id = 0x%04x retry cnt=%d\n",
  1860. vha->host_no,
  1861. fcport->port_name[0],
  1862. fcport->port_name[1],
  1863. fcport->port_name[2],
  1864. fcport->port_name[3],
  1865. fcport->port_name[4],
  1866. fcport->port_name[5],
  1867. fcport->port_name[6],
  1868. fcport->port_name[7],
  1869. fcport->loop_id,
  1870. fcport->login_retry));
  1871. }
  1872. }
  1873. /*
  1874. * qla2x00_mark_all_devices_lost
  1875. * Updates fcport state when device goes offline.
  1876. *
  1877. * Input:
  1878. * ha = adapter block pointer.
  1879. * fcport = port structure pointer.
  1880. *
  1881. * Return:
  1882. * None.
  1883. *
  1884. * Context:
  1885. */
  1886. void
  1887. qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
  1888. {
  1889. fc_port_t *fcport;
  1890. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1891. if (vha->vp_idx != fcport->vp_idx)
  1892. continue;
  1893. /*
  1894. * No point in marking the device as lost, if the device is
  1895. * already DEAD.
  1896. */
  1897. if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
  1898. continue;
  1899. if (atomic_read(&fcport->state) == FCS_ONLINE) {
  1900. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1901. qla2x00_schedule_rport_del(vha, fcport, defer);
  1902. } else
  1903. atomic_set(&fcport->state, FCS_DEVICE_LOST);
  1904. }
  1905. }
  1906. /*
  1907. * qla2x00_mem_alloc
  1908. * Allocates adapter memory.
  1909. *
  1910. * Returns:
  1911. * 0 = success.
  1912. * !0 = failure.
  1913. */
  1914. static int
  1915. qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
  1916. struct req_que **req, struct rsp_que **rsp)
  1917. {
  1918. char name[16];
  1919. ha->init_cb_size = sizeof(init_cb_t);
  1920. if (IS_QLA2XXX_MIDTYPE(ha))
  1921. ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
  1922. ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
  1923. &ha->init_cb_dma, GFP_KERNEL);
  1924. if (!ha->init_cb)
  1925. goto fail;
  1926. ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
  1927. &ha->gid_list_dma, GFP_KERNEL);
  1928. if (!ha->gid_list)
  1929. goto fail_free_init_cb;
  1930. ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
  1931. if (!ha->srb_mempool)
  1932. goto fail_free_gid_list;
  1933. /* Get memory for cached NVRAM */
  1934. ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
  1935. if (!ha->nvram)
  1936. goto fail_free_srb_mempool;
  1937. snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
  1938. ha->pdev->device);
  1939. ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
  1940. DMA_POOL_SIZE, 8, 0);
  1941. if (!ha->s_dma_pool)
  1942. goto fail_free_nvram;
  1943. /* Allocate memory for SNS commands */
  1944. if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
  1945. /* Get consistent memory allocated for SNS commands */
  1946. ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
  1947. sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
  1948. if (!ha->sns_cmd)
  1949. goto fail_dma_pool;
  1950. } else {
  1951. /* Get consistent memory allocated for MS IOCB */
  1952. ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  1953. &ha->ms_iocb_dma);
  1954. if (!ha->ms_iocb)
  1955. goto fail_dma_pool;
  1956. /* Get consistent memory allocated for CT SNS commands */
  1957. ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
  1958. sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
  1959. if (!ha->ct_sns)
  1960. goto fail_free_ms_iocb;
  1961. }
  1962. /* Allocate memory for request ring */
  1963. *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
  1964. if (!*req) {
  1965. DEBUG(printk("Unable to allocate memory for req\n"));
  1966. goto fail_req;
  1967. }
  1968. (*req)->length = req_len;
  1969. (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
  1970. ((*req)->length + 1) * sizeof(request_t),
  1971. &(*req)->dma, GFP_KERNEL);
  1972. if (!(*req)->ring) {
  1973. DEBUG(printk("Unable to allocate memory for req_ring\n"));
  1974. goto fail_req_ring;
  1975. }
  1976. /* Allocate memory for response ring */
  1977. *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
  1978. if (!*rsp) {
  1979. qla_printk(KERN_WARNING, ha,
  1980. "Unable to allocate memory for rsp\n");
  1981. goto fail_rsp;
  1982. }
  1983. (*rsp)->hw = ha;
  1984. (*rsp)->length = rsp_len;
  1985. (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
  1986. ((*rsp)->length + 1) * sizeof(response_t),
  1987. &(*rsp)->dma, GFP_KERNEL);
  1988. if (!(*rsp)->ring) {
  1989. qla_printk(KERN_WARNING, ha,
  1990. "Unable to allocate memory for rsp_ring\n");
  1991. goto fail_rsp_ring;
  1992. }
  1993. (*req)->rsp = *rsp;
  1994. (*rsp)->req = *req;
  1995. /* Allocate memory for NVRAM data for vports */
  1996. if (ha->nvram_npiv_size) {
  1997. ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
  1998. ha->nvram_npiv_size, GFP_KERNEL);
  1999. if (!ha->npiv_info) {
  2000. qla_printk(KERN_WARNING, ha,
  2001. "Unable to allocate memory for npiv info\n");
  2002. goto fail_npiv_info;
  2003. }
  2004. } else
  2005. ha->npiv_info = NULL;
  2006. INIT_LIST_HEAD(&ha->vp_list);
  2007. return 1;
  2008. fail_npiv_info:
  2009. dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
  2010. sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
  2011. (*rsp)->ring = NULL;
  2012. (*rsp)->dma = 0;
  2013. fail_rsp_ring:
  2014. kfree(*rsp);
  2015. fail_rsp:
  2016. dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
  2017. sizeof(request_t), (*req)->ring, (*req)->dma);
  2018. (*req)->ring = NULL;
  2019. (*req)->dma = 0;
  2020. fail_req_ring:
  2021. kfree(*req);
  2022. fail_req:
  2023. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  2024. ha->ct_sns, ha->ct_sns_dma);
  2025. ha->ct_sns = NULL;
  2026. ha->ct_sns_dma = 0;
  2027. fail_free_ms_iocb:
  2028. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  2029. ha->ms_iocb = NULL;
  2030. ha->ms_iocb_dma = 0;
  2031. fail_dma_pool:
  2032. dma_pool_destroy(ha->s_dma_pool);
  2033. ha->s_dma_pool = NULL;
  2034. fail_free_nvram:
  2035. kfree(ha->nvram);
  2036. ha->nvram = NULL;
  2037. fail_free_srb_mempool:
  2038. mempool_destroy(ha->srb_mempool);
  2039. ha->srb_mempool = NULL;
  2040. fail_free_gid_list:
  2041. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  2042. ha->gid_list_dma);
  2043. ha->gid_list = NULL;
  2044. ha->gid_list_dma = 0;
  2045. fail_free_init_cb:
  2046. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
  2047. ha->init_cb_dma);
  2048. ha->init_cb = NULL;
  2049. ha->init_cb_dma = 0;
  2050. fail:
  2051. DEBUG(printk("%s: Memory allocation failure\n", __func__));
  2052. return -ENOMEM;
  2053. }
  2054. /*
  2055. * qla2x00_mem_free
  2056. * Frees all adapter allocated memory.
  2057. *
  2058. * Input:
  2059. * ha = adapter block pointer.
  2060. */
  2061. static void
  2062. qla2x00_mem_free(struct qla_hw_data *ha)
  2063. {
  2064. if (ha->srb_mempool)
  2065. mempool_destroy(ha->srb_mempool);
  2066. if (ha->fce)
  2067. dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
  2068. ha->fce_dma);
  2069. if (ha->fw_dump) {
  2070. if (ha->eft)
  2071. dma_free_coherent(&ha->pdev->dev,
  2072. ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
  2073. vfree(ha->fw_dump);
  2074. }
  2075. if (ha->sns_cmd)
  2076. dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
  2077. ha->sns_cmd, ha->sns_cmd_dma);
  2078. if (ha->ct_sns)
  2079. dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
  2080. ha->ct_sns, ha->ct_sns_dma);
  2081. if (ha->sfp_data)
  2082. dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
  2083. if (ha->ms_iocb)
  2084. dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
  2085. if (ha->s_dma_pool)
  2086. dma_pool_destroy(ha->s_dma_pool);
  2087. if (ha->gid_list)
  2088. dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
  2089. ha->gid_list_dma);
  2090. if (ha->init_cb)
  2091. dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
  2092. ha->init_cb, ha->init_cb_dma);
  2093. vfree(ha->optrom_buffer);
  2094. kfree(ha->nvram);
  2095. kfree(ha->npiv_info);
  2096. ha->srb_mempool = NULL;
  2097. ha->eft = NULL;
  2098. ha->eft_dma = 0;
  2099. ha->sns_cmd = NULL;
  2100. ha->sns_cmd_dma = 0;
  2101. ha->ct_sns = NULL;
  2102. ha->ct_sns_dma = 0;
  2103. ha->ms_iocb = NULL;
  2104. ha->ms_iocb_dma = 0;
  2105. ha->init_cb = NULL;
  2106. ha->init_cb_dma = 0;
  2107. ha->s_dma_pool = NULL;
  2108. ha->gid_list = NULL;
  2109. ha->gid_list_dma = 0;
  2110. ha->fw_dump = NULL;
  2111. ha->fw_dumped = 0;
  2112. ha->fw_dump_reading = 0;
  2113. }
  2114. struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
  2115. struct qla_hw_data *ha)
  2116. {
  2117. struct Scsi_Host *host;
  2118. struct scsi_qla_host *vha = NULL;
  2119. host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
  2120. if (host == NULL) {
  2121. printk(KERN_WARNING
  2122. "qla2xxx: Couldn't allocate host from scsi layer!\n");
  2123. goto fail;
  2124. }
  2125. /* Clear our data area */
  2126. vha = shost_priv(host);
  2127. memset(vha, 0, sizeof(scsi_qla_host_t));
  2128. vha->host = host;
  2129. vha->host_no = host->host_no;
  2130. vha->hw = ha;
  2131. INIT_LIST_HEAD(&vha->vp_fcports);
  2132. INIT_LIST_HEAD(&vha->work_list);
  2133. INIT_LIST_HEAD(&vha->list);
  2134. sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
  2135. return vha;
  2136. fail:
  2137. return vha;
  2138. }
  2139. static struct qla_work_evt *
  2140. qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type,
  2141. int locked)
  2142. {
  2143. struct qla_work_evt *e;
  2144. e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
  2145. GFP_KERNEL);
  2146. if (!e)
  2147. return NULL;
  2148. INIT_LIST_HEAD(&e->list);
  2149. e->type = type;
  2150. e->flags = QLA_EVT_FLAG_FREE;
  2151. return e;
  2152. }
  2153. static int
  2154. qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e, int locked)
  2155. {
  2156. unsigned long uninitialized_var(flags);
  2157. struct qla_hw_data *ha = vha->hw;
  2158. if (!locked)
  2159. spin_lock_irqsave(&ha->hardware_lock, flags);
  2160. list_add_tail(&e->list, &vha->work_list);
  2161. qla2xxx_wake_dpc(vha);
  2162. if (!locked)
  2163. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2164. return QLA_SUCCESS;
  2165. }
  2166. int
  2167. qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
  2168. u32 data)
  2169. {
  2170. struct qla_work_evt *e;
  2171. e = qla2x00_alloc_work(vha, QLA_EVT_AEN, 1);
  2172. if (!e)
  2173. return QLA_FUNCTION_FAILED;
  2174. e->u.aen.code = code;
  2175. e->u.aen.data = data;
  2176. return qla2x00_post_work(vha, e, 1);
  2177. }
  2178. static void
  2179. qla2x00_do_work(struct scsi_qla_host *vha)
  2180. {
  2181. struct qla_work_evt *e;
  2182. struct qla_hw_data *ha = vha->hw;
  2183. spin_lock_irq(&ha->hardware_lock);
  2184. while (!list_empty(&vha->work_list)) {
  2185. e = list_entry(vha->work_list.next, struct qla_work_evt, list);
  2186. list_del_init(&e->list);
  2187. spin_unlock_irq(&ha->hardware_lock);
  2188. switch (e->type) {
  2189. case QLA_EVT_AEN:
  2190. fc_host_post_event(vha->host, fc_get_event_number(),
  2191. e->u.aen.code, e->u.aen.data);
  2192. break;
  2193. }
  2194. if (e->flags & QLA_EVT_FLAG_FREE)
  2195. kfree(e);
  2196. spin_lock_irq(&ha->hardware_lock);
  2197. }
  2198. spin_unlock_irq(&ha->hardware_lock);
  2199. }
  2200. /* Relogins all the fcports of a vport
  2201. * Context: dpc thread
  2202. */
  2203. void qla2x00_relogin(struct scsi_qla_host *vha)
  2204. {
  2205. fc_port_t *fcport;
  2206. uint8_t status;
  2207. uint16_t next_loopid = 0;
  2208. struct qla_hw_data *ha = vha->hw;
  2209. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2210. /*
  2211. * If the port is not ONLINE then try to login
  2212. * to it if we haven't run out of retries.
  2213. */
  2214. if (atomic_read(&fcport->state) !=
  2215. FCS_ONLINE && fcport->login_retry) {
  2216. if (fcport->flags & FCF_FABRIC_DEVICE) {
  2217. if (fcport->flags & FCF_TAPE_PRESENT)
  2218. ha->isp_ops->fabric_logout(vha,
  2219. fcport->loop_id,
  2220. fcport->d_id.b.domain,
  2221. fcport->d_id.b.area,
  2222. fcport->d_id.b.al_pa);
  2223. status = qla2x00_fabric_login(vha, fcport,
  2224. &next_loopid);
  2225. } else
  2226. status = qla2x00_local_device_login(vha,
  2227. fcport);
  2228. fcport->login_retry--;
  2229. if (status == QLA_SUCCESS) {
  2230. fcport->old_loop_id = fcport->loop_id;
  2231. DEBUG(printk("scsi(%ld): port login OK: logged "
  2232. "in ID 0x%x\n", vha->host_no, fcport->loop_id));
  2233. qla2x00_update_fcport(vha, fcport);
  2234. } else if (status == 1) {
  2235. set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
  2236. /* retry the login again */
  2237. DEBUG(printk("scsi(%ld): Retrying"
  2238. " %d login again loop_id 0x%x\n",
  2239. vha->host_no, fcport->login_retry,
  2240. fcport->loop_id));
  2241. } else {
  2242. fcport->login_retry = 0;
  2243. }
  2244. if (fcport->login_retry == 0 && status != QLA_SUCCESS)
  2245. fcport->loop_id = FC_NO_LOOP_ID;
  2246. }
  2247. if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
  2248. break;
  2249. }
  2250. }
  2251. /**************************************************************************
  2252. * qla2x00_do_dpc
  2253. * This kernel thread is a task that is schedule by the interrupt handler
  2254. * to perform the background processing for interrupts.
  2255. *
  2256. * Notes:
  2257. * This task always run in the context of a kernel thread. It
  2258. * is kick-off by the driver's detect code and starts up
  2259. * up one per adapter. It immediately goes to sleep and waits for
  2260. * some fibre event. When either the interrupt handler or
  2261. * the timer routine detects a event it will one of the task
  2262. * bits then wake us up.
  2263. **************************************************************************/
  2264. static int
  2265. qla2x00_do_dpc(void *data)
  2266. {
  2267. int rval;
  2268. scsi_qla_host_t *base_vha;
  2269. struct qla_hw_data *ha;
  2270. ha = (struct qla_hw_data *)data;
  2271. base_vha = pci_get_drvdata(ha->pdev);
  2272. set_user_nice(current, -20);
  2273. while (!kthread_should_stop()) {
  2274. DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
  2275. set_current_state(TASK_INTERRUPTIBLE);
  2276. schedule();
  2277. __set_current_state(TASK_RUNNING);
  2278. DEBUG3(printk("qla2x00: DPC handler waking up\n"));
  2279. /* Initialization not yet finished. Don't do anything yet. */
  2280. if (!base_vha->flags.init_done)
  2281. continue;
  2282. DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
  2283. ha->dpc_active = 1;
  2284. if (ha->flags.mbox_busy) {
  2285. ha->dpc_active = 0;
  2286. continue;
  2287. }
  2288. qla2x00_do_work(base_vha);
  2289. if (test_and_clear_bit(ISP_ABORT_NEEDED,
  2290. &base_vha->dpc_flags)) {
  2291. DEBUG(printk("scsi(%ld): dpc: sched "
  2292. "qla2x00_abort_isp ha = %p\n",
  2293. base_vha->host_no, ha));
  2294. if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
  2295. &base_vha->dpc_flags))) {
  2296. if (qla2x00_abort_isp(base_vha)) {
  2297. /* failed. retry later */
  2298. set_bit(ISP_ABORT_NEEDED,
  2299. &base_vha->dpc_flags);
  2300. }
  2301. clear_bit(ABORT_ISP_ACTIVE,
  2302. &base_vha->dpc_flags);
  2303. }
  2304. DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
  2305. base_vha->host_no));
  2306. }
  2307. if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
  2308. qla2x00_update_fcports(base_vha);
  2309. clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
  2310. }
  2311. if (test_and_clear_bit(RESET_MARKER_NEEDED,
  2312. &base_vha->dpc_flags) &&
  2313. (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
  2314. DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
  2315. base_vha->host_no));
  2316. qla2x00_rst_aen(base_vha);
  2317. clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
  2318. }
  2319. /* Retry each device up to login retry count */
  2320. if ((test_and_clear_bit(RELOGIN_NEEDED,
  2321. &base_vha->dpc_flags)) &&
  2322. !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
  2323. atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
  2324. DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
  2325. base_vha->host_no));
  2326. qla2x00_relogin(base_vha);
  2327. DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
  2328. base_vha->host_no));
  2329. }
  2330. if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
  2331. &base_vha->dpc_flags)) {
  2332. DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
  2333. base_vha->host_no));
  2334. if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
  2335. &base_vha->dpc_flags))) {
  2336. rval = qla2x00_loop_resync(base_vha);
  2337. clear_bit(LOOP_RESYNC_ACTIVE,
  2338. &base_vha->dpc_flags);
  2339. }
  2340. DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
  2341. base_vha->host_no));
  2342. }
  2343. if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
  2344. atomic_read(&base_vha->loop_state) == LOOP_READY) {
  2345. clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
  2346. qla2xxx_flash_npiv_conf(base_vha);
  2347. }
  2348. if (!ha->interrupts_on)
  2349. ha->isp_ops->enable_intrs(ha);
  2350. if (test_and_clear_bit(BEACON_BLINK_NEEDED,
  2351. &base_vha->dpc_flags))
  2352. ha->isp_ops->beacon_blink(base_vha);
  2353. qla2x00_do_dpc_all_vps(base_vha);
  2354. ha->dpc_active = 0;
  2355. } /* End of while(1) */
  2356. DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
  2357. /*
  2358. * Make sure that nobody tries to wake us up again.
  2359. */
  2360. ha->dpc_active = 0;
  2361. return 0;
  2362. }
  2363. void
  2364. qla2xxx_wake_dpc(struct scsi_qla_host *vha)
  2365. {
  2366. struct qla_hw_data *ha = vha->hw;
  2367. struct task_struct *t = ha->dpc_thread;
  2368. if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
  2369. wake_up_process(t);
  2370. }
  2371. /*
  2372. * qla2x00_rst_aen
  2373. * Processes asynchronous reset.
  2374. *
  2375. * Input:
  2376. * ha = adapter block pointer.
  2377. */
  2378. static void
  2379. qla2x00_rst_aen(scsi_qla_host_t *vha)
  2380. {
  2381. if (vha->flags.online && !vha->flags.reset_active &&
  2382. !atomic_read(&vha->loop_down_timer) &&
  2383. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
  2384. do {
  2385. clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
  2386. /*
  2387. * Issue marker command only when we are going to start
  2388. * the I/O.
  2389. */
  2390. vha->marker_needed = 1;
  2391. } while (!atomic_read(&vha->loop_down_timer) &&
  2392. (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
  2393. }
  2394. }
  2395. static void
  2396. qla2x00_sp_free_dma(srb_t *sp)
  2397. {
  2398. struct scsi_cmnd *cmd = sp->cmd;
  2399. if (sp->flags & SRB_DMA_VALID) {
  2400. scsi_dma_unmap(cmd);
  2401. sp->flags &= ~SRB_DMA_VALID;
  2402. }
  2403. CMD_SP(cmd) = NULL;
  2404. }
  2405. void
  2406. qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
  2407. {
  2408. struct scsi_cmnd *cmd = sp->cmd;
  2409. qla2x00_sp_free_dma(sp);
  2410. mempool_free(sp, ha->srb_mempool);
  2411. cmd->scsi_done(cmd);
  2412. }
  2413. /**************************************************************************
  2414. * qla2x00_timer
  2415. *
  2416. * Description:
  2417. * One second timer
  2418. *
  2419. * Context: Interrupt
  2420. ***************************************************************************/
  2421. void
  2422. qla2x00_timer(scsi_qla_host_t *vha)
  2423. {
  2424. unsigned long cpu_flags = 0;
  2425. fc_port_t *fcport;
  2426. int start_dpc = 0;
  2427. int index;
  2428. srb_t *sp;
  2429. int t;
  2430. struct qla_hw_data *ha = vha->hw;
  2431. struct req_que *req;
  2432. /*
  2433. * Ports - Port down timer.
  2434. *
  2435. * Whenever, a port is in the LOST state we start decrementing its port
  2436. * down timer every second until it reaches zero. Once it reaches zero
  2437. * the port it marked DEAD.
  2438. */
  2439. t = 0;
  2440. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  2441. if (fcport->port_type != FCT_TARGET)
  2442. continue;
  2443. if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
  2444. if (atomic_read(&fcport->port_down_timer) == 0)
  2445. continue;
  2446. if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
  2447. atomic_set(&fcport->state, FCS_DEVICE_DEAD);
  2448. DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
  2449. "%d remaining\n",
  2450. vha->host_no,
  2451. t, atomic_read(&fcport->port_down_timer)));
  2452. }
  2453. t++;
  2454. } /* End of for fcport */
  2455. /* Loop down handler. */
  2456. if (atomic_read(&vha->loop_down_timer) > 0 &&
  2457. !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
  2458. && vha->flags.online) {
  2459. if (atomic_read(&vha->loop_down_timer) ==
  2460. vha->loop_down_abort_time) {
  2461. DEBUG(printk("scsi(%ld): Loop Down - aborting the "
  2462. "queues before time expire\n",
  2463. vha->host_no));
  2464. if (!IS_QLA2100(ha) && vha->link_down_timeout)
  2465. atomic_set(&vha->loop_state, LOOP_DEAD);
  2466. /* Schedule an ISP abort to return any tape commands. */
  2467. /* NPIV - scan physical port only */
  2468. if (!vha->vp_idx) {
  2469. spin_lock_irqsave(&ha->hardware_lock,
  2470. cpu_flags);
  2471. req = ha->req_q_map[0];
  2472. for (index = 1;
  2473. index < MAX_OUTSTANDING_COMMANDS;
  2474. index++) {
  2475. fc_port_t *sfcp;
  2476. sp = req->outstanding_cmds[index];
  2477. if (!sp)
  2478. continue;
  2479. sfcp = sp->fcport;
  2480. if (!(sfcp->flags & FCF_TAPE_PRESENT))
  2481. continue;
  2482. set_bit(ISP_ABORT_NEEDED,
  2483. &vha->dpc_flags);
  2484. break;
  2485. }
  2486. spin_unlock_irqrestore(&ha->hardware_lock,
  2487. cpu_flags);
  2488. }
  2489. set_bit(ABORT_QUEUES_NEEDED, &vha->dpc_flags);
  2490. start_dpc++;
  2491. }
  2492. /* if the loop has been down for 4 minutes, reinit adapter */
  2493. if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
  2494. DEBUG(printk("scsi(%ld): Loop down exceed 4 mins - "
  2495. "restarting queues.\n",
  2496. vha->host_no));
  2497. set_bit(RESTART_QUEUES_NEEDED, &vha->dpc_flags);
  2498. start_dpc++;
  2499. if (!(vha->device_flags & DFLG_NO_CABLE) &&
  2500. !vha->vp_idx) {
  2501. DEBUG(printk("scsi(%ld): Loop down - "
  2502. "aborting ISP.\n",
  2503. vha->host_no));
  2504. qla_printk(KERN_WARNING, ha,
  2505. "Loop down - aborting ISP.\n");
  2506. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  2507. }
  2508. }
  2509. DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
  2510. vha->host_no,
  2511. atomic_read(&vha->loop_down_timer)));
  2512. }
  2513. /* Check if beacon LED needs to be blinked */
  2514. if (ha->beacon_blink_led == 1) {
  2515. set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
  2516. start_dpc++;
  2517. }
  2518. /* Process any deferred work. */
  2519. if (!list_empty(&vha->work_list))
  2520. start_dpc++;
  2521. /* Schedule the DPC routine if needed */
  2522. if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  2523. test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
  2524. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
  2525. start_dpc ||
  2526. test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
  2527. test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
  2528. test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
  2529. test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
  2530. qla2xxx_wake_dpc(vha);
  2531. qla2x00_restart_timer(vha, WATCH_INTERVAL);
  2532. }
  2533. /* Firmware interface routines. */
  2534. #define FW_BLOBS 7
  2535. #define FW_ISP21XX 0
  2536. #define FW_ISP22XX 1
  2537. #define FW_ISP2300 2
  2538. #define FW_ISP2322 3
  2539. #define FW_ISP24XX 4
  2540. #define FW_ISP25XX 5
  2541. #define FW_ISP81XX 6
  2542. #define FW_FILE_ISP21XX "ql2100_fw.bin"
  2543. #define FW_FILE_ISP22XX "ql2200_fw.bin"
  2544. #define FW_FILE_ISP2300 "ql2300_fw.bin"
  2545. #define FW_FILE_ISP2322 "ql2322_fw.bin"
  2546. #define FW_FILE_ISP24XX "ql2400_fw.bin"
  2547. #define FW_FILE_ISP25XX "ql2500_fw.bin"
  2548. #define FW_FILE_ISP81XX "ql8100_fw.bin"
  2549. static DEFINE_MUTEX(qla_fw_lock);
  2550. static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
  2551. { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
  2552. { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
  2553. { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
  2554. { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
  2555. { .name = FW_FILE_ISP24XX, },
  2556. { .name = FW_FILE_ISP25XX, },
  2557. { .name = FW_FILE_ISP81XX, },
  2558. };
  2559. struct fw_blob *
  2560. qla2x00_request_firmware(scsi_qla_host_t *vha)
  2561. {
  2562. struct qla_hw_data *ha = vha->hw;
  2563. struct fw_blob *blob;
  2564. blob = NULL;
  2565. if (IS_QLA2100(ha)) {
  2566. blob = &qla_fw_blobs[FW_ISP21XX];
  2567. } else if (IS_QLA2200(ha)) {
  2568. blob = &qla_fw_blobs[FW_ISP22XX];
  2569. } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
  2570. blob = &qla_fw_blobs[FW_ISP2300];
  2571. } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  2572. blob = &qla_fw_blobs[FW_ISP2322];
  2573. } else if (IS_QLA24XX_TYPE(ha)) {
  2574. blob = &qla_fw_blobs[FW_ISP24XX];
  2575. } else if (IS_QLA25XX(ha)) {
  2576. blob = &qla_fw_blobs[FW_ISP25XX];
  2577. } else if (IS_QLA81XX(ha)) {
  2578. blob = &qla_fw_blobs[FW_ISP81XX];
  2579. }
  2580. mutex_lock(&qla_fw_lock);
  2581. if (blob->fw)
  2582. goto out;
  2583. if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
  2584. DEBUG2(printk("scsi(%ld): Failed to load firmware image "
  2585. "(%s).\n", vha->host_no, blob->name));
  2586. blob->fw = NULL;
  2587. blob = NULL;
  2588. goto out;
  2589. }
  2590. out:
  2591. mutex_unlock(&qla_fw_lock);
  2592. return blob;
  2593. }
  2594. static void
  2595. qla2x00_release_firmware(void)
  2596. {
  2597. int idx;
  2598. mutex_lock(&qla_fw_lock);
  2599. for (idx = 0; idx < FW_BLOBS; idx++)
  2600. if (qla_fw_blobs[idx].fw)
  2601. release_firmware(qla_fw_blobs[idx].fw);
  2602. mutex_unlock(&qla_fw_lock);
  2603. }
  2604. static pci_ers_result_t
  2605. qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  2606. {
  2607. switch (state) {
  2608. case pci_channel_io_normal:
  2609. return PCI_ERS_RESULT_CAN_RECOVER;
  2610. case pci_channel_io_frozen:
  2611. pci_disable_device(pdev);
  2612. return PCI_ERS_RESULT_NEED_RESET;
  2613. case pci_channel_io_perm_failure:
  2614. qla2x00_remove_one(pdev);
  2615. return PCI_ERS_RESULT_DISCONNECT;
  2616. }
  2617. return PCI_ERS_RESULT_NEED_RESET;
  2618. }
  2619. static pci_ers_result_t
  2620. qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
  2621. {
  2622. int risc_paused = 0;
  2623. uint32_t stat;
  2624. unsigned long flags;
  2625. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  2626. struct qla_hw_data *ha = base_vha->hw;
  2627. struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
  2628. struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
  2629. spin_lock_irqsave(&ha->hardware_lock, flags);
  2630. if (IS_QLA2100(ha) || IS_QLA2200(ha)){
  2631. stat = RD_REG_DWORD(&reg->hccr);
  2632. if (stat & HCCR_RISC_PAUSE)
  2633. risc_paused = 1;
  2634. } else if (IS_QLA23XX(ha)) {
  2635. stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
  2636. if (stat & HSR_RISC_PAUSED)
  2637. risc_paused = 1;
  2638. } else if (IS_FWI2_CAPABLE(ha)) {
  2639. stat = RD_REG_DWORD(&reg24->host_status);
  2640. if (stat & HSRX_RISC_PAUSED)
  2641. risc_paused = 1;
  2642. }
  2643. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2644. if (risc_paused) {
  2645. qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
  2646. "Dumping firmware!\n");
  2647. ha->isp_ops->fw_dump(base_vha, 0);
  2648. return PCI_ERS_RESULT_NEED_RESET;
  2649. } else
  2650. return PCI_ERS_RESULT_RECOVERED;
  2651. }
  2652. static pci_ers_result_t
  2653. qla2xxx_pci_slot_reset(struct pci_dev *pdev)
  2654. {
  2655. pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
  2656. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  2657. struct qla_hw_data *ha = base_vha->hw;
  2658. int rc;
  2659. if (ha->mem_only)
  2660. rc = pci_enable_device_mem(pdev);
  2661. else
  2662. rc = pci_enable_device(pdev);
  2663. if (rc) {
  2664. qla_printk(KERN_WARNING, ha,
  2665. "Can't re-enable PCI device after reset.\n");
  2666. return ret;
  2667. }
  2668. pci_set_master(pdev);
  2669. if (ha->isp_ops->pci_config(base_vha))
  2670. return ret;
  2671. set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  2672. if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
  2673. ret = PCI_ERS_RESULT_RECOVERED;
  2674. clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
  2675. return ret;
  2676. }
  2677. static void
  2678. qla2xxx_pci_resume(struct pci_dev *pdev)
  2679. {
  2680. scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
  2681. struct qla_hw_data *ha = base_vha->hw;
  2682. int ret;
  2683. ret = qla2x00_wait_for_hba_online(base_vha);
  2684. if (ret != QLA_SUCCESS) {
  2685. qla_printk(KERN_ERR, ha,
  2686. "the device failed to resume I/O "
  2687. "from slot/link_reset");
  2688. }
  2689. pci_cleanup_aer_uncorrect_error_status(pdev);
  2690. }
  2691. static struct pci_error_handlers qla2xxx_err_handler = {
  2692. .error_detected = qla2xxx_pci_error_detected,
  2693. .mmio_enabled = qla2xxx_pci_mmio_enabled,
  2694. .slot_reset = qla2xxx_pci_slot_reset,
  2695. .resume = qla2xxx_pci_resume,
  2696. };
  2697. static struct pci_device_id qla2xxx_pci_tbl[] = {
  2698. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
  2699. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
  2700. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
  2701. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
  2702. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
  2703. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
  2704. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
  2705. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
  2706. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
  2707. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
  2708. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
  2709. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
  2710. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
  2711. { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
  2712. { 0 },
  2713. };
  2714. MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
  2715. static struct pci_driver qla2xxx_pci_driver = {
  2716. .name = QLA2XXX_DRIVER_NAME,
  2717. .driver = {
  2718. .owner = THIS_MODULE,
  2719. },
  2720. .id_table = qla2xxx_pci_tbl,
  2721. .probe = qla2x00_probe_one,
  2722. .remove = qla2x00_remove_one,
  2723. .err_handler = &qla2xxx_err_handler,
  2724. };
  2725. /**
  2726. * qla2x00_module_init - Module initialization.
  2727. **/
  2728. static int __init
  2729. qla2x00_module_init(void)
  2730. {
  2731. int ret = 0;
  2732. /* Allocate cache for SRBs. */
  2733. srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
  2734. SLAB_HWCACHE_ALIGN, NULL);
  2735. if (srb_cachep == NULL) {
  2736. printk(KERN_ERR
  2737. "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
  2738. return -ENOMEM;
  2739. }
  2740. /* Derive version string. */
  2741. strcpy(qla2x00_version_str, QLA2XXX_VERSION);
  2742. if (ql2xextended_error_logging)
  2743. strcat(qla2x00_version_str, "-debug");
  2744. qla2xxx_transport_template =
  2745. fc_attach_transport(&qla2xxx_transport_functions);
  2746. if (!qla2xxx_transport_template) {
  2747. kmem_cache_destroy(srb_cachep);
  2748. return -ENODEV;
  2749. }
  2750. qla2xxx_transport_vport_template =
  2751. fc_attach_transport(&qla2xxx_transport_vport_functions);
  2752. if (!qla2xxx_transport_vport_template) {
  2753. kmem_cache_destroy(srb_cachep);
  2754. fc_release_transport(qla2xxx_transport_template);
  2755. return -ENODEV;
  2756. }
  2757. printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
  2758. qla2x00_version_str);
  2759. ret = pci_register_driver(&qla2xxx_pci_driver);
  2760. if (ret) {
  2761. kmem_cache_destroy(srb_cachep);
  2762. fc_release_transport(qla2xxx_transport_template);
  2763. fc_release_transport(qla2xxx_transport_vport_template);
  2764. }
  2765. return ret;
  2766. }
  2767. /**
  2768. * qla2x00_module_exit - Module cleanup.
  2769. **/
  2770. static void __exit
  2771. qla2x00_module_exit(void)
  2772. {
  2773. pci_unregister_driver(&qla2xxx_pci_driver);
  2774. qla2x00_release_firmware();
  2775. kmem_cache_destroy(srb_cachep);
  2776. fc_release_transport(qla2xxx_transport_template);
  2777. fc_release_transport(qla2xxx_transport_vport_template);
  2778. }
  2779. module_init(qla2x00_module_init);
  2780. module_exit(qla2x00_module_exit);
  2781. MODULE_AUTHOR("QLogic Corporation");
  2782. MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
  2783. MODULE_LICENSE("GPL");
  2784. MODULE_VERSION(QLA2XXX_VERSION);
  2785. MODULE_FIRMWARE(FW_FILE_ISP21XX);
  2786. MODULE_FIRMWARE(FW_FILE_ISP22XX);
  2787. MODULE_FIRMWARE(FW_FILE_ISP2300);
  2788. MODULE_FIRMWARE(FW_FILE_ISP2322);
  2789. MODULE_FIRMWARE(FW_FILE_ISP24XX);
  2790. MODULE_FIRMWARE(FW_FILE_ISP25XX);
  2791. MODULE_FIRMWARE(FW_FILE_ISP81XX);