zfcp_fsf.c 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2008
  7. */
  8. #include "zfcp_ext.h"
  9. static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *);
  10. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *);
  11. static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *);
  12. static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *);
  13. static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *);
  14. static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *);
  15. static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *);
  16. static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *);
  17. static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *);
  18. static int zfcp_fsf_send_fcp_command_task_management_handler(
  19. struct zfcp_fsf_req *);
  20. static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *);
  21. static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *);
  22. static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *);
  23. static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *);
  24. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
  25. static inline int zfcp_fsf_req_sbal_check(
  26. unsigned long *, struct zfcp_qdio_queue *, int);
  27. static inline int zfcp_use_one_sbal(
  28. struct scatterlist *, int, struct scatterlist *, int);
  29. static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int);
  30. static int zfcp_fsf_req_send(struct zfcp_fsf_req *);
  31. static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *);
  32. static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *);
  33. static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
  34. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *, u8,
  35. struct fsf_link_down_info *);
  36. static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
  37. /* association between FSF command and FSF QTCB type */
  38. static u32 fsf_qtcb_type[] = {
  39. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  40. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  41. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  42. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  43. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  44. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  45. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  47. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  48. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  49. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  50. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  51. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  52. };
  53. static const char zfcp_act_subtable_type[5][8] = {
  54. "unknown", "OS", "WWPN", "DID", "LUN"
  55. };
  56. static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
  57. {
  58. u16 subtable = (table & 0xffff0000) >> 16;
  59. u16 rule = table & 0xffff;
  60. if (subtable > 0 &&
  61. subtable < ARRAY_SIZE(zfcp_act_subtable_type)) {
  62. dev_warn(&adapter->ccw_device->dev,
  63. "Access denied in subtable %s, rule %d.\n",
  64. zfcp_act_subtable_type[subtable], rule);
  65. }
  66. }
  67. static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
  68. struct zfcp_port *port)
  69. {
  70. struct fsf_qtcb_header *header = &req->qtcb->header;
  71. dev_warn(&req->adapter->ccw_device->dev,
  72. "Access denied, cannot send command to port 0x%016Lx.\n",
  73. port->wwpn);
  74. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  75. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  76. zfcp_erp_port_access_denied(port, 55, req);
  77. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  78. }
  79. static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
  80. struct zfcp_unit *unit)
  81. {
  82. struct fsf_qtcb_header *header = &req->qtcb->header;
  83. dev_warn(&req->adapter->ccw_device->dev,
  84. "Access denied for unit 0x%016Lx on port 0x%016Lx.\n",
  85. unit->fcp_lun, unit->port->wwpn);
  86. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  87. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  88. zfcp_erp_unit_access_denied(unit, 59, req);
  89. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  90. }
  91. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  92. {
  93. dev_err(&req->adapter->ccw_device->dev,
  94. "Required FC class not supported by adapter, "
  95. "shutting down adapter.\n");
  96. zfcp_erp_adapter_shutdown(req->adapter, 0, 123, req);
  97. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  98. }
  99. /****************************************************************/
  100. /*************** FSF related Functions *************************/
  101. /****************************************************************/
  102. /*
  103. * function: zfcp_fsf_req_alloc
  104. *
  105. * purpose: Obtains an fsf_req and potentially a qtcb (for all but
  106. * unsolicited requests) via helper functions
  107. * Does some initial fsf request set-up.
  108. *
  109. * returns: pointer to allocated fsf_req if successfull
  110. * NULL otherwise
  111. *
  112. * locks: none
  113. *
  114. */
  115. static struct zfcp_fsf_req *
  116. zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
  117. {
  118. size_t size;
  119. void *ptr;
  120. struct zfcp_fsf_req *fsf_req = NULL;
  121. if (req_flags & ZFCP_REQ_NO_QTCB)
  122. size = sizeof(struct zfcp_fsf_req);
  123. else
  124. size = sizeof(struct zfcp_fsf_req_qtcb);
  125. if (likely(pool))
  126. ptr = mempool_alloc(pool, GFP_ATOMIC);
  127. else {
  128. if (req_flags & ZFCP_REQ_NO_QTCB)
  129. ptr = kmalloc(size, GFP_ATOMIC);
  130. else
  131. ptr = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
  132. GFP_ATOMIC);
  133. }
  134. if (unlikely(!ptr))
  135. goto out;
  136. memset(ptr, 0, size);
  137. if (req_flags & ZFCP_REQ_NO_QTCB) {
  138. fsf_req = (struct zfcp_fsf_req *) ptr;
  139. } else {
  140. fsf_req = &((struct zfcp_fsf_req_qtcb *) ptr)->fsf_req;
  141. fsf_req->qtcb = &((struct zfcp_fsf_req_qtcb *) ptr)->qtcb;
  142. }
  143. fsf_req->pool = pool;
  144. out:
  145. return fsf_req;
  146. }
  147. /*
  148. * function: zfcp_fsf_req_free
  149. *
  150. * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
  151. * returns it into the pool via helper functions.
  152. *
  153. * returns: sod all
  154. *
  155. * locks: none
  156. */
  157. void
  158. zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
  159. {
  160. if (likely(fsf_req->pool)) {
  161. mempool_free(fsf_req, fsf_req->pool);
  162. return;
  163. }
  164. if (fsf_req->qtcb) {
  165. kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, fsf_req);
  166. return;
  167. }
  168. kfree(fsf_req);
  169. }
  170. /*
  171. * Never ever call this without shutting down the adapter first.
  172. * Otherwise the adapter would continue using and corrupting s390 storage.
  173. * Included BUG_ON() call to ensure this is done.
  174. * ERP is supposed to be the only user of this function.
  175. */
  176. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  177. {
  178. struct zfcp_fsf_req *fsf_req, *tmp;
  179. unsigned long flags;
  180. LIST_HEAD(remove_queue);
  181. unsigned int i;
  182. BUG_ON(atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status));
  183. spin_lock_irqsave(&adapter->req_list_lock, flags);
  184. for (i = 0; i < REQUEST_LIST_SIZE; i++)
  185. list_splice_init(&adapter->req_list[i], &remove_queue);
  186. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  187. list_for_each_entry_safe(fsf_req, tmp, &remove_queue, list) {
  188. list_del(&fsf_req->list);
  189. fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  190. zfcp_fsf_req_complete(fsf_req);
  191. }
  192. }
  193. /*
  194. * function: zfcp_fsf_req_complete
  195. *
  196. * purpose: Updates active counts and timers for openfcp-reqs
  197. * May cleanup request after req_eval returns
  198. *
  199. * returns: 0 - success
  200. * !0 - failure
  201. *
  202. * context:
  203. */
  204. int
  205. zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
  206. {
  207. int retval = 0;
  208. int cleanup;
  209. if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  210. /*
  211. * Note: all cleanup handling is done in the callchain of
  212. * the function call-chain below.
  213. */
  214. zfcp_fsf_status_read_handler(fsf_req);
  215. goto out;
  216. } else {
  217. del_timer(&fsf_req->timer);
  218. zfcp_fsf_protstatus_eval(fsf_req);
  219. }
  220. /*
  221. * fsf_req may be deleted due to waking up functions, so
  222. * cleanup is saved here and used later
  223. */
  224. if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  225. cleanup = 1;
  226. else
  227. cleanup = 0;
  228. fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
  229. /* cleanup request if requested by initiator */
  230. if (likely(cleanup)) {
  231. /*
  232. * lock must not be held here since it will be
  233. * grabed by the called routine, too
  234. */
  235. zfcp_fsf_req_free(fsf_req);
  236. } else {
  237. /* notify initiator waiting for the requests completion */
  238. /*
  239. * FIXME: Race! We must not access fsf_req here as it might have been
  240. * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
  241. * flag. It's an improbable case. But, we have the same paranoia for
  242. * the cleanup flag already.
  243. * Might better be handled using complete()?
  244. * (setting the flag and doing wakeup ought to be atomic
  245. * with regard to checking the flag as long as waitqueue is
  246. * part of the to be released structure)
  247. */
  248. wake_up(&fsf_req->completion_wq);
  249. }
  250. out:
  251. return retval;
  252. }
  253. /*
  254. * function: zfcp_fsf_protstatus_eval
  255. *
  256. * purpose: evaluates the QTCB of the finished FSF request
  257. * and initiates appropriate actions
  258. * (usually calling FSF command specific handlers)
  259. *
  260. * returns:
  261. *
  262. * context:
  263. *
  264. * locks:
  265. */
  266. static int
  267. zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
  268. {
  269. int retval = 0;
  270. struct zfcp_adapter *adapter = fsf_req->adapter;
  271. struct fsf_qtcb *qtcb = fsf_req->qtcb;
  272. union fsf_prot_status_qual *prot_status_qual =
  273. &qtcb->prefix.prot_status_qual;
  274. zfcp_hba_dbf_event_fsf_response(fsf_req);
  275. if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  276. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  277. ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
  278. goto skip_protstatus;
  279. }
  280. /* evaluate FSF Protocol Status */
  281. switch (qtcb->prefix.prot_status) {
  282. case FSF_PROT_GOOD:
  283. case FSF_PROT_FSF_STATUS_PRESENTED:
  284. break;
  285. case FSF_PROT_QTCB_VERSION_ERROR:
  286. dev_err(&adapter->ccw_device->dev,
  287. "The QTCB version requested by zfcp (0x%x) is not "
  288. "supported by the FCP adapter (lowest supported 0x%x, "
  289. "highest supported 0x%x).\n",
  290. ZFCP_QTCB_VERSION, prot_status_qual->word[0],
  291. prot_status_qual->word[1]);
  292. zfcp_erp_adapter_shutdown(adapter, 0, 117, fsf_req);
  293. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  294. break;
  295. case FSF_PROT_SEQ_NUMB_ERROR:
  296. zfcp_erp_adapter_reopen(adapter, 0, 98, fsf_req);
  297. fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
  298. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  299. break;
  300. case FSF_PROT_UNSUPP_QTCB_TYPE:
  301. dev_err(&adapter->ccw_device->dev,
  302. "Packet header type used by the device driver is "
  303. "incompatible with that used on the adapter.\n");
  304. zfcp_erp_adapter_shutdown(adapter, 0, 118, fsf_req);
  305. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  306. break;
  307. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  308. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  309. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  310. &(adapter->status));
  311. break;
  312. case FSF_PROT_DUPLICATE_REQUEST_ID:
  313. dev_err(&adapter->ccw_device->dev,
  314. "The request identifier 0x%Lx is ambiguous.\n",
  315. (unsigned long long)qtcb->bottom.support.req_handle);
  316. zfcp_erp_adapter_shutdown(adapter, 0, 78, fsf_req);
  317. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  318. break;
  319. case FSF_PROT_LINK_DOWN:
  320. zfcp_fsf_link_down_info_eval(fsf_req, 37,
  321. &prot_status_qual->link_down_info);
  322. /* FIXME: reopening adapter now? better wait for link up */
  323. zfcp_erp_adapter_reopen(adapter, 0, 79, fsf_req);
  324. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  325. break;
  326. case FSF_PROT_REEST_QUEUE:
  327. /* All ports should be marked as ready to run again */
  328. zfcp_erp_modify_adapter_status(adapter, 28, NULL,
  329. ZFCP_STATUS_COMMON_RUNNING,
  330. ZFCP_SET);
  331. zfcp_erp_adapter_reopen(adapter,
  332. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
  333. | ZFCP_STATUS_COMMON_ERP_FAILED,
  334. 99, fsf_req);
  335. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  336. break;
  337. case FSF_PROT_ERROR_STATE:
  338. zfcp_erp_adapter_reopen(adapter, 0, 100, fsf_req);
  339. fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
  340. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  341. break;
  342. default:
  343. dev_err(&adapter->ccw_device->dev,
  344. "Transfer protocol status information"
  345. "provided by the adapter (0x%x) "
  346. "is not compatible with the device driver.\n",
  347. qtcb->prefix.prot_status);
  348. zfcp_erp_adapter_shutdown(adapter, 0, 119, fsf_req);
  349. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  350. }
  351. skip_protstatus:
  352. /*
  353. * always call specific handlers to give them a chance to do
  354. * something meaningful even in error cases
  355. */
  356. zfcp_fsf_fsfstatus_eval(fsf_req);
  357. return retval;
  358. }
  359. /*
  360. * function: zfcp_fsf_fsfstatus_eval
  361. *
  362. * purpose: evaluates FSF status of completed FSF request
  363. * and acts accordingly
  364. *
  365. * returns:
  366. */
  367. static int
  368. zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
  369. {
  370. int retval = 0;
  371. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  372. goto skip_fsfstatus;
  373. }
  374. /* evaluate FSF Status */
  375. switch (fsf_req->qtcb->header.fsf_status) {
  376. case FSF_UNKNOWN_COMMAND:
  377. dev_err(&fsf_req->adapter->ccw_device->dev,
  378. "Command issued by the device driver (0x%x) is "
  379. "not known by the adapter.\n",
  380. fsf_req->qtcb->header.fsf_command);
  381. zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 120, fsf_req);
  382. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  383. break;
  384. case FSF_ADAPTER_STATUS_AVAILABLE:
  385. zfcp_fsf_fsfstatus_qual_eval(fsf_req);
  386. break;
  387. }
  388. skip_fsfstatus:
  389. /*
  390. * always call specific handlers to give them a chance to do
  391. * something meaningful even in error cases
  392. */
  393. zfcp_fsf_req_dispatch(fsf_req);
  394. return retval;
  395. }
  396. /*
  397. * function: zfcp_fsf_fsfstatus_qual_eval
  398. *
  399. * purpose: evaluates FSF status-qualifier of completed FSF request
  400. * and acts accordingly
  401. *
  402. * returns:
  403. */
  404. static int
  405. zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
  406. {
  407. int retval = 0;
  408. switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
  409. case FSF_SQ_FCP_RSP_AVAILABLE:
  410. break;
  411. case FSF_SQ_RETRY_IF_POSSIBLE:
  412. /* The SCSI-stack may now issue retries or escalate */
  413. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  414. break;
  415. case FSF_SQ_COMMAND_ABORTED:
  416. /* Carry the aborted state on to upper layer */
  417. fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
  418. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  419. break;
  420. case FSF_SQ_NO_RECOM:
  421. dev_err(&fsf_req->adapter->ccw_device->dev,
  422. "No recommendation could be given for a "
  423. "problem on the adapter.\n");
  424. zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 121, fsf_req);
  425. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  426. break;
  427. case FSF_SQ_ULP_PROGRAMMING_ERROR:
  428. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  429. break;
  430. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  431. case FSF_SQ_NO_RETRY_POSSIBLE:
  432. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  433. /* dealt with in the respective functions */
  434. break;
  435. default:
  436. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  437. break;
  438. }
  439. return retval;
  440. }
  441. /**
  442. * zfcp_fsf_link_down_info_eval - evaluate link down information block
  443. */
  444. static void
  445. zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *fsf_req, u8 id,
  446. struct fsf_link_down_info *link_down)
  447. {
  448. struct zfcp_adapter *adapter = fsf_req->adapter;
  449. if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
  450. &adapter->status))
  451. return;
  452. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  453. if (link_down == NULL)
  454. goto out;
  455. switch (link_down->error_code) {
  456. case FSF_PSQ_LINK_NO_LIGHT:
  457. dev_warn(&fsf_req->adapter->ccw_device->dev,
  458. "The local link is down: "
  459. "no light detected.\n");
  460. break;
  461. case FSF_PSQ_LINK_WRAP_PLUG:
  462. dev_warn(&fsf_req->adapter->ccw_device->dev,
  463. "The local link is down: "
  464. "wrap plug detected.\n");
  465. break;
  466. case FSF_PSQ_LINK_NO_FCP:
  467. dev_warn(&fsf_req->adapter->ccw_device->dev,
  468. "The local link is down: "
  469. "adjacent node on link does not support FCP.\n");
  470. break;
  471. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  472. dev_warn(&fsf_req->adapter->ccw_device->dev,
  473. "The local link is down: "
  474. "firmware update in progress.\n");
  475. break;
  476. case FSF_PSQ_LINK_INVALID_WWPN:
  477. dev_warn(&fsf_req->adapter->ccw_device->dev,
  478. "The local link is down: "
  479. "duplicate or invalid WWPN detected.\n");
  480. break;
  481. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  482. dev_warn(&fsf_req->adapter->ccw_device->dev,
  483. "The local link is down: "
  484. "no support for NPIV by Fabric.\n");
  485. break;
  486. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  487. dev_warn(&fsf_req->adapter->ccw_device->dev,
  488. "The local link is down: "
  489. "out of resource in FCP daughtercard.\n");
  490. break;
  491. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  492. dev_warn(&fsf_req->adapter->ccw_device->dev,
  493. "The local link is down: "
  494. "out of resource in Fabric.\n");
  495. break;
  496. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  497. dev_warn(&fsf_req->adapter->ccw_device->dev,
  498. "The local link is down: "
  499. "unable to login to Fabric.\n");
  500. break;
  501. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  502. dev_warn(&fsf_req->adapter->ccw_device->dev,
  503. "WWPN assignment file corrupted on adapter.\n");
  504. break;
  505. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  506. dev_warn(&fsf_req->adapter->ccw_device->dev,
  507. "Mode table corrupted on adapter.\n");
  508. break;
  509. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  510. dev_warn(&fsf_req->adapter->ccw_device->dev,
  511. "No WWPN for assignment table on adapter.\n");
  512. break;
  513. default:
  514. dev_warn(&fsf_req->adapter->ccw_device->dev,
  515. "The local link to adapter is down.\n");
  516. }
  517. out:
  518. zfcp_erp_adapter_failed(adapter, id, fsf_req);
  519. }
  520. /*
  521. * function: zfcp_fsf_req_dispatch
  522. *
  523. * purpose: calls the appropriate command specific handler
  524. *
  525. * returns:
  526. */
  527. static int
  528. zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
  529. {
  530. struct zfcp_erp_action *erp_action = fsf_req->erp_action;
  531. int retval = 0;
  532. switch (fsf_req->fsf_command) {
  533. case FSF_QTCB_FCP_CMND:
  534. zfcp_fsf_send_fcp_command_handler(fsf_req);
  535. break;
  536. case FSF_QTCB_ABORT_FCP_CMND:
  537. zfcp_fsf_abort_fcp_command_handler(fsf_req);
  538. break;
  539. case FSF_QTCB_SEND_GENERIC:
  540. zfcp_fsf_send_ct_handler(fsf_req);
  541. break;
  542. case FSF_QTCB_OPEN_PORT_WITH_DID:
  543. zfcp_fsf_open_port_handler(fsf_req);
  544. break;
  545. case FSF_QTCB_OPEN_LUN:
  546. zfcp_fsf_open_unit_handler(fsf_req);
  547. break;
  548. case FSF_QTCB_CLOSE_LUN:
  549. zfcp_fsf_close_unit_handler(fsf_req);
  550. break;
  551. case FSF_QTCB_CLOSE_PORT:
  552. zfcp_fsf_close_port_handler(fsf_req);
  553. break;
  554. case FSF_QTCB_CLOSE_PHYSICAL_PORT:
  555. zfcp_fsf_close_physical_port_handler(fsf_req);
  556. break;
  557. case FSF_QTCB_EXCHANGE_CONFIG_DATA:
  558. zfcp_fsf_exchange_config_data_handler(fsf_req);
  559. break;
  560. case FSF_QTCB_EXCHANGE_PORT_DATA:
  561. zfcp_fsf_exchange_port_data_handler(fsf_req);
  562. break;
  563. case FSF_QTCB_SEND_ELS:
  564. zfcp_fsf_send_els_handler(fsf_req);
  565. break;
  566. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  567. zfcp_fsf_control_file_handler(fsf_req);
  568. break;
  569. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  570. zfcp_fsf_control_file_handler(fsf_req);
  571. break;
  572. }
  573. if (!erp_action)
  574. return retval;
  575. zfcp_erp_async_handler(erp_action, 0);
  576. return retval;
  577. }
  578. /*
  579. * function: zfcp_fsf_status_read
  580. *
  581. * purpose: initiates a Status Read command at the specified adapter
  582. *
  583. * returns:
  584. */
  585. int
  586. zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
  587. {
  588. struct zfcp_fsf_req *fsf_req;
  589. struct fsf_status_read_buffer *status_buffer;
  590. unsigned long lock_flags;
  591. volatile struct qdio_buffer_element *sbale;
  592. int retval;
  593. /* setup new FSF request */
  594. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
  595. req_flags | ZFCP_REQ_NO_QTCB,
  596. adapter->pool.fsf_req_status_read,
  597. &lock_flags, &fsf_req);
  598. if (retval < 0)
  599. goto failed_req_create;
  600. sbale = zfcp_qdio_sbale_req(fsf_req);
  601. sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
  602. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  603. fsf_req->sbale_curr = 2;
  604. retval = -ENOMEM;
  605. status_buffer =
  606. mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
  607. if (!status_buffer)
  608. goto failed_buf;
  609. memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
  610. fsf_req->data = (unsigned long) status_buffer;
  611. /* insert pointer to respective buffer */
  612. sbale = zfcp_qdio_sbale_curr(fsf_req);
  613. sbale->addr = (void *) status_buffer;
  614. sbale->length = sizeof(struct fsf_status_read_buffer);
  615. retval = zfcp_fsf_req_send(fsf_req);
  616. if (retval)
  617. goto failed_req_send;
  618. goto out;
  619. failed_req_send:
  620. mempool_free(status_buffer, adapter->pool.data_status_read);
  621. failed_buf:
  622. zfcp_fsf_req_free(fsf_req);
  623. failed_req_create:
  624. zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
  625. out:
  626. write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
  627. return retval;
  628. }
  629. static int
  630. zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
  631. {
  632. struct fsf_status_read_buffer *status_buffer;
  633. struct zfcp_adapter *adapter;
  634. struct zfcp_port *port;
  635. unsigned long flags;
  636. status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
  637. adapter = fsf_req->adapter;
  638. read_lock_irqsave(&zfcp_data.config_lock, flags);
  639. list_for_each_entry(port, &adapter->port_list_head, list)
  640. if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
  641. break;
  642. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  643. if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK)))
  644. goto out;
  645. switch (status_buffer->status_subtype) {
  646. case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
  647. zfcp_erp_port_reopen(port, 0, 101, fsf_req);
  648. break;
  649. case FSF_STATUS_READ_SUB_ERROR_PORT:
  650. zfcp_erp_port_shutdown(port, 0, 122, fsf_req);
  651. break;
  652. }
  653. out:
  654. return 0;
  655. }
  656. static void zfcp_fsf_bit_error_threshold(struct zfcp_fsf_req *req)
  657. {
  658. struct zfcp_adapter *adapter = req->adapter;
  659. struct fsf_status_read_buffer *buf =
  660. (struct fsf_status_read_buffer *) req->data;
  661. struct fsf_bit_error_payload *err =
  662. (struct fsf_bit_error_payload *) buf->payload;
  663. dev_warn(&adapter->ccw_device->dev,
  664. "Warning: bit error threshold data "
  665. "received for the adapter: "
  666. "link failures = %i, loss of sync errors = %i, "
  667. "loss of signal errors = %i, "
  668. "primitive sequence errors = %i, "
  669. "invalid transmission word errors = %i, "
  670. "CRC errors = %i).\n",
  671. err->link_failure_error_count,
  672. err->loss_of_sync_error_count,
  673. err->loss_of_signal_error_count,
  674. err->primitive_sequence_error_count,
  675. err->invalid_transmission_word_error_count,
  676. err->crc_error_count);
  677. dev_warn(&adapter->ccw_device->dev,
  678. "Additional bit error threshold data of the adapter: "
  679. "primitive sequence event time-outs = %i, "
  680. "elastic buffer overrun errors = %i, "
  681. "advertised receive buffer-to-buffer credit = %i, "
  682. "current receice buffer-to-buffer credit = %i, "
  683. "advertised transmit buffer-to-buffer credit = %i, "
  684. "current transmit buffer-to-buffer credit = %i).\n",
  685. err->primitive_sequence_event_timeout_count,
  686. err->elastic_buffer_overrun_error_count,
  687. err->advertised_receive_b2b_credit,
  688. err->current_receive_b2b_credit,
  689. err->advertised_transmit_b2b_credit,
  690. err->current_transmit_b2b_credit);
  691. }
  692. /*
  693. * function: zfcp_fsf_status_read_handler
  694. *
  695. * purpose: is called for finished Open Port command
  696. *
  697. * returns:
  698. */
  699. static int
  700. zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
  701. {
  702. int retval = 0;
  703. struct zfcp_adapter *adapter = fsf_req->adapter;
  704. struct fsf_status_read_buffer *status_buffer =
  705. (struct fsf_status_read_buffer *) fsf_req->data;
  706. if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  707. zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
  708. mempool_free(status_buffer, adapter->pool.data_status_read);
  709. zfcp_fsf_req_free(fsf_req);
  710. goto out;
  711. }
  712. zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
  713. switch (status_buffer->status_type) {
  714. case FSF_STATUS_READ_PORT_CLOSED:
  715. zfcp_fsf_status_read_port_closed(fsf_req);
  716. break;
  717. case FSF_STATUS_READ_INCOMING_ELS:
  718. zfcp_fc_incoming_els(fsf_req);
  719. break;
  720. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  721. break;
  722. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  723. zfcp_fsf_bit_error_threshold(fsf_req);
  724. break;
  725. case FSF_STATUS_READ_LINK_DOWN:
  726. switch (status_buffer->status_subtype) {
  727. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  728. dev_warn(&adapter->ccw_device->dev,
  729. "Physical link is down.\n");
  730. zfcp_fsf_link_down_info_eval(fsf_req, 38,
  731. (struct fsf_link_down_info *)
  732. &status_buffer->payload);
  733. break;
  734. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  735. dev_warn(&adapter->ccw_device->dev,
  736. "Local link is down "
  737. "due to failed FDISC login.\n");
  738. zfcp_fsf_link_down_info_eval(fsf_req, 39,
  739. (struct fsf_link_down_info *)
  740. &status_buffer->payload);
  741. break;
  742. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  743. dev_warn(&adapter->ccw_device->dev,
  744. "Local link is down "
  745. "due to firmware update on adapter.\n");
  746. zfcp_fsf_link_down_info_eval(fsf_req, 40, NULL);
  747. break;
  748. default:
  749. dev_warn(&adapter->ccw_device->dev,
  750. "Local link is down.\n");
  751. zfcp_fsf_link_down_info_eval(fsf_req, 41, NULL);
  752. };
  753. break;
  754. case FSF_STATUS_READ_LINK_UP:
  755. dev_info(&adapter->ccw_device->dev,
  756. "Local link was replugged.\n");
  757. /* All ports should be marked as ready to run again */
  758. zfcp_erp_modify_adapter_status(adapter, 30, NULL,
  759. ZFCP_STATUS_COMMON_RUNNING,
  760. ZFCP_SET);
  761. zfcp_erp_adapter_reopen(adapter,
  762. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
  763. | ZFCP_STATUS_COMMON_ERP_FAILED,
  764. 102, fsf_req);
  765. break;
  766. case FSF_STATUS_READ_NOTIFICATION_LOST:
  767. if (status_buffer->status_subtype &
  768. FSF_STATUS_READ_SUB_ACT_UPDATED)
  769. zfcp_erp_adapter_access_changed(adapter, 135, fsf_req);
  770. if (status_buffer->status_subtype &
  771. FSF_STATUS_READ_SUB_INCOMING_ELS)
  772. schedule_work(&adapter->scan_work);
  773. break;
  774. case FSF_STATUS_READ_CFDC_UPDATED:
  775. zfcp_erp_adapter_access_changed(adapter, 136, fsf_req);
  776. break;
  777. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  778. adapter->adapter_features = *(u32*) status_buffer->payload;
  779. break;
  780. }
  781. mempool_free(status_buffer, adapter->pool.data_status_read);
  782. zfcp_fsf_req_free(fsf_req);
  783. /*
  784. * recycle buffer and start new request repeat until outbound
  785. * queue is empty or adapter shutdown is requested
  786. */
  787. /*
  788. * FIXME(qdio):
  789. * we may wait in the req_create for 5s during shutdown, so
  790. * qdio_cleanup will have to wait at least that long before returning
  791. * with failure to allow us a proper cleanup under all circumstances
  792. */
  793. /*
  794. * FIXME:
  795. * allocation failure possible? (Is this code needed?)
  796. */
  797. atomic_inc(&adapter->stat_miss);
  798. schedule_work(&adapter->stat_work);
  799. out:
  800. return retval;
  801. }
  802. /*
  803. * function: zfcp_fsf_abort_fcp_command
  804. *
  805. * purpose: tells FSF to abort a running SCSI command
  806. *
  807. * returns: address of initiated FSF request
  808. * NULL - request could not be initiated
  809. *
  810. * FIXME(design): should be watched by a timeout !!!
  811. * FIXME(design) shouldn't this be modified to return an int
  812. * also...don't know how though
  813. */
  814. struct zfcp_fsf_req *
  815. zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  816. struct zfcp_adapter *adapter,
  817. struct zfcp_unit *unit, int req_flags)
  818. {
  819. volatile struct qdio_buffer_element *sbale;
  820. struct zfcp_fsf_req *fsf_req = NULL;
  821. unsigned long lock_flags;
  822. int retval = 0;
  823. /* setup new FSF request */
  824. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
  825. req_flags, adapter->pool.fsf_req_abort,
  826. &lock_flags, &fsf_req);
  827. if (retval < 0)
  828. goto out;
  829. if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
  830. &unit->status)))
  831. goto unit_blocked;
  832. sbale = zfcp_qdio_sbale_req(fsf_req);
  833. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  834. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  835. fsf_req->data = (unsigned long) unit;
  836. /* set handles of unit and its parent port in QTCB */
  837. fsf_req->qtcb->header.lun_handle = unit->handle;
  838. fsf_req->qtcb->header.port_handle = unit->port->handle;
  839. /* set handle of request which should be aborted */
  840. fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  841. zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
  842. retval = zfcp_fsf_req_send(fsf_req);
  843. if (!retval)
  844. goto out;
  845. unit_blocked:
  846. zfcp_fsf_req_free(fsf_req);
  847. fsf_req = NULL;
  848. out:
  849. write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
  850. return fsf_req;
  851. }
  852. /*
  853. * function: zfcp_fsf_abort_fcp_command_handler
  854. *
  855. * purpose: is called for finished Abort FCP Command request
  856. *
  857. * returns:
  858. */
  859. static int
  860. zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
  861. {
  862. int retval = -EINVAL;
  863. struct zfcp_unit *unit;
  864. union fsf_status_qual *fsf_stat_qual =
  865. &new_fsf_req->qtcb->header.fsf_status_qual;
  866. if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  867. /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
  868. goto skip_fsfstatus;
  869. }
  870. unit = (struct zfcp_unit *) new_fsf_req->data;
  871. /* evaluate FSF status in QTCB */
  872. switch (new_fsf_req->qtcb->header.fsf_status) {
  873. case FSF_PORT_HANDLE_NOT_VALID:
  874. if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
  875. /*
  876. * In this case a command that was sent prior to a port
  877. * reopen was aborted (handles are different). This is
  878. * fine.
  879. */
  880. } else {
  881. /* Let's hope this sorts out the mess */
  882. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
  883. new_fsf_req);
  884. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  885. }
  886. break;
  887. case FSF_LUN_HANDLE_NOT_VALID:
  888. if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
  889. /*
  890. * In this case a command that was sent prior to a unit
  891. * reopen was aborted (handles are different).
  892. * This is fine.
  893. */
  894. } else {
  895. /* Let's hope this sorts out the mess */
  896. zfcp_erp_port_reopen(unit->port, 0, 105, new_fsf_req);
  897. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  898. }
  899. break;
  900. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  901. retval = 0;
  902. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  903. break;
  904. case FSF_PORT_BOXED:
  905. zfcp_erp_port_boxed(unit->port, 47, new_fsf_req);
  906. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
  907. | ZFCP_STATUS_FSFREQ_RETRY;
  908. break;
  909. case FSF_LUN_BOXED:
  910. zfcp_erp_unit_boxed(unit, 48, new_fsf_req);
  911. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
  912. | ZFCP_STATUS_FSFREQ_RETRY;
  913. break;
  914. case FSF_ADAPTER_STATUS_AVAILABLE:
  915. switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
  916. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  917. zfcp_test_link(unit->port);
  918. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  919. break;
  920. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  921. /* SCSI stack will escalate */
  922. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  923. break;
  924. }
  925. break;
  926. case FSF_GOOD:
  927. retval = 0;
  928. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  929. break;
  930. }
  931. skip_fsfstatus:
  932. return retval;
  933. }
  934. /**
  935. * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
  936. * one SBALE
  937. * Two scatter-gather lists are passed, one for the reqeust and one for the
  938. * response.
  939. */
  940. static inline int
  941. zfcp_use_one_sbal(struct scatterlist *req, int req_count,
  942. struct scatterlist *resp, int resp_count)
  943. {
  944. return ((req_count == 1) &&
  945. (resp_count == 1) &&
  946. (((unsigned long) zfcp_sg_to_address(&req[0]) &
  947. PAGE_MASK) ==
  948. ((unsigned long) (zfcp_sg_to_address(&req[0]) +
  949. req[0].length - 1) & PAGE_MASK)) &&
  950. (((unsigned long) zfcp_sg_to_address(&resp[0]) &
  951. PAGE_MASK) ==
  952. ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
  953. resp[0].length - 1) & PAGE_MASK)));
  954. }
  955. /**
  956. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  957. * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
  958. * the request
  959. * @pool: pointer to memory pool, if non-null this pool is used to allocate
  960. * a struct zfcp_fsf_req
  961. * @erp_action: pointer to erp_action, if non-null the Generic Service request
  962. * is sent within error recovery
  963. */
  964. int
  965. zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
  966. struct zfcp_erp_action *erp_action)
  967. {
  968. volatile struct qdio_buffer_element *sbale;
  969. struct zfcp_port *port;
  970. struct zfcp_adapter *adapter;
  971. struct zfcp_fsf_req *fsf_req;
  972. unsigned long lock_flags;
  973. int bytes;
  974. int ret = 0;
  975. port = ct->port;
  976. adapter = port->adapter;
  977. ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
  978. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  979. pool, &lock_flags, &fsf_req);
  980. if (ret < 0)
  981. goto failed_req;
  982. sbale = zfcp_qdio_sbale_req(fsf_req);
  983. if (zfcp_use_one_sbal(ct->req, ct->req_count,
  984. ct->resp, ct->resp_count)){
  985. /* both request buffer and response buffer
  986. fit into one sbale each */
  987. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  988. sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
  989. sbale[2].length = ct->req[0].length;
  990. sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
  991. sbale[3].length = ct->resp[0].length;
  992. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  993. } else if (adapter->adapter_features &
  994. FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
  995. /* try to use chained SBALs */
  996. bytes = zfcp_qdio_sbals_from_sg(fsf_req,
  997. SBAL_FLAGS0_TYPE_WRITE_READ,
  998. ct->req,
  999. ZFCP_MAX_SBALS_PER_CT_REQ);
  1000. if (bytes <= 0) {
  1001. if (bytes == 0)
  1002. ret = -ENOMEM;
  1003. else
  1004. ret = bytes;
  1005. goto failed_send;
  1006. }
  1007. fsf_req->qtcb->bottom.support.req_buf_length = bytes;
  1008. fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  1009. bytes = zfcp_qdio_sbals_from_sg(fsf_req,
  1010. SBAL_FLAGS0_TYPE_WRITE_READ,
  1011. ct->resp,
  1012. ZFCP_MAX_SBALS_PER_CT_REQ);
  1013. if (bytes <= 0) {
  1014. if (bytes == 0)
  1015. ret = -ENOMEM;
  1016. else
  1017. ret = bytes;
  1018. goto failed_send;
  1019. }
  1020. fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
  1021. } else {
  1022. /* reject send generic request */
  1023. ret = -EOPNOTSUPP;
  1024. goto failed_send;
  1025. }
  1026. /* settings in QTCB */
  1027. fsf_req->qtcb->header.port_handle = port->handle;
  1028. fsf_req->qtcb->bottom.support.service_class =
  1029. ZFCP_FC_SERVICE_CLASS_DEFAULT;
  1030. fsf_req->qtcb->bottom.support.timeout = ct->timeout;
  1031. fsf_req->data = (unsigned long) ct;
  1032. zfcp_san_dbf_event_ct_request(fsf_req);
  1033. if (erp_action) {
  1034. erp_action->fsf_req = fsf_req;
  1035. fsf_req->erp_action = erp_action;
  1036. zfcp_erp_start_timer(fsf_req);
  1037. } else
  1038. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  1039. ret = zfcp_fsf_req_send(fsf_req);
  1040. if (ret)
  1041. goto failed_send;
  1042. goto out;
  1043. failed_send:
  1044. zfcp_fsf_req_free(fsf_req);
  1045. if (erp_action != NULL) {
  1046. erp_action->fsf_req = NULL;
  1047. }
  1048. failed_req:
  1049. out:
  1050. write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
  1051. return ret;
  1052. }
  1053. /**
  1054. * zfcp_fsf_send_ct_handler - handler for Generic Service requests
  1055. * @fsf_req: pointer to struct zfcp_fsf_req
  1056. *
  1057. * Data specific for the Generic Service request is passed using
  1058. * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
  1059. * Usually a specific handler for the CT request is called which is
  1060. * found in this structure.
  1061. */
  1062. static int
  1063. zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
  1064. {
  1065. struct zfcp_port *port;
  1066. struct zfcp_adapter *adapter;
  1067. struct zfcp_send_ct *send_ct;
  1068. struct fsf_qtcb_header *header;
  1069. struct fsf_qtcb_bottom_support *bottom;
  1070. int retval = -EINVAL;
  1071. adapter = fsf_req->adapter;
  1072. send_ct = (struct zfcp_send_ct *) fsf_req->data;
  1073. port = send_ct->port;
  1074. header = &fsf_req->qtcb->header;
  1075. bottom = &fsf_req->qtcb->bottom.support;
  1076. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1077. goto skip_fsfstatus;
  1078. /* evaluate FSF status in QTCB */
  1079. switch (header->fsf_status) {
  1080. case FSF_GOOD:
  1081. zfcp_san_dbf_event_ct_response(fsf_req);
  1082. retval = 0;
  1083. break;
  1084. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1085. zfcp_fsf_class_not_supp(fsf_req);
  1086. break;
  1087. case FSF_ADAPTER_STATUS_AVAILABLE:
  1088. switch (header->fsf_status_qual.word[0]){
  1089. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1090. /* reopening link to port */
  1091. zfcp_test_link(port);
  1092. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1093. break;
  1094. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1095. /* ERP strategy will escalate */
  1096. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1097. break;
  1098. }
  1099. break;
  1100. case FSF_ACCESS_DENIED:
  1101. zfcp_fsf_access_denied_port(fsf_req, port);
  1102. break;
  1103. case FSF_GENERIC_COMMAND_REJECTED:
  1104. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1105. break;
  1106. case FSF_PORT_HANDLE_NOT_VALID:
  1107. zfcp_erp_adapter_reopen(adapter, 0, 106, fsf_req);
  1108. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1109. break;
  1110. case FSF_PORT_BOXED:
  1111. zfcp_erp_port_boxed(port, 49, fsf_req);
  1112. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
  1113. | ZFCP_STATUS_FSFREQ_RETRY;
  1114. break;
  1115. /* following states should never occure, all cases avoided
  1116. in zfcp_fsf_send_ct - but who knows ... */
  1117. case FSF_PAYLOAD_SIZE_MISMATCH:
  1118. case FSF_REQUEST_SIZE_TOO_LARGE:
  1119. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1120. case FSF_SBAL_MISMATCH:
  1121. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1122. break;
  1123. default:
  1124. break;
  1125. }
  1126. skip_fsfstatus:
  1127. send_ct->status = retval;
  1128. if (send_ct->handler != NULL)
  1129. send_ct->handler(send_ct->handler_data);
  1130. return retval;
  1131. }
  1132. /**
  1133. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1134. * @els: pointer to struct zfcp_send_els which contains all needed data for
  1135. * the command.
  1136. */
  1137. int
  1138. zfcp_fsf_send_els(struct zfcp_send_els *els)
  1139. {
  1140. volatile struct qdio_buffer_element *sbale;
  1141. struct zfcp_fsf_req *fsf_req;
  1142. u32 d_id;
  1143. struct zfcp_adapter *adapter;
  1144. unsigned long lock_flags;
  1145. int bytes;
  1146. int ret = 0;
  1147. d_id = els->d_id;
  1148. adapter = els->adapter;
  1149. ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
  1150. ZFCP_REQ_AUTO_CLEANUP,
  1151. NULL, &lock_flags, &fsf_req);
  1152. if (ret < 0)
  1153. goto failed_req;
  1154. if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
  1155. &els->port->status))) {
  1156. ret = -EBUSY;
  1157. goto port_blocked;
  1158. }
  1159. sbale = zfcp_qdio_sbale_req(fsf_req);
  1160. if (zfcp_use_one_sbal(els->req, els->req_count,
  1161. els->resp, els->resp_count)){
  1162. /* both request buffer and response buffer
  1163. fit into one sbale each */
  1164. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  1165. sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
  1166. sbale[2].length = els->req[0].length;
  1167. sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
  1168. sbale[3].length = els->resp[0].length;
  1169. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  1170. } else if (adapter->adapter_features &
  1171. FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
  1172. /* try to use chained SBALs */
  1173. bytes = zfcp_qdio_sbals_from_sg(fsf_req,
  1174. SBAL_FLAGS0_TYPE_WRITE_READ,
  1175. els->req,
  1176. ZFCP_MAX_SBALS_PER_ELS_REQ);
  1177. if (bytes <= 0) {
  1178. if (bytes == 0) {
  1179. ret = -ENOMEM;
  1180. } else {
  1181. ret = bytes;
  1182. }
  1183. goto failed_send;
  1184. }
  1185. fsf_req->qtcb->bottom.support.req_buf_length = bytes;
  1186. fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  1187. bytes = zfcp_qdio_sbals_from_sg(fsf_req,
  1188. SBAL_FLAGS0_TYPE_WRITE_READ,
  1189. els->resp,
  1190. ZFCP_MAX_SBALS_PER_ELS_REQ);
  1191. if (bytes <= 0) {
  1192. if (bytes == 0) {
  1193. ret = -ENOMEM;
  1194. } else {
  1195. ret = bytes;
  1196. }
  1197. goto failed_send;
  1198. }
  1199. fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
  1200. } else {
  1201. /* reject request */
  1202. ret = -EOPNOTSUPP;
  1203. goto failed_send;
  1204. }
  1205. /* settings in QTCB */
  1206. fsf_req->qtcb->bottom.support.d_id = d_id;
  1207. fsf_req->qtcb->bottom.support.service_class =
  1208. ZFCP_FC_SERVICE_CLASS_DEFAULT;
  1209. fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
  1210. fsf_req->data = (unsigned long) els;
  1211. sbale = zfcp_qdio_sbale_req(fsf_req);
  1212. zfcp_san_dbf_event_els_request(fsf_req);
  1213. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  1214. ret = zfcp_fsf_req_send(fsf_req);
  1215. if (ret)
  1216. goto failed_send;
  1217. goto out;
  1218. port_blocked:
  1219. failed_send:
  1220. zfcp_fsf_req_free(fsf_req);
  1221. failed_req:
  1222. out:
  1223. write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
  1224. return ret;
  1225. }
  1226. /**
  1227. * zfcp_fsf_send_els_handler - handler for ELS commands
  1228. * @fsf_req: pointer to struct zfcp_fsf_req
  1229. *
  1230. * Data specific for the ELS command is passed using
  1231. * fsf_req->data. There we find the pointer to struct zfcp_send_els.
  1232. * Usually a specific handler for the ELS command is called which is
  1233. * found in this structure.
  1234. */
  1235. static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
  1236. {
  1237. struct zfcp_adapter *adapter;
  1238. struct zfcp_port *port;
  1239. u32 d_id;
  1240. struct fsf_qtcb_header *header;
  1241. struct fsf_qtcb_bottom_support *bottom;
  1242. struct zfcp_send_els *send_els;
  1243. int retval = -EINVAL;
  1244. send_els = (struct zfcp_send_els *) fsf_req->data;
  1245. adapter = send_els->adapter;
  1246. port = send_els->port;
  1247. d_id = send_els->d_id;
  1248. header = &fsf_req->qtcb->header;
  1249. bottom = &fsf_req->qtcb->bottom.support;
  1250. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1251. goto skip_fsfstatus;
  1252. switch (header->fsf_status) {
  1253. case FSF_GOOD:
  1254. zfcp_san_dbf_event_els_response(fsf_req);
  1255. retval = 0;
  1256. break;
  1257. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1258. zfcp_fsf_class_not_supp(fsf_req);
  1259. break;
  1260. case FSF_ADAPTER_STATUS_AVAILABLE:
  1261. switch (header->fsf_status_qual.word[0]){
  1262. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1263. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  1264. zfcp_test_link(port);
  1265. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1266. break;
  1267. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1268. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1269. break;
  1270. case FSF_SQ_RETRY_IF_POSSIBLE:
  1271. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1272. break;
  1273. }
  1274. break;
  1275. case FSF_ELS_COMMAND_REJECTED:
  1276. case FSF_PAYLOAD_SIZE_MISMATCH:
  1277. case FSF_REQUEST_SIZE_TOO_LARGE:
  1278. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1279. break;
  1280. case FSF_SBAL_MISMATCH:
  1281. /* should never occure, avoided in zfcp_fsf_send_els */
  1282. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1283. break;
  1284. case FSF_ACCESS_DENIED:
  1285. zfcp_fsf_access_denied_port(fsf_req, port);
  1286. break;
  1287. default:
  1288. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1289. break;
  1290. }
  1291. skip_fsfstatus:
  1292. send_els->status = retval;
  1293. if (send_els->handler)
  1294. send_els->handler(send_els->handler_data);
  1295. return retval;
  1296. }
  1297. int
  1298. zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1299. {
  1300. volatile struct qdio_buffer_element *sbale;
  1301. struct zfcp_fsf_req *fsf_req;
  1302. struct zfcp_adapter *adapter = erp_action->adapter;
  1303. unsigned long lock_flags;
  1304. int retval;
  1305. /* setup new FSF request */
  1306. retval = zfcp_fsf_req_create(adapter,
  1307. FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1308. ZFCP_REQ_AUTO_CLEANUP,
  1309. adapter->pool.fsf_req_erp,
  1310. &lock_flags, &fsf_req);
  1311. if (retval) {
  1312. write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
  1313. return retval;
  1314. }
  1315. sbale = zfcp_qdio_sbale_req(fsf_req);
  1316. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1317. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1318. fsf_req->qtcb->bottom.config.feature_selection =
  1319. FSF_FEATURE_CFDC |
  1320. FSF_FEATURE_LUN_SHARING |
  1321. FSF_FEATURE_NOTIFICATION_LOST |
  1322. FSF_FEATURE_UPDATE_ALERT;
  1323. fsf_req->erp_action = erp_action;
  1324. erp_action->fsf_req = fsf_req;
  1325. zfcp_erp_start_timer(fsf_req);
  1326. retval = zfcp_fsf_req_send(fsf_req);
  1327. write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
  1328. if (retval) {
  1329. zfcp_fsf_req_free(fsf_req);
  1330. erp_action->fsf_req = NULL;
  1331. }
  1332. return retval;
  1333. }
  1334. int
  1335. zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
  1336. struct fsf_qtcb_bottom_config *data)
  1337. {
  1338. volatile struct qdio_buffer_element *sbale;
  1339. struct zfcp_fsf_req *fsf_req;
  1340. unsigned long lock_flags;
  1341. int retval;
  1342. /* setup new FSF request */
  1343. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1344. ZFCP_WAIT_FOR_SBAL, NULL, &lock_flags,
  1345. &fsf_req);
  1346. if (retval) {
  1347. write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
  1348. return retval;
  1349. }
  1350. sbale = zfcp_qdio_sbale_req(fsf_req);
  1351. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1352. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1353. fsf_req->qtcb->bottom.config.feature_selection =
  1354. FSF_FEATURE_CFDC |
  1355. FSF_FEATURE_LUN_SHARING |
  1356. FSF_FEATURE_NOTIFICATION_LOST |
  1357. FSF_FEATURE_UPDATE_ALERT;
  1358. if (data)
  1359. fsf_req->data = (unsigned long) data;
  1360. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  1361. retval = zfcp_fsf_req_send(fsf_req);
  1362. write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
  1363. if (!retval)
  1364. wait_event(fsf_req->completion_wq,
  1365. fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1366. zfcp_fsf_req_free(fsf_req);
  1367. return retval;
  1368. }
  1369. /**
  1370. * zfcp_fsf_exchange_config_evaluate
  1371. * @fsf_req: fsf_req which belongs to xchg config data request
  1372. * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
  1373. *
  1374. * returns: -EIO on error, 0 otherwise
  1375. */
  1376. static int
  1377. zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
  1378. {
  1379. struct fsf_qtcb_bottom_config *bottom;
  1380. struct zfcp_adapter *adapter = fsf_req->adapter;
  1381. struct Scsi_Host *shost = adapter->scsi_host;
  1382. bottom = &fsf_req->qtcb->bottom.config;
  1383. adapter->fsf_lic_version = bottom->lic_version;
  1384. adapter->adapter_features = bottom->adapter_features;
  1385. adapter->connection_features = bottom->connection_features;
  1386. adapter->peer_wwpn = 0;
  1387. adapter->peer_wwnn = 0;
  1388. adapter->peer_d_id = 0;
  1389. if (xchg_ok) {
  1390. if (fsf_req->data)
  1391. memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data,
  1392. bottom, sizeof (struct fsf_qtcb_bottom_config));
  1393. fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
  1394. fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
  1395. fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
  1396. fc_host_speed(shost) = bottom->fc_link_speed;
  1397. fc_host_supported_classes(shost) =
  1398. FC_COS_CLASS2 | FC_COS_CLASS3;
  1399. adapter->hydra_version = bottom->adapter_type;
  1400. adapter->timer_ticks = bottom->timer_interval;
  1401. if (fc_host_permanent_port_name(shost) == -1)
  1402. fc_host_permanent_port_name(shost) =
  1403. fc_host_port_name(shost);
  1404. if (bottom->fc_topology == FSF_TOPO_P2P) {
  1405. adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
  1406. adapter->peer_wwpn = bottom->plogi_payload.wwpn;
  1407. adapter->peer_wwnn = bottom->plogi_payload.wwnn;
  1408. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  1409. } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
  1410. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  1411. else if (bottom->fc_topology == FSF_TOPO_AL)
  1412. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  1413. else
  1414. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  1415. } else {
  1416. fc_host_node_name(shost) = 0;
  1417. fc_host_port_name(shost) = 0;
  1418. fc_host_port_id(shost) = 0;
  1419. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  1420. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  1421. adapter->hydra_version = 0;
  1422. }
  1423. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  1424. adapter->hardware_version = bottom->hardware_version;
  1425. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  1426. min(FC_SERIAL_NUMBER_SIZE, 17));
  1427. EBCASC(fc_host_serial_number(shost),
  1428. min(FC_SERIAL_NUMBER_SIZE, 17));
  1429. }
  1430. if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
  1431. dev_err(&adapter->ccw_device->dev,
  1432. "The adapter only supports newer control block "
  1433. "versions, try updated device driver.\n");
  1434. zfcp_erp_adapter_shutdown(adapter, 0, 125, fsf_req);
  1435. return -EIO;
  1436. }
  1437. if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
  1438. dev_err(&adapter->ccw_device->dev,
  1439. "The adapter only supports older control block "
  1440. "versions, consider a microcode upgrade.\n");
  1441. zfcp_erp_adapter_shutdown(adapter, 0, 126, fsf_req);
  1442. return -EIO;
  1443. }
  1444. return 0;
  1445. }
  1446. /**
  1447. * function: zfcp_fsf_exchange_config_data_handler
  1448. *
  1449. * purpose: is called for finished Exchange Configuration Data command
  1450. *
  1451. * returns:
  1452. */
  1453. static int
  1454. zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
  1455. {
  1456. struct fsf_qtcb_bottom_config *bottom;
  1457. struct zfcp_adapter *adapter = fsf_req->adapter;
  1458. struct fsf_qtcb *qtcb = fsf_req->qtcb;
  1459. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1460. return -EIO;
  1461. switch (qtcb->header.fsf_status) {
  1462. case FSF_GOOD:
  1463. if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
  1464. return -EIO;
  1465. switch (fc_host_port_type(adapter->scsi_host)) {
  1466. case FC_PORTTYPE_PTP:
  1467. if (fsf_req->erp_action)
  1468. dev_info(&adapter->ccw_device->dev,
  1469. "Point-to-Point fibrechannel "
  1470. "configuration detected.\n");
  1471. break;
  1472. case FC_PORTTYPE_NLPORT:
  1473. dev_err(&adapter->ccw_device->dev,
  1474. "Unsupported arbitrated loop fibrechannel "
  1475. "topology detected, shutting down adapter\n");
  1476. zfcp_erp_adapter_shutdown(adapter, 0, 127, fsf_req);
  1477. return -EIO;
  1478. case FC_PORTTYPE_NPORT:
  1479. if (fsf_req->erp_action)
  1480. dev_info(&adapter->ccw_device->dev,
  1481. "Switched fabric fibrechannel "
  1482. "network detected.\n");
  1483. break;
  1484. default:
  1485. dev_err(&adapter->ccw_device->dev,
  1486. "The fibrechannel topology reported by the "
  1487. "adapter is not known by the zfcp driver, "
  1488. "shutting down adapter.\n");
  1489. zfcp_erp_adapter_shutdown(adapter, 0, 128, fsf_req);
  1490. return -EIO;
  1491. }
  1492. bottom = &qtcb->bottom.config;
  1493. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  1494. dev_err(&adapter->ccw_device->dev,
  1495. "Maximum QTCB size (%d bytes) allowed by "
  1496. "the adapter is lower than the minimum "
  1497. "required by the driver (%ld bytes).\n",
  1498. bottom->max_qtcb_size, sizeof(struct fsf_qtcb));
  1499. zfcp_erp_adapter_shutdown(adapter, 0, 129, fsf_req);
  1500. return -EIO;
  1501. }
  1502. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  1503. &adapter->status);
  1504. break;
  1505. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  1506. if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
  1507. return -EIO;
  1508. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  1509. &adapter->status);
  1510. zfcp_fsf_link_down_info_eval(fsf_req, 42,
  1511. &qtcb->header.fsf_status_qual.link_down_info);
  1512. break;
  1513. default:
  1514. zfcp_erp_adapter_shutdown(adapter, 0, 130, fsf_req);
  1515. return -EIO;
  1516. }
  1517. return 0;
  1518. }
  1519. /**
  1520. * zfcp_fsf_exchange_port_data - request information about local port
  1521. * @erp_action: ERP action for the adapter for which port data is requested
  1522. */
  1523. int
  1524. zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1525. {
  1526. volatile struct qdio_buffer_element *sbale;
  1527. struct zfcp_fsf_req *fsf_req;
  1528. struct zfcp_adapter *adapter = erp_action->adapter;
  1529. unsigned long lock_flags;
  1530. int retval;
  1531. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1532. return -EOPNOTSUPP;
  1533. /* setup new FSF request */
  1534. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1535. ZFCP_REQ_AUTO_CLEANUP,
  1536. adapter->pool.fsf_req_erp,
  1537. &lock_flags, &fsf_req);
  1538. if (retval) {
  1539. write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
  1540. return retval;
  1541. }
  1542. sbale = zfcp_qdio_sbale_req(fsf_req);
  1543. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1544. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1545. erp_action->fsf_req = fsf_req;
  1546. fsf_req->erp_action = erp_action;
  1547. zfcp_erp_start_timer(fsf_req);
  1548. retval = zfcp_fsf_req_send(fsf_req);
  1549. write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
  1550. if (retval) {
  1551. zfcp_fsf_req_free(fsf_req);
  1552. erp_action->fsf_req = NULL;
  1553. }
  1554. return retval;
  1555. }
  1556. /**
  1557. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1558. * and wait until information is ready
  1559. */
  1560. int
  1561. zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
  1562. struct fsf_qtcb_bottom_port *data)
  1563. {
  1564. volatile struct qdio_buffer_element *sbale;
  1565. struct zfcp_fsf_req *fsf_req;
  1566. unsigned long lock_flags;
  1567. int retval;
  1568. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1569. return -EOPNOTSUPP;
  1570. /* setup new FSF request */
  1571. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1572. 0, NULL, &lock_flags, &fsf_req);
  1573. if (retval) {
  1574. write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
  1575. return retval;
  1576. }
  1577. if (data)
  1578. fsf_req->data = (unsigned long) data;
  1579. sbale = zfcp_qdio_sbale_req(fsf_req);
  1580. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1581. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1582. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  1583. retval = zfcp_fsf_req_send(fsf_req);
  1584. write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
  1585. if (!retval)
  1586. wait_event(fsf_req->completion_wq,
  1587. fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1588. zfcp_fsf_req_free(fsf_req);
  1589. return retval;
  1590. }
  1591. /**
  1592. * zfcp_fsf_exchange_port_evaluate
  1593. * @fsf_req: fsf_req which belongs to xchg port data request
  1594. * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
  1595. */
  1596. static void
  1597. zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
  1598. {
  1599. struct zfcp_adapter *adapter;
  1600. struct fsf_qtcb_bottom_port *bottom;
  1601. struct Scsi_Host *shost;
  1602. adapter = fsf_req->adapter;
  1603. bottom = &fsf_req->qtcb->bottom.port;
  1604. shost = adapter->scsi_host;
  1605. if (fsf_req->data)
  1606. memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom,
  1607. sizeof(struct fsf_qtcb_bottom_port));
  1608. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  1609. fc_host_permanent_port_name(shost) = bottom->wwpn;
  1610. else
  1611. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  1612. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  1613. fc_host_supported_speeds(shost) = bottom->supported_speed;
  1614. }
  1615. /**
  1616. * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
  1617. * @fsf_req: pointer to struct zfcp_fsf_req
  1618. */
  1619. static void
  1620. zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
  1621. {
  1622. struct zfcp_adapter *adapter;
  1623. struct fsf_qtcb *qtcb;
  1624. adapter = fsf_req->adapter;
  1625. qtcb = fsf_req->qtcb;
  1626. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1627. return;
  1628. switch (qtcb->header.fsf_status) {
  1629. case FSF_GOOD:
  1630. zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
  1631. atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
  1632. break;
  1633. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  1634. zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
  1635. atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
  1636. zfcp_fsf_link_down_info_eval(fsf_req, 43,
  1637. &qtcb->header.fsf_status_qual.link_down_info);
  1638. break;
  1639. }
  1640. }
  1641. /*
  1642. * function: zfcp_fsf_open_port
  1643. *
  1644. * purpose:
  1645. *
  1646. * returns: address of initiated FSF request
  1647. * NULL - request could not be initiated
  1648. */
  1649. int
  1650. zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1651. {
  1652. volatile struct qdio_buffer_element *sbale;
  1653. struct zfcp_fsf_req *fsf_req;
  1654. unsigned long lock_flags;
  1655. int retval = 0;
  1656. /* setup new FSF request */
  1657. retval = zfcp_fsf_req_create(erp_action->adapter,
  1658. FSF_QTCB_OPEN_PORT_WITH_DID,
  1659. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  1660. erp_action->adapter->pool.fsf_req_erp,
  1661. &lock_flags, &fsf_req);
  1662. if (retval < 0)
  1663. goto out;
  1664. sbale = zfcp_qdio_sbale_req(fsf_req);
  1665. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1666. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1667. fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
  1668. atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
  1669. fsf_req->data = (unsigned long) erp_action->port;
  1670. fsf_req->erp_action = erp_action;
  1671. erp_action->fsf_req = fsf_req;
  1672. zfcp_erp_start_timer(fsf_req);
  1673. retval = zfcp_fsf_req_send(fsf_req);
  1674. if (retval) {
  1675. zfcp_fsf_req_free(fsf_req);
  1676. erp_action->fsf_req = NULL;
  1677. goto out;
  1678. }
  1679. out:
  1680. write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags);
  1681. return retval;
  1682. }
  1683. /*
  1684. * function: zfcp_fsf_open_port_handler
  1685. *
  1686. * purpose: is called for finished Open Port command
  1687. *
  1688. * returns:
  1689. */
  1690. static int
  1691. zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
  1692. {
  1693. int retval = -EINVAL;
  1694. struct zfcp_port *port;
  1695. struct fsf_plogi *plogi;
  1696. struct fsf_qtcb_header *header;
  1697. port = (struct zfcp_port *) fsf_req->data;
  1698. header = &fsf_req->qtcb->header;
  1699. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1700. /* don't change port status in our bookkeeping */
  1701. goto skip_fsfstatus;
  1702. }
  1703. /* evaluate FSF status in QTCB */
  1704. switch (header->fsf_status) {
  1705. case FSF_PORT_ALREADY_OPEN:
  1706. /*
  1707. * This is a bug, however operation should continue normally
  1708. * if it is simply ignored
  1709. */
  1710. break;
  1711. case FSF_ACCESS_DENIED:
  1712. zfcp_fsf_access_denied_port(fsf_req, port);
  1713. break;
  1714. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1715. dev_warn(&fsf_req->adapter->ccw_device->dev,
  1716. "The adapter is out of resources. The remote port "
  1717. "0x%016Lx could not be opened, disabling it.\n",
  1718. port->wwpn);
  1719. zfcp_erp_port_failed(port, 31, fsf_req);
  1720. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1721. break;
  1722. case FSF_ADAPTER_STATUS_AVAILABLE:
  1723. switch (header->fsf_status_qual.word[0]) {
  1724. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1725. /* ERP strategy will escalate */
  1726. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1727. break;
  1728. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1729. /* ERP strategy will escalate */
  1730. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1731. break;
  1732. case FSF_SQ_NO_RETRY_POSSIBLE:
  1733. dev_warn(&fsf_req->adapter->ccw_device->dev,
  1734. "The remote port 0x%016Lx could not be "
  1735. "opened. Disabling it.\n", port->wwpn);
  1736. zfcp_erp_port_failed(port, 32, fsf_req);
  1737. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1738. break;
  1739. default:
  1740. break;
  1741. }
  1742. break;
  1743. case FSF_GOOD:
  1744. /* save port handle assigned by FSF */
  1745. port->handle = header->port_handle;
  1746. /* mark port as open */
  1747. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1748. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1749. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1750. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1751. &port->status);
  1752. retval = 0;
  1753. /* check whether D_ID has changed during open */
  1754. /*
  1755. * FIXME: This check is not airtight, as the FCP channel does
  1756. * not monitor closures of target port connections caused on
  1757. * the remote side. Thus, they might miss out on invalidating
  1758. * locally cached WWPNs (and other N_Port parameters) of gone
  1759. * target ports. So, our heroic attempt to make things safe
  1760. * could be undermined by 'open port' response data tagged with
  1761. * obsolete WWPNs. Another reason to monitor potential
  1762. * connection closures ourself at least (by interpreting
  1763. * incoming ELS' and unsolicited status). It just crosses my
  1764. * mind that one should be able to cross-check by means of
  1765. * another GID_PN straight after a port has been opened.
  1766. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1767. */
  1768. plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
  1769. if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
  1770. {
  1771. if (fsf_req->qtcb->bottom.support.els1_length <
  1772. sizeof (struct fsf_plogi)) {
  1773. /* skip sanity check and assume wwpn is ok */
  1774. } else {
  1775. if (plogi->serv_param.wwpn != port->wwpn) {
  1776. atomic_clear_mask(
  1777. ZFCP_STATUS_PORT_DID_DID,
  1778. &port->status);
  1779. } else {
  1780. port->wwnn = plogi->serv_param.wwnn;
  1781. zfcp_fc_plogi_evaluate(port, plogi);
  1782. }
  1783. }
  1784. }
  1785. break;
  1786. case FSF_UNKNOWN_OP_SUBTYPE:
  1787. /* should never occure, subtype not set in zfcp_fsf_open_port */
  1788. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1789. break;
  1790. default:
  1791. break;
  1792. }
  1793. skip_fsfstatus:
  1794. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
  1795. return retval;
  1796. }
  1797. /*
  1798. * function: zfcp_fsf_close_port
  1799. *
  1800. * purpose: submit FSF command "close port"
  1801. *
  1802. * returns: address of initiated FSF request
  1803. * NULL - request could not be initiated
  1804. */
  1805. int
  1806. zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1807. {
  1808. volatile struct qdio_buffer_element *sbale;
  1809. struct zfcp_fsf_req *fsf_req;
  1810. unsigned long lock_flags;
  1811. int retval = 0;
  1812. /* setup new FSF request */
  1813. retval = zfcp_fsf_req_create(erp_action->adapter,
  1814. FSF_QTCB_CLOSE_PORT,
  1815. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  1816. erp_action->adapter->pool.fsf_req_erp,
  1817. &lock_flags, &fsf_req);
  1818. if (retval < 0)
  1819. goto out;
  1820. sbale = zfcp_qdio_sbale_req(fsf_req);
  1821. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1822. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1823. atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
  1824. fsf_req->data = (unsigned long) erp_action->port;
  1825. fsf_req->erp_action = erp_action;
  1826. fsf_req->qtcb->header.port_handle = erp_action->port->handle;
  1827. fsf_req->erp_action = erp_action;
  1828. erp_action->fsf_req = fsf_req;
  1829. zfcp_erp_start_timer(fsf_req);
  1830. retval = zfcp_fsf_req_send(fsf_req);
  1831. if (retval) {
  1832. zfcp_fsf_req_free(fsf_req);
  1833. erp_action->fsf_req = NULL;
  1834. goto out;
  1835. }
  1836. out:
  1837. write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags);
  1838. return retval;
  1839. }
  1840. /*
  1841. * function: zfcp_fsf_close_port_handler
  1842. *
  1843. * purpose: is called for finished Close Port FSF command
  1844. *
  1845. * returns:
  1846. */
  1847. static int
  1848. zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
  1849. {
  1850. int retval = -EINVAL;
  1851. struct zfcp_port *port;
  1852. port = (struct zfcp_port *) fsf_req->data;
  1853. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1854. /* don't change port status in our bookkeeping */
  1855. goto skip_fsfstatus;
  1856. }
  1857. /* evaluate FSF status in QTCB */
  1858. switch (fsf_req->qtcb->header.fsf_status) {
  1859. case FSF_PORT_HANDLE_NOT_VALID:
  1860. zfcp_erp_adapter_reopen(port->adapter, 0, 107, fsf_req);
  1861. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1862. break;
  1863. case FSF_ADAPTER_STATUS_AVAILABLE:
  1864. /* Note: FSF has actually closed the port in this case.
  1865. * The status code is just daft. Fingers crossed for a change
  1866. */
  1867. retval = 0;
  1868. break;
  1869. case FSF_GOOD:
  1870. zfcp_erp_modify_port_status(port, 33, fsf_req,
  1871. ZFCP_STATUS_COMMON_OPEN,
  1872. ZFCP_CLEAR);
  1873. retval = 0;
  1874. break;
  1875. }
  1876. skip_fsfstatus:
  1877. atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
  1878. return retval;
  1879. }
  1880. /*
  1881. * function: zfcp_fsf_close_physical_port
  1882. *
  1883. * purpose: submit FSF command "close physical port"
  1884. *
  1885. * returns: address of initiated FSF request
  1886. * NULL - request could not be initiated
  1887. */
  1888. int
  1889. zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1890. {
  1891. volatile struct qdio_buffer_element *sbale;
  1892. struct zfcp_fsf_req *fsf_req;
  1893. unsigned long lock_flags;
  1894. int retval = 0;
  1895. /* setup new FSF request */
  1896. retval = zfcp_fsf_req_create(erp_action->adapter,
  1897. FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1898. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  1899. erp_action->adapter->pool.fsf_req_erp,
  1900. &lock_flags, &fsf_req);
  1901. if (retval < 0)
  1902. goto out;
  1903. sbale = zfcp_qdio_sbale_req(fsf_req);
  1904. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1905. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1906. /* mark port as being closed */
  1907. atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
  1908. &erp_action->port->status);
  1909. /* save a pointer to this port */
  1910. fsf_req->data = (unsigned long) erp_action->port;
  1911. fsf_req->qtcb->header.port_handle = erp_action->port->handle;
  1912. fsf_req->erp_action = erp_action;
  1913. erp_action->fsf_req = fsf_req;
  1914. zfcp_erp_start_timer(fsf_req);
  1915. retval = zfcp_fsf_req_send(fsf_req);
  1916. if (retval) {
  1917. zfcp_fsf_req_free(fsf_req);
  1918. erp_action->fsf_req = NULL;
  1919. goto out;
  1920. }
  1921. out:
  1922. write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags);
  1923. return retval;
  1924. }
  1925. /*
  1926. * function: zfcp_fsf_close_physical_port_handler
  1927. *
  1928. * purpose: is called for finished Close Physical Port FSF command
  1929. *
  1930. * returns:
  1931. */
  1932. static int
  1933. zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
  1934. {
  1935. int retval = -EINVAL;
  1936. struct zfcp_port *port;
  1937. struct zfcp_unit *unit;
  1938. struct fsf_qtcb_header *header;
  1939. port = (struct zfcp_port *) fsf_req->data;
  1940. header = &fsf_req->qtcb->header;
  1941. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1942. /* don't change port status in our bookkeeping */
  1943. goto skip_fsfstatus;
  1944. }
  1945. /* evaluate FSF status in QTCB */
  1946. switch (header->fsf_status) {
  1947. case FSF_PORT_HANDLE_NOT_VALID:
  1948. zfcp_erp_adapter_reopen(port->adapter, 0, 108, fsf_req);
  1949. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1950. break;
  1951. case FSF_ACCESS_DENIED:
  1952. zfcp_fsf_access_denied_port(fsf_req, port);
  1953. break;
  1954. case FSF_PORT_BOXED:
  1955. zfcp_erp_port_boxed(port, 50, fsf_req);
  1956. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1957. ZFCP_STATUS_FSFREQ_RETRY;
  1958. /* can't use generic zfcp_erp_modify_port_status because
  1959. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1960. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1961. list_for_each_entry(unit, &port->unit_list_head, list)
  1962. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1963. &unit->status);
  1964. break;
  1965. case FSF_ADAPTER_STATUS_AVAILABLE:
  1966. switch (header->fsf_status_qual.word[0]) {
  1967. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1968. /* This will now be escalated by ERP */
  1969. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1970. break;
  1971. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1972. /* ERP strategy will escalate */
  1973. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1974. break;
  1975. }
  1976. break;
  1977. case FSF_GOOD:
  1978. /* can't use generic zfcp_erp_modify_port_status because
  1979. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1980. */
  1981. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1982. list_for_each_entry(unit, &port->unit_list_head, list)
  1983. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1984. retval = 0;
  1985. break;
  1986. }
  1987. skip_fsfstatus:
  1988. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
  1989. return retval;
  1990. }
  1991. /*
  1992. * function: zfcp_fsf_open_unit
  1993. *
  1994. * purpose:
  1995. *
  1996. * returns:
  1997. *
  1998. * assumptions: This routine does not check whether the associated
  1999. * remote port has already been opened. This should be
  2000. * done by calling routines. Otherwise some status
  2001. * may be presented by FSF
  2002. */
  2003. int
  2004. zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  2005. {
  2006. volatile struct qdio_buffer_element *sbale;
  2007. struct zfcp_fsf_req *fsf_req;
  2008. unsigned long lock_flags;
  2009. int retval = 0;
  2010. /* setup new FSF request */
  2011. retval = zfcp_fsf_req_create(erp_action->adapter,
  2012. FSF_QTCB_OPEN_LUN,
  2013. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2014. erp_action->adapter->pool.fsf_req_erp,
  2015. &lock_flags, &fsf_req);
  2016. if (retval < 0)
  2017. goto out;
  2018. sbale = zfcp_qdio_sbale_req(fsf_req);
  2019. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2020. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2021. fsf_req->qtcb->header.port_handle = erp_action->port->handle;
  2022. fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  2023. if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  2024. fsf_req->qtcb->bottom.support.option =
  2025. FSF_OPEN_LUN_SUPPRESS_BOXING;
  2026. atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
  2027. fsf_req->data = (unsigned long) erp_action->unit;
  2028. fsf_req->erp_action = erp_action;
  2029. erp_action->fsf_req = fsf_req;
  2030. zfcp_erp_start_timer(fsf_req);
  2031. retval = zfcp_fsf_req_send(erp_action->fsf_req);
  2032. if (retval) {
  2033. zfcp_fsf_req_free(fsf_req);
  2034. erp_action->fsf_req = NULL;
  2035. goto out;
  2036. }
  2037. out:
  2038. write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags);
  2039. return retval;
  2040. }
  2041. /*
  2042. * function: zfcp_fsf_open_unit_handler
  2043. *
  2044. * purpose: is called for finished Open LUN command
  2045. *
  2046. * returns:
  2047. */
  2048. static int
  2049. zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
  2050. {
  2051. int retval = -EINVAL;
  2052. struct zfcp_adapter *adapter;
  2053. struct zfcp_unit *unit;
  2054. struct fsf_qtcb_header *header;
  2055. struct fsf_qtcb_bottom_support *bottom;
  2056. struct fsf_queue_designator *queue_designator;
  2057. int exclusive, readwrite;
  2058. unit = (struct zfcp_unit *) fsf_req->data;
  2059. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2060. /* don't change unit status in our bookkeeping */
  2061. goto skip_fsfstatus;
  2062. }
  2063. adapter = fsf_req->adapter;
  2064. header = &fsf_req->qtcb->header;
  2065. bottom = &fsf_req->qtcb->bottom.support;
  2066. queue_designator = &header->fsf_status_qual.fsf_queue_designator;
  2067. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  2068. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  2069. ZFCP_STATUS_UNIT_SHARED |
  2070. ZFCP_STATUS_UNIT_READONLY,
  2071. &unit->status);
  2072. /* evaluate FSF status in QTCB */
  2073. switch (header->fsf_status) {
  2074. case FSF_PORT_HANDLE_NOT_VALID:
  2075. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, fsf_req);
  2076. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2077. break;
  2078. case FSF_LUN_ALREADY_OPEN:
  2079. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2080. break;
  2081. case FSF_ACCESS_DENIED:
  2082. zfcp_fsf_access_denied_unit(fsf_req, unit);
  2083. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  2084. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  2085. break;
  2086. case FSF_PORT_BOXED:
  2087. zfcp_erp_port_boxed(unit->port, 51, fsf_req);
  2088. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2089. ZFCP_STATUS_FSFREQ_RETRY;
  2090. break;
  2091. case FSF_LUN_SHARING_VIOLATION:
  2092. if (header->fsf_status_qual.word[0] != 0) {
  2093. dev_warn(&adapter->ccw_device->dev,
  2094. "FCP-LUN 0x%Lx at the remote port "
  2095. "with WWPN 0x%Lx "
  2096. "connected to the adapter "
  2097. "is already in use in LPAR%d, CSS%d.\n",
  2098. unit->fcp_lun,
  2099. unit->port->wwpn,
  2100. queue_designator->hla,
  2101. queue_designator->cssid);
  2102. } else
  2103. zfcp_act_eval_err(adapter,
  2104. header->fsf_status_qual.word[2]);
  2105. zfcp_erp_unit_access_denied(unit, 60, fsf_req);
  2106. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  2107. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  2108. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2109. break;
  2110. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  2111. dev_warn(&fsf_req->adapter->ccw_device->dev,
  2112. "The adapter ran out of resources. There is no "
  2113. "handle available for unit 0x%016Lx on port 0x%016Lx.",
  2114. unit->fcp_lun, unit->port->wwpn);
  2115. zfcp_erp_unit_failed(unit, 34, fsf_req);
  2116. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2117. break;
  2118. case FSF_ADAPTER_STATUS_AVAILABLE:
  2119. switch (header->fsf_status_qual.word[0]) {
  2120. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  2121. /* Re-establish link to port */
  2122. zfcp_test_link(unit->port);
  2123. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2124. break;
  2125. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  2126. /* ERP strategy will escalate */
  2127. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2128. break;
  2129. }
  2130. break;
  2131. case FSF_INVALID_COMMAND_OPTION:
  2132. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2133. retval = -EINVAL;
  2134. break;
  2135. case FSF_GOOD:
  2136. /* save LUN handle assigned by FSF */
  2137. unit->handle = header->lun_handle;
  2138. /* mark unit as open */
  2139. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  2140. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  2141. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  2142. (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
  2143. exclusive = (bottom->lun_access_info &
  2144. FSF_UNIT_ACCESS_EXCLUSIVE);
  2145. readwrite = (bottom->lun_access_info &
  2146. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  2147. if (!exclusive)
  2148. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  2149. &unit->status);
  2150. if (!readwrite) {
  2151. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  2152. &unit->status);
  2153. dev_info(&fsf_req->adapter->ccw_device->dev,
  2154. "Read-only access for unit 0x%016Lx "
  2155. "on port 0x%016Lx.\n",
  2156. unit->fcp_lun, unit->port->wwpn);
  2157. }
  2158. if (exclusive && !readwrite) {
  2159. dev_err(&fsf_req->adapter->ccw_device->dev,
  2160. "Exclusive access of read-only unit "
  2161. "0x%016Lx on port 0x%016Lx not "
  2162. "supported, disabling unit.\n",
  2163. unit->fcp_lun, unit->port->wwpn);
  2164. zfcp_erp_unit_failed(unit, 35, fsf_req);
  2165. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2166. zfcp_erp_unit_shutdown(unit, 0, 80, fsf_req);
  2167. } else if (!exclusive && readwrite) {
  2168. dev_err(&fsf_req->adapter->ccw_device->dev,
  2169. "Shared access of read-write unit "
  2170. "0x%016Lx on port 0x%016Lx not "
  2171. "supported, disabling unit.\n",
  2172. unit->fcp_lun, unit->port->wwpn);
  2173. zfcp_erp_unit_failed(unit, 36, fsf_req);
  2174. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2175. zfcp_erp_unit_shutdown(unit, 0, 81, fsf_req);
  2176. }
  2177. }
  2178. retval = 0;
  2179. break;
  2180. }
  2181. skip_fsfstatus:
  2182. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
  2183. return retval;
  2184. }
  2185. /*
  2186. * function: zfcp_fsf_close_unit
  2187. *
  2188. * purpose:
  2189. *
  2190. * returns: address of fsf_req - request successfully initiated
  2191. * NULL -
  2192. *
  2193. * assumptions: This routine does not check whether the associated
  2194. * remote port/lun has already been opened. This should be
  2195. * done by calling routines. Otherwise some status
  2196. * may be presented by FSF
  2197. */
  2198. int
  2199. zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  2200. {
  2201. volatile struct qdio_buffer_element *sbale;
  2202. struct zfcp_fsf_req *fsf_req;
  2203. unsigned long lock_flags;
  2204. int retval = 0;
  2205. /* setup new FSF request */
  2206. retval = zfcp_fsf_req_create(erp_action->adapter,
  2207. FSF_QTCB_CLOSE_LUN,
  2208. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2209. erp_action->adapter->pool.fsf_req_erp,
  2210. &lock_flags, &fsf_req);
  2211. if (retval < 0)
  2212. goto out;
  2213. sbale = zfcp_qdio_sbale_req(fsf_req);
  2214. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2215. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2216. fsf_req->qtcb->header.port_handle = erp_action->port->handle;
  2217. fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
  2218. atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
  2219. fsf_req->data = (unsigned long) erp_action->unit;
  2220. fsf_req->erp_action = erp_action;
  2221. erp_action->fsf_req = fsf_req;
  2222. zfcp_erp_start_timer(fsf_req);
  2223. retval = zfcp_fsf_req_send(erp_action->fsf_req);
  2224. if (retval) {
  2225. zfcp_fsf_req_free(fsf_req);
  2226. erp_action->fsf_req = NULL;
  2227. goto out;
  2228. }
  2229. out:
  2230. write_unlock_irqrestore(&erp_action->adapter->req_q.lock, lock_flags);
  2231. return retval;
  2232. }
  2233. /*
  2234. * function: zfcp_fsf_close_unit_handler
  2235. *
  2236. * purpose: is called for finished Close LUN FSF command
  2237. *
  2238. * returns:
  2239. */
  2240. static int
  2241. zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
  2242. {
  2243. int retval = -EINVAL;
  2244. struct zfcp_unit *unit;
  2245. unit = (struct zfcp_unit *) fsf_req->data;
  2246. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2247. /* don't change unit status in our bookkeeping */
  2248. goto skip_fsfstatus;
  2249. }
  2250. /* evaluate FSF status in QTCB */
  2251. switch (fsf_req->qtcb->header.fsf_status) {
  2252. case FSF_PORT_HANDLE_NOT_VALID:
  2253. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, fsf_req);
  2254. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2255. break;
  2256. case FSF_LUN_HANDLE_NOT_VALID:
  2257. zfcp_erp_port_reopen(unit->port, 0, 111, fsf_req);
  2258. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2259. break;
  2260. case FSF_PORT_BOXED:
  2261. zfcp_erp_port_boxed(unit->port, 52, fsf_req);
  2262. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2263. ZFCP_STATUS_FSFREQ_RETRY;
  2264. break;
  2265. case FSF_ADAPTER_STATUS_AVAILABLE:
  2266. switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
  2267. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  2268. /* re-establish link to port */
  2269. zfcp_test_link(unit->port);
  2270. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2271. break;
  2272. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  2273. /* ERP strategy will escalate */
  2274. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2275. break;
  2276. default:
  2277. break;
  2278. }
  2279. break;
  2280. case FSF_GOOD:
  2281. /* mark unit as closed */
  2282. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  2283. retval = 0;
  2284. break;
  2285. }
  2286. skip_fsfstatus:
  2287. atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
  2288. return retval;
  2289. }
  2290. /**
  2291. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  2292. * @adapter: adapter where scsi command is issued
  2293. * @unit: unit where command is sent to
  2294. * @scsi_cmnd: scsi command to be sent
  2295. * @timer: timer to be started when request is initiated
  2296. * @req_flags: flags for fsf_request
  2297. */
  2298. int
  2299. zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
  2300. struct zfcp_unit *unit,
  2301. struct scsi_cmnd * scsi_cmnd,
  2302. int use_timer, int req_flags)
  2303. {
  2304. struct zfcp_fsf_req *fsf_req = NULL;
  2305. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2306. unsigned int sbtype;
  2307. unsigned long lock_flags;
  2308. int real_bytes = 0;
  2309. int retval = 0;
  2310. int mask;
  2311. /* setup new FSF request */
  2312. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  2313. adapter->pool.fsf_req_scsi,
  2314. &lock_flags, &fsf_req);
  2315. if (unlikely(retval < 0))
  2316. goto failed_req_create;
  2317. if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
  2318. &unit->status))) {
  2319. retval = -EBUSY;
  2320. goto unit_blocked;
  2321. }
  2322. zfcp_unit_get(unit);
  2323. fsf_req->unit = unit;
  2324. /* associate FSF request with SCSI request (for look up on abort) */
  2325. scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
  2326. /* associate SCSI command with FSF request */
  2327. fsf_req->data = (unsigned long) scsi_cmnd;
  2328. /* set handles of unit and its parent port in QTCB */
  2329. fsf_req->qtcb->header.lun_handle = unit->handle;
  2330. fsf_req->qtcb->header.port_handle = unit->port->handle;
  2331. /* FSF does not define the structure of the FCP_CMND IU */
  2332. fcp_cmnd_iu = (struct fcp_cmnd_iu *)
  2333. &(fsf_req->qtcb->bottom.io.fcp_cmnd);
  2334. /*
  2335. * set depending on data direction:
  2336. * data direction bits in SBALE (SB Type)
  2337. * data direction bits in QTCB
  2338. * data direction bits in FCP_CMND IU
  2339. */
  2340. switch (scsi_cmnd->sc_data_direction) {
  2341. case DMA_NONE:
  2342. fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2343. /*
  2344. * FIXME(qdio):
  2345. * what is the correct type for commands
  2346. * without 'real' data buffers?
  2347. */
  2348. sbtype = SBAL_FLAGS0_TYPE_READ;
  2349. break;
  2350. case DMA_FROM_DEVICE:
  2351. fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  2352. sbtype = SBAL_FLAGS0_TYPE_READ;
  2353. fcp_cmnd_iu->rddata = 1;
  2354. break;
  2355. case DMA_TO_DEVICE:
  2356. fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  2357. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  2358. fcp_cmnd_iu->wddata = 1;
  2359. break;
  2360. case DMA_BIDIRECTIONAL:
  2361. default:
  2362. /*
  2363. * dummy, catch this condition earlier
  2364. * in zfcp_scsi_queuecommand
  2365. */
  2366. goto failed_scsi_cmnd;
  2367. }
  2368. /* set FC service class in QTCB (3 per default) */
  2369. fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
  2370. /* set FCP_LUN in FCP_CMND IU in QTCB */
  2371. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2372. mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
  2373. /* set task attributes in FCP_CMND IU in QTCB */
  2374. if (likely((scsi_cmnd->device->simple_tags) ||
  2375. (atomic_test_mask(mask, &unit->status))))
  2376. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  2377. else
  2378. fcp_cmnd_iu->task_attribute = UNTAGGED;
  2379. /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
  2380. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
  2381. fcp_cmnd_iu->add_fcp_cdb_length
  2382. = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  2383. /*
  2384. * copy SCSI CDB (including additional length, if any) to
  2385. * FCP_CDB in FCP_CMND IU in QTCB
  2386. */
  2387. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  2388. /* FCP CMND IU length in QTCB */
  2389. fsf_req->qtcb->bottom.io.fcp_cmnd_length =
  2390. sizeof (struct fcp_cmnd_iu) +
  2391. fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
  2392. /* generate SBALEs from data buffer */
  2393. real_bytes = zfcp_qdio_sbals_from_sg(fsf_req, sbtype,
  2394. scsi_sglist(scsi_cmnd),
  2395. ZFCP_MAX_SBALS_PER_REQ);
  2396. if (unlikely(real_bytes < 0)) {
  2397. if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ)
  2398. retval = -EIO;
  2399. else {
  2400. dev_err(&adapter->ccw_device->dev,
  2401. "SCSI request too large. "
  2402. "Shutting down unit 0x%016Lx on port "
  2403. "0x%016Lx.\n", unit->fcp_lun,
  2404. unit->port->wwpn);
  2405. zfcp_erp_unit_shutdown(unit, 0, 131, fsf_req);
  2406. retval = -EINVAL;
  2407. }
  2408. goto no_fit;
  2409. }
  2410. /* set length of FCP data length in FCP_CMND IU in QTCB */
  2411. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  2412. if (use_timer)
  2413. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  2414. retval = zfcp_fsf_req_send(fsf_req);
  2415. if (unlikely(retval < 0))
  2416. goto send_failed;
  2417. goto success;
  2418. send_failed:
  2419. no_fit:
  2420. failed_scsi_cmnd:
  2421. zfcp_unit_put(unit);
  2422. unit_blocked:
  2423. zfcp_fsf_req_free(fsf_req);
  2424. fsf_req = NULL;
  2425. scsi_cmnd->host_scribble = NULL;
  2426. success:
  2427. failed_req_create:
  2428. write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
  2429. return retval;
  2430. }
  2431. struct zfcp_fsf_req *
  2432. zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
  2433. struct zfcp_unit *unit,
  2434. u8 tm_flags, int req_flags)
  2435. {
  2436. struct zfcp_fsf_req *fsf_req = NULL;
  2437. int retval = 0;
  2438. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2439. unsigned long lock_flags;
  2440. volatile struct qdio_buffer_element *sbale;
  2441. /* setup new FSF request */
  2442. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  2443. adapter->pool.fsf_req_scsi,
  2444. &lock_flags, &fsf_req);
  2445. if (retval < 0)
  2446. goto out;
  2447. if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
  2448. &unit->status)))
  2449. goto unit_blocked;
  2450. /*
  2451. * Used to decide on proper handler in the return path,
  2452. * could be either zfcp_fsf_send_fcp_command_task_handler or
  2453. * zfcp_fsf_send_fcp_command_task_management_handler */
  2454. fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2455. /*
  2456. * hold a pointer to the unit being target of this
  2457. * task management request
  2458. */
  2459. fsf_req->data = (unsigned long) unit;
  2460. /* set FSF related fields in QTCB */
  2461. fsf_req->qtcb->header.lun_handle = unit->handle;
  2462. fsf_req->qtcb->header.port_handle = unit->port->handle;
  2463. fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2464. fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
  2465. fsf_req->qtcb->bottom.io.fcp_cmnd_length =
  2466. sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
  2467. sbale = zfcp_qdio_sbale_req(fsf_req);
  2468. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2469. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2470. /* set FCP related fields in FCP_CMND IU in QTCB */
  2471. fcp_cmnd_iu = (struct fcp_cmnd_iu *)
  2472. &(fsf_req->qtcb->bottom.io.fcp_cmnd);
  2473. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2474. fcp_cmnd_iu->task_management_flags = tm_flags;
  2475. zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
  2476. retval = zfcp_fsf_req_send(fsf_req);
  2477. if (!retval)
  2478. goto out;
  2479. unit_blocked:
  2480. zfcp_fsf_req_free(fsf_req);
  2481. fsf_req = NULL;
  2482. out:
  2483. write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
  2484. return fsf_req;
  2485. }
  2486. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  2487. {
  2488. lat_rec->sum += lat;
  2489. if (lat_rec->min > lat)
  2490. lat_rec->min = lat;
  2491. if (lat_rec->max < lat)
  2492. lat_rec->max = lat;
  2493. }
  2494. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *fsf_req)
  2495. {
  2496. struct fsf_qual_latency_info *lat_inf;
  2497. struct latency_cont *lat;
  2498. struct zfcp_unit *unit;
  2499. unsigned long flags;
  2500. lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
  2501. unit = fsf_req->unit;
  2502. switch (fsf_req->qtcb->bottom.io.data_direction) {
  2503. case FSF_DATADIR_READ:
  2504. lat = &unit->latencies.read;
  2505. break;
  2506. case FSF_DATADIR_WRITE:
  2507. lat = &unit->latencies.write;
  2508. break;
  2509. case FSF_DATADIR_CMND:
  2510. lat = &unit->latencies.cmd;
  2511. break;
  2512. default:
  2513. return;
  2514. }
  2515. spin_lock_irqsave(&unit->latencies.lock, flags);
  2516. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  2517. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  2518. lat->counter++;
  2519. spin_unlock_irqrestore(&unit->latencies.lock, flags);
  2520. }
  2521. /*
  2522. * function: zfcp_fsf_send_fcp_command_handler
  2523. *
  2524. * purpose: is called for finished Send FCP Command
  2525. *
  2526. * returns:
  2527. */
  2528. static int
  2529. zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
  2530. {
  2531. int retval = -EINVAL;
  2532. struct zfcp_unit *unit;
  2533. struct fsf_qtcb_header *header;
  2534. header = &fsf_req->qtcb->header;
  2535. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  2536. unit = (struct zfcp_unit *) fsf_req->data;
  2537. else
  2538. unit = fsf_req->unit;
  2539. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  2540. /* go directly to calls of special handlers */
  2541. goto skip_fsfstatus;
  2542. }
  2543. /* evaluate FSF status in QTCB */
  2544. switch (header->fsf_status) {
  2545. case FSF_PORT_HANDLE_NOT_VALID:
  2546. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, fsf_req);
  2547. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2548. break;
  2549. case FSF_LUN_HANDLE_NOT_VALID:
  2550. zfcp_erp_port_reopen(unit->port, 0, 113, fsf_req);
  2551. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2552. break;
  2553. case FSF_HANDLE_MISMATCH:
  2554. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 114, fsf_req);
  2555. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2556. break;
  2557. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  2558. zfcp_fsf_class_not_supp(fsf_req);
  2559. break;
  2560. case FSF_FCPLUN_NOT_VALID:
  2561. zfcp_erp_port_reopen(unit->port, 0, 115, fsf_req);
  2562. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2563. break;
  2564. case FSF_ACCESS_DENIED:
  2565. zfcp_fsf_access_denied_unit(fsf_req, unit);
  2566. break;
  2567. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  2568. dev_err(&fsf_req->adapter->ccw_device->dev,
  2569. "Invalid data direction (%d) given for unit 0x%016Lx "
  2570. "on port 0x%016Lx, shutting down adapter.\n",
  2571. fsf_req->qtcb->bottom.io.data_direction,
  2572. unit->fcp_lun, unit->port->wwpn);
  2573. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, fsf_req);
  2574. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2575. break;
  2576. case FSF_CMND_LENGTH_NOT_VALID:
  2577. dev_err(&fsf_req->adapter->ccw_device->dev,
  2578. "An invalid control-data-block length field (%d) "
  2579. "was found in a command for unit 0x%016Lx on port "
  2580. "0x%016Lx. Shutting down adapter.\n",
  2581. fsf_req->qtcb->bottom.io.fcp_cmnd_length,
  2582. unit->fcp_lun, unit->port->wwpn);
  2583. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, fsf_req);
  2584. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2585. break;
  2586. case FSF_PORT_BOXED:
  2587. zfcp_erp_port_boxed(unit->port, 53, fsf_req);
  2588. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2589. ZFCP_STATUS_FSFREQ_RETRY;
  2590. break;
  2591. case FSF_LUN_BOXED:
  2592. zfcp_erp_unit_boxed(unit, 54, fsf_req);
  2593. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
  2594. | ZFCP_STATUS_FSFREQ_RETRY;
  2595. break;
  2596. case FSF_ADAPTER_STATUS_AVAILABLE:
  2597. switch (header->fsf_status_qual.word[0]) {
  2598. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  2599. /* re-establish link to port */
  2600. zfcp_test_link(unit->port);
  2601. break;
  2602. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  2603. /* FIXME(hw) need proper specs for proper action */
  2604. /* let scsi stack deal with retries and escalation */
  2605. break;
  2606. }
  2607. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2608. break;
  2609. case FSF_GOOD:
  2610. break;
  2611. case FSF_FCP_RSP_AVAILABLE:
  2612. break;
  2613. }
  2614. skip_fsfstatus:
  2615. if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
  2616. retval =
  2617. zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
  2618. } else {
  2619. retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
  2620. fsf_req->unit = NULL;
  2621. zfcp_unit_put(unit);
  2622. }
  2623. return retval;
  2624. }
  2625. /*
  2626. * function: zfcp_fsf_send_fcp_command_task_handler
  2627. *
  2628. * purpose: evaluates FCP_RSP IU
  2629. *
  2630. * returns:
  2631. */
  2632. static int
  2633. zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
  2634. {
  2635. int retval = 0;
  2636. struct scsi_cmnd *scpnt;
  2637. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  2638. &(fsf_req->qtcb->bottom.io.fcp_rsp);
  2639. u32 sns_len;
  2640. char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
  2641. unsigned long flags;
  2642. read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
  2643. scpnt = (struct scsi_cmnd *) fsf_req->data;
  2644. if (unlikely(!scpnt))
  2645. goto out;
  2646. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  2647. /* FIXME: (design) mid-layer should handle DID_ABORT like
  2648. * DID_SOFT_ERROR by retrying the request for devices
  2649. * that allow retries.
  2650. */
  2651. set_host_byte(&scpnt->result, DID_SOFT_ERROR);
  2652. set_driver_byte(&scpnt->result, SUGGEST_RETRY);
  2653. goto skip_fsfstatus;
  2654. }
  2655. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  2656. set_host_byte(&scpnt->result, DID_ERROR);
  2657. goto skip_fsfstatus;
  2658. }
  2659. /* set message byte of result in SCSI command */
  2660. scpnt->result |= COMMAND_COMPLETE << 8;
  2661. /*
  2662. * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
  2663. * of result in SCSI command
  2664. */
  2665. scpnt->result |= fcp_rsp_iu->scsi_status;
  2666. if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  2667. zfcp_fsf_req_latency(fsf_req);
  2668. /* check FCP_RSP_INFO */
  2669. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  2670. switch (fcp_rsp_info[3]) {
  2671. case RSP_CODE_GOOD:
  2672. /* ok, continue */
  2673. set_host_byte(&scpnt->result, DID_OK);
  2674. break;
  2675. case RSP_CODE_LENGTH_MISMATCH:
  2676. /* hardware bug */
  2677. set_host_byte(&scpnt->result, DID_ERROR);
  2678. goto skip_fsfstatus;
  2679. case RSP_CODE_FIELD_INVALID:
  2680. /* driver or hardware bug */
  2681. set_host_byte(&scpnt->result, DID_ERROR);
  2682. goto skip_fsfstatus;
  2683. case RSP_CODE_RO_MISMATCH:
  2684. /* hardware bug */
  2685. set_host_byte(&scpnt->result, DID_ERROR);
  2686. goto skip_fsfstatus;
  2687. default:
  2688. /* invalid FCP response code */
  2689. set_host_byte(&scpnt->result, DID_ERROR);
  2690. goto skip_fsfstatus;
  2691. }
  2692. }
  2693. /* check for sense data */
  2694. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  2695. sns_len = FSF_FCP_RSP_SIZE -
  2696. sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
  2697. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  2698. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  2699. memcpy(scpnt->sense_buffer,
  2700. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  2701. }
  2702. /* check for underrun */
  2703. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  2704. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  2705. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  2706. scpnt->underflow)
  2707. set_host_byte(&scpnt->result, DID_ERROR);
  2708. }
  2709. skip_fsfstatus:
  2710. if (scpnt->result != 0)
  2711. zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
  2712. else if (scpnt->retries > 0)
  2713. zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
  2714. else
  2715. zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
  2716. /* cleanup pointer (need this especially for abort) */
  2717. scpnt->host_scribble = NULL;
  2718. /* always call back */
  2719. (scpnt->scsi_done) (scpnt);
  2720. /*
  2721. * We must hold this lock until scsi_done has been called.
  2722. * Otherwise we may call scsi_done after abort regarding this
  2723. * command has completed.
  2724. * Note: scsi_done must not block!
  2725. */
  2726. out:
  2727. read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
  2728. return retval;
  2729. }
  2730. /*
  2731. * function: zfcp_fsf_send_fcp_command_task_management_handler
  2732. *
  2733. * purpose: evaluates FCP_RSP IU
  2734. *
  2735. * returns:
  2736. */
  2737. static int
  2738. zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
  2739. {
  2740. int retval = 0;
  2741. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  2742. &(fsf_req->qtcb->bottom.io.fcp_rsp);
  2743. char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
  2744. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2745. fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  2746. goto skip_fsfstatus;
  2747. }
  2748. /* check FCP_RSP_INFO */
  2749. switch (fcp_rsp_info[3]) {
  2750. case RSP_CODE_GOOD:
  2751. /* ok, continue */
  2752. break;
  2753. case RSP_CODE_TASKMAN_UNSUPP:
  2754. fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
  2755. break;
  2756. case RSP_CODE_TASKMAN_FAILED:
  2757. fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  2758. break;
  2759. default:
  2760. /* invalid FCP response code */
  2761. fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  2762. }
  2763. skip_fsfstatus:
  2764. return retval;
  2765. }
  2766. /*
  2767. * function: zfcp_fsf_control_file
  2768. *
  2769. * purpose: Initiator of the control file upload/download FSF requests
  2770. *
  2771. * returns: 0 - FSF request is successfuly created and queued
  2772. * -EOPNOTSUPP - The FCP adapter does not have Control File support
  2773. * -EINVAL - Invalid direction specified
  2774. * -ENOMEM - Insufficient memory
  2775. * -EPERM - Cannot create FSF request or place it in QDIO queue
  2776. */
  2777. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2778. struct zfcp_fsf_cfdc *fsf_cfdc)
  2779. {
  2780. struct zfcp_fsf_req *fsf_req;
  2781. struct fsf_qtcb_bottom_support *bottom;
  2782. volatile struct qdio_buffer_element *sbale;
  2783. unsigned long lock_flags;
  2784. int direction;
  2785. int retval;
  2786. int bytes;
  2787. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2788. return ERR_PTR(-EOPNOTSUPP);
  2789. switch (fsf_cfdc->command) {
  2790. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2791. direction = SBAL_FLAGS0_TYPE_WRITE;
  2792. break;
  2793. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2794. direction = SBAL_FLAGS0_TYPE_READ;
  2795. break;
  2796. default:
  2797. return ERR_PTR(-EINVAL);
  2798. }
  2799. retval = zfcp_fsf_req_create(adapter, fsf_cfdc->command,
  2800. ZFCP_WAIT_FOR_SBAL,
  2801. NULL, &lock_flags, &fsf_req);
  2802. if (retval < 0) {
  2803. retval = -EPERM;
  2804. goto unlock_queue_lock;
  2805. }
  2806. sbale = zfcp_qdio_sbale_req(fsf_req);
  2807. sbale[0].flags |= direction;
  2808. bottom = &fsf_req->qtcb->bottom.support;
  2809. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2810. bottom->option = fsf_cfdc->option;
  2811. bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
  2812. fsf_cfdc->sg,
  2813. ZFCP_MAX_SBALS_PER_REQ);
  2814. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2815. retval = -ENOMEM;
  2816. goto free_fsf_req;
  2817. }
  2818. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  2819. retval = zfcp_fsf_req_send(fsf_req);
  2820. if (retval < 0) {
  2821. retval = -EPERM;
  2822. goto free_fsf_req;
  2823. }
  2824. write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
  2825. wait_event(fsf_req->completion_wq,
  2826. fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2827. return fsf_req;
  2828. free_fsf_req:
  2829. zfcp_fsf_req_free(fsf_req);
  2830. unlock_queue_lock:
  2831. write_unlock_irqrestore(&adapter->req_q.lock, lock_flags);
  2832. return ERR_PTR(retval);
  2833. }
  2834. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
  2835. {
  2836. if (fsf_req->qtcb->header.fsf_status != FSF_GOOD)
  2837. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2838. }
  2839. static inline int
  2840. zfcp_fsf_req_sbal_check(unsigned long *flags,
  2841. struct zfcp_qdio_queue *queue, int needed)
  2842. {
  2843. write_lock_irqsave(&queue->lock, *flags);
  2844. if (likely(atomic_read(&queue->count) >= needed))
  2845. return 1;
  2846. write_unlock_irqrestore(&queue->lock, *flags);
  2847. return 0;
  2848. }
  2849. /*
  2850. * set qtcb pointer in fsf_req and initialize QTCB
  2851. */
  2852. static void
  2853. zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
  2854. {
  2855. if (likely(fsf_req->qtcb != NULL)) {
  2856. fsf_req->qtcb->prefix.req_seq_no =
  2857. fsf_req->adapter->fsf_req_seq_no;
  2858. fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
  2859. fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
  2860. fsf_req->qtcb->prefix.qtcb_type =
  2861. fsf_qtcb_type[fsf_req->fsf_command];
  2862. fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
  2863. fsf_req->qtcb->header.req_handle = fsf_req->req_id;
  2864. fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
  2865. }
  2866. }
  2867. /**
  2868. * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
  2869. * @adapter: adapter for which request queue is examined
  2870. * @req_flags: flags indicating whether to wait for needed SBAL or not
  2871. * @lock_flags: lock_flags if queue_lock is taken
  2872. * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
  2873. * Locks: lock adapter->req_q->lock on success
  2874. */
  2875. static int
  2876. zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
  2877. unsigned long *lock_flags)
  2878. {
  2879. long ret;
  2880. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  2881. if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
  2882. ret = wait_event_interruptible_timeout(adapter->request_wq,
  2883. zfcp_fsf_req_sbal_check(lock_flags, req_q, 1),
  2884. ZFCP_SBAL_TIMEOUT);
  2885. if (ret < 0)
  2886. return ret;
  2887. if (!ret)
  2888. return -EIO;
  2889. } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_q, 1))
  2890. return -EIO;
  2891. return 0;
  2892. }
  2893. /*
  2894. * function: zfcp_fsf_req_create
  2895. *
  2896. * purpose: create an FSF request at the specified adapter and
  2897. * setup common fields
  2898. *
  2899. * returns: -ENOMEM if there was insufficient memory for a request
  2900. * -EIO if no qdio buffers could be allocate to the request
  2901. * -EINVAL/-EPERM on bug conditions in req_dequeue
  2902. * 0 in success
  2903. *
  2904. * note: The created request is returned by reference.
  2905. *
  2906. * locks: lock of concerned request queue must not be held,
  2907. * but is held on completion (write, irqsave)
  2908. */
  2909. int
  2910. zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
  2911. mempool_t *pool, unsigned long *lock_flags,
  2912. struct zfcp_fsf_req **fsf_req_p)
  2913. {
  2914. volatile struct qdio_buffer_element *sbale;
  2915. struct zfcp_fsf_req *fsf_req = NULL;
  2916. int ret = 0;
  2917. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  2918. /* allocate new FSF request */
  2919. fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
  2920. if (unlikely(!fsf_req)) {
  2921. ret = -ENOMEM;
  2922. goto failed_fsf_req;
  2923. }
  2924. fsf_req->adapter = adapter;
  2925. fsf_req->fsf_command = fsf_cmd;
  2926. INIT_LIST_HEAD(&fsf_req->list);
  2927. init_timer(&fsf_req->timer);
  2928. /* initialize waitqueue which may be used to wait on
  2929. this request completion */
  2930. init_waitqueue_head(&fsf_req->completion_wq);
  2931. ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
  2932. if (ret < 0)
  2933. goto failed_sbals;
  2934. /* this is serialized (we are holding req_queue-lock of adapter) */
  2935. if (adapter->req_no == 0)
  2936. adapter->req_no++;
  2937. fsf_req->req_id = adapter->req_no++;
  2938. zfcp_fsf_req_qtcb_init(fsf_req);
  2939. /*
  2940. * We hold queue_lock here. Check if QDIOUP is set and let request fail
  2941. * if it is not set (see also *_open_qdio and *_close_qdio).
  2942. */
  2943. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
  2944. write_unlock_irqrestore(&req_q->lock, *lock_flags);
  2945. ret = -EIO;
  2946. goto failed_sbals;
  2947. }
  2948. if (fsf_req->qtcb) {
  2949. fsf_req->seq_no = adapter->fsf_req_seq_no;
  2950. fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  2951. }
  2952. fsf_req->sbal_number = 1;
  2953. fsf_req->sbal_first = req_q->first;
  2954. fsf_req->sbal_last = req_q->first;
  2955. fsf_req->sbale_curr = 1;
  2956. if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
  2957. fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  2958. }
  2959. sbale = zfcp_qdio_sbale_req(fsf_req);
  2960. /* setup common SBALE fields */
  2961. sbale[0].addr = (void *) fsf_req->req_id;
  2962. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  2963. if (likely(fsf_req->qtcb != NULL)) {
  2964. sbale[1].addr = (void *) fsf_req->qtcb;
  2965. sbale[1].length = sizeof(struct fsf_qtcb);
  2966. }
  2967. goto success;
  2968. failed_sbals:
  2969. /* dequeue new FSF request previously enqueued */
  2970. zfcp_fsf_req_free(fsf_req);
  2971. fsf_req = NULL;
  2972. failed_fsf_req:
  2973. write_lock_irqsave(&req_q->lock, *lock_flags);
  2974. success:
  2975. *fsf_req_p = fsf_req;
  2976. return ret;
  2977. }
  2978. /*
  2979. * function: zfcp_fsf_req_send
  2980. *
  2981. * purpose: start transfer of FSF request via QDIO
  2982. *
  2983. * returns: 0 - request transfer succesfully started
  2984. * !0 - start of request transfer failed
  2985. */
  2986. static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
  2987. {
  2988. struct zfcp_adapter *adapter;
  2989. struct zfcp_qdio_queue *req_q;
  2990. volatile struct qdio_buffer_element *sbale;
  2991. int inc_seq_no;
  2992. int retval = 0;
  2993. adapter = fsf_req->adapter;
  2994. req_q = &adapter->req_q;
  2995. sbale = zfcp_qdio_sbale_req(fsf_req);
  2996. /* put allocated FSF request into hash table */
  2997. spin_lock(&adapter->req_list_lock);
  2998. zfcp_reqlist_add(adapter, fsf_req);
  2999. spin_unlock(&adapter->req_list_lock);
  3000. inc_seq_no = (fsf_req->qtcb != NULL);
  3001. fsf_req->issued = get_clock();
  3002. retval = zfcp_qdio_send(fsf_req);
  3003. if (unlikely(retval)) {
  3004. /* Queues are down..... */
  3005. del_timer(&fsf_req->timer);
  3006. spin_lock(&adapter->req_list_lock);
  3007. zfcp_reqlist_remove(adapter, fsf_req);
  3008. spin_unlock(&adapter->req_list_lock);
  3009. /* undo changes in request queue made for this request */
  3010. atomic_add(fsf_req->sbal_number, &req_q->count);
  3011. req_q->first -= fsf_req->sbal_number;
  3012. req_q->first += QDIO_MAX_BUFFERS_PER_Q;
  3013. req_q->first %= QDIO_MAX_BUFFERS_PER_Q;
  3014. zfcp_erp_adapter_reopen(adapter, 0, 116, fsf_req);
  3015. retval = -EIO;
  3016. } else {
  3017. /*
  3018. * increase FSF sequence counter -
  3019. * this must only be done for request successfully enqueued to
  3020. * QDIO this rejected requests may be cleaned up by calling
  3021. * routines resulting in missing sequence counter values
  3022. * otherwise,
  3023. */
  3024. /* Don't increase for unsolicited status */
  3025. if (inc_seq_no)
  3026. adapter->fsf_req_seq_no++;
  3027. }
  3028. return retval;
  3029. }