zfcp_fsf.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2009
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/blktrace_api.h>
  11. #include "zfcp_ext.h"
  12. #include "zfcp_dbf.h"
  13. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  14. {
  15. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  16. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  17. "fsrth_1", NULL);
  18. }
  19. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  20. unsigned long timeout)
  21. {
  22. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  23. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  24. fsf_req->timer.expires = jiffies + timeout;
  25. add_timer(&fsf_req->timer);
  26. }
  27. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  28. {
  29. BUG_ON(!fsf_req->erp_action);
  30. fsf_req->timer.function = zfcp_erp_timeout_handler;
  31. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  32. fsf_req->timer.expires = jiffies + 30 * HZ;
  33. add_timer(&fsf_req->timer);
  34. }
  35. /* association between FSF command and FSF QTCB type */
  36. static u32 fsf_qtcb_type[] = {
  37. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  38. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  39. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  40. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  41. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  42. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  43. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  44. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  45. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  47. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  48. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  49. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  50. };
  51. static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
  52. {
  53. u16 subtable = table >> 16;
  54. u16 rule = table & 0xffff;
  55. const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
  56. if (subtable && subtable < ARRAY_SIZE(act_type))
  57. dev_warn(&adapter->ccw_device->dev,
  58. "Access denied according to ACT rule type %s, "
  59. "rule %d\n", act_type[subtable], rule);
  60. }
  61. static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
  62. struct zfcp_port *port)
  63. {
  64. struct fsf_qtcb_header *header = &req->qtcb->header;
  65. dev_warn(&req->adapter->ccw_device->dev,
  66. "Access denied to port 0x%016Lx\n",
  67. (unsigned long long)port->wwpn);
  68. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  69. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  70. zfcp_erp_port_access_denied(port, "fspad_1", req);
  71. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  72. }
  73. static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
  74. struct zfcp_unit *unit)
  75. {
  76. struct fsf_qtcb_header *header = &req->qtcb->header;
  77. dev_warn(&req->adapter->ccw_device->dev,
  78. "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
  79. (unsigned long long)unit->fcp_lun,
  80. (unsigned long long)unit->port->wwpn);
  81. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  82. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  83. zfcp_erp_unit_access_denied(unit, "fsuad_1", req);
  84. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  85. }
  86. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  87. {
  88. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  89. "operational because of an unsupported FC class\n");
  90. zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1", req);
  91. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  92. }
  93. /**
  94. * zfcp_fsf_req_free - free memory used by fsf request
  95. * @fsf_req: pointer to struct zfcp_fsf_req
  96. */
  97. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  98. {
  99. if (likely(req->pool)) {
  100. if (likely(req->qtcb))
  101. mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
  102. mempool_free(req, req->pool);
  103. return;
  104. }
  105. if (likely(req->qtcb))
  106. kmem_cache_free(zfcp_data.qtcb_cache, req->qtcb);
  107. kfree(req);
  108. }
  109. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  110. {
  111. struct fsf_status_read_buffer *sr_buf = req->data;
  112. struct zfcp_adapter *adapter = req->adapter;
  113. struct zfcp_port *port;
  114. int d_id = sr_buf->d_id & ZFCP_DID_MASK;
  115. unsigned long flags;
  116. read_lock_irqsave(&zfcp_data.config_lock, flags);
  117. list_for_each_entry(port, &adapter->port_list_head, list)
  118. if (port->d_id == d_id) {
  119. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  120. zfcp_erp_port_reopen(port, 0, "fssrpc1", req);
  121. return;
  122. }
  123. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  124. }
  125. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, char *id,
  126. struct fsf_link_down_info *link_down)
  127. {
  128. struct zfcp_adapter *adapter = req->adapter;
  129. unsigned long flags;
  130. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  131. return;
  132. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  133. read_lock_irqsave(&zfcp_data.config_lock, flags);
  134. zfcp_scsi_schedule_rports_block(adapter);
  135. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  136. if (!link_down)
  137. goto out;
  138. switch (link_down->error_code) {
  139. case FSF_PSQ_LINK_NO_LIGHT:
  140. dev_warn(&req->adapter->ccw_device->dev,
  141. "There is no light signal from the local "
  142. "fibre channel cable\n");
  143. break;
  144. case FSF_PSQ_LINK_WRAP_PLUG:
  145. dev_warn(&req->adapter->ccw_device->dev,
  146. "There is a wrap plug instead of a fibre "
  147. "channel cable\n");
  148. break;
  149. case FSF_PSQ_LINK_NO_FCP:
  150. dev_warn(&req->adapter->ccw_device->dev,
  151. "The adjacent fibre channel node does not "
  152. "support FCP\n");
  153. break;
  154. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  155. dev_warn(&req->adapter->ccw_device->dev,
  156. "The FCP device is suspended because of a "
  157. "firmware update\n");
  158. break;
  159. case FSF_PSQ_LINK_INVALID_WWPN:
  160. dev_warn(&req->adapter->ccw_device->dev,
  161. "The FCP device detected a WWPN that is "
  162. "duplicate or not valid\n");
  163. break;
  164. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  165. dev_warn(&req->adapter->ccw_device->dev,
  166. "The fibre channel fabric does not support NPIV\n");
  167. break;
  168. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  169. dev_warn(&req->adapter->ccw_device->dev,
  170. "The FCP adapter cannot support more NPIV ports\n");
  171. break;
  172. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  173. dev_warn(&req->adapter->ccw_device->dev,
  174. "The adjacent switch cannot support "
  175. "more NPIV ports\n");
  176. break;
  177. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  178. dev_warn(&req->adapter->ccw_device->dev,
  179. "The FCP adapter could not log in to the "
  180. "fibre channel fabric\n");
  181. break;
  182. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  183. dev_warn(&req->adapter->ccw_device->dev,
  184. "The WWPN assignment file on the FCP adapter "
  185. "has been damaged\n");
  186. break;
  187. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  188. dev_warn(&req->adapter->ccw_device->dev,
  189. "The mode table on the FCP adapter "
  190. "has been damaged\n");
  191. break;
  192. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  193. dev_warn(&req->adapter->ccw_device->dev,
  194. "All NPIV ports on the FCP adapter have "
  195. "been assigned\n");
  196. break;
  197. default:
  198. dev_warn(&req->adapter->ccw_device->dev,
  199. "The link between the FCP adapter and "
  200. "the FC fabric is down\n");
  201. }
  202. out:
  203. zfcp_erp_adapter_failed(adapter, id, req);
  204. }
  205. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  206. {
  207. struct fsf_status_read_buffer *sr_buf = req->data;
  208. struct fsf_link_down_info *ldi =
  209. (struct fsf_link_down_info *) &sr_buf->payload;
  210. switch (sr_buf->status_subtype) {
  211. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  212. zfcp_fsf_link_down_info_eval(req, "fssrld1", ldi);
  213. break;
  214. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  215. zfcp_fsf_link_down_info_eval(req, "fssrld2", ldi);
  216. break;
  217. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  218. zfcp_fsf_link_down_info_eval(req, "fssrld3", NULL);
  219. };
  220. }
  221. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  222. {
  223. struct zfcp_adapter *adapter = req->adapter;
  224. struct fsf_status_read_buffer *sr_buf = req->data;
  225. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  226. zfcp_dbf_hba_fsf_unsol("dism", adapter->dbf, sr_buf);
  227. mempool_free(sr_buf, adapter->pool.status_read_data);
  228. zfcp_fsf_req_free(req);
  229. return;
  230. }
  231. zfcp_dbf_hba_fsf_unsol("read", adapter->dbf, sr_buf);
  232. switch (sr_buf->status_type) {
  233. case FSF_STATUS_READ_PORT_CLOSED:
  234. zfcp_fsf_status_read_port_closed(req);
  235. break;
  236. case FSF_STATUS_READ_INCOMING_ELS:
  237. zfcp_fc_incoming_els(req);
  238. break;
  239. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  240. break;
  241. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  242. dev_warn(&adapter->ccw_device->dev,
  243. "The error threshold for checksum statistics "
  244. "has been exceeded\n");
  245. zfcp_dbf_hba_berr(adapter->dbf, req);
  246. break;
  247. case FSF_STATUS_READ_LINK_DOWN:
  248. zfcp_fsf_status_read_link_down(req);
  249. break;
  250. case FSF_STATUS_READ_LINK_UP:
  251. dev_info(&adapter->ccw_device->dev,
  252. "The local link has been restored\n");
  253. /* All ports should be marked as ready to run again */
  254. zfcp_erp_modify_adapter_status(adapter, "fssrh_1", NULL,
  255. ZFCP_STATUS_COMMON_RUNNING,
  256. ZFCP_SET);
  257. zfcp_erp_adapter_reopen(adapter,
  258. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  259. ZFCP_STATUS_COMMON_ERP_FAILED,
  260. "fssrh_2", req);
  261. break;
  262. case FSF_STATUS_READ_NOTIFICATION_LOST:
  263. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  264. zfcp_erp_adapter_access_changed(adapter, "fssrh_3",
  265. req);
  266. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  267. schedule_work(&adapter->scan_work);
  268. break;
  269. case FSF_STATUS_READ_CFDC_UPDATED:
  270. zfcp_erp_adapter_access_changed(adapter, "fssrh_4", req);
  271. break;
  272. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  273. adapter->adapter_features = sr_buf->payload.word[0];
  274. break;
  275. }
  276. mempool_free(sr_buf, adapter->pool.status_read_data);
  277. zfcp_fsf_req_free(req);
  278. atomic_inc(&adapter->stat_miss);
  279. queue_work(adapter->work_queue, &adapter->stat_work);
  280. }
  281. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  282. {
  283. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  284. case FSF_SQ_FCP_RSP_AVAILABLE:
  285. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  286. case FSF_SQ_NO_RETRY_POSSIBLE:
  287. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  288. return;
  289. case FSF_SQ_COMMAND_ABORTED:
  290. req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
  291. break;
  292. case FSF_SQ_NO_RECOM:
  293. dev_err(&req->adapter->ccw_device->dev,
  294. "The FCP adapter reported a problem "
  295. "that cannot be recovered\n");
  296. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1", req);
  297. break;
  298. }
  299. /* all non-return stats set FSFREQ_ERROR*/
  300. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  301. }
  302. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  303. {
  304. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  305. return;
  306. switch (req->qtcb->header.fsf_status) {
  307. case FSF_UNKNOWN_COMMAND:
  308. dev_err(&req->adapter->ccw_device->dev,
  309. "The FCP adapter does not recognize the command 0x%x\n",
  310. req->qtcb->header.fsf_command);
  311. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1", req);
  312. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  313. break;
  314. case FSF_ADAPTER_STATUS_AVAILABLE:
  315. zfcp_fsf_fsfstatus_qual_eval(req);
  316. break;
  317. }
  318. }
  319. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  320. {
  321. struct zfcp_adapter *adapter = req->adapter;
  322. struct fsf_qtcb *qtcb = req->qtcb;
  323. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  324. zfcp_dbf_hba_fsf_response(req);
  325. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  326. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  327. ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
  328. return;
  329. }
  330. switch (qtcb->prefix.prot_status) {
  331. case FSF_PROT_GOOD:
  332. case FSF_PROT_FSF_STATUS_PRESENTED:
  333. return;
  334. case FSF_PROT_QTCB_VERSION_ERROR:
  335. dev_err(&adapter->ccw_device->dev,
  336. "QTCB version 0x%x not supported by FCP adapter "
  337. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  338. psq->word[0], psq->word[1]);
  339. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1", req);
  340. break;
  341. case FSF_PROT_ERROR_STATE:
  342. case FSF_PROT_SEQ_NUMB_ERROR:
  343. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2", req);
  344. req->status |= ZFCP_STATUS_FSFREQ_RETRY;
  345. break;
  346. case FSF_PROT_UNSUPP_QTCB_TYPE:
  347. dev_err(&adapter->ccw_device->dev,
  348. "The QTCB type is not supported by the FCP adapter\n");
  349. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3", req);
  350. break;
  351. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  352. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  353. &adapter->status);
  354. break;
  355. case FSF_PROT_DUPLICATE_REQUEST_ID:
  356. dev_err(&adapter->ccw_device->dev,
  357. "0x%Lx is an ambiguous request identifier\n",
  358. (unsigned long long)qtcb->bottom.support.req_handle);
  359. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4", req);
  360. break;
  361. case FSF_PROT_LINK_DOWN:
  362. zfcp_fsf_link_down_info_eval(req, "fspse_5",
  363. &psq->link_down_info);
  364. /* FIXME: reopening adapter now? better wait for link up */
  365. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6", req);
  366. break;
  367. case FSF_PROT_REEST_QUEUE:
  368. /* All ports should be marked as ready to run again */
  369. zfcp_erp_modify_adapter_status(adapter, "fspse_7", NULL,
  370. ZFCP_STATUS_COMMON_RUNNING,
  371. ZFCP_SET);
  372. zfcp_erp_adapter_reopen(adapter,
  373. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  374. ZFCP_STATUS_COMMON_ERP_FAILED,
  375. "fspse_8", req);
  376. break;
  377. default:
  378. dev_err(&adapter->ccw_device->dev,
  379. "0x%x is not a valid transfer protocol status\n",
  380. qtcb->prefix.prot_status);
  381. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9", req);
  382. }
  383. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  384. }
  385. /**
  386. * zfcp_fsf_req_complete - process completion of a FSF request
  387. * @fsf_req: The FSF request that has been completed.
  388. *
  389. * When a request has been completed either from the FCP adapter,
  390. * or it has been dismissed due to a queue shutdown, this function
  391. * is called to process the completion status and trigger further
  392. * events related to the FSF request.
  393. */
  394. static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  395. {
  396. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  397. zfcp_fsf_status_read_handler(req);
  398. return;
  399. }
  400. del_timer(&req->timer);
  401. zfcp_fsf_protstatus_eval(req);
  402. zfcp_fsf_fsfstatus_eval(req);
  403. req->handler(req);
  404. if (req->erp_action)
  405. zfcp_erp_notify(req->erp_action, 0);
  406. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  407. zfcp_fsf_req_free(req);
  408. else
  409. complete(&req->completion);
  410. }
  411. /**
  412. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  413. * @adapter: pointer to struct zfcp_adapter
  414. *
  415. * Never ever call this without shutting down the adapter first.
  416. * Otherwise the adapter would continue using and corrupting s390 storage.
  417. * Included BUG_ON() call to ensure this is done.
  418. * ERP is supposed to be the only user of this function.
  419. */
  420. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  421. {
  422. struct zfcp_fsf_req *req, *tmp;
  423. unsigned long flags;
  424. LIST_HEAD(remove_queue);
  425. unsigned int i;
  426. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  427. spin_lock_irqsave(&adapter->req_list_lock, flags);
  428. for (i = 0; i < REQUEST_LIST_SIZE; i++)
  429. list_splice_init(&adapter->req_list[i], &remove_queue);
  430. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  431. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  432. list_del(&req->list);
  433. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  434. zfcp_fsf_req_complete(req);
  435. }
  436. }
  437. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  438. {
  439. struct fsf_qtcb_bottom_config *bottom;
  440. struct zfcp_adapter *adapter = req->adapter;
  441. struct Scsi_Host *shost = adapter->scsi_host;
  442. bottom = &req->qtcb->bottom.config;
  443. if (req->data)
  444. memcpy(req->data, bottom, sizeof(*bottom));
  445. fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
  446. fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
  447. fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
  448. fc_host_speed(shost) = bottom->fc_link_speed;
  449. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  450. adapter->hydra_version = bottom->adapter_type;
  451. adapter->timer_ticks = bottom->timer_interval;
  452. if (fc_host_permanent_port_name(shost) == -1)
  453. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  454. switch (bottom->fc_topology) {
  455. case FSF_TOPO_P2P:
  456. adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
  457. adapter->peer_wwpn = bottom->plogi_payload.wwpn;
  458. adapter->peer_wwnn = bottom->plogi_payload.wwnn;
  459. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  460. break;
  461. case FSF_TOPO_FABRIC:
  462. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  463. break;
  464. case FSF_TOPO_AL:
  465. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  466. /* fall through */
  467. default:
  468. dev_err(&adapter->ccw_device->dev,
  469. "Unknown or unsupported arbitrated loop "
  470. "fibre channel topology detected\n");
  471. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1", req);
  472. return -EIO;
  473. }
  474. return 0;
  475. }
  476. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  477. {
  478. struct zfcp_adapter *adapter = req->adapter;
  479. struct fsf_qtcb *qtcb = req->qtcb;
  480. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  481. struct Scsi_Host *shost = adapter->scsi_host;
  482. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  483. return;
  484. adapter->fsf_lic_version = bottom->lic_version;
  485. adapter->adapter_features = bottom->adapter_features;
  486. adapter->connection_features = bottom->connection_features;
  487. adapter->peer_wwpn = 0;
  488. adapter->peer_wwnn = 0;
  489. adapter->peer_d_id = 0;
  490. switch (qtcb->header.fsf_status) {
  491. case FSF_GOOD:
  492. if (zfcp_fsf_exchange_config_evaluate(req))
  493. return;
  494. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  495. dev_err(&adapter->ccw_device->dev,
  496. "FCP adapter maximum QTCB size (%d bytes) "
  497. "is too small\n",
  498. bottom->max_qtcb_size);
  499. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1", req);
  500. return;
  501. }
  502. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  503. &adapter->status);
  504. break;
  505. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  506. fc_host_node_name(shost) = 0;
  507. fc_host_port_name(shost) = 0;
  508. fc_host_port_id(shost) = 0;
  509. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  510. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  511. adapter->hydra_version = 0;
  512. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  513. &adapter->status);
  514. zfcp_fsf_link_down_info_eval(req, "fsecdh2",
  515. &qtcb->header.fsf_status_qual.link_down_info);
  516. break;
  517. default:
  518. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3", req);
  519. return;
  520. }
  521. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  522. adapter->hardware_version = bottom->hardware_version;
  523. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  524. min(FC_SERIAL_NUMBER_SIZE, 17));
  525. EBCASC(fc_host_serial_number(shost),
  526. min(FC_SERIAL_NUMBER_SIZE, 17));
  527. }
  528. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  529. dev_err(&adapter->ccw_device->dev,
  530. "The FCP adapter only supports newer "
  531. "control block versions\n");
  532. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4", req);
  533. return;
  534. }
  535. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  536. dev_err(&adapter->ccw_device->dev,
  537. "The FCP adapter only supports older "
  538. "control block versions\n");
  539. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5", req);
  540. }
  541. }
  542. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  543. {
  544. struct zfcp_adapter *adapter = req->adapter;
  545. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  546. struct Scsi_Host *shost = adapter->scsi_host;
  547. if (req->data)
  548. memcpy(req->data, bottom, sizeof(*bottom));
  549. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  550. fc_host_permanent_port_name(shost) = bottom->wwpn;
  551. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  552. } else
  553. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  554. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  555. fc_host_supported_speeds(shost) = bottom->supported_speed;
  556. }
  557. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  558. {
  559. struct fsf_qtcb *qtcb = req->qtcb;
  560. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  561. return;
  562. switch (qtcb->header.fsf_status) {
  563. case FSF_GOOD:
  564. zfcp_fsf_exchange_port_evaluate(req);
  565. break;
  566. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  567. zfcp_fsf_exchange_port_evaluate(req);
  568. zfcp_fsf_link_down_info_eval(req, "fsepdh1",
  569. &qtcb->header.fsf_status_qual.link_down_info);
  570. break;
  571. }
  572. }
  573. static int zfcp_fsf_sbal_check(struct zfcp_qdio *qdio)
  574. {
  575. struct zfcp_qdio_queue *req_q = &qdio->req_q;
  576. spin_lock_bh(&qdio->req_q_lock);
  577. if (atomic_read(&req_q->count))
  578. return 1;
  579. spin_unlock_bh(&qdio->req_q_lock);
  580. return 0;
  581. }
  582. static int zfcp_fsf_req_sbal_get(struct zfcp_qdio *qdio)
  583. {
  584. struct zfcp_adapter *adapter = qdio->adapter;
  585. long ret;
  586. spin_unlock_bh(&qdio->req_q_lock);
  587. ret = wait_event_interruptible_timeout(qdio->req_q_wq,
  588. zfcp_fsf_sbal_check(qdio), 5 * HZ);
  589. if (ret > 0)
  590. return 0;
  591. if (!ret) {
  592. atomic_inc(&qdio->req_q_full);
  593. /* assume hanging outbound queue, try queue recovery */
  594. zfcp_erp_adapter_reopen(adapter, 0, "fsrsg_1", NULL);
  595. }
  596. spin_lock_bh(&qdio->req_q_lock);
  597. return -EIO;
  598. }
  599. static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
  600. {
  601. struct zfcp_fsf_req *req;
  602. if (likely(pool))
  603. req = mempool_alloc(pool, GFP_ATOMIC);
  604. else
  605. req = kmalloc(sizeof(*req), GFP_ATOMIC);
  606. if (unlikely(!req))
  607. return NULL;
  608. memset(req, 0, sizeof(*req));
  609. req->pool = pool;
  610. return req;
  611. }
  612. static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
  613. {
  614. struct fsf_qtcb *qtcb;
  615. if (likely(pool))
  616. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  617. else
  618. qtcb = kmem_cache_alloc(zfcp_data.qtcb_cache, GFP_ATOMIC);
  619. if (unlikely(!qtcb))
  620. return NULL;
  621. memset(qtcb, 0, sizeof(*qtcb));
  622. return qtcb;
  623. }
  624. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
  625. u32 fsf_cmd, mempool_t *pool)
  626. {
  627. struct qdio_buffer_element *sbale;
  628. struct zfcp_qdio_queue *req_q = &qdio->req_q;
  629. struct zfcp_adapter *adapter = qdio->adapter;
  630. struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
  631. if (unlikely(!req))
  632. return ERR_PTR(-ENOMEM);
  633. if (adapter->req_no == 0)
  634. adapter->req_no++;
  635. INIT_LIST_HEAD(&req->list);
  636. init_timer(&req->timer);
  637. init_completion(&req->completion);
  638. req->adapter = adapter;
  639. req->fsf_command = fsf_cmd;
  640. req->req_id = adapter->req_no;
  641. req->queue_req.sbal_number = 1;
  642. req->queue_req.sbal_first = req_q->first;
  643. req->queue_req.sbal_last = req_q->first;
  644. req->queue_req.sbale_curr = 1;
  645. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  646. sbale[0].addr = (void *) req->req_id;
  647. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  648. if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
  649. if (likely(pool))
  650. req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
  651. else
  652. req->qtcb = zfcp_qtcb_alloc(NULL);
  653. if (unlikely(!req->qtcb)) {
  654. zfcp_fsf_req_free(req);
  655. return ERR_PTR(-ENOMEM);
  656. }
  657. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  658. req->qtcb->prefix.req_id = req->req_id;
  659. req->qtcb->prefix.ulp_info = 26;
  660. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  661. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  662. req->qtcb->header.req_handle = req->req_id;
  663. req->qtcb->header.fsf_command = req->fsf_command;
  664. req->seq_no = adapter->fsf_req_seq_no;
  665. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  666. sbale[1].addr = (void *) req->qtcb;
  667. sbale[1].length = sizeof(struct fsf_qtcb);
  668. }
  669. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
  670. zfcp_fsf_req_free(req);
  671. return ERR_PTR(-EIO);
  672. }
  673. return req;
  674. }
  675. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  676. {
  677. struct zfcp_adapter *adapter = req->adapter;
  678. struct zfcp_qdio *qdio = adapter->qdio;
  679. unsigned long flags;
  680. int idx;
  681. int with_qtcb = (req->qtcb != NULL);
  682. /* put allocated FSF request into hash table */
  683. spin_lock_irqsave(&adapter->req_list_lock, flags);
  684. idx = zfcp_reqlist_hash(req->req_id);
  685. list_add_tail(&req->list, &adapter->req_list[idx]);
  686. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  687. req->queue_req.qdio_outb_usage = atomic_read(&qdio->req_q.count);
  688. req->issued = get_clock();
  689. if (zfcp_qdio_send(qdio, &req->queue_req)) {
  690. del_timer(&req->timer);
  691. spin_lock_irqsave(&adapter->req_list_lock, flags);
  692. /* lookup request again, list might have changed */
  693. if (zfcp_reqlist_find_safe(adapter, req))
  694. zfcp_reqlist_remove(adapter, req);
  695. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  696. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1", req);
  697. return -EIO;
  698. }
  699. /* Don't increase for unsolicited status */
  700. if (with_qtcb)
  701. adapter->fsf_req_seq_no++;
  702. adapter->req_no++;
  703. return 0;
  704. }
  705. /**
  706. * zfcp_fsf_status_read - send status read request
  707. * @adapter: pointer to struct zfcp_adapter
  708. * @req_flags: request flags
  709. * Returns: 0 on success, ERROR otherwise
  710. */
  711. int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
  712. {
  713. struct zfcp_adapter *adapter = qdio->adapter;
  714. struct zfcp_fsf_req *req;
  715. struct fsf_status_read_buffer *sr_buf;
  716. struct qdio_buffer_element *sbale;
  717. int retval = -EIO;
  718. spin_lock_bh(&qdio->req_q_lock);
  719. if (zfcp_fsf_req_sbal_get(qdio))
  720. goto out;
  721. req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
  722. adapter->pool.status_read_req);
  723. if (IS_ERR(req)) {
  724. retval = PTR_ERR(req);
  725. goto out;
  726. }
  727. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  728. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  729. req->queue_req.sbale_curr = 2;
  730. sr_buf = mempool_alloc(adapter->pool.status_read_data, GFP_ATOMIC);
  731. if (!sr_buf) {
  732. retval = -ENOMEM;
  733. goto failed_buf;
  734. }
  735. memset(sr_buf, 0, sizeof(*sr_buf));
  736. req->data = sr_buf;
  737. sbale = zfcp_qdio_sbale_curr(qdio, &req->queue_req);
  738. sbale->addr = (void *) sr_buf;
  739. sbale->length = sizeof(*sr_buf);
  740. retval = zfcp_fsf_req_send(req);
  741. if (retval)
  742. goto failed_req_send;
  743. goto out;
  744. failed_req_send:
  745. mempool_free(sr_buf, adapter->pool.status_read_data);
  746. failed_buf:
  747. zfcp_fsf_req_free(req);
  748. zfcp_dbf_hba_fsf_unsol("fail", adapter->dbf, NULL);
  749. out:
  750. spin_unlock_bh(&qdio->req_q_lock);
  751. return retval;
  752. }
  753. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  754. {
  755. struct zfcp_unit *unit = req->data;
  756. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  757. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  758. return;
  759. switch (req->qtcb->header.fsf_status) {
  760. case FSF_PORT_HANDLE_NOT_VALID:
  761. if (fsq->word[0] == fsq->word[1]) {
  762. zfcp_erp_adapter_reopen(unit->port->adapter, 0,
  763. "fsafch1", req);
  764. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  765. }
  766. break;
  767. case FSF_LUN_HANDLE_NOT_VALID:
  768. if (fsq->word[0] == fsq->word[1]) {
  769. zfcp_erp_port_reopen(unit->port, 0, "fsafch2", req);
  770. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  771. }
  772. break;
  773. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  774. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  775. break;
  776. case FSF_PORT_BOXED:
  777. zfcp_erp_port_boxed(unit->port, "fsafch3", req);
  778. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  779. ZFCP_STATUS_FSFREQ_RETRY;
  780. break;
  781. case FSF_LUN_BOXED:
  782. zfcp_erp_unit_boxed(unit, "fsafch4", req);
  783. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  784. ZFCP_STATUS_FSFREQ_RETRY;
  785. break;
  786. case FSF_ADAPTER_STATUS_AVAILABLE:
  787. switch (fsq->word[0]) {
  788. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  789. zfcp_fc_test_link(unit->port);
  790. /* fall through */
  791. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  792. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  793. break;
  794. }
  795. break;
  796. case FSF_GOOD:
  797. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  798. break;
  799. }
  800. }
  801. /**
  802. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  803. * @old_req_id: unsigned long
  804. * @unit: pointer to struct zfcp_unit
  805. * Returns: pointer to struct zfcp_fsf_req
  806. */
  807. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  808. struct zfcp_unit *unit)
  809. {
  810. struct qdio_buffer_element *sbale;
  811. struct zfcp_fsf_req *req = NULL;
  812. struct zfcp_qdio *qdio = unit->port->adapter->qdio;
  813. spin_lock_bh(&qdio->req_q_lock);
  814. if (zfcp_fsf_req_sbal_get(qdio))
  815. goto out;
  816. req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
  817. qdio->adapter->pool.scsi_abort);
  818. if (IS_ERR(req)) {
  819. req = NULL;
  820. goto out;
  821. }
  822. if (unlikely(!(atomic_read(&unit->status) &
  823. ZFCP_STATUS_COMMON_UNBLOCKED)))
  824. goto out_error_free;
  825. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  826. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  827. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  828. req->data = unit;
  829. req->handler = zfcp_fsf_abort_fcp_command_handler;
  830. req->qtcb->header.lun_handle = unit->handle;
  831. req->qtcb->header.port_handle = unit->port->handle;
  832. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  833. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  834. if (!zfcp_fsf_req_send(req))
  835. goto out;
  836. out_error_free:
  837. zfcp_fsf_req_free(req);
  838. req = NULL;
  839. out:
  840. spin_unlock_bh(&qdio->req_q_lock);
  841. return req;
  842. }
  843. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  844. {
  845. struct zfcp_adapter *adapter = req->adapter;
  846. struct zfcp_send_ct *send_ct = req->data;
  847. struct fsf_qtcb_header *header = &req->qtcb->header;
  848. send_ct->status = -EINVAL;
  849. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  850. goto skip_fsfstatus;
  851. switch (header->fsf_status) {
  852. case FSF_GOOD:
  853. zfcp_dbf_san_ct_response(req);
  854. send_ct->status = 0;
  855. break;
  856. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  857. zfcp_fsf_class_not_supp(req);
  858. break;
  859. case FSF_ADAPTER_STATUS_AVAILABLE:
  860. switch (header->fsf_status_qual.word[0]){
  861. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  862. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  863. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  864. break;
  865. }
  866. break;
  867. case FSF_ACCESS_DENIED:
  868. break;
  869. case FSF_PORT_BOXED:
  870. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  871. ZFCP_STATUS_FSFREQ_RETRY;
  872. break;
  873. case FSF_PORT_HANDLE_NOT_VALID:
  874. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1", req);
  875. /* fall through */
  876. case FSF_GENERIC_COMMAND_REJECTED:
  877. case FSF_PAYLOAD_SIZE_MISMATCH:
  878. case FSF_REQUEST_SIZE_TOO_LARGE:
  879. case FSF_RESPONSE_SIZE_TOO_LARGE:
  880. case FSF_SBAL_MISMATCH:
  881. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  882. break;
  883. }
  884. skip_fsfstatus:
  885. if (send_ct->handler)
  886. send_ct->handler(send_ct->handler_data);
  887. }
  888. static void zfcp_fsf_setup_ct_els_unchained(struct qdio_buffer_element *sbale,
  889. struct scatterlist *sg_req,
  890. struct scatterlist *sg_resp)
  891. {
  892. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  893. sbale[2].addr = sg_virt(sg_req);
  894. sbale[2].length = sg_req->length;
  895. sbale[3].addr = sg_virt(sg_resp);
  896. sbale[3].length = sg_resp->length;
  897. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  898. }
  899. static int zfcp_fsf_one_sbal(struct scatterlist *sg)
  900. {
  901. return sg_is_last(sg) && sg->length <= PAGE_SIZE;
  902. }
  903. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  904. struct scatterlist *sg_req,
  905. struct scatterlist *sg_resp,
  906. int max_sbals)
  907. {
  908. struct zfcp_adapter *adapter = req->adapter;
  909. struct qdio_buffer_element *sbale = zfcp_qdio_sbale_req(adapter->qdio,
  910. &req->queue_req);
  911. u32 feat = adapter->adapter_features;
  912. int bytes;
  913. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS)) {
  914. if (!zfcp_fsf_one_sbal(sg_req) || !zfcp_fsf_one_sbal(sg_resp))
  915. return -EOPNOTSUPP;
  916. zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
  917. return 0;
  918. }
  919. /* use single, unchained SBAL if it can hold the request */
  920. if (zfcp_fsf_one_sbal(sg_req) && zfcp_fsf_one_sbal(sg_resp)) {
  921. zfcp_fsf_setup_ct_els_unchained(sbale, sg_req, sg_resp);
  922. return 0;
  923. }
  924. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
  925. SBAL_FLAGS0_TYPE_WRITE_READ,
  926. sg_req, max_sbals);
  927. if (bytes <= 0)
  928. return -EIO;
  929. req->qtcb->bottom.support.req_buf_length = bytes;
  930. req->queue_req.sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  931. bytes = zfcp_qdio_sbals_from_sg(adapter->qdio, &req->queue_req,
  932. SBAL_FLAGS0_TYPE_WRITE_READ,
  933. sg_resp, max_sbals);
  934. req->qtcb->bottom.support.resp_buf_length = bytes;
  935. if (bytes <= 0)
  936. return -EIO;
  937. return 0;
  938. }
  939. static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
  940. struct scatterlist *sg_req,
  941. struct scatterlist *sg_resp,
  942. int max_sbals)
  943. {
  944. int ret;
  945. ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp, max_sbals);
  946. if (ret)
  947. return ret;
  948. /* common settings for ct/gs and els requests */
  949. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  950. req->qtcb->bottom.support.timeout = 2 * R_A_TOV;
  951. zfcp_fsf_start_timer(req, 2 * R_A_TOV + 10);
  952. return 0;
  953. }
  954. /**
  955. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  956. * @ct: pointer to struct zfcp_send_ct with data for request
  957. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  958. */
  959. int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool)
  960. {
  961. struct zfcp_wka_port *wka_port = ct->wka_port;
  962. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  963. struct zfcp_fsf_req *req;
  964. int ret = -EIO;
  965. spin_lock_bh(&qdio->req_q_lock);
  966. if (zfcp_fsf_req_sbal_get(qdio))
  967. goto out;
  968. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC, pool);
  969. if (IS_ERR(req)) {
  970. ret = PTR_ERR(req);
  971. goto out;
  972. }
  973. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  974. ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp,
  975. FSF_MAX_SBALS_PER_REQ);
  976. if (ret)
  977. goto failed_send;
  978. req->handler = zfcp_fsf_send_ct_handler;
  979. req->qtcb->header.port_handle = wka_port->handle;
  980. req->data = ct;
  981. zfcp_dbf_san_ct_request(req);
  982. ret = zfcp_fsf_req_send(req);
  983. if (ret)
  984. goto failed_send;
  985. goto out;
  986. failed_send:
  987. zfcp_fsf_req_free(req);
  988. out:
  989. spin_unlock_bh(&qdio->req_q_lock);
  990. return ret;
  991. }
  992. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  993. {
  994. struct zfcp_send_els *send_els = req->data;
  995. struct zfcp_port *port = send_els->port;
  996. struct fsf_qtcb_header *header = &req->qtcb->header;
  997. send_els->status = -EINVAL;
  998. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  999. goto skip_fsfstatus;
  1000. switch (header->fsf_status) {
  1001. case FSF_GOOD:
  1002. zfcp_dbf_san_els_response(req);
  1003. send_els->status = 0;
  1004. break;
  1005. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1006. zfcp_fsf_class_not_supp(req);
  1007. break;
  1008. case FSF_ADAPTER_STATUS_AVAILABLE:
  1009. switch (header->fsf_status_qual.word[0]){
  1010. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1011. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  1012. zfcp_fc_test_link(port);
  1013. /*fall through */
  1014. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1015. case FSF_SQ_RETRY_IF_POSSIBLE:
  1016. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1017. break;
  1018. }
  1019. break;
  1020. case FSF_ELS_COMMAND_REJECTED:
  1021. case FSF_PAYLOAD_SIZE_MISMATCH:
  1022. case FSF_REQUEST_SIZE_TOO_LARGE:
  1023. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1024. break;
  1025. case FSF_ACCESS_DENIED:
  1026. if (port)
  1027. zfcp_fsf_access_denied_port(req, port);
  1028. break;
  1029. case FSF_SBAL_MISMATCH:
  1030. /* should never occure, avoided in zfcp_fsf_send_els */
  1031. /* fall through */
  1032. default:
  1033. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1034. break;
  1035. }
  1036. skip_fsfstatus:
  1037. if (send_els->handler)
  1038. send_els->handler(send_els->handler_data);
  1039. }
  1040. /**
  1041. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1042. * @els: pointer to struct zfcp_send_els with data for the command
  1043. */
  1044. int zfcp_fsf_send_els(struct zfcp_send_els *els)
  1045. {
  1046. struct zfcp_fsf_req *req;
  1047. struct zfcp_qdio *qdio = els->adapter->qdio;
  1048. int ret = -EIO;
  1049. spin_lock_bh(&qdio->req_q_lock);
  1050. if (zfcp_fsf_req_sbal_get(qdio))
  1051. goto out;
  1052. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS, NULL);
  1053. if (IS_ERR(req)) {
  1054. ret = PTR_ERR(req);
  1055. goto out;
  1056. }
  1057. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1058. ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, 2);
  1059. if (ret)
  1060. goto failed_send;
  1061. req->qtcb->bottom.support.d_id = els->d_id;
  1062. req->handler = zfcp_fsf_send_els_handler;
  1063. req->data = els;
  1064. zfcp_dbf_san_els_request(req);
  1065. ret = zfcp_fsf_req_send(req);
  1066. if (ret)
  1067. goto failed_send;
  1068. goto out;
  1069. failed_send:
  1070. zfcp_fsf_req_free(req);
  1071. out:
  1072. spin_unlock_bh(&qdio->req_q_lock);
  1073. return ret;
  1074. }
  1075. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1076. {
  1077. struct qdio_buffer_element *sbale;
  1078. struct zfcp_fsf_req *req;
  1079. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1080. int retval = -EIO;
  1081. spin_lock_bh(&qdio->req_q_lock);
  1082. if (zfcp_fsf_req_sbal_get(qdio))
  1083. goto out;
  1084. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1085. qdio->adapter->pool.erp_req);
  1086. if (IS_ERR(req)) {
  1087. retval = PTR_ERR(req);
  1088. goto out;
  1089. }
  1090. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1091. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1092. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1093. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1094. req->qtcb->bottom.config.feature_selection =
  1095. FSF_FEATURE_CFDC |
  1096. FSF_FEATURE_LUN_SHARING |
  1097. FSF_FEATURE_NOTIFICATION_LOST |
  1098. FSF_FEATURE_UPDATE_ALERT;
  1099. req->erp_action = erp_action;
  1100. req->handler = zfcp_fsf_exchange_config_data_handler;
  1101. erp_action->fsf_req = req;
  1102. zfcp_fsf_start_erp_timer(req);
  1103. retval = zfcp_fsf_req_send(req);
  1104. if (retval) {
  1105. zfcp_fsf_req_free(req);
  1106. erp_action->fsf_req = NULL;
  1107. }
  1108. out:
  1109. spin_unlock_bh(&qdio->req_q_lock);
  1110. return retval;
  1111. }
  1112. int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
  1113. struct fsf_qtcb_bottom_config *data)
  1114. {
  1115. struct qdio_buffer_element *sbale;
  1116. struct zfcp_fsf_req *req = NULL;
  1117. int retval = -EIO;
  1118. spin_lock_bh(&qdio->req_q_lock);
  1119. if (zfcp_fsf_req_sbal_get(qdio))
  1120. goto out_unlock;
  1121. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA, NULL);
  1122. if (IS_ERR(req)) {
  1123. retval = PTR_ERR(req);
  1124. goto out_unlock;
  1125. }
  1126. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1127. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1128. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1129. req->handler = zfcp_fsf_exchange_config_data_handler;
  1130. req->qtcb->bottom.config.feature_selection =
  1131. FSF_FEATURE_CFDC |
  1132. FSF_FEATURE_LUN_SHARING |
  1133. FSF_FEATURE_NOTIFICATION_LOST |
  1134. FSF_FEATURE_UPDATE_ALERT;
  1135. if (data)
  1136. req->data = data;
  1137. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1138. retval = zfcp_fsf_req_send(req);
  1139. spin_unlock_bh(&qdio->req_q_lock);
  1140. if (!retval)
  1141. wait_for_completion(&req->completion);
  1142. zfcp_fsf_req_free(req);
  1143. return retval;
  1144. out_unlock:
  1145. spin_unlock_bh(&qdio->req_q_lock);
  1146. return retval;
  1147. }
  1148. /**
  1149. * zfcp_fsf_exchange_port_data - request information about local port
  1150. * @erp_action: ERP action for the adapter for which port data is requested
  1151. * Returns: 0 on success, error otherwise
  1152. */
  1153. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1154. {
  1155. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1156. struct qdio_buffer_element *sbale;
  1157. struct zfcp_fsf_req *req;
  1158. int retval = -EIO;
  1159. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1160. return -EOPNOTSUPP;
  1161. spin_lock_bh(&qdio->req_q_lock);
  1162. if (zfcp_fsf_req_sbal_get(qdio))
  1163. goto out;
  1164. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1165. qdio->adapter->pool.erp_req);
  1166. if (IS_ERR(req)) {
  1167. retval = PTR_ERR(req);
  1168. goto out;
  1169. }
  1170. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1171. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1172. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1173. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1174. req->handler = zfcp_fsf_exchange_port_data_handler;
  1175. req->erp_action = erp_action;
  1176. erp_action->fsf_req = req;
  1177. zfcp_fsf_start_erp_timer(req);
  1178. retval = zfcp_fsf_req_send(req);
  1179. if (retval) {
  1180. zfcp_fsf_req_free(req);
  1181. erp_action->fsf_req = NULL;
  1182. }
  1183. out:
  1184. spin_unlock_bh(&qdio->req_q_lock);
  1185. return retval;
  1186. }
  1187. /**
  1188. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1189. * @qdio: pointer to struct zfcp_qdio
  1190. * @data: pointer to struct fsf_qtcb_bottom_port
  1191. * Returns: 0 on success, error otherwise
  1192. */
  1193. int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
  1194. struct fsf_qtcb_bottom_port *data)
  1195. {
  1196. struct qdio_buffer_element *sbale;
  1197. struct zfcp_fsf_req *req = NULL;
  1198. int retval = -EIO;
  1199. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1200. return -EOPNOTSUPP;
  1201. spin_lock_bh(&qdio->req_q_lock);
  1202. if (zfcp_fsf_req_sbal_get(qdio))
  1203. goto out_unlock;
  1204. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA, NULL);
  1205. if (IS_ERR(req)) {
  1206. retval = PTR_ERR(req);
  1207. goto out_unlock;
  1208. }
  1209. if (data)
  1210. req->data = data;
  1211. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1212. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1213. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1214. req->handler = zfcp_fsf_exchange_port_data_handler;
  1215. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1216. retval = zfcp_fsf_req_send(req);
  1217. spin_unlock_bh(&qdio->req_q_lock);
  1218. if (!retval)
  1219. wait_for_completion(&req->completion);
  1220. zfcp_fsf_req_free(req);
  1221. return retval;
  1222. out_unlock:
  1223. spin_unlock_bh(&qdio->req_q_lock);
  1224. return retval;
  1225. }
  1226. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1227. {
  1228. struct zfcp_port *port = req->data;
  1229. struct fsf_qtcb_header *header = &req->qtcb->header;
  1230. struct fsf_plogi *plogi;
  1231. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1232. goto out;
  1233. switch (header->fsf_status) {
  1234. case FSF_PORT_ALREADY_OPEN:
  1235. break;
  1236. case FSF_ACCESS_DENIED:
  1237. zfcp_fsf_access_denied_port(req, port);
  1238. break;
  1239. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1240. dev_warn(&req->adapter->ccw_device->dev,
  1241. "Not enough FCP adapter resources to open "
  1242. "remote port 0x%016Lx\n",
  1243. (unsigned long long)port->wwpn);
  1244. zfcp_erp_port_failed(port, "fsoph_1", req);
  1245. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1246. break;
  1247. case FSF_ADAPTER_STATUS_AVAILABLE:
  1248. switch (header->fsf_status_qual.word[0]) {
  1249. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1250. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1251. case FSF_SQ_NO_RETRY_POSSIBLE:
  1252. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1253. break;
  1254. }
  1255. break;
  1256. case FSF_GOOD:
  1257. port->handle = header->port_handle;
  1258. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1259. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1260. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1261. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1262. &port->status);
  1263. /* check whether D_ID has changed during open */
  1264. /*
  1265. * FIXME: This check is not airtight, as the FCP channel does
  1266. * not monitor closures of target port connections caused on
  1267. * the remote side. Thus, they might miss out on invalidating
  1268. * locally cached WWPNs (and other N_Port parameters) of gone
  1269. * target ports. So, our heroic attempt to make things safe
  1270. * could be undermined by 'open port' response data tagged with
  1271. * obsolete WWPNs. Another reason to monitor potential
  1272. * connection closures ourself at least (by interpreting
  1273. * incoming ELS' and unsolicited status). It just crosses my
  1274. * mind that one should be able to cross-check by means of
  1275. * another GID_PN straight after a port has been opened.
  1276. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1277. */
  1278. plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
  1279. if (req->qtcb->bottom.support.els1_length >=
  1280. FSF_PLOGI_MIN_LEN) {
  1281. if (plogi->serv_param.wwpn != port->wwpn)
  1282. port->d_id = 0;
  1283. else {
  1284. port->wwnn = plogi->serv_param.wwnn;
  1285. zfcp_fc_plogi_evaluate(port, plogi);
  1286. }
  1287. }
  1288. break;
  1289. case FSF_UNKNOWN_OP_SUBTYPE:
  1290. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1291. break;
  1292. }
  1293. out:
  1294. zfcp_port_put(port);
  1295. }
  1296. /**
  1297. * zfcp_fsf_open_port - create and send open port request
  1298. * @erp_action: pointer to struct zfcp_erp_action
  1299. * Returns: 0 on success, error otherwise
  1300. */
  1301. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1302. {
  1303. struct qdio_buffer_element *sbale;
  1304. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1305. struct zfcp_port *port = erp_action->port;
  1306. struct zfcp_fsf_req *req;
  1307. int retval = -EIO;
  1308. spin_lock_bh(&qdio->req_q_lock);
  1309. if (zfcp_fsf_req_sbal_get(qdio))
  1310. goto out;
  1311. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1312. qdio->adapter->pool.erp_req);
  1313. if (IS_ERR(req)) {
  1314. retval = PTR_ERR(req);
  1315. goto out;
  1316. }
  1317. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1318. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1319. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1320. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1321. req->handler = zfcp_fsf_open_port_handler;
  1322. req->qtcb->bottom.support.d_id = port->d_id;
  1323. req->data = port;
  1324. req->erp_action = erp_action;
  1325. erp_action->fsf_req = req;
  1326. zfcp_port_get(port);
  1327. zfcp_fsf_start_erp_timer(req);
  1328. retval = zfcp_fsf_req_send(req);
  1329. if (retval) {
  1330. zfcp_fsf_req_free(req);
  1331. erp_action->fsf_req = NULL;
  1332. zfcp_port_put(port);
  1333. }
  1334. out:
  1335. spin_unlock_bh(&qdio->req_q_lock);
  1336. return retval;
  1337. }
  1338. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1339. {
  1340. struct zfcp_port *port = req->data;
  1341. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1342. return;
  1343. switch (req->qtcb->header.fsf_status) {
  1344. case FSF_PORT_HANDLE_NOT_VALID:
  1345. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1", req);
  1346. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1347. break;
  1348. case FSF_ADAPTER_STATUS_AVAILABLE:
  1349. break;
  1350. case FSF_GOOD:
  1351. zfcp_erp_modify_port_status(port, "fscph_2", req,
  1352. ZFCP_STATUS_COMMON_OPEN,
  1353. ZFCP_CLEAR);
  1354. break;
  1355. }
  1356. }
  1357. /**
  1358. * zfcp_fsf_close_port - create and send close port request
  1359. * @erp_action: pointer to struct zfcp_erp_action
  1360. * Returns: 0 on success, error otherwise
  1361. */
  1362. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1363. {
  1364. struct qdio_buffer_element *sbale;
  1365. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1366. struct zfcp_fsf_req *req;
  1367. int retval = -EIO;
  1368. spin_lock_bh(&qdio->req_q_lock);
  1369. if (zfcp_fsf_req_sbal_get(qdio))
  1370. goto out;
  1371. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1372. qdio->adapter->pool.erp_req);
  1373. if (IS_ERR(req)) {
  1374. retval = PTR_ERR(req);
  1375. goto out;
  1376. }
  1377. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1378. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1379. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1380. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1381. req->handler = zfcp_fsf_close_port_handler;
  1382. req->data = erp_action->port;
  1383. req->erp_action = erp_action;
  1384. req->qtcb->header.port_handle = erp_action->port->handle;
  1385. erp_action->fsf_req = req;
  1386. zfcp_fsf_start_erp_timer(req);
  1387. retval = zfcp_fsf_req_send(req);
  1388. if (retval) {
  1389. zfcp_fsf_req_free(req);
  1390. erp_action->fsf_req = NULL;
  1391. }
  1392. out:
  1393. spin_unlock_bh(&qdio->req_q_lock);
  1394. return retval;
  1395. }
  1396. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1397. {
  1398. struct zfcp_wka_port *wka_port = req->data;
  1399. struct fsf_qtcb_header *header = &req->qtcb->header;
  1400. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1401. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1402. goto out;
  1403. }
  1404. switch (header->fsf_status) {
  1405. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1406. dev_warn(&req->adapter->ccw_device->dev,
  1407. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1408. /* fall through */
  1409. case FSF_ADAPTER_STATUS_AVAILABLE:
  1410. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1411. /* fall through */
  1412. case FSF_ACCESS_DENIED:
  1413. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1414. break;
  1415. case FSF_GOOD:
  1416. wka_port->handle = header->port_handle;
  1417. /* fall through */
  1418. case FSF_PORT_ALREADY_OPEN:
  1419. wka_port->status = ZFCP_WKA_PORT_ONLINE;
  1420. }
  1421. out:
  1422. wake_up(&wka_port->completion_wq);
  1423. }
  1424. /**
  1425. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1426. * @wka_port: pointer to struct zfcp_wka_port
  1427. * Returns: 0 on success, error otherwise
  1428. */
  1429. int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
  1430. {
  1431. struct qdio_buffer_element *sbale;
  1432. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1433. struct zfcp_fsf_req *req;
  1434. int retval = -EIO;
  1435. spin_lock_bh(&qdio->req_q_lock);
  1436. if (zfcp_fsf_req_sbal_get(qdio))
  1437. goto out;
  1438. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1439. qdio->adapter->pool.erp_req);
  1440. if (unlikely(IS_ERR(req))) {
  1441. retval = PTR_ERR(req);
  1442. goto out;
  1443. }
  1444. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1445. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1446. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1447. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1448. req->handler = zfcp_fsf_open_wka_port_handler;
  1449. req->qtcb->bottom.support.d_id = wka_port->d_id;
  1450. req->data = wka_port;
  1451. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1452. retval = zfcp_fsf_req_send(req);
  1453. if (retval)
  1454. zfcp_fsf_req_free(req);
  1455. out:
  1456. spin_unlock_bh(&qdio->req_q_lock);
  1457. return retval;
  1458. }
  1459. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1460. {
  1461. struct zfcp_wka_port *wka_port = req->data;
  1462. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1463. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1464. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1", req);
  1465. }
  1466. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1467. wake_up(&wka_port->completion_wq);
  1468. }
  1469. /**
  1470. * zfcp_fsf_close_wka_port - create and send close wka port request
  1471. * @erp_action: pointer to struct zfcp_erp_action
  1472. * Returns: 0 on success, error otherwise
  1473. */
  1474. int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
  1475. {
  1476. struct qdio_buffer_element *sbale;
  1477. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1478. struct zfcp_fsf_req *req;
  1479. int retval = -EIO;
  1480. spin_lock_bh(&qdio->req_q_lock);
  1481. if (zfcp_fsf_req_sbal_get(qdio))
  1482. goto out;
  1483. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1484. qdio->adapter->pool.erp_req);
  1485. if (unlikely(IS_ERR(req))) {
  1486. retval = PTR_ERR(req);
  1487. goto out;
  1488. }
  1489. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1490. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1491. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1492. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1493. req->handler = zfcp_fsf_close_wka_port_handler;
  1494. req->data = wka_port;
  1495. req->qtcb->header.port_handle = wka_port->handle;
  1496. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1497. retval = zfcp_fsf_req_send(req);
  1498. if (retval)
  1499. zfcp_fsf_req_free(req);
  1500. out:
  1501. spin_unlock_bh(&qdio->req_q_lock);
  1502. return retval;
  1503. }
  1504. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1505. {
  1506. struct zfcp_port *port = req->data;
  1507. struct fsf_qtcb_header *header = &req->qtcb->header;
  1508. struct zfcp_unit *unit;
  1509. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1510. return;
  1511. switch (header->fsf_status) {
  1512. case FSF_PORT_HANDLE_NOT_VALID:
  1513. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1", req);
  1514. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1515. break;
  1516. case FSF_ACCESS_DENIED:
  1517. zfcp_fsf_access_denied_port(req, port);
  1518. break;
  1519. case FSF_PORT_BOXED:
  1520. /* can't use generic zfcp_erp_modify_port_status because
  1521. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1522. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1523. list_for_each_entry(unit, &port->unit_list_head, list)
  1524. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1525. &unit->status);
  1526. zfcp_erp_port_boxed(port, "fscpph2", req);
  1527. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1528. ZFCP_STATUS_FSFREQ_RETRY;
  1529. break;
  1530. case FSF_ADAPTER_STATUS_AVAILABLE:
  1531. switch (header->fsf_status_qual.word[0]) {
  1532. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1533. /* fall through */
  1534. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1535. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1536. break;
  1537. }
  1538. break;
  1539. case FSF_GOOD:
  1540. /* can't use generic zfcp_erp_modify_port_status because
  1541. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1542. */
  1543. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1544. list_for_each_entry(unit, &port->unit_list_head, list)
  1545. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1546. &unit->status);
  1547. break;
  1548. }
  1549. }
  1550. /**
  1551. * zfcp_fsf_close_physical_port - close physical port
  1552. * @erp_action: pointer to struct zfcp_erp_action
  1553. * Returns: 0 on success
  1554. */
  1555. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1556. {
  1557. struct qdio_buffer_element *sbale;
  1558. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1559. struct zfcp_fsf_req *req;
  1560. int retval = -EIO;
  1561. spin_lock_bh(&qdio->req_q_lock);
  1562. if (zfcp_fsf_req_sbal_get(qdio))
  1563. goto out;
  1564. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1565. qdio->adapter->pool.erp_req);
  1566. if (IS_ERR(req)) {
  1567. retval = PTR_ERR(req);
  1568. goto out;
  1569. }
  1570. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1571. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1572. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1573. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1574. req->data = erp_action->port;
  1575. req->qtcb->header.port_handle = erp_action->port->handle;
  1576. req->erp_action = erp_action;
  1577. req->handler = zfcp_fsf_close_physical_port_handler;
  1578. erp_action->fsf_req = req;
  1579. zfcp_fsf_start_erp_timer(req);
  1580. retval = zfcp_fsf_req_send(req);
  1581. if (retval) {
  1582. zfcp_fsf_req_free(req);
  1583. erp_action->fsf_req = NULL;
  1584. }
  1585. out:
  1586. spin_unlock_bh(&qdio->req_q_lock);
  1587. return retval;
  1588. }
  1589. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1590. {
  1591. struct zfcp_adapter *adapter = req->adapter;
  1592. struct zfcp_unit *unit = req->data;
  1593. struct fsf_qtcb_header *header = &req->qtcb->header;
  1594. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1595. struct fsf_queue_designator *queue_designator =
  1596. &header->fsf_status_qual.fsf_queue_designator;
  1597. int exclusive, readwrite;
  1598. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1599. return;
  1600. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1601. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1602. ZFCP_STATUS_UNIT_SHARED |
  1603. ZFCP_STATUS_UNIT_READONLY,
  1604. &unit->status);
  1605. switch (header->fsf_status) {
  1606. case FSF_PORT_HANDLE_NOT_VALID:
  1607. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fsouh_1", req);
  1608. /* fall through */
  1609. case FSF_LUN_ALREADY_OPEN:
  1610. break;
  1611. case FSF_ACCESS_DENIED:
  1612. zfcp_fsf_access_denied_unit(req, unit);
  1613. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1614. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1615. break;
  1616. case FSF_PORT_BOXED:
  1617. zfcp_erp_port_boxed(unit->port, "fsouh_2", req);
  1618. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1619. ZFCP_STATUS_FSFREQ_RETRY;
  1620. break;
  1621. case FSF_LUN_SHARING_VIOLATION:
  1622. if (header->fsf_status_qual.word[0])
  1623. dev_warn(&adapter->ccw_device->dev,
  1624. "LUN 0x%Lx on port 0x%Lx is already in "
  1625. "use by CSS%d, MIF Image ID %x\n",
  1626. (unsigned long long)unit->fcp_lun,
  1627. (unsigned long long)unit->port->wwpn,
  1628. queue_designator->cssid,
  1629. queue_designator->hla);
  1630. else
  1631. zfcp_act_eval_err(adapter,
  1632. header->fsf_status_qual.word[2]);
  1633. zfcp_erp_unit_access_denied(unit, "fsouh_3", req);
  1634. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1635. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1636. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1637. break;
  1638. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1639. dev_warn(&adapter->ccw_device->dev,
  1640. "No handle is available for LUN "
  1641. "0x%016Lx on port 0x%016Lx\n",
  1642. (unsigned long long)unit->fcp_lun,
  1643. (unsigned long long)unit->port->wwpn);
  1644. zfcp_erp_unit_failed(unit, "fsouh_4", req);
  1645. /* fall through */
  1646. case FSF_INVALID_COMMAND_OPTION:
  1647. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1648. break;
  1649. case FSF_ADAPTER_STATUS_AVAILABLE:
  1650. switch (header->fsf_status_qual.word[0]) {
  1651. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1652. zfcp_fc_test_link(unit->port);
  1653. /* fall through */
  1654. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1655. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1656. break;
  1657. }
  1658. break;
  1659. case FSF_GOOD:
  1660. unit->handle = header->lun_handle;
  1661. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1662. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1663. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1664. !zfcp_ccw_priv_sch(adapter)) {
  1665. exclusive = (bottom->lun_access_info &
  1666. FSF_UNIT_ACCESS_EXCLUSIVE);
  1667. readwrite = (bottom->lun_access_info &
  1668. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1669. if (!exclusive)
  1670. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1671. &unit->status);
  1672. if (!readwrite) {
  1673. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1674. &unit->status);
  1675. dev_info(&adapter->ccw_device->dev,
  1676. "SCSI device at LUN 0x%016Lx on port "
  1677. "0x%016Lx opened read-only\n",
  1678. (unsigned long long)unit->fcp_lun,
  1679. (unsigned long long)unit->port->wwpn);
  1680. }
  1681. if (exclusive && !readwrite) {
  1682. dev_err(&adapter->ccw_device->dev,
  1683. "Exclusive read-only access not "
  1684. "supported (unit 0x%016Lx, "
  1685. "port 0x%016Lx)\n",
  1686. (unsigned long long)unit->fcp_lun,
  1687. (unsigned long long)unit->port->wwpn);
  1688. zfcp_erp_unit_failed(unit, "fsouh_5", req);
  1689. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1690. zfcp_erp_unit_shutdown(unit, 0, "fsouh_6", req);
  1691. } else if (!exclusive && readwrite) {
  1692. dev_err(&adapter->ccw_device->dev,
  1693. "Shared read-write access not "
  1694. "supported (unit 0x%016Lx, port "
  1695. "0x%016Lx)\n",
  1696. (unsigned long long)unit->fcp_lun,
  1697. (unsigned long long)unit->port->wwpn);
  1698. zfcp_erp_unit_failed(unit, "fsouh_7", req);
  1699. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1700. zfcp_erp_unit_shutdown(unit, 0, "fsouh_8", req);
  1701. }
  1702. }
  1703. break;
  1704. }
  1705. }
  1706. /**
  1707. * zfcp_fsf_open_unit - open unit
  1708. * @erp_action: pointer to struct zfcp_erp_action
  1709. * Returns: 0 on success, error otherwise
  1710. */
  1711. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1712. {
  1713. struct qdio_buffer_element *sbale;
  1714. struct zfcp_adapter *adapter = erp_action->adapter;
  1715. struct zfcp_qdio *qdio = adapter->qdio;
  1716. struct zfcp_fsf_req *req;
  1717. int retval = -EIO;
  1718. spin_lock_bh(&qdio->req_q_lock);
  1719. if (zfcp_fsf_req_sbal_get(qdio))
  1720. goto out;
  1721. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
  1722. adapter->pool.erp_req);
  1723. if (IS_ERR(req)) {
  1724. retval = PTR_ERR(req);
  1725. goto out;
  1726. }
  1727. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1728. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1729. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1730. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1731. req->qtcb->header.port_handle = erp_action->port->handle;
  1732. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1733. req->handler = zfcp_fsf_open_unit_handler;
  1734. req->data = erp_action->unit;
  1735. req->erp_action = erp_action;
  1736. erp_action->fsf_req = req;
  1737. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1738. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1739. zfcp_fsf_start_erp_timer(req);
  1740. retval = zfcp_fsf_req_send(req);
  1741. if (retval) {
  1742. zfcp_fsf_req_free(req);
  1743. erp_action->fsf_req = NULL;
  1744. }
  1745. out:
  1746. spin_unlock_bh(&qdio->req_q_lock);
  1747. return retval;
  1748. }
  1749. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1750. {
  1751. struct zfcp_unit *unit = req->data;
  1752. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1753. return;
  1754. switch (req->qtcb->header.fsf_status) {
  1755. case FSF_PORT_HANDLE_NOT_VALID:
  1756. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fscuh_1", req);
  1757. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1758. break;
  1759. case FSF_LUN_HANDLE_NOT_VALID:
  1760. zfcp_erp_port_reopen(unit->port, 0, "fscuh_2", req);
  1761. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1762. break;
  1763. case FSF_PORT_BOXED:
  1764. zfcp_erp_port_boxed(unit->port, "fscuh_3", req);
  1765. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1766. ZFCP_STATUS_FSFREQ_RETRY;
  1767. break;
  1768. case FSF_ADAPTER_STATUS_AVAILABLE:
  1769. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1770. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1771. zfcp_fc_test_link(unit->port);
  1772. /* fall through */
  1773. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1774. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1775. break;
  1776. }
  1777. break;
  1778. case FSF_GOOD:
  1779. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1780. break;
  1781. }
  1782. }
  1783. /**
  1784. * zfcp_fsf_close_unit - close zfcp unit
  1785. * @erp_action: pointer to struct zfcp_unit
  1786. * Returns: 0 on success, error otherwise
  1787. */
  1788. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1789. {
  1790. struct qdio_buffer_element *sbale;
  1791. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1792. struct zfcp_fsf_req *req;
  1793. int retval = -EIO;
  1794. spin_lock_bh(&qdio->req_q_lock);
  1795. if (zfcp_fsf_req_sbal_get(qdio))
  1796. goto out;
  1797. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
  1798. qdio->adapter->pool.erp_req);
  1799. if (IS_ERR(req)) {
  1800. retval = PTR_ERR(req);
  1801. goto out;
  1802. }
  1803. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1804. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  1805. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1806. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1807. req->qtcb->header.port_handle = erp_action->port->handle;
  1808. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1809. req->handler = zfcp_fsf_close_unit_handler;
  1810. req->data = erp_action->unit;
  1811. req->erp_action = erp_action;
  1812. erp_action->fsf_req = req;
  1813. zfcp_fsf_start_erp_timer(req);
  1814. retval = zfcp_fsf_req_send(req);
  1815. if (retval) {
  1816. zfcp_fsf_req_free(req);
  1817. erp_action->fsf_req = NULL;
  1818. }
  1819. out:
  1820. spin_unlock_bh(&qdio->req_q_lock);
  1821. return retval;
  1822. }
  1823. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1824. {
  1825. lat_rec->sum += lat;
  1826. lat_rec->min = min(lat_rec->min, lat);
  1827. lat_rec->max = max(lat_rec->max, lat);
  1828. }
  1829. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
  1830. {
  1831. struct fsf_qual_latency_info *lat_inf;
  1832. struct latency_cont *lat;
  1833. struct zfcp_unit *unit = req->unit;
  1834. lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
  1835. switch (req->qtcb->bottom.io.data_direction) {
  1836. case FSF_DATADIR_READ:
  1837. lat = &unit->latencies.read;
  1838. break;
  1839. case FSF_DATADIR_WRITE:
  1840. lat = &unit->latencies.write;
  1841. break;
  1842. case FSF_DATADIR_CMND:
  1843. lat = &unit->latencies.cmd;
  1844. break;
  1845. default:
  1846. return;
  1847. }
  1848. spin_lock(&unit->latencies.lock);
  1849. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  1850. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  1851. lat->counter++;
  1852. spin_unlock(&unit->latencies.lock);
  1853. }
  1854. #ifdef CONFIG_BLK_DEV_IO_TRACE
  1855. static void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1856. {
  1857. struct fsf_qual_latency_info *lat_inf;
  1858. struct scsi_cmnd *scsi_cmnd = (struct scsi_cmnd *)fsf_req->data;
  1859. struct request *req = scsi_cmnd->request;
  1860. struct zfcp_blk_drv_data trace;
  1861. int ticks = fsf_req->adapter->timer_ticks;
  1862. trace.flags = 0;
  1863. trace.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1864. if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA) {
  1865. trace.flags |= ZFCP_BLK_LAT_VALID;
  1866. lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
  1867. trace.channel_lat = lat_inf->channel_lat * ticks;
  1868. trace.fabric_lat = lat_inf->fabric_lat * ticks;
  1869. }
  1870. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1871. trace.flags |= ZFCP_BLK_REQ_ERROR;
  1872. trace.inb_usage = fsf_req->queue_req.qdio_inb_usage;
  1873. trace.outb_usage = fsf_req->queue_req.qdio_outb_usage;
  1874. blk_add_driver_data(req->q, req, &trace, sizeof(trace));
  1875. }
  1876. #else
  1877. static inline void zfcp_fsf_trace_latency(struct zfcp_fsf_req *fsf_req)
  1878. {
  1879. }
  1880. #endif
  1881. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1882. {
  1883. struct scsi_cmnd *scpnt;
  1884. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1885. &(req->qtcb->bottom.io.fcp_rsp);
  1886. u32 sns_len;
  1887. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1888. unsigned long flags;
  1889. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1890. scpnt = req->data;
  1891. if (unlikely(!scpnt)) {
  1892. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1893. return;
  1894. }
  1895. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  1896. set_host_byte(scpnt, DID_SOFT_ERROR);
  1897. goto skip_fsfstatus;
  1898. }
  1899. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1900. set_host_byte(scpnt, DID_ERROR);
  1901. goto skip_fsfstatus;
  1902. }
  1903. set_msg_byte(scpnt, COMMAND_COMPLETE);
  1904. scpnt->result |= fcp_rsp_iu->scsi_status;
  1905. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  1906. zfcp_fsf_req_latency(req);
  1907. zfcp_fsf_trace_latency(req);
  1908. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  1909. if (fcp_rsp_info[3] == RSP_CODE_GOOD)
  1910. set_host_byte(scpnt, DID_OK);
  1911. else {
  1912. set_host_byte(scpnt, DID_ERROR);
  1913. goto skip_fsfstatus;
  1914. }
  1915. }
  1916. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  1917. sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
  1918. fcp_rsp_iu->fcp_rsp_len;
  1919. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  1920. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  1921. memcpy(scpnt->sense_buffer,
  1922. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  1923. }
  1924. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  1925. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  1926. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  1927. scpnt->underflow)
  1928. set_host_byte(scpnt, DID_ERROR);
  1929. }
  1930. skip_fsfstatus:
  1931. if (scpnt->result != 0)
  1932. zfcp_dbf_scsi_result("erro", 3, req->adapter->dbf, scpnt, req);
  1933. else if (scpnt->retries > 0)
  1934. zfcp_dbf_scsi_result("retr", 4, req->adapter->dbf, scpnt, req);
  1935. else
  1936. zfcp_dbf_scsi_result("norm", 6, req->adapter->dbf, scpnt, req);
  1937. scpnt->host_scribble = NULL;
  1938. (scpnt->scsi_done) (scpnt);
  1939. /*
  1940. * We must hold this lock until scsi_done has been called.
  1941. * Otherwise we may call scsi_done after abort regarding this
  1942. * command has completed.
  1943. * Note: scsi_done must not block!
  1944. */
  1945. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1946. }
  1947. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1948. {
  1949. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1950. &(req->qtcb->bottom.io.fcp_rsp);
  1951. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1952. if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
  1953. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1954. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1955. }
  1956. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1957. {
  1958. struct zfcp_unit *unit;
  1959. struct fsf_qtcb_header *header = &req->qtcb->header;
  1960. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1961. unit = req->data;
  1962. else
  1963. unit = req->unit;
  1964. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1965. goto skip_fsfstatus;
  1966. switch (header->fsf_status) {
  1967. case FSF_HANDLE_MISMATCH:
  1968. case FSF_PORT_HANDLE_NOT_VALID:
  1969. zfcp_erp_adapter_reopen(unit->port->adapter, 0, "fssfch1", req);
  1970. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1971. break;
  1972. case FSF_FCPLUN_NOT_VALID:
  1973. case FSF_LUN_HANDLE_NOT_VALID:
  1974. zfcp_erp_port_reopen(unit->port, 0, "fssfch2", req);
  1975. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1976. break;
  1977. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1978. zfcp_fsf_class_not_supp(req);
  1979. break;
  1980. case FSF_ACCESS_DENIED:
  1981. zfcp_fsf_access_denied_unit(req, unit);
  1982. break;
  1983. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1984. dev_err(&req->adapter->ccw_device->dev,
  1985. "Incorrect direction %d, unit 0x%016Lx on port "
  1986. "0x%016Lx closed\n",
  1987. req->qtcb->bottom.io.data_direction,
  1988. (unsigned long long)unit->fcp_lun,
  1989. (unsigned long long)unit->port->wwpn);
  1990. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch3",
  1991. req);
  1992. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1993. break;
  1994. case FSF_CMND_LENGTH_NOT_VALID:
  1995. dev_err(&req->adapter->ccw_device->dev,
  1996. "Incorrect CDB length %d, unit 0x%016Lx on "
  1997. "port 0x%016Lx closed\n",
  1998. req->qtcb->bottom.io.fcp_cmnd_length,
  1999. (unsigned long long)unit->fcp_lun,
  2000. (unsigned long long)unit->port->wwpn);
  2001. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, "fssfch4",
  2002. req);
  2003. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2004. break;
  2005. case FSF_PORT_BOXED:
  2006. zfcp_erp_port_boxed(unit->port, "fssfch5", req);
  2007. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2008. ZFCP_STATUS_FSFREQ_RETRY;
  2009. break;
  2010. case FSF_LUN_BOXED:
  2011. zfcp_erp_unit_boxed(unit, "fssfch6", req);
  2012. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2013. ZFCP_STATUS_FSFREQ_RETRY;
  2014. break;
  2015. case FSF_ADAPTER_STATUS_AVAILABLE:
  2016. if (header->fsf_status_qual.word[0] ==
  2017. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  2018. zfcp_fc_test_link(unit->port);
  2019. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2020. break;
  2021. }
  2022. skip_fsfstatus:
  2023. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  2024. zfcp_fsf_send_fcp_ctm_handler(req);
  2025. else {
  2026. zfcp_fsf_send_fcp_command_task_handler(req);
  2027. req->unit = NULL;
  2028. zfcp_unit_put(unit);
  2029. }
  2030. }
  2031. static void zfcp_set_fcp_dl(struct fcp_cmnd_iu *fcp_cmd, u32 fcp_dl)
  2032. {
  2033. u32 *fcp_dl_ptr;
  2034. /*
  2035. * fcp_dl_addr = start address of fcp_cmnd structure +
  2036. * size of fixed part + size of dynamically sized add_dcp_cdb field
  2037. * SEE FCP-2 documentation
  2038. */
  2039. fcp_dl_ptr = (u32 *) ((unsigned char *) &fcp_cmd[1] +
  2040. (fcp_cmd->add_fcp_cdb_length << 2));
  2041. *fcp_dl_ptr = fcp_dl;
  2042. }
  2043. /**
  2044. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  2045. * @unit: unit where command is sent to
  2046. * @scsi_cmnd: scsi command to be sent
  2047. */
  2048. int zfcp_fsf_send_fcp_command_task(struct zfcp_unit *unit,
  2049. struct scsi_cmnd *scsi_cmnd)
  2050. {
  2051. struct zfcp_fsf_req *req;
  2052. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2053. unsigned int sbtype = SBAL_FLAGS0_TYPE_READ;
  2054. int real_bytes, retval = -EIO;
  2055. struct zfcp_adapter *adapter = unit->port->adapter;
  2056. struct zfcp_qdio *qdio = adapter->qdio;
  2057. if (unlikely(!(atomic_read(&unit->status) &
  2058. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2059. return -EBUSY;
  2060. spin_lock(&qdio->req_q_lock);
  2061. if (atomic_read(&qdio->req_q.count) <= 0) {
  2062. atomic_inc(&qdio->req_q_full);
  2063. goto out;
  2064. }
  2065. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  2066. adapter->pool.scsi_req);
  2067. if (IS_ERR(req)) {
  2068. retval = PTR_ERR(req);
  2069. goto out;
  2070. }
  2071. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  2072. zfcp_unit_get(unit);
  2073. req->unit = unit;
  2074. req->data = scsi_cmnd;
  2075. req->handler = zfcp_fsf_send_fcp_command_handler;
  2076. req->qtcb->header.lun_handle = unit->handle;
  2077. req->qtcb->header.port_handle = unit->port->handle;
  2078. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2079. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  2080. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
  2081. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2082. /*
  2083. * set depending on data direction:
  2084. * data direction bits in SBALE (SB Type)
  2085. * data direction bits in QTCB
  2086. * data direction bits in FCP_CMND IU
  2087. */
  2088. switch (scsi_cmnd->sc_data_direction) {
  2089. case DMA_NONE:
  2090. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2091. break;
  2092. case DMA_FROM_DEVICE:
  2093. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  2094. fcp_cmnd_iu->rddata = 1;
  2095. break;
  2096. case DMA_TO_DEVICE:
  2097. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  2098. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  2099. fcp_cmnd_iu->wddata = 1;
  2100. break;
  2101. case DMA_BIDIRECTIONAL:
  2102. goto failed_scsi_cmnd;
  2103. }
  2104. if (likely((scsi_cmnd->device->simple_tags) ||
  2105. ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
  2106. (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
  2107. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  2108. else
  2109. fcp_cmnd_iu->task_attribute = UNTAGGED;
  2110. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
  2111. fcp_cmnd_iu->add_fcp_cdb_length =
  2112. (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  2113. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  2114. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2115. fcp_cmnd_iu->add_fcp_cdb_length + sizeof(u32);
  2116. real_bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req, sbtype,
  2117. scsi_sglist(scsi_cmnd),
  2118. FSF_MAX_SBALS_PER_REQ);
  2119. if (unlikely(real_bytes < 0)) {
  2120. if (req->queue_req.sbal_number >= FSF_MAX_SBALS_PER_REQ) {
  2121. dev_err(&adapter->ccw_device->dev,
  2122. "Oversize data package, unit 0x%016Lx "
  2123. "on port 0x%016Lx closed\n",
  2124. (unsigned long long)unit->fcp_lun,
  2125. (unsigned long long)unit->port->wwpn);
  2126. zfcp_erp_unit_shutdown(unit, 0, "fssfct1", req);
  2127. retval = -EINVAL;
  2128. }
  2129. goto failed_scsi_cmnd;
  2130. }
  2131. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  2132. retval = zfcp_fsf_req_send(req);
  2133. if (unlikely(retval))
  2134. goto failed_scsi_cmnd;
  2135. goto out;
  2136. failed_scsi_cmnd:
  2137. zfcp_unit_put(unit);
  2138. zfcp_fsf_req_free(req);
  2139. scsi_cmnd->host_scribble = NULL;
  2140. out:
  2141. spin_unlock(&qdio->req_q_lock);
  2142. return retval;
  2143. }
  2144. /**
  2145. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  2146. * @unit: pointer to struct zfcp_unit
  2147. * @tm_flags: unsigned byte for task management flags
  2148. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2149. */
  2150. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_unit *unit, u8 tm_flags)
  2151. {
  2152. struct qdio_buffer_element *sbale;
  2153. struct zfcp_fsf_req *req = NULL;
  2154. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2155. struct zfcp_qdio *qdio = unit->port->adapter->qdio;
  2156. if (unlikely(!(atomic_read(&unit->status) &
  2157. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2158. return NULL;
  2159. spin_lock_bh(&qdio->req_q_lock);
  2160. if (zfcp_fsf_req_sbal_get(qdio))
  2161. goto out;
  2162. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  2163. qdio->adapter->pool.scsi_req);
  2164. if (IS_ERR(req)) {
  2165. req = NULL;
  2166. goto out;
  2167. }
  2168. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2169. req->data = unit;
  2170. req->handler = zfcp_fsf_send_fcp_command_handler;
  2171. req->qtcb->header.lun_handle = unit->handle;
  2172. req->qtcb->header.port_handle = unit->port->handle;
  2173. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2174. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2175. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2176. sizeof(u32);
  2177. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  2178. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2179. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2180. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
  2181. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2182. fcp_cmnd_iu->task_management_flags = tm_flags;
  2183. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2184. if (!zfcp_fsf_req_send(req))
  2185. goto out;
  2186. zfcp_fsf_req_free(req);
  2187. req = NULL;
  2188. out:
  2189. spin_unlock_bh(&qdio->req_q_lock);
  2190. return req;
  2191. }
  2192. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2193. {
  2194. }
  2195. /**
  2196. * zfcp_fsf_control_file - control file upload/download
  2197. * @adapter: pointer to struct zfcp_adapter
  2198. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2199. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2200. */
  2201. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2202. struct zfcp_fsf_cfdc *fsf_cfdc)
  2203. {
  2204. struct qdio_buffer_element *sbale;
  2205. struct zfcp_qdio *qdio = adapter->qdio;
  2206. struct zfcp_fsf_req *req = NULL;
  2207. struct fsf_qtcb_bottom_support *bottom;
  2208. int direction, retval = -EIO, bytes;
  2209. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2210. return ERR_PTR(-EOPNOTSUPP);
  2211. switch (fsf_cfdc->command) {
  2212. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2213. direction = SBAL_FLAGS0_TYPE_WRITE;
  2214. break;
  2215. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2216. direction = SBAL_FLAGS0_TYPE_READ;
  2217. break;
  2218. default:
  2219. return ERR_PTR(-EINVAL);
  2220. }
  2221. spin_lock_bh(&qdio->req_q_lock);
  2222. if (zfcp_fsf_req_sbal_get(qdio))
  2223. goto out;
  2224. req = zfcp_fsf_req_create(qdio, fsf_cfdc->command, NULL);
  2225. if (IS_ERR(req)) {
  2226. retval = -EPERM;
  2227. goto out;
  2228. }
  2229. req->handler = zfcp_fsf_control_file_handler;
  2230. sbale = zfcp_qdio_sbale_req(qdio, &req->queue_req);
  2231. sbale[0].flags |= direction;
  2232. bottom = &req->qtcb->bottom.support;
  2233. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2234. bottom->option = fsf_cfdc->option;
  2235. bytes = zfcp_qdio_sbals_from_sg(qdio, &req->queue_req,
  2236. direction, fsf_cfdc->sg,
  2237. FSF_MAX_SBALS_PER_REQ);
  2238. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2239. zfcp_fsf_req_free(req);
  2240. goto out;
  2241. }
  2242. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2243. retval = zfcp_fsf_req_send(req);
  2244. out:
  2245. spin_unlock_bh(&qdio->req_q_lock);
  2246. if (!retval) {
  2247. wait_for_completion(&req->completion);
  2248. return req;
  2249. }
  2250. return ERR_PTR(retval);
  2251. }
  2252. /**
  2253. * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
  2254. * @adapter: pointer to struct zfcp_adapter
  2255. * @sbal_idx: response queue index of SBAL to be processed
  2256. */
  2257. void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
  2258. {
  2259. struct zfcp_adapter *adapter = qdio->adapter;
  2260. struct qdio_buffer *sbal = qdio->resp_q.sbal[sbal_idx];
  2261. struct qdio_buffer_element *sbale;
  2262. struct zfcp_fsf_req *fsf_req;
  2263. unsigned long flags, req_id;
  2264. int idx;
  2265. for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
  2266. sbale = &sbal->element[idx];
  2267. req_id = (unsigned long) sbale->addr;
  2268. spin_lock_irqsave(&adapter->req_list_lock, flags);
  2269. fsf_req = zfcp_reqlist_find(adapter, req_id);
  2270. if (!fsf_req)
  2271. /*
  2272. * Unknown request means that we have potentially memory
  2273. * corruption and must stop the machine immediately.
  2274. */
  2275. panic("error: unknown req_id (%lx) on adapter %s.\n",
  2276. req_id, dev_name(&adapter->ccw_device->dev));
  2277. list_del(&fsf_req->list);
  2278. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  2279. fsf_req->queue_req.sbal_response = sbal_idx;
  2280. fsf_req->queue_req.qdio_inb_usage =
  2281. atomic_read(&qdio->resp_q.count);
  2282. zfcp_fsf_req_complete(fsf_req);
  2283. if (likely(sbale->flags & SBAL_FLAGS_LAST_ENTRY))
  2284. break;
  2285. }
  2286. }